Specs can now pass in an expected status code
This commit is contained in:
parent
8c524e6c57
commit
94b2e8e282
1 changed files with 8 additions and 7 deletions
|
@ -85,12 +85,12 @@ RSpec.shared_context :shared_user_context do
|
||||||
end
|
end
|
||||||
|
|
||||||
def accept(user_to_signin, method, action, *args)
|
def accept(user_to_signin, method, action, *args)
|
||||||
without_json_response = method_without_json_view?(args)
|
test_variables = collect_test_variables(args)
|
||||||
request.accept = 'application/json' unless without_json_response
|
request.accept = 'application/json' unless test_variables[:without_json_view]
|
||||||
sign_in user_to_signin if user_to_signin
|
sign_in user_to_signin if user_to_signin
|
||||||
# allows us to run the helpers but ignore what the controller action does
|
# allows us to run the helpers but ignore what the controller action does
|
||||||
|
|
||||||
if without_json_response
|
if test_variables[:without_json_view]
|
||||||
expect_any_instance_of(described_class).to receive(action).and_return(ActionDispatch::IntegrationTest.new(200))
|
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)
|
expect_any_instance_of(described_class).to receive(:render).and_return(nil)
|
||||||
send(method, action, reduce_params(*args))
|
send(method, action, reduce_params(*args))
|
||||||
|
@ -98,7 +98,7 @@ RSpec.shared_context :shared_user_context do
|
||||||
else
|
else
|
||||||
expect_any_instance_of(described_class).to receive(action).and_return(ActionDispatch::IntegrationTest.new(204))
|
expect_any_instance_of(described_class).to receive(action).and_return(ActionDispatch::IntegrationTest.new(204))
|
||||||
send(method, action, reduce_params(*args))
|
send(method, action, reduce_params(*args))
|
||||||
expect(response.status).to eq 204
|
expect(response.status).to eq(test_variables[:with_status] || 204)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -114,15 +114,16 @@ RSpec.shared_context :shared_user_context do
|
||||||
{ params: args.reduce({}, :merge) }
|
{ params: args.reduce({}, :merge) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def method_without_json_view?(*args)
|
def collect_test_variables(*args)
|
||||||
|
test_vars = {}
|
||||||
args.collect do |items|
|
args.collect do |items|
|
||||||
if items.kind_of?(Array)
|
if items.kind_of?(Array)
|
||||||
items.each do |k, v|
|
items.each do |k, v|
|
||||||
return k[:without_json_view] if k.kind_of?(Hash) && k[:without_json_view]
|
test_vars.merge!(k.slice(:without_json_view, :with_status)) if k.kind_of?(Hash)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return false
|
return test_vars
|
||||||
end
|
end
|
||||||
|
|
||||||
def fix_args(*args)
|
def fix_args(*args)
|
||||||
|
|
Loading…
Reference in a new issue