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
#
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
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)
@ -111,7 +119,7 @@ RSpec.shared_context :shared_user_context do
{ params: args.reduce({}, :merge) }
end
def fix_args( *args)
def fix_args(*args)
replacements = {
__our_np: nonprofit.id,
__our_campaign: campaign.id,
@ -198,7 +206,7 @@ end
RSpec.shared_context :open_to_np_associate do |method, action, *args|
include_context :shared_user_context
let(:fixed_args){
fix_args( *args)
fix_args(*args)
}
it 'rejects no user' do