Skip to content

Commit 7f0cde5

Browse files
committedFeb 2, 2012
Update path parameters from do_request
1 parent 73c393c commit 7f0cde5

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed
 

‎lib/rspec_api_documentation/dsl.rb

+8-1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def callback_url
9696

9797
def do_request(extra_params = {})
9898
@extra_params = extra_params
99+
99100
params_or_body = nil
100101
path_or_query = path
101102

@@ -139,7 +140,9 @@ def path_params
139140

140141
def path
141142
example.metadata[:path].gsub(/:(\w+)/) do |match|
142-
if respond_to?($1)
143+
if extra_params.keys.include?($1)
144+
delete_extra_param($1)
145+
elsif respond_to?($1)
143146
send($1)
144147
else
145148
match
@@ -172,6 +175,10 @@ def extra_params
172175
end
173176
end
174177

178+
def delete_extra_param(key)
179+
@extra_params.delete(key.to_sym) || @extra_params.delete(key.to_s)
180+
end
181+
175182
def set_param(hash, param)
176183
key = param[:name]
177184
return hash if !respond_to?(key) || in_path?(key)

‎spec/dsl_spec.rb

+18
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,19 @@
125125
end
126126
end
127127
end
128+
end
129+
130+
put "/orders/:id" do
131+
parameter :type, "The type of drink you want."
132+
parameter :size, "The size of drink you want."
133+
parameter :note, "Any additional notes about your order."
134+
135+
required_parameters :type, :size
136+
137+
let(:type) { "coffee" }
138+
let(:size) { "medium" }
139+
140+
let(:id) { 1 }
128141

129142
describe "do_request" do
130143
context "when raw_post is defined" do
@@ -152,6 +165,11 @@
152165
client.should_receive(method).with(path, params.merge("size" => "large"))
153166
do_request(:size => "large")
154167
end
168+
169+
it "should overwrite path variables" do
170+
client.should_receive(method).with("/orders/2", params)
171+
do_request(:id => 2)
172+
end
155173
end
156174
end
157175

0 commit comments

Comments
 (0)