Sha256: 99940ec995a32c979f6bcf5dbb5316033b6c9742156b5ac6bca719475275a3ac

Contents?: true

Size: 1.56 KB

Versions: 52

Compression:

Stored size: 1.56 KB

Contents

require 'test_helper'

class CloneTest < Test::Unit::TestCase
  context "Document" do
    setup do
      @document = Doc()
      @embedded = EDoc()
      @document.many :widgets, :class => @embedded
      @tags = ['red', 'green', 'blue']
      @doc = @document.create({
        :name    => "foo",
        :age     => 27,
        :tags    => @tags,
        :widgets => [@embedded.new, @embedded.new],
      })
    end

    context "#clone" do
      should "be new" do
        @doc.clone.should be_new
      end

      should "copy the attributes" do
        clone = @doc.clone
        clone.name.should == "foo"
        clone.age.should == 27
      end

      should "clone duplicable attributes" do
        @doc.clone.tags.should_not equal(@tags)
      end

      should "clone many embedded documents" do
        @doc.clone.widgets.should_not equal(@doc.widgets)
      end

      should "not be destroyed" do
        @doc.destroy
        @doc.clone.should_not be_destroyed
      end
    end
  end

  context "EmbeddedDocument" do
    setup do
      @document = EDoc do
        key :name, String
        key :age, Integer
      end
    end

    context "#clone" do
      should "regenerate the id" do
        doc = @document.new(:name => "foo", :age => 27)
        doc_id = doc.id
        clone = doc.clone
        clone_id = clone.id
        clone_id.should_not == doc_id
      end

      should "copy the attributes" do
        doc = @document.new(:name => "foo", :age => 27)
        clone = doc.clone
        clone.name.should == "foo"
        clone.age.should == 27
      end
    end
  end
end

Version data entries

52 entries across 52 versions & 3 rubygems

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