Sha256: 074eff0ef8a71c51a86748f7940fc08d80a310e6cc87aaf360ea5cc449b25eea
Contents?: true
Size: 1.09 KB
Versions: 9
Compression:
Stored size: 1.09 KB
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 "regenerates id" do user.clone.tap do |clone| clone.id.should_not be_nil clone.id.should_not == user.id end 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
9 entries across 9 versions & 1 rubygems