aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/CHANGELOG.md5
-rw-r--r--activerecord/lib/active_record/enum.rb10
-rw-r--r--activerecord/lib/active_record/inheritance.rb2
-rw-r--r--activerecord/test/cases/enum_test.rb13
-rw-r--r--activerecord/test/schema/schema.rb4
-rw-r--r--guides/source/4_1_release_notes.md3
6 files changed, 25 insertions, 12 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index e874486b53..c1739f113a 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,3 +1,8 @@
+* Deprecate unused `ActiveRecord::Base.symbolized_base_class`
+ and `ActiveRecord::Base.symbolized_sti_name` without replacement.
+
+ *Yves Senn*
+
* Since the `test_help.rb` in Railties now automatically maintains
your test schema, the `rake db:test:*` tasks are deprecated. This
doesn't stop you manually running other tasks on your test database
diff --git a/activerecord/lib/active_record/enum.rb b/activerecord/lib/active_record/enum.rb
index c042a2f232..c43b311223 100644
--- a/activerecord/lib/active_record/enum.rb
+++ b/activerecord/lib/active_record/enum.rb
@@ -72,10 +72,16 @@ module ActiveRecord
_enum_methods_module.module_eval do
# def status=(value) self[:status] = STATUS[value] end
define_method("#{name}=") { |value|
- unless enum_values.has_key?(value) || enum_values.has_value?(value) || value.blank?
+ if enum_values.has_key?(value) || value.blank?
+ self[name] = enum_values[value]
+ elsif enum_values.has_value?(value)
+ # Assigning a value directly is not a end-user fetaure, hence it's not documented.
+ # This is used internally to make building objects from the generated scopes work
+ # as expected, i.e. +Conversation.archived.build.archived?+ should be true.
+ self[name] = value
+ else
raise ArgumentError, "'#{value}' is not a valid #{name}"
end
- self[name] = enum_values[value]
}
# def status() STATUS.key self[:status] end
diff --git a/activerecord/lib/active_record/inheritance.rb b/activerecord/lib/active_record/inheritance.rb
index 7e1e120288..f144d84946 100644
--- a/activerecord/lib/active_record/inheritance.rb
+++ b/activerecord/lib/active_record/inheritance.rb
@@ -45,10 +45,12 @@ module ActiveRecord
end
def symbolized_base_class
+ ActiveSupport::Deprecation.warn("ActiveRecord::Base.symbolized_base_class is deprecated and will be removed without replacement.")
@symbolized_base_class ||= base_class.to_s.to_sym
end
def symbolized_sti_name
+ ActiveSupport::Deprecation.warn("ActiveRecord::Base.symbolized_sti_name is deprecated and will be removed without replacement.")
@symbolized_sti_name ||= sti_name.present? ? sti_name.to_sym : symbolized_base_class
end
diff --git a/activerecord/test/cases/enum_test.rb b/activerecord/test/cases/enum_test.rb
index 47e3dfc3ad..c09e58fbf1 100644
--- a/activerecord/test/cases/enum_test.rb
+++ b/activerecord/test/cases/enum_test.rb
@@ -79,12 +79,13 @@ class EnumTest < ActiveRecord::TestCase
assert_equal 2, Book::STATUS[:published]
end
- test "first_or_initialize with enums' scopes" do
- class Issue < ActiveRecord::Base
- enum status: [:open, :closed]
- end
+ test "building new objects with enum scopes" do
+ assert Book.written.build.written?
+ assert Book.read.build.read?
+ end
- assert Issue.open.empty?
- assert Issue.open.first_or_initialize
+ test "creating new objects with enum scopes" do
+ assert Book.written.create.written?
+ assert Book.read.create.read?
end
end
diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb
index 9f504801af..ac546fc296 100644
--- a/activerecord/test/schema/schema.rb
+++ b/activerecord/test/schema/schema.rb
@@ -327,10 +327,6 @@ ActiveRecord::Schema.define do
t.string :color
end
- create_table :issues, force: true do |t|
- t.integer :status
- end
-
create_table :items, force: true do |t|
t.column :name, :string
end
diff --git a/guides/source/4_1_release_notes.md b/guides/source/4_1_release_notes.md
index 0de7860f7d..d2c3ba0493 100644
--- a/guides/source/4_1_release_notes.md
+++ b/guides/source/4_1_release_notes.md
@@ -432,6 +432,9 @@ for detailed changes.
automatically maintained. See railties release notes. ([Pull
Request](https://github.com/rails/rails/pull/13528))
+* Deprecate unused `ActiveRecord::Base.symbolized_base_class`
+ and `ActiveRecord::Base.symbolized_sti_name` without replacement.
+
### Notable changes
* Added `ActiveRecord::Base.to_param` for convenient "pretty" URLs derived from