Sha256: 91c199ca35ccac28d5371e3d2ea9d26d5a10f3e9e72852c3f58ef5ae3a673240

Contents?: true

Size: 1.23 KB

Versions: 4

Compression:

Stored size: 1.23 KB

Contents

require 'test_helper'
require 'models'

class BelongsToProxyTest < Test::Unit::TestCase
  def setup
    clear_all_collections
  end
  
  should "default to nil" do
    status = Status.new
    status.project.should be_nil
    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.should_not be_nil
    from_db.project.inspect.should_not be_empty
    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.should be_nil
    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.should be_nil
      @status.project.inspect.should == "nil"
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
djsun-mongomapper-0.3.5.1 test/functional/associations/test_belongs_to_proxy.rb
djsun-mongomapper-0.3.5.2 test/functional/associations/test_belongs_to_proxy.rb
djsun-mongomapper-0.3.5.4 test/functional/associations/test_belongs_to_proxy.rb
djsun-mongomapper-0.3.5.5 test/functional/associations/test_belongs_to_proxy.rb