Sha256: 440566c32bd8a61408f21dc3e406dd35fc069ca36805cd5a37c5cc8f04ccacab

Contents?: true

Size: 985 Bytes

Versions: 3

Compression:

Stored size: 985 Bytes

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.should be_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.should_not be_nil
    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.should be_nil
    from_db.target_id.should be_nil
    from_db.target.should be_nil
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
djsun-mongomapper-0.3.1.1 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
djsun-mongomapper-0.3.1 test/functional/associations/test_belongs_to_polymorphic_proxy.rb
jnunemaker-mongomapper-0.3.2 test/functional/associations/test_belongs_to_polymorphic_proxy.rb