test(shared_user_ctx): add conditional specs for types of methods

This commit is contained in:
Luis Castro 2019-07-23 21:20:54 +02:00
parent 9f6ea91224
commit 84f8a583ba
No known key found for this signature in database
GPG key ID: 0A8F33D4C4E27639
2 changed files with 16 additions and 8 deletions

View file

@ -30,7 +30,7 @@
respond_to do |format|
format.html
format.json {render json: @nonprofit}
format.json {@nonprofit}
end
end

View file

@ -90,13 +90,21 @@ RSpec.shared_context :shared_user_context do
end
def accept(user_to_signin, method, action, *args)
without_json_response = [:cancellation, :all_npos].include?(action)
request.accept = "application/json" unless without_json_response
sign_in user_to_signin if user_to_signin
# allows us to run the helpers but ignore what the controller action does
#
if without_json_response
expect_any_instance_of(described_class).to receive(action).and_return(ActionDispatch::IntegrationTest.new(200))
expect_any_instance_of(described_class).to receive(:render).and_return(nil)
send(method, action, reduce_params(*args))
expect(response.status).to eq 200
else
expect_any_instance_of(described_class).to receive(action).and_return(ActionDispatch::IntegrationTest.new(204))
send(method, action, reduce_params(*args))
expect(response.status).to eq 204
end
end
def reject(user_to_signin, method, action, *args)