Permalink
Browse files

adding support in resource and resource creator to support links hash…

… with string keys
  • Loading branch information...
felipecvo committed Jun 25, 2012
1 parent 390aad6 commit cd93c00e0568d71fe732746ba1a86e3ee55bd9ae
@@ -96,11 +96,11 @@ def parse_links(json)
links = [links] unless links.is_a?(Array)
links.map do |link|
- if link[:href].nil? || link[:rel].nil?
+ if (link[:href].nil? && link['href'].nil?) || (link[:rel].nil? && link['rel'].nil?)
msg = "Invalid hash link: #{link.inspect}"
raise(RuntimeError, msg, caller)
end
- EntryPoint.new(link[:href], link[:rel])
+ EntryPoint.new(link[:href] || link['href'], link[:rel] || link['rel'])
end
end
@@ -108,7 +108,7 @@ def resource_class
#
# Returns attributes to be ignored when creating Resource.
def attributes_to_dont_parse
- [:links, :link].freeze
+ [:links, :link, 'links', 'link'].freeze
end
# Internal: Check if value is eligible to become a Restfolia::Resource.
@@ -22,6 +22,11 @@ def creator.resource_class
resource.must_be_instance_of(OpenStruct)
end
+ it "don't transforms nested link hash in Resource" do
+ resource = subject.create('link' => {:rel => "nested",:href => "http://localhost"})
+ resource.link.must_be_instance_of(Hash)
+ end
+
it "transforms nested hash in Resource" do
resource = subject.create(:attr_test => {:nested => "nested"})
resource.attr_test.must_be_instance_of(OpenStruct)
@@ -100,6 +100,11 @@
resource.links("rel2").must_be_instance_of(Restfolia::EntryPoint)
end
+ it "returns EntryPoint even when hash key is string" do
+ resource = subject.new('link' => {'rel' => 'rel2', 'href' => 'http://localhost/'})
+ resource.links("rel2").must_be_instance_of(Restfolia::EntryPoint)
+ end
+
end
end

0 comments on commit cd93c00

Please sign in to comment.