Sha256: 888a97c890b1d0d7c0685e793854655051bf7bc167fcfae063844e5d207409ab

Contents?: true

Size: 964 Bytes

Versions: 2

Compression:

Stored size: 964 Bytes

Contents

require 'helper'

describe Toy::Cloneable do
  uses_objects('User')

  before do
    User.attribute(:name, String)
    User.attribute(:skills, Array)

    @user = User.new({
      :name   => 'John',
      :skills => ['looking awesome', 'growing beards'],
    })
  end
  let(:user)  { @user }

  describe "#clone" do
    it "clones the @attributes hash" do
      user.clone.instance_variable_get("@attributes").should_not equal(user.instance_variable_get("@attributes"))
    end

    it "copies the attributes" do
      user.clone.tap do |clone|
        clone.name.should == user.name
        clone.skills.should == user.skills
      end
    end

    it "clones duplicable attributes" do
      user.clone.skills.should_not equal(user.skills)
    end

    it "nullifies defined instance variables" do
      user.instance_variable_set("@foo", true)
      user.clone.tap do |clone|
        clone.instance_variable_get("@foo").should be_nil
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
toystore-0.13.2 spec/toy/cloneable_spec.rb
toystore-0.13.1 spec/toy/cloneable_spec.rb