aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/enum.rb3
-rw-r--r--activerecord/test/cases/enum_test.rb4
2 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/enum.rb b/activerecord/lib/active_record/enum.rb
index 9ad718a02a..d1bc785bee 100644
--- a/activerecord/lib/active_record/enum.rb
+++ b/activerecord/lib/active_record/enum.rb
@@ -87,6 +87,9 @@ module ActiveRecord
# def status() STATUS.key self[:status] end
define_method(name) { enum_values.key self[name] }
+ # def status_before_type_cast() STATUS.key self[:status] end
+ define_method("#{name}_before_type_cast") { enum_values.key self[name] }
+
pairs = values.respond_to?(:each_pair) ? values.each_pair : values.each_with_index
pairs.each do |value, i|
enum_values[value] = i
diff --git a/activerecord/test/cases/enum_test.rb b/activerecord/test/cases/enum_test.rb
index c09e58fbf1..0075df8b8d 100644
--- a/activerecord/test/cases/enum_test.rb
+++ b/activerecord/test/cases/enum_test.rb
@@ -88,4 +88,8 @@ class EnumTest < ActiveRecord::TestCase
assert Book.written.create.written?
assert Book.read.create.read?
end
+
+ test "_before_type_cast returns the enum label (required for form fields)" do
+ assert_equal "proposed", @book.status_before_type_cast
+ end
end