Sha256: 6d2b8630087e9f1474b1d29543014b9ee9e60d4852226cd69796b4ccb9a64d9c

Contents?: true

Size: 1.49 KB

Versions: 55

Compression:

Stored size: 1.49 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.new.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.new.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.new.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

55 entries across 55 versions & 8 rubygems

Version Path
drogus-mongo_mapper-0.6.10 test/unit/test_serialization.rb
mongo_mapper-rails3-0.7.0.1 test/unit/test_serialization.rb
mongo_mapper-unstable-2010.2.28 test/unit/test_serialization.rb
mongo_mapper-unstable-2010.2.27 test/unit/test_serialization.rb
mongo_mapper-unstable-2010.2.26 test/unit/test_serialization.rb
mongo_mapper-unstable-2010.2.25 test/unit/test_serialization.rb
mongo_mapper-unstable-2010.2.24 test/unit/test_serialization.rb
mongo_mapper-unstable-2010.2.23 test/unit/test_serialization.rb
mongo_mapper-unstable-2010.2.22 test/unit/test_serialization.rb
mongo_mapper-unstable-2010.2.19 test/unit/test_serialization.rb
mongo_mapper-unstable-2010.2.18 test/unit/test_serialization.rb
mongo_mapper-unstable-2010.2.17 test/unit/test_serialization.rb
mongo_mapper-unstable-2010.2.16 test/unit/test_serialization.rb
mongo_mapper-unstable-2010.2.15 test/unit/test_serialization.rb
mongo_mapper-unstable-2010.2.12 test/unit/test_serialization.rb
mongo_mapper-unstable-2010.2.11 test/unit/test_serialization.rb
mongo_mapper-unstable-2010.2.10 test/unit/test_serialization.rb
mongo_mapper-0.7.0 test/unit/test_serialization.rb
mongo_mapper-unstable-2010.2.9 test/unit/test_serialization.rb
mongo_mapper-unstable-2010.2.8 test/unit/test_serialization.rb