File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,10 @@ def as_json(options=nil)
4040 end
4141 end
4242
43+ def initialize_copy ( original )
44+ @options = original . options . deep_dup
45+ end
46+
4347 def inspect
4448 "#<#{ self . class . name || "Anonymous(Trestle::Configurable)" } >"
4549 end
Original file line number Diff line number Diff line change 5252 end
5353 end
5454
55+ describe "#dup" do
56+ let ( :original_options ) { config . options }
57+ let ( :duplicate ) { config . dup }
58+
59+ it "returns a new instance with a clone of the options" do
60+ expect ( duplicate . options ) . to eq ( original_options )
61+ expect ( duplicate . options ) . not_to be ( original_options )
62+ end
63+ end
64+
65+ describe "#clone" do
66+ let ( :original_options ) { config . options }
67+ let ( :duplicate ) { config . clone }
68+
69+ it "returns a new instance with a clone of the options" do
70+ expect ( duplicate . options ) . to eq ( original_options )
71+ expect ( duplicate . options ) . not_to be ( original_options )
72+ end
73+ end
74+
5575 describe ".option" do
5676 it "defines accessors for the option" do
5777 configurable . option :myoption
112132 config . first . second . third = "value"
113133 expect ( config . as_json ( { } ) ) . to eq ( { first : { second : { third : "value" } } } )
114134 end
135+
136+ describe "#dup" do
137+ it "creates clones of nested options" do
138+ config . first . second . third = "value"
139+ duplicate = config . dup
140+
141+ expect ( duplicate . second . options ) . to eq ( config . second . options )
142+ expect ( duplicate . second . options ) . not_to be ( config . second . options )
143+ end
144+ end
115145 end
116146end
You can’t perform that action at this time.
0 commit comments