test/structure_test.rb in structure-0.20.1 vs test/structure_test.rb in structure-0.21.0
- old
+ new
@@ -24,10 +24,28 @@
assert_raise(NameError) { double.class }
::Kernel.const_set(:Foo, 1)
assert_kind_of Fixnum, double
end
+ def test_anonymous
+ hsh = { 'FirstName' => 'John', 'LastName' => 'Doe' }
+ str = Structure.new(hsh)
+ assert_equal hsh['FirstName'], str.first_name
+ assert_equal hsh['LastName'], str.last_name
+ assert_raise(NoMethodError) { str.FirstName }
+ end
+
+ def test_anonymous_recursion
+ hsh = { 'Name' => 'John',
+ 'Address' => { 'City' => 'Oslo' },
+ 'Friends' => [{ 'Name' => 'Jane' }]
+ }
+ str = Structure.new(hsh)
+ assert_equal hsh['Address']['City'], str.address.city
+ assert_equal hsh['Friends'].first['Name'], str.friends.first.name
+ end
+
def test_enumeration
assert_respond_to Person.new, :map
end
def test_accessors
@@ -78,10 +96,10 @@
assert_equal false, person.respond_to?(:as_json)
require 'active_support/ordered_hash'
require 'active_support/json'
- require 'structure/active_support'
+ require 'structure/ext/active_support'
assert_equal true, person.as_json(:only => :name).has_key?(:name)
assert_equal false, person.as_json(:except => :name).has_key?(:name)
end
end