Changeset 6444
- Timestamp:
- 03/18/07 07:30:09 (3 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/xml_serialization.rb (modified) (1 diff)
- trunk/activerecord/test/base_test.rb (modified) (1 diff)
- trunk/activerecord/test/xml_serialization_test.rb (modified) (4 diffs)
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/hash/conversions.rb (modified) (3 diffs)
- trunk/activesupport/test/core_ext/hash_ext_test.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r6440 r6444 1 1 *SVN* 2 3 * Base#to_xml supports serialized attributes. #7502 [jonathan] 2 4 3 5 * Base.update_all :order and :limit options. Useful for MySQL updates that must be ordered to avoid violating unique constraints. [Jeremy Kemper] trunk/activerecord/lib/active_record/xml_serialization.rb
r5210 r6444 276 276 protected 277 277 def compute_type 278 type = @record.class. columns_hash[name].type278 type = @record.class.serialized_attributes.has_key?(name) ? :yaml : @record.class.columns_hash[name].type 279 279 280 280 case type trunk/activerecord/test/base_test.rb
r6440 r6444 1510 1510 assert xml.include?(%(<replies-count type="integer">1</replies-count>)) 1511 1511 assert xml.include?(%(<written-on type="datetime">#{written_on_in_current_timezone}</written-on>)) 1512 assert xml.include?(%(<content >Have a nice day</content>))1512 assert xml.include?(%(<content type="yaml">--- Have a nice day\n</content>)) 1513 1513 assert xml.include?(%(<author-email-address>david@loudthinking.com</author-email-address>)) 1514 1514 assert xml.match(%(<parent-id type="integer"></parent-id>)) trunk/activerecord/test/xml_serialization_test.rb
r5170 r6444 10 10 end 11 11 12 column :name, :string 13 column :age, :integer 14 column :avatar, :binary 15 column :created_at, :datetime 16 column :awesome, :boolean 12 column :name, :string 13 column :age, :integer 14 column :avatar, :binary 15 column :created_at, :datetime 16 column :awesome, :boolean 17 column :preferences, :string 18 19 serialize :preferences 17 20 end 18 21 … … 58 61 class DefaultXmlSerializationTest < Test::Unit::TestCase 59 62 def setup 60 @xml = Contact.new(:name => 'aaron stack', :age => 25, :avatar => 'binarydata', :created_at => Time.utc(2006, 8, 1), :awesome => false ).to_xml63 @xml = Contact.new(:name => 'aaron stack', :age => 25, :avatar => 'binarydata', :created_at => Time.utc(2006, 8, 1), :awesome => false, :preferences => { :gem => 'ruby' }).to_xml 61 64 end 62 65 … … 81 84 def test_should_serialize_boolean 82 85 assert_match %r{<awesome type=\"boolean\">false</awesome>}, @xml 86 end 87 88 def test_should_serialize_yaml 89 assert_match %r{<preferences type=\"yaml\">--- \n:gem: ruby\n</preferences>}, @xml 83 90 end 84 91 end … … 110 117 assert_match %r{<awesome type=\"boolean\"></awesome>}, @xml 111 118 end 119 120 def test_should_serialize_yaml 121 assert_match %r{<preferences type=\"yaml\"></preferences>}, @xml 122 end 112 123 end 113 124 trunk/activesupport/CHANGELOG
r6443 r6444 1 1 *SVN* 2 3 * Hash#to_xml supports YAML attributes. #7502 [jonathan] 2 4 3 5 * Refactor ActiveSupport::JSON to be less obtuse. Add support for JSON decoding by way of Syck with ActiveSupport::JSON.decode(json_string). Prevent hash keys that are JavaScript reserved words from being unquoted during encoding. [Sam Stephenson] trunk/activesupport/lib/active_support/core_ext/hash/conversions.rb
r6378 r6444 39 39 "date" => Proc.new { |date| date.to_s(:db) }, 40 40 "datetime" => Proc.new { |time| time.xmlschema }, 41 "binary" => Proc.new { |binary| Base64.encode64(binary) } 41 "binary" => Proc.new { |binary| Base64.encode64(binary) }, 42 "yaml" => Proc.new { |yaml| yaml.to_yaml } 42 43 } unless defined? XML_FORMATTING 43 44 … … 106 107 def from_xml(xml) 107 108 # TODO: Refactor this into something much cleaner that doesn't rely on XmlSimple 108 undasherize_keys(typecast_xml_value(XmlSimple.xml_in(xml,109 typecast_xml_value(undasherize_keys(XmlSimple.xml_in(xml, 109 110 'forcearray' => false, 110 111 'forcecontent' => true, … … 130 131 when "datetime" then ::Time.parse(content).utc 131 132 when "date" then ::Date.parse(content) 133 when "yaml" then YAML::load(content) rescue content 132 134 else content 133 135 end trunk/activesupport/test/core_ext/hash_ext_test.rb
r6378 r6444 377 377 <written-on type="date">2003-07-16</written-on> 378 378 <viewed-at type="datetime">2003-07-16T09:28:00+0000</viewed-at> 379 <content >Have a nice day</content>379 <content type="yaml">--- \n1: should be an integer\n:message: Have a nice day\narray: \n- should-have-dashes: true\n should_have_underscores: true\n</content> 380 380 <author-email-address>david@loudthinking.com</author-email-address> 381 381 <parent-id></parent-id> … … 392 392 :written_on => Date.new(2003, 7, 16), 393 393 :viewed_at => Time.utc(2003, 7, 16, 9, 28), 394 :content => "Have a nice day",394 :content => { :message => "Have a nice day", 1 => "should be an integer", "array" => [{ "should-have-dashes" => true, "should_have_underscores" => true }] }, 395 395 :author_email_address => "david@loudthinking.com", 396 396 :parent_id => nil … … 408 408 <written-on type="date"></written-on> 409 409 <viewed-at type="datetime"></viewed-at> 410 <content type="yaml"></content> 410 411 <parent-id></parent-id> 411 412 </topic> … … 417 418 :approved => nil, 418 419 :written_on => nil, 419 :viewed_at => nil, 420 :viewed_at => nil, 421 :content => nil, 420 422 :parent_id => nil 421 423 }.stringify_keys