Skip to content
This repository has been archived by the owner on Jan 2, 2018. It is now read-only.

Commit

Permalink
Added WSList.find(verb, route)
Browse files Browse the repository at this point in the history
  • Loading branch information
drnic committed May 14, 2012
1 parent 4b159f8 commit 0c68fe3
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lib/ws_list.rb
Expand Up @@ -53,6 +53,18 @@ def [](url)
@list.find{|service| service.url == url}
end

# Returns a service based on its verb and url
#
# @param [String] verb The request method (GET, POST, PUT, DELETE)
# @param [String] url The url of the service you are looking for.
# @return [Nil, WeaselDiesel] The found service.
#
# @api public
def find(verb, url)
verb = verb.to_s.downcase.to_sym
@list.find{|service| service.verb == verb && service.url == url}
end


end

28 changes: 27 additions & 1 deletion spec/test_services.rb
@@ -1,4 +1,6 @@
WeaselDieselSpecOptions = ['RSpec', 'Bacon'] # usually pulled from a model
unless Object.const_defined?("WeaselDieselSpecOptions")
WeaselDieselSpecOptions = ['RSpec', 'Bacon'] # usually pulled from a model
end

describe_service "services/test.xml" do |service|
service.formats :xml, :json
Expand Down Expand Up @@ -78,6 +80,30 @@
end
end

describe_service "services/test.xml" do |service|
service.formats :xml, :json
service.http_verb :delete

service.params do |p|
p.integer :id, :doc => "id of item to be deleted"
end

service.response do |response|
response.element(:name => "player_creation_ratings") do |e|
e.integer :id, :doc => "id doc"
end
end


service.documentation do |doc|
# doc.overall <markdown description text>
doc.overall <<-DOC
This deletes a test service.
DOC
end
end



describe_service "services/test_no_params.xml" do |service|
service.formats :xml
Expand Down
16 changes: 16 additions & 0 deletions spec/ws_list_spec.rb
@@ -0,0 +1,16 @@
require File.expand_path("spec_helper", File.dirname(__FILE__))

describe WSList do

it "find service by verb/route" do
service = WSList.find(:get, 'services/test.xml')
service.should_not be_nil

service.url.should == 'services/test.xml'
service.verb.should == :get

service = WSList.find(:delete, 'services/test.xml')
service.url.should == 'services/test.xml'
service.verb.should == :delete
end
end

0 comments on commit 0c68fe3

Please sign in to comment.