Sha256: ebbf870179c047709ededf64eafc9c381f739e6af452d359ee74f16ac6db66d7

Contents?: true

Size: 1.24 KB

Versions: 10

Compression:

Stored size: 1.24 KB

Contents

require 'test_helper'
require 'models'

class BelongsToProxyTest < Test::Unit::TestCase
  def setup
    Status.collection.clear
    Project.collection.clear
  end
  
  should "default to nil" do
    status = Status.new
    status.project.nil?.should == true
    status.project.inspect.should == 'nil'
  end
  
  should "be able to replace the association" do
    status = Status.new
    project = Project.new(:name => "mongomapper")
    status.project = project
    status.save.should be_true
    
    from_db = Status.find(status.id)
    from_db.project.nil?.should be_false
    from_db.project.name.should == "mongomapper"
  end
  
  should "unset the association" do
    status = Status.new
    project = Project.new(:name => "mongomapper")
    status.project = project
    status.save.should be_true
    
    from_db = Status.find(status.id)
    from_db.project = nil
    from_db.project.nil?.should be_true
    from_db.project.inspect.should == 'nil'
  end
  
  context "association id set but document not found" do
    setup do
      @status = Status.new(:name => 'Foo', :project_id => '1234')
    end

    should "return nil instead of raising error" do
      @status.project.nil?.should be_true
      @status.project.inspect.should == 'nil'
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
djsun-mongo_mapper-0.5.6.6 test/functional/associations/test_belongs_to_proxy.rb
djsun-mongo_mapper-0.5.6.5 test/functional/associations/test_belongs_to_proxy.rb
djsun-mongo_mapper-0.5.6.4 test/functional/associations/test_belongs_to_proxy.rb
djsun-mongo_mapper-0.5.6.3 test/functional/associations/test_belongs_to_proxy.rb
djsun-mongo_mapper-0.5.6.2 test/functional/associations/test_belongs_to_proxy.rb
djsun-mongo_mapper-0.5.6.1 test/functional/associations/test_belongs_to_proxy.rb
djsun-mongo_mapper-0.5.5.3 test/functional/associations/test_belongs_to_proxy.rb
djsun-mongo_mapper-0.5.5.2 test/functional/associations/test_belongs_to_proxy.rb
djsun-mongo_mapper-0.5.4.1 test/functional/associations/test_belongs_to_proxy.rb
djsun-mongo_mapper-0.5.3.1 test/functional/associations/test_belongs_to_proxy.rb