test(shared_user_ctx): add conditional specs for types of methods
This commit is contained in:
parent
9f6ea91224
commit
84f8a583ba
2 changed files with 16 additions and 8 deletions
|
@ -30,7 +30,7 @@
|
|||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.json {render json: @nonprofit}
|
||||
format.json {@nonprofit}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue