Permalink
Browse files

integration test for api routing and on_headers

  • Loading branch information...
1 parent 9e7c588 commit 48be820fd3f7c07a5efa755eba2035c10046a4e7 @joshbuddy joshbuddy committed Sep 6, 2011
Showing with 32 additions and 3 deletions.
  1. +15 −0 examples/rack_routes.rb
  2. +0 −3 lib/goliath/api.rb
  3. +17 −0 spec/integration/rack_routes_spec.rb
View
@@ -26,6 +26,17 @@ def response(env)
end
end
+class HeaderCollector < Goliath::API
+ def on_headers(env, header)
+ @headers ||= {}
+ @headers.merge!(header)
+ end
+
+ def response(env)
+ [200, {}, "headers: #{@headers.inspect}"]
+ end
+end
+
class HelloNumber < Goliath::API
use Goliath::Rack::Params
def response(env)
@@ -76,6 +87,10 @@ class RackRoutes < Goliath::API
run HelloWorld.new
end
+ map "/headers", HeaderCollector do
+ use Goliath::Rack::Validation::RequestMethod, %w(GET)
+ end
+
map "/bonjour" do
run Bonjour.new
end
View
@@ -125,9 +125,6 @@ def maps?
def map(name, *args, &block)
opts = args.last.is_a?(Hash) ? args.pop : {}
klass = args.first
- if klass && block_given?
- raise "Can't provide class and block to map"
- end
maps.push([name, klass, opts, block])
end
@@ -140,5 +140,22 @@
end
end
+ context "with event handlers" do
+ it "collects header events" do
+ with_api(RackRoutes) do
+ get_request({:path => '/headers'}, err) do |c|
+ c.response_header.status.should == 200
+ c.response.should == 'headers: {"Connection"=>"close", "Host"=>"localhost:9900", "User-Agent"=>"EventMachine HttpClient"}'
+ end
+
+ post_request({:path => '/headers'}, err) do |c|
+ # the /headers route only supports GET requests
+ c.response_header.status.should == 405
+ c.response.should == '[:error, "Invalid request method"]'
+ c.response_header['ALLOW'].should == 'GET'
+ end
+ end
+ end
+ end
end
end

0 comments on commit 48be820

Please sign in to comment.