Sha256: 50589a207553259b4d719b6f994fc203e51809ef498528827f8a89050b6e2bd8

Contents?: true

Size: 1.26 KB

Versions: 20

Compression:

Stored size: 1.26 KB

Contents

require 'test_helper'
require 'models'

class BelongsToProxyTest < Test::Unit::TestCase
  def setup    
    @post_class = Class.new do
      include MongoMapper::Document
    end
    
    @comment_class = Class.new do
      include MongoMapper::Document
      key :post_id, String
    end
    @comment_class.belongs_to :post, :class => @post_class
    
    @post_class.collection.remove
    @comment_class.collection.remove
  end
  
  should "default to nil" do
    @comment_class.new.post.nil?.should be_true
  end
  
  should "be able to replace the association" do
    post = @post_class.new(:name => 'mongomapper')
    comment = @comment_class.new(:name => 'Foo!', :post => post)
    comment.save.should be_true
    
    comment = comment.reload
    comment.post.should == post
    comment.post.nil?.should be_false
  end
  
  should "unset the association" do
    post = @post_class.new(:name => 'mongomapper')
    comment = @comment_class.new(:name => 'Foo!', :post => post)
    comment.save.should be_true
    
    comment = comment.reload
    comment.post = nil
    comment.post.nil?.should be_true
  end
  
  should "return nil if id set but document not found" do
    id = Mongo::ObjectID.new
    @comment_class.new(:name => 'Foo', :post_id => id).post.nil?.should be_true
  end
end

Version data entries

20 entries across 20 versions & 5 rubygems

Version Path
tpitale-mongo_mapper-0.6.9 test/functional/associations/test_belongs_to_proxy.rb
mongo_mapper-unstable-2009.12.30 test/functional/associations/test_belongs_to_proxy.rb
mongo_mapper-unstable-2009.12.29 test/functional/associations/test_belongs_to_proxy.rb
mongo_mapper-unstable-2009.12.23 test/functional/associations/test_belongs_to_proxy.rb
mongo_mapper-unstable-2009.12.22 test/functional/associations/test_belongs_to_proxy.rb
mongo_mapper-unstable-2009.12.16 test/functional/associations/test_belongs_to_proxy.rb
mongo_mapper-0.6.8 test/functional/associations/test_belongs_to_proxy.rb
mongo_mapper-unstable-2009.12.14 test/functional/associations/test_belongs_to_proxy.rb
mongo_mapper-0.6.7 test/functional/associations/test_belongs_to_proxy.rb
mongo_mapper-0.6.6 test/functional/associations/test_belongs_to_proxy.rb
mongo_mapper-unstable-2009.12.4 test/functional/associations/test_belongs_to_proxy.rb
danielharan-mongo_mapper-0.6.5 test/functional/associations/test_belongs_to_proxy.rb
mongo_mapper-0.6.5 test/functional/associations/test_belongs_to_proxy.rb
webbynode-mongo_mapper-0.6.4 test/functional/associations/test_belongs_to_proxy.rb
mongo_mapper-0.6.4 test/functional/associations/test_belongs_to_proxy.rb
mongo_mapper-0.6.3 test/functional/associations/test_belongs_to_proxy.rb
mongo_mapper-0.6.2 test/functional/associations/test_belongs_to_proxy.rb
mongo_mapper-0.6.1 test/functional/associations/test_belongs_to_proxy.rb
mongo_mapper-unstable-2009.11.18 test/functional/associations/test_belongs_to_proxy.rb
mongo_mapper-0.6.0 test/functional/associations/test_belongs_to_proxy.rb