Sha256: e5ae241bc8a27fb6b8a873cc9c67cfbe5097e05e309a30f53ed8cd51219a53a3

Contents?: true

Size: 1.62 KB

Versions: 59

Compression:

Stored size: 1.62 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

59 entries across 59 versions & 7 rubygems

Version Path
jonbell-mongo_mapper-0.8.6 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
ssherman-mongo_mapper-0.8.6 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-0.8.6 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-0.8.5 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
honkster-mongo_mapper-0.8.4 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-0.8.4 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.19 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.18 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.17 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.16 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.15 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.14 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.13 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.12 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.11 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.10 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.09 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-0.8.3 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.08 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.06 test/functional/associations/test_belongs_to_polymorphic_proxy.rb