Sha256: d7ee8119b4d6b42122bf634adf5ba3fd1d10ecd7b14f11086040aa1f16acd4a4
Contents?: true
Size: 1.46 KB
Versions: 61
Compression:
Stored size: 1.46 KB
Contents
require 'test_helper' class SerializationTest < Test::Unit::TestCase def setup @document = EDoc do key :name, String key :age, Integer key :awesome, Boolean key :preferences, Hash key :created_at, Time end @instance = @document.new( :name => 'John Doe', :age => 25, :awesome => true, :preferences => {:language => 'Ruby'}, :created_at => Time.now.change(:usec => 0) ) end [:json].each do |format| context format do should "be reversable" do serialized = @instance.send("to_#{format}") unserialized = @document.send("from_#{format}", serialized) assert_equal @instance, unserialized end should "allow attribute only filtering" do serialized = @instance.send("to_#{format}", :only => [ :age, :name ]) unserialized = @document.send("from_#{format}", serialized) assert_equal @instance.name, unserialized.name assert_equal @instance.age, unserialized.age assert ! unserialized.awesome assert_nil unserialized.created_at end should "allow attribute except filtering" do serialized = @instance.send("to_#{format}", :except => [ :age, :name ]) unserialized = @document.send("from_#{format}", serialized) assert_nil unserialized.name assert_nil unserialized.age assert_equal @instance.awesome, unserialized.awesome end end end end
Version data entries
61 entries across 61 versions & 8 rubygems
Version | Path |
---|---|
pwnash-mongo_mapper-0.7.5 | test/unit/test_serialization.rb |