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.07.05 test/unit/test_clone.rb
mongo_mapper-unstable-2010.07.02 test/unit/test_clone.rb
mongo_mapper-unstable-2010.07.01 test/unit/test_clone.rb
mongo_mapper-unstable-2010.06.30 test/unit/test_clone.rb
mongo_mapper-unstable-2010.06.29 test/unit/test_clone.rb
mongo_mapper-unstable-2010.06.28 test/unit/test_clone.rb
mongo_mapper-unstable-2010.06.25 test/unit/test_clone.rb
mongo_mapper-unstable-2010.06.24 test/unit/test_clone.rb
mongo_mapper-unstable-2010.06.23 test/unit/test_clone.rb
mongo_mapper-0.8.2 test/unit/test_clone.rb
mongo_mapper-0.8.1 test/unit/test_clone.rb
mongo_mapper-0.8.0 test/unit/test_clone.rb