Permalink
Browse files

Yield the rack response triplet to the response_version hook.

  • Loading branch information...
1 parent 3a5d34c commit 57487a4878ed03fb2820ff02218fc57ba929703e @myronmarston myronmarston committed Oct 15, 2012
View
4 lib/interpol/configuration.rb
@@ -66,8 +66,8 @@ def endpoints=(endpoints)
instance_variable_set(:"@#{type}_version_block", block || lambda { |*a| version })
end
- define_method :"#{type}_version_for" do |rack_env, endpoint=nil|
- instance_variable_get(:"@#{type}_version_block").call(rack_env, endpoint).to_s
+ define_method :"#{type}_version_for" do |rack_env, *extra_args|
+ instance_variable_get(:"@#{type}_version_block").call(rack_env, *extra_args).to_s
end
end
View
6 lib/interpol/response_schema_validator.rb
@@ -69,9 +69,13 @@ def path
def validator
@validator ||= @config.endpoints.
find_definition(request_method, path, 'response', status) do |endpoint|
- @config.response_version_for(env, endpoint)
+ @config.response_version_for(env, endpoint, response_triplet)
end
end
+
+ def response_triplet
+ [status, headers, extracted_body]
+ end
end
# Private: Subclasses Handler in order to convert validation errors
View
11 spec/unit/interpol/response_schema_validator_spec.rb
@@ -99,7 +99,7 @@ def stub_lookup(v = validator)
default_config_called.should be_true
end
- it 'calls the response_version callback with the rack env and the endpoint' do
+ it 'calls the response_version hook with the rack env, the endpoint and the response triplet' do
endpoint.stub(:method => :get, :route_matches? => true)
self.definition_finder = [endpoint].extend(Interpol::DefinitionFinder)
@@ -113,7 +113,14 @@ def stub_lookup(v = validator)
expect { get '/search/200/overview' }.to raise_error(NoEndpointDefinitionFoundError)
- yielded_args.map(&:class).should eq([Hash, Interpol::Endpoint])
+ yielded_args[0].should be_a(Hash) # rack env
+ yielded_args[1].should be_a(Interpol::Endpoint)
+
+ response = yielded_args[2]
+ response.should be_an(Array)
+ response[0].should eq(200)
+ response[1].should have_key("Content-Type")
+ response[2].should eq([%|{"a":"b"}|])
end
it 'yields the env, status, headers and body from the validate_if callback' do

0 comments on commit 57487a4

Please sign in to comment.