Sha256: a0f6792be842ef64f3d5a44faf20165e615bee1aa8e7e5d476415c263574b7bc

Contents?: true

Size: 1.06 KB

Versions: 21

Compression:

Stored size: 1.06 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
  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.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
  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
    end
  end
end

Version data entries

21 entries across 21 versions & 6 rubygems

Version Path
crnixon-mongomapper-0.3.4 test/functional/associations/test_belongs_to_proxy.rb
djsun-mongomapper-0.3.3 test/functional/associations/test_belongs_to_proxy.rb
djsun-mongomapper-0.3.5 test/functional/associations/test_belongs_to_proxy.rb
hashrocket-mongomapper-0.3.10 test/functional/associations/test_belongs_to_proxy.rb
hashrocket-mongomapper-0.3.11 test/functional/associations/test_belongs_to_proxy.rb
hashrocket-mongomapper-0.3.12 test/functional/associations/test_belongs_to_proxy.rb
hashrocket-mongomapper-0.3.13 test/functional/associations/test_belongs_to_proxy.rb
hashrocket-mongomapper-0.3.14 test/functional/associations/test_belongs_to_proxy.rb
hashrocket-mongomapper-0.3.15 test/functional/associations/test_belongs_to_proxy.rb
hashrocket-mongomapper-0.3.3 test/functional/associations/test_belongs_to_proxy.rb
hashrocket-mongomapper-0.3.4.1 test/functional/associations/test_belongs_to_proxy.rb
hashrocket-mongomapper-0.3.4 test/functional/associations/test_belongs_to_proxy.rb
hashrocket-mongomapper-0.3.5 test/functional/associations/test_belongs_to_proxy.rb
hashrocket-mongomapper-0.3.6 test/functional/associations/test_belongs_to_proxy.rb
hashrocket-mongomapper-0.3.7 test/functional/associations/test_belongs_to_proxy.rb
hashrocket-mongomapper-0.3.8 test/functional/associations/test_belongs_to_proxy.rb
jnunemaker-mongomapper-0.3.3 test/functional/associations/test_belongs_to_proxy.rb
jnunemaker-mongomapper-0.3.4 test/functional/associations/test_belongs_to_proxy.rb
jnunemaker-mongomapper-0.3.5 test/functional/associations/test_belongs_to_proxy.rb
nirvdrum-mongomapper-0.3.3 test/functional/associations/test_belongs_to_proxy.rb