Skip to content

Commit

Permalink
Merge pull request #13593 from oliveiraethales/store_yaml_coder
Browse files Browse the repository at this point in the history
Fix: ActiveRecord::Store TypeError conversion when using YAML coder
Conflicts:
	activerecord/CHANGELOG.md
	activerecord/lib/active_record/store.rb
	activerecord/test/schema/schema.rb
  • Loading branch information
senny committed Jan 6, 2014
1 parent 5d3a8f1 commit 7678ab6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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*

* Fix presence validator for association when the associated record responds to `to_a`.

*gmarik*
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def dump(obj)
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)
Expand Down
4 changes: 4 additions & 0 deletions activerecord/test/cases/store_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,8 @@ class StoreTest < ActiveRecord::TestCase
assert_raise(NoMethodError) { @john.stored_attributes = Hash.new }
assert_raise(NoMethodError) { @john.stored_attributes }
end

test "YAML coder initializes the store when a Nil value is given" do
assert_equal({}, @john.params)
end
end
1 change: 1 addition & 0 deletions activerecord/test/models/admin/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def load(s)
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 ]
Expand Down
1 change: 1 addition & 0 deletions activerecord/test/schema/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def create_table(*args, &block)
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

Expand Down

0 comments on commit 7678ab6

Please sign in to comment.