Skip to content

Commit

Permalink
answering to link names
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermesilveira committed Apr 6, 2010
1 parent 7242637 commit 44f09a1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/restfulie/client/http/marshal.rb
Expand Up @@ -3,6 +3,17 @@ module Restfulie::Client::HTTP

module ResponseHolder
attr_accessor :response

def respond_to?(symbol)
respond_to_rel?(symbol.to_s) || super(symbol)
end

private
# whether this response contains specific relations
def respond_to_rel?(rel)
links.any? { |link| link.rel==rel }
end

end

module RequestMarshaller
Expand Down
22 changes: 22 additions & 0 deletions spec/units/client/http/marshal_spec.rb
Expand Up @@ -17,5 +17,27 @@
raw_response.response.code.should == 200
raw_response.response.body.should == response_data( 'atoms', 'songs' )
end

class Link
attr_reader :rel
def initialize(rel)
@rel = rel
end
end
class Linked
attr_reader :links
def initialize(links)
@links = []
links.each do |l|
@links << Link.new(l)
end
end
end
it 'respond whether a resource contains a rel link' do
result = Linked.new(["first", "payment"])
result.extend Restfulie::Client::HTTP::ResponseHolder
result.respond_to?("search").should be_false
result.respond_to?("payment").should be_true
end

end

0 comments on commit 44f09a1

Please sign in to comment.