1. Michael Granger
  2. Strelka

Commits

Michael Granger  committed e8958f7

Make response filters always receive a response

...even if the handler returns a Symbol, e.g., for the templating plugin.

  • Participants
  • Parent commits bc94898
  • Branches default

Comments (0)

Files changed (3)

File lib/strelka/app/filters.rb

View file
 
 		self.apply_request_filters( request )
 		response = super
-		self.apply_response_filters( response )
+		self.apply_response_filters( request.response )
 
 		return response
 	end

File lib/strelka/app/templating.rb

View file
 		# Not templated; returned as-is
 		else
 			self.log.debug "  response isn't templated; returning nil"
+			# :TODO: Return the response instead of nil
 			return nil
 		end
 	end

File spec/strelka/app/filters_spec.rb

View file
 	it_should_behave_like( "A Strelka Plugin" )
 
 
-	describe "an including App" do
+	context "an including App" do
 
 		before( :each ) do
 			@app = Class.new( Strelka::App ) do
 		end
 
 
-		describe "that doesn't declare any filters" do
+		context "that doesn't declare any filters" do
 
 			it "doesn't have any request filters" do
 				expect( @app.request_filters ).to be_empty()
 		end
 
 
-		describe "that declares a filter without a phase" do
+		context "that declares a filter without a phase" do
 
 			before( :each ) do
-				@app.class_eval do
-					filter do |reqres|
-						if reqres.is_a?( Strelka::HTTPRequest )
-							reqres.notes[:saw][:request] = true
-						else
-							reqres.notes[:saw][:response] = true
-						end
+				@app.filter do |reqres|
+					if reqres.is_a?( Strelka::HTTPRequest )
+						reqres.notes[:saw][:request] = true
+					else
+						reqres.notes[:saw][:response] = true
 					end
 				end
 			end
 
 		end
 
-		describe "that declares a request filter" do
+		context "that declares a request filter" do
 
 			before( :each ) do
-				@app.class_eval do
-					filter( :request ) do |reqres|
-						if reqres.is_a?( Strelka::HTTPRequest )
-							reqres.notes[:saw][:request] = true
-						else
-							reqres.notes[:saw][:response] = true
-						end
+				@app.filter( :request ) do |reqres|
+					if reqres.is_a?( Strelka::HTTPRequest )
+						reqres.notes[:saw][:request] = true
+					else
+						reqres.notes[:saw][:response] = true
 					end
 				end
 			end
 
 		end
 
-		describe "that declares a response filter" do
+		context "that declares a response filter" do
 
 			before( :each ) do
-				@app.class_eval do
-					filter( :response ) do |reqres|
-						if reqres.is_a?( Strelka::HTTPRequest )
-							reqres.notes[:saw][:request] = true
-						else
-							reqres.notes[:saw][:response] = true
-						end
+				@app.filter( :response ) do |reqres|
+					if reqres.is_a?( Strelka::HTTPRequest )
+						reqres.notes[:saw][:request] = true
+					else
+						reqres.notes[:saw][:response] = true
 					end
 				end
 			end
 
 		end
 
+
+		context "that returns something other than an HTTPResponse from its handler" do
+
+			before( :each ) do
+				@app.class_eval do
+					plugin :templating
+					templates :main => 'spec/data/main.tmpl'
+					def handle_request( req )
+						super { :main }
+					end
+				end
+			end
+
+			it "still gives the response filter an HTTPResponse" do
+				@app.filter( :response ) do |res|
+					expect( res ).to be_a( Strelka::HTTPResponse )
+				end
+
+				req = @request_factory.get( '/account/118811' )
+				res = @app.new.handle( req )
+
+				expect( res.status_line ).to match( /200 ok/i )
+			end
+		end
+
 	end