Permalink
Browse files

clone options in Definition.

  • Loading branch information...
1 parent 53d2304 commit 523ebbc1986d9ccce0c6649c48d7cf3d7eaee8be @apotonick apotonick committed Apr 3, 2012
Showing with 15 additions and 0 deletions.
  1. +4 −0 lib/representable/definition.rb
  2. +11 −0 test/definition_test.rb
@@ -8,6 +8,10 @@ def initialize(sym, options={})
@name = sym.to_s
@options = options
end
+
+ def clone
+ self.class.new(name, options.clone) # DISCUSS: make generic Definition.cloned_attribute that passes list to constructor.
+ end
def setter
:"#{name}="
@@ -42,6 +42,17 @@ class DefinitionTest < MiniTest::Spec
it "responds to #sought_type" do
assert_equal nil, @def.sought_type
end
+
+ describe "#clone" do
+ it "clones @options" do
+ @def.options[:volume] = 9
+ cloned = @def.clone
+ cloned.options[:volume] = 8
+
+ assert_equal @def.options[:volume], 9
+ assert_equal cloned.options[:volume], 8
+ end
+ end
end

0 comments on commit 523ebbc

Please sign in to comment.