File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -204,8 +204,8 @@ def enum(definitions)
204
204
205
205
pairs = values . respond_to? ( :each_pair ) ? values . each_pair : values . each_with_index
206
206
pairs . each do |label , value |
207
- label = label . to_s
208
207
enum_values [ label ] = value
208
+ label = label . to_s
209
209
210
210
value_method_name = "#{ prefix } #{ label } #{ suffix } "
211
211
value_method_names << value_method_name
Original file line number Diff line number Diff line change @@ -700,6 +700,18 @@ def self.name; "Book"; end
700
700
assert_not_predicate computer , :"Etc/GMT-1?"
701
701
end
702
702
703
+ test "deserialize enum value to original hash key" do
704
+ proposed = Class . new
705
+ written = Class . new
706
+ klass = Class . new ( ActiveRecord ::Base ) do
707
+ self . table_name = "books"
708
+ enum status : { proposed => 0 , written => 1 }
709
+ end
710
+
711
+ book = klass . create! ( status : 0 )
712
+ assert_equal proposed , book . status
713
+ end
714
+
703
715
test "enum logs a warning if auto-generated negative scopes would clash with other enum names" do
704
716
old_logger = ActiveRecord ::Base . logger
705
717
logger = ActiveSupport ::LogSubscriber ::TestHelper ::MockLogger . new
You can’t perform that action at this time.
0 commit comments