test/unit/namespace_data_tests.rb in ns-options-1.1.0 vs test/unit/namespace_data_tests.rb in ns-options-1.1.1
- old
+ new
@@ -125,26 +125,10 @@
should "know if it has a namespace" do
assert subject.has_namespace? 'child_a'
assert_not subject.has_namespace? 'dlakjsglasdjgaklsdgjas'
end
- should "return its Hash representation" do
- exp_hash = {
- :first => nil, :second => nil, :third => nil,
- :child_a => {
- :fourth => nil, :fifth => nil,
- :child_b => { :sixth => nil }
- }
- }
- assert_equal(exp_hash, subject.to_hash)
- end
-
- should "apply a given hash value to itself" do
- subject.apply(@named_values)
- assert_equal @named_values, subject.to_hash
- end
-
end
class EachTests < HandlingTests
desc "iterated with the each method"
setup do
@@ -211,32 +195,72 @@
assert_not_same @from_child_ns, subject.child_namespaces[:ns1]
end
end
- class ApplyTests < BaseTests
+ class HashHandlingTests < BaseTests
setup do
@data.define do
option :first; option :second; option :third
namespace(:child_a) do
option(:fourth); option(:fifth)
namespace(:child_b) { option(:sixth) }
end
end
+ @shared_array = []
@named_values = {
:first => "1", :second => "2", :third => "3", :twenty_one => "21",
:child_a => {
:fourth => "4", :fifth => "5",
:child_b => { :sixth => "6" }
},
- :child_c => { :what => "?" }
+ :child_c => { :what => "?" },
+ :shared => @shared_array
}
end
+ end
+
+ class ToHashTests < HashHandlingTests
+
+ should "return its Hash representation" do
+ exp_hash = {
+ :first => nil, :second => nil, :third => nil,
+ :child_a => {
+ :fourth => nil, :fifth => nil,
+ :child_b => { :sixth => nil }
+ }
+ }
+ assert_equal(exp_hash, subject.to_hash)
+ end
+
+ should "use distinct values in its Hash representation" do
+ subject.add_option(:shared)
+ subject.set_option(:shared, [])
+ hash_rep = subject.to_hash
+ subject.get_option(:shared) << 1
+
+ assert_not_empty subject.get_option(:shared)
+ assert_empty hash_rep[:shared]
+ assert_not_equal subject.get_option(:shared).object_id, hash_rep[:shared].object_id
+ end
+
+ end
+
+ class ApplyTests < HashHandlingTests
+
should "apply a given hash value to itself" do
subject.apply(@named_values)
assert_equal @named_values, subject.to_hash
+ end
+
+ should "use distinct values when applying hashes" do
+ subject.apply(@named_values)
+ @shared_array << 1
+
+ assert_empty subject.get_option(:shared)
+ assert_not_equal @shared_array.object_id, subject.get_option(:shared).object_id
end
should "ignore applying non-hash values to namespaces" do
assert_nil subject.ns.child_a.fourth
prev_child_b = subject.ns.child_a.child_b.dup