Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added WSList.find(verb, route)

  • Loading branch information...
commit 0c68fe341761e987e39055034f3ce742b4e83326 1 parent 4b159f8
@drnic drnic authored
Showing with 55 additions and 1 deletion.
  1. +12 −0 lib/ws_list.rb
  2. +27 −1 spec/test_services.rb
  3. +16 −0 spec/ws_list_spec.rb
View
12 lib/ws_list.rb
@@ -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
View
28 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
@@ -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
View
16 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
Please sign in to comment.
Something went wrong with that request. Please try again.