Sha256: 4340437f5e976332b94f78e0827875e8fcca4e55b3bea101df794b7f1f1d6263

Contents?: true

Size: 1.23 KB

Versions: 40

Compression:

Stored size: 1.23 KB

Contents

require 'test_helper'
require 'models'

class KeyTest < Test::Unit::TestCase
  include MongoMapper::Plugins::Keys

  context ".key?(:symbol)" do
    should "be true if document has key" do
      Address.key?(:city).should be_true
    end

    should "be false if document does not have key" do
      Address.key?(:foo).should be_false
    end
  end

  context ".key?('string')" do
    should "be true if document has key" do
      Address.key?('city').should be_true
    end

    should "be false if document does not have key" do
      Address.key?('foo').should be_false
    end
  end

  context ".new (from database)" do
    setup do
      @klass = Doc do
        key :user, Hash

        def user=(user)
          super(:id => user.id, :name => user.name)
        end
      end

      user_class = Struct.new(:id, :name)
      @klass.create(:user => user_class.new(1, 'John Nunemaker'))
    end

    should "use []= for keys instead of public writer" do
      assert_nothing_raised do
        doc = @klass.first
        doc.user['id'].should   == 1
        doc.user['name'].should == 'John Nunemaker'
      end
    end
  end

  context ".load" do
    should "return nil if argument is nil" do
      Doc().load(nil).should be_nil
    end
  end
end # KeyTest

Version data entries

40 entries across 40 versions & 3 rubygems

Version Path
mongo_mapper-unstable-2010.08.08 test/unit/test_keys.rb
mongo_mapper-unstable-2010.08.06 test/unit/test_keys.rb
mongo_mapper-unstable-2010.08.05 test/unit/test_keys.rb
mongo_mapper-unstable-2010.08.04 test/unit/test_keys.rb
mongo_mapper-unstable-2010.08.03 test/unit/test_keys.rb
mongo_mapper-unstable-2010.08.02 test/unit/test_keys.rb
mongo_mapper-unstable-2010.08.01 test/unit/test_keys.rb
mongo_mapper-unstable-2010.07.31 test/unit/test_keys.rb
mongo_mapper-unstable-2010.07.30 test/unit/test_keys.rb
mongo_mapper-unstable-2010.07.29 test/unit/test_keys.rb
mongo_mapper-unstable-2010.07.28 test/unit/test_keys.rb
mongo_mapper-unstable-2010.07.27 test/unit/test_keys.rb
thorsson-mongo_mapper-0.8.2 test/unit/test_keys.rb
mongo_mapper-unstable-2010.07.26 test/unit/test_keys.rb
mongo_mapper-unstable-2010.07.23 test/unit/test_keys.rb
mongo_mapper-unstable-2010.07.21 test/unit/test_keys.rb
mongo_mapper-unstable-2010.07.20 test/unit/test_keys.rb
mongo_mapper-unstable-2010.07.19 test/unit/test_keys.rb
mongo_mapper-unstable-2010.07.18 test/unit/test_keys.rb
mongo_mapper-unstable-2010.07.16 test/unit/test_keys.rb