Created
December 1, 2010 03:36
-
-
Save michaeldv/722889 to your computer and use it in GitHub Desktop.
activerecord/test/cases/xml_serialization_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<toy> | |
<created-at type="datetime">2010-11-30T19:00:36-08:00</created-at> | |
<integer type="integer" nil="true"></integer> | |
<name>Mickey</name> | |
<pet-id type="integer" nil="true"></pet-id> | |
<toy-id type="integer">1</toy-id> | |
<updated-at type="datetime">2006-08-01T00:00:00Z</updated-at> | |
</toy> | |
<?xml version="1.0" encoding="UTF-8"?> | |
<toy> | |
<created-at type="datetime">2010-11-30T19:00:36-08:00</created-at> | |
<integer type="integer" nil="true"></integer> | |
<name>Minnie</name> | |
<pet-id type="integer" nil="true"></pet-id> | |
<toy-id type="integer">2</toy-id> | |
<updated-at type="datetime">2006-07-31T17:00:00-07:00</updated-at> | |
</toy> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveModel | |
# == Active Model XML Serializer | |
module Serializers | |
module Xml | |
extend ActiveSupport::Concern | |
include ActiveModel::Serialization | |
class Serializer #:nodoc: | |
class Attribute #:nodoc: | |
attr_reader :name, :value, :type | |
def initialize(name, serializable, raw_value=nil) | |
@name, @serializable = name, serializable | |
### The following line seems to fix the tests. | |
raw_value = raw_value.in_time_zone if raw_value.respond_to?(:in_time_zone) | |
@value = raw_value || @serializable.send(name) | |
@type = compute_type | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'models/toy' | |
class DefaultXmlSerializationTimezoneTest < ActiveRecord::TestCase | |
def test_should_serialize_datetime_with_timezone | |
timezone, Time.zone = Time.zone, "Pacific Time (US & Canada)" | |
toy = Toy.create(:name => 'Mickey', :updated_at => Time.utc(2006, 8, 1)) | |
### puts toy.to_xml | |
assert_match %r{<updated-at type=\"datetime\">2006-07-31T17:00:00-07:00</updated-at>}, toy.to_xml | |
ensure | |
Time.zone = timezone | |
end | |
def test_should_serialize_datetime_with_timezone_reloaded | |
timezone, Time.zone = Time.zone, "Pacific Time (US & Canada)" | |
toy = Toy.create(:name => 'Minnie', :updated_at => Time.utc(2006, 8, 1)).reload | |
### puts toy.to_xml | |
assert_match %r{<updated-at type=\"datetime\">2006-07-31T17:00:00-07:00</updated-at>}, toy.to_xml | |
ensure | |
Time.zone = timezone | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment