Sha256: 7480676ecac72908205d11da45ccea45022975388f751d628aabf11d75dcffbc

Contents?: true

Size: 1.43 KB

Versions: 23

Compression:

Stored size: 1.43 KB

Contents

require 'test_helper'
require 'models'

class BelongsToPolymorphicProxyTest < Test::Unit::TestCase
  def setup
    Status.collection.remove
    Project.collection.remove
  end
  
  should "default to nil" do
    status = Status.new
    status.target.nil?.should be_true
    status.target.inspect.should == "nil"
  end

  should "be able to replace the association" do
    status = Status.new(:name => 'Foo!')
    project = Project.new(:name => "mongomapper")
    status.target = project
    status.save.should be_true

    status = status.reload
    status.target.nil?.should be_false
    status.target_id.should == project._id
    status.target_type.should == "Project"
    status.target.name.should == "mongomapper"
  end

  should "unset the association" do
    status = Status.new(:name => 'Foo!')
    project = Project.new(:name => "mongomapper")
    status.target = project
    status.save.should be_true

    status = status.reload
    status.target = nil
    status.target_type.nil?.should be_true
    status.target_id.nil?.should be_true
    status.target.nil?.should be_true
  end
  
  context "association id set but document not found" do
    setup do
      @status = Status.new(:name => 'Foo!')
      project = Project.new(:name => "mongomapper")
      @status.target = project
      @status.save.should be_true
      project.destroy
    end

    should "return nil instead of raising error" do
      @status.target.nil?.should be_true
    end
  end
end

Version data entries

23 entries across 23 versions & 6 rubygems

Version Path
mrkurt-mongo_mapper-0.6.9 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-0.6.9 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mrkurt-mongo_mapper-0.6.8 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
tpitale-mongo_mapper-0.6.9 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2009.12.30 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2009.12.29 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2009.12.23 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2009.12.22 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2009.12.16 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-0.6.8 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2009.12.14 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-0.6.7 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-0.6.6 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2009.12.4 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
danielharan-mongo_mapper-0.6.5 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-0.6.5 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
webbynode-mongo_mapper-0.6.4 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-0.6.4 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-0.6.3 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-0.6.2 test/functional/associations/test_belongs_to_polymorphic_proxy.rb