Sha256: 9d693458381ce429184457bfa4cdf525418566bfe9be99bc8487b1db99b59d85

Contents?: true

Size: 1.67 KB

Versions: 4

Compression:

Stored size: 1.67 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 "send object id to target" do
    @post_class.one :author, :class => @author_class

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

    post.author.object_id.should == post.author.target.object_id
  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 "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

4 entries across 4 versions & 3 rubygems

Version Path
pwnash-mongo_mapper-0.7.5 test/functional/associations/test_one_embedded_proxy.rb
mongo_mapper-0.7.5 test/functional/associations/test_one_embedded_proxy.rb
mongo_mapper_ign-0.7.4 test/functional/associations/test_one_embedded_proxy.rb
mongo_mapper-0.7.4 test/functional/associations/test_one_embedded_proxy.rb