Skip to content

Commit

Permalink
prevent batching of requests by appending "unbatch=true" param to req…
Browse files Browse the repository at this point in the history
…uest url
  • Loading branch information
lynndylanhurley committed Oct 25, 2015
1 parent 4922d90 commit 2b8f2af
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def resource_class(m=nil)


def is_batch_request?(user, client_id)
not params[:unbatch] and
user.tokens[client_id] and
user.tokens[client_id]['updated_at'] and
Time.parse(user.tokens[client_id]['updated_at']) > @request_started_at - DeviseTokenAuth.batch_request_buffer_throttle
Expand Down
25 changes: 25 additions & 0 deletions test/controllers/demo_user_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,31 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest
end
end

describe 'unbatch' do
before do
@resource.reload
age_token(@resource, @client_id)

get '/demo/members_only', {}, @auth_headers

@first_is_batch_request = assigns(:is_batch_request)
@first_user = assigns(:resource).dup
@first_access_token = response.headers['access-token']
@first_response_status = response.status

get '/demo/members_only?unbatch=true', {}, @auth_headers

@second_is_batch_request = assigns(:is_batch_request)
@second_user = assigns(:resource)
@second_access_token = response.headers['access-token']
@second_response_status = response.status
end

it 'should NOT treat the second request as a batch request when "unbatch" param is set' do
refute @second_is_batch_request
end
end

describe 'time out' do
before do
@resource.reload
Expand Down

0 comments on commit 2b8f2af

Please sign in to comment.