Sha256: cc7e6963ddd6fbc325e9dabe3f84580de0a8e8ac37446c4e957bfaadb97b9a30

Contents?: true

Size: 1.41 KB

Versions: 18

Compression:

Stored size: 1.41 KB

Contents

require 'test_helper'
require 'models'

class BelongsToPolymorphicProxyTest < Test::Unit::TestCase
  def setup
    Status.collection.clear
    Project.collection.clear
  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
    project = Project.new(:name => "mongomapper")
    status.target = project
    status.save.should be_true

    from_db = Status.find(status.id)
    from_db.target.nil?.should be_false
    from_db.target_id.should == project.id
    from_db.target_type.should == "Project"
    from_db.target.name.should == "mongomapper"
  end

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

    from_db = Status.find(status.id)
    from_db.target = nil
    from_db.target_type.nil?.should be_true
    from_db.target_id.nil?.should be_true
    from_db.target.nil?.should be_true
  end
  
  context "association id set but document not found" do
    setup do
      @status = Status.new
      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

18 entries across 18 versions & 3 rubygems

Version Path
djsun-mongo_mapper-0.5.6.6 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
djsun-mongo_mapper-0.5.6.5 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-0.5.7 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
djsun-mongo_mapper-0.5.6.4 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
djsun-mongo_mapper-0.5.6.3 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
djsun-mongo_mapper-0.5.6.2 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
djsun-mongo_mapper-0.5.6.1 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-0.5.6 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
djsun-mongo_mapper-0.5.5.3 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2009.10.16 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
djsun-mongo_mapper-0.5.5.2 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-0.5.5 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2009.10.12 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
djsun-mongo_mapper-0.5.4.1 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
djsun-mongo_mapper-0.5.3.1 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-0.5.4 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-0.5.3 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2009.10.11 test/functional/associations/test_belongs_to_polymorphic_proxy.rb