aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-01-06 05:43:14 -0800
committerYves Senn <yves.senn@gmail.com>2014-01-06 05:43:14 -0800
commitf2b80a41b5c163b32dfdd0fa797466543c6ec0e9 (patch)
tree5bdab91c538ddd338c7e4b72699f84398409abbd
parent2d1d426c675b35bc34a25c5a5960a7f0a75c520b (diff)
parent901a0c8b4a3b1de8ff1ec8feb4b67f727c07dc8b (diff)
downloadrails-f2b80a41b5c163b32dfdd0fa797466543c6ec0e9.tar.gz
rails-f2b80a41b5c163b32dfdd0fa797466543c6ec0e9.tar.bz2
rails-f2b80a41b5c163b32dfdd0fa797466543c6ec0e9.zip
Merge pull request #13593 from oliveiraethales/store_yaml_coder
Fix: ActiveRecord::Store TypeError conversion when using YAML coder
-rw-r--r--activerecord/CHANGELOG.md7
-rw-r--r--activerecord/lib/active_record/store.rb2
-rw-r--r--activerecord/test/cases/store_test.rb4
-rw-r--r--activerecord/test/models/admin/user.rb1
-rw-r--r--activerecord/test/schema/schema.rb1
5 files changed, 14 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 4a321c7a59..efe29fbc88 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -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.
diff --git a/activerecord/lib/active_record/store.rb b/activerecord/lib/active_record/store.rb
index 186a737561..79a6ccbda0 100644
--- a/activerecord/lib/active_record/store.rb
+++ b/activerecord/lib/active_record/store.rb
@@ -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)
diff --git a/activerecord/test/cases/store_test.rb b/activerecord/test/cases/store_test.rb
index 0c9f7ccd55..6f632b4d8d 100644
--- a/activerecord/test/cases/store_test.rb
+++ b/activerecord/test/cases/store_test.rb
@@ -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
diff --git a/activerecord/test/models/admin/user.rb b/activerecord/test/models/admin/user.rb
index 4c3b71e8f9..9a80aaba01 100644
--- a/activerecord/test/models/admin/user.rb
+++ b/activerecord/test/models/admin/user.rb
@@ -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 ]
diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb
index ac546fc296..ddfc1ac0d6 100644
--- a/activerecord/test/schema/schema.rb
+++ b/activerecord/test/schema/schema.rb
@@ -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