Sha256: cf50c5a91b3dbe16dc649496a1e7d79411c3471c342ffd199e1a868bb1de180d

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

require 'test_helper'
require 'models'

class BelongsToPolymorphicProxyTest < Test::Unit::TestCase
  def setup
    clear_all_collections
  end
  
  should "default to nil" do
    status = Status.new
    status.target.nil?.should == 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 == 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 == true
    from_db.target_id.nil?.should == true
    from_db.target.nil?.should == 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 == true
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
djsun-mongomapper-0.4.1.2 test/functional/associations/test_belongs_to_polymorphic_proxy.rb