mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #13593 from oliveiraethales/store_yaml_coder
Fix: ActiveRecord::Store TypeError conversion when using YAML coder
This commit is contained in:
commit
f2b80a41b5
5 changed files with 14 additions and 1 deletions
|
@ -1,3 +1,10 @@
|
|||
* Fixed ActiveRecord::Store nil conversion TypeError when using YAML coder.
|
||||
In case the YAML passed as paramter is nil, uses an empty string.
|
||||
|
||||
Fixes #13570.
|
||||
|
||||
*Thales Oliveira*
|
||||
|
||||
* Deprecate unused `ActiveRecord::Base.symbolized_base_class`
|
||||
and `ActiveRecord::Base.symbolized_sti_name` without replacement.
|
||||
|
||||
|
|
|
@ -178,7 +178,7 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def load(yaml)
|
||||
self.class.as_indifferent_hash(@coder.load(yaml))
|
||||
self.class.as_indifferent_hash(@coder.load(yaml || ''))
|
||||
end
|
||||
|
||||
def self.as_indifferent_hash(obj)
|
||||
|
|
|
@ -162,4 +162,8 @@ class StoreTest < ActiveRecord::TestCase
|
|||
assert_equal [:color], first_model.stored_attributes[:data]
|
||||
assert_equal [:width, :height], second_model.stored_attributes[:data]
|
||||
end
|
||||
|
||||
test "YAML coder initializes the store when a Nil value is given" do
|
||||
assert_equal({}, @john.params)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,6 +14,7 @@ class Admin::User < ActiveRecord::Base
|
|||
end
|
||||
|
||||
belongs_to :account
|
||||
store :params, accessors: [ :color ], coder: YAML
|
||||
store :settings, :accessors => [ :color, :homepage ]
|
||||
store_accessor :settings, :favorite_food
|
||||
store :preferences, :accessors => [ :remember_login ]
|
||||
|
|
|
@ -45,6 +45,7 @@ ActiveRecord::Schema.define do
|
|||
t.string :preferences, null: true, default: '', limit: 1024
|
||||
t.string :json_data, null: true, limit: 1024
|
||||
t.string :json_data_empty, null: true, default: "", limit: 1024
|
||||
t.text :params
|
||||
t.references :account
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue