Skip to content

Commit

Permalink
Merge pull request #657 from yahonda/branch_655
Browse files Browse the repository at this point in the history
Fix serialized value becomes from yaml to string once saved
  • Loading branch information
yahonda committed Jun 30, 2015
2 parents 8ee9222 + 05ff0c7 commit 912adbb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Expand Up @@ -826,7 +826,7 @@ def write_lobs(table_name, klass, attributes, columns) #:nodoc:
value = attributes[col.name]
# changed sequence of next two lines - should check if value is nil before converting to yaml
next if value.nil? || (value == '')
value = value.to_yaml if value.is_a?(String) && klass.serialized_attributes[col.name]
value = value.to_yaml if klass.serialized_attributes[col.name]
uncached do
sql = is_with_cpk ? "SELECT #{quote_column_name(col.name)} FROM #{quote_table_name(table_name)} WHERE #{klass.composite_where_clause(id)} FOR UPDATE" :
"SELECT #{quote_column_name(col.name)} FROM #{quote_table_name(table_name)} WHERE #{quote_column_name(klass.primary_key)} = #{id} FOR UPDATE"
Expand Down
Expand Up @@ -1087,6 +1087,18 @@ class ::TestSerializeEmployee < ActiveRecord::Base
@employee.reload
@employee.comments.should == "initial serialized data"
end

it "should keep serialized data after save" do
@employee = Test2Employee.new
@employee.comments = {:length=>{:is=>1}}
@employee.save
@employee.reload
@employee.comments.should == {:length=>{:is=>1}}
@employee.comments = {:length=>{:is=>2}}
@employee.save
@employee.reload
@employee.comments.should == {:length=>{:is=>2}}
end
end

describe "OracleEnhancedAdapter handling of BLOB columns" do
Expand Down

0 comments on commit 912adbb

Please sign in to comment.