Sha256: 0aa00e82e18ba4836e2bfcef3f3e6055b42efe5797fc5dc5be02bc1cbc592797

Contents?: true

Size: 1.65 KB

Versions: 50

Compression:

Stored size: 1.65 KB

Contents

require 'test_helper'

class OneEmbeddedProxyTest < Test::Unit::TestCase
  def setup
    @post_class = Doc('Post') do
      key :title, String
    end
    @author_class = EDoc('Author') do
      key :name, String
      embedded_in :post
    end
  end

  should "default to nil" do
    @post_class.one :author, :class => @author_class
    @post_class.new.author.should be_nil
  end

  should "be able to build" do
    @post_class.one :author, :class => @author_class

    post = @post_class.create
    author = post.author.build(:name => "John")
    post.author.should be_instance_of(@author_class)
    post.author.should be_new
    post.author.name.should == 'John'
    post.author.should == author
    post.author.post.should == post
  end

  should "be able to replace the association" do
    @post_class.one :author, :class => @author_class

    post = @post_class.new
    author = @author_class.new(:name => 'Frank')
    post.author = author
    post.save
    post.reload

    post.author.should == author
    post.author.nil?.should be_false

    new_author = @author_class.new(:name => 'Emily')
    post.author = new_author
    post.author.should == new_author
  end

  should "not have problem loading root document if embedded one is nil" do
    @post_class.one :author, :class => @author_class
    post = @post_class.create
    
    lambda {
      @post_class.find(post.id)
    }.should_not raise_error
  end

  should "have boolean method for testing presence" do
    @post_class.one :author, :class => @author_class

    post = @post_class.new
    post.author?.should be_false

    post.author = @author_class.new(:name => 'Frank')
    post.author?.should be_true
  end

end

Version data entries

50 entries across 50 versions & 3 rubygems

Version Path
mongo_mapper-unstable-2010.08.19 test/functional/associations/test_one_embedded_proxy.rb
mongo_mapper-unstable-2010.08.18 test/functional/associations/test_one_embedded_proxy.rb
mongo_mapper-unstable-2010.08.17 test/functional/associations/test_one_embedded_proxy.rb
mongo_mapper-unstable-2010.08.16 test/functional/associations/test_one_embedded_proxy.rb
mongo_mapper-unstable-2010.08.15 test/functional/associations/test_one_embedded_proxy.rb
mongo_mapper-unstable-2010.08.14 test/functional/associations/test_one_embedded_proxy.rb
mongo_mapper-unstable-2010.08.13 test/functional/associations/test_one_embedded_proxy.rb
mongo_mapper-unstable-2010.08.12 test/functional/associations/test_one_embedded_proxy.rb
mongo_mapper-unstable-2010.08.11 test/functional/associations/test_one_embedded_proxy.rb
mongo_mapper-unstable-2010.08.10 test/functional/associations/test_one_embedded_proxy.rb
mongo_mapper-unstable-2010.08.09 test/functional/associations/test_one_embedded_proxy.rb
mongo_mapper-0.8.3 test/functional/associations/test_one_embedded_proxy.rb
mongo_mapper-unstable-2010.08.08 test/functional/associations/test_one_embedded_proxy.rb
mongo_mapper-unstable-2010.08.06 test/functional/associations/test_one_embedded_proxy.rb
mongo_mapper-unstable-2010.08.05 test/functional/associations/test_one_embedded_proxy.rb
mongo_mapper-unstable-2010.08.04 test/functional/associations/test_one_embedded_proxy.rb
mongo_mapper-unstable-2010.08.03 test/functional/associations/test_one_embedded_proxy.rb
mongo_mapper-unstable-2010.08.02 test/functional/associations/test_one_embedded_proxy.rb
mongo_mapper-unstable-2010.08.01 test/functional/associations/test_one_embedded_proxy.rb
mongo_mapper-unstable-2010.07.31 test/functional/associations/test_one_embedded_proxy.rb