Skip to content

Commit 894d892

Browse files
author
Michael Bleigh
committed
Endpoints now properly reset before each request.
1 parent 6bcb12d commit 894d892

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

lib/grape/endpoint.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,17 @@ def header(key = nil, val = nil)
5252
end
5353
end
5454

55+
def reset!
56+
@params = nil
57+
@env = nil
58+
@request = nil
59+
@header = {}
60+
end
61+
5562
def call(env)
63+
reset!
5664
@env = env
5765
@request = Rack::Request.new(@env)
58-
@header = {}
5966

6067
response_text = instance_eval &@block
6168

lib/grape/middleware/formatter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def encode_json(object)
9999
end
100100

101101
def encode_txt(object)
102-
body.respond_to?(:to_txt) ? body.to_txt : body.to_s
102+
object.respond_to?(:to_txt) ? object.to_txt : object.to_s
103103
end
104104
end
105105
end

spec/grape/endpoint_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,16 @@ def app; subject end
7272
last_response.body.should == "Unauthorized."
7373
end
7474
end
75+
76+
it 'should not persist params between calls' do
77+
subject.post('/new') do
78+
params[:text]
79+
end
80+
81+
post '/new', :text => 'abc'
82+
last_response.body.should == 'abc'
83+
84+
post '/new', :text => 'def'
85+
last_response.body.should == 'def'
86+
end
7587
end

0 commit comments

Comments
 (0)