Permalink
Browse files

Add Endpoint#parse_request_params method.

  • Loading branch information...
1 parent a948aac commit 56483da2aebcca4a1afb48b6010613f59f6b1d89 @myronmarston myronmarston committed Sep 10, 2012
Showing with 27 additions and 0 deletions.
  1. +8 −0 lib/interpol/endpoint.rb
  2. +19 −0 spec/unit/interpol/endpoint_spec.rb
@@ -184,8 +184,16 @@ def example_status_code
@example_status_code ||= @status_codes.example_status_code
end
+ def parse_request_params(request_params)
+ request_params_parser.parse(request_params)
+ end
+
private
+ def request_params_parser
+ @request_params_parser ||= RequestParamsParser.new(self)
+ end
+
def make_schema_strict!(raw_schema, modify_object=true)
return unless Hash === raw_schema
@@ -223,6 +223,25 @@ def build_hash(hash = {})
end
end
+ describe "#parse_request_params" do
+ let(:parser_class) { fire_replaced_class_double("Interpol::RequestParamsParser") }
+ let(:parser) { fire_double("Interpol::RequestParamsParser") }
+ let(:definition) { EndpointDefinition.new(endpoint, version, 'response', build_hash) }
+
+ it 'parses the given params using a RequestParamsParser' do
+ parser_class.should_receive(:new).
+ with(definition).
+ and_return(parser)
+
+ parser.should_receive(:parse).
+ with("the" => "params").
+ and_return("parsed" => "params")
+
+ parsed = definition.parse_request_params("the" => "params")
+ parsed.should eq("parsed" => "params")
+ end
+ end
+
describe "#validate_data" do
let(:schema) do {
'type' => 'object',

0 comments on commit 56483da

Please sign in to comment.