Sha256: 2a2571848f15f5a08d5386653b03e1c87449035ddf47f00a9cda7a7ef0efccc4

Contents?: true

Size: 1.63 KB

Versions: 64

Compression:

Stored size: 1.63 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 "have boolean presence method" do
    status = Status.new
    status.target?.should be_false
    
    status.target = Project.new(:name => 'mongomapper')
    status.target?.should be_true
  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

64 entries across 64 versions & 9 rubygems

Version Path
mongo_mapper-unstable-2010.2.16 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.15 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.12 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.11 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.10 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-0.7.0 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.9 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.8 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.5 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.4 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
novelys_mongo_mapper-0.6.12 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
novelys_mongo_mapper-0.6.11 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.3 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
novelys_mongo_mapper-0.6.10 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.2 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.1 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.31 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.30 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.29 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.28 test/functional/associations/test_belongs_to_polymorphic_proxy.rb