Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings #16

Merged
merged 5 commits into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/committee/rails/request_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Committee::Rails
class RequestObject
delegate(*ActionDispatch::Request.public_instance_methods, to: :@request)
delegate_missing_to :@request

def initialize(request)
@request = request
Expand Down
2 changes: 1 addition & 1 deletion lib/committee/rails/test/methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def committee_options
if defined?(RSpec) && (options = RSpec.try(:configuration).try(:committee_options))
options
else
{ schema_path: default_schema }
{ schema_path: default_schema, query_hash_key: 'rack.request.query_hash', parse_response_by_content_type: false }
end
end

Expand Down
31 changes: 17 additions & 14 deletions spec/lib/methods_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
context 'when set option' do
before do
RSpec.configuration.add_setting :committee_options
RSpec.configuration.committee_options = { schema_path: Rails.root.join('schema', 'schema.yml').to_s, old_assert_behavior: false }
RSpec.configuration.committee_options = { schema_path: Rails.root.join('schema', 'schema.yml').to_s, old_assert_behavior: false, query_hash_key: 'rack.request.query_hash', parse_response_by_content_type: false }
end

context 'and when response conform YAML Schema' do
it 'pass' do
post '/users', params: { nickname: 'willnet' }.to_json, headers: { 'Content-Type' => 'application/json' }
assert_schema_conform
assert_schema_conform(200)
end

context 'and override #request method' do
Expand All @@ -22,7 +22,7 @@ def request

it 'pass' do
post '/users', params: { nickname: 'willnet' }.to_json, headers: { 'Content-Type' => 'application/json' }
assert_schema_conform
assert_schema_conform(200)
end
end

Expand All @@ -33,30 +33,33 @@ def response

it 'pass' do
post '/users', params: { nickname: 'willnet' }.to_json, headers: { 'Content-Type' => 'application/json' }
assert_schema_conform
assert_schema_conform(200)
end
end
end

context "and when response doesn't conform YAML Schema" do
it 'raise Committee::InvalidResponse' do
patch '/users/1', params: { nickname: 'willnet' }.to_json, headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }
expect { assert_schema_conform }.to raise_error(Committee::InvalidResponse)
expect { assert_schema_conform(200) }.to raise_error(Committee::InvalidResponse)
end
end

context 'and when bad request' do
around do |example|
original_show_detailed_exceptions = Rails.application.env_config['action_dispatch.show_detailed_exceptions']
original_show_exceptions = Rails.application.env_config['action_dispatch.show_exceptions']
Rails.application.env_config['action_dispatch.show_detailed_exceptions'] = false
Rails.application.env_config['action_dispatch.show_exceptions'] = true

example.run

Rails.application.env_config['action_dispatch.show_detailed_exceptions'] = true
Rails.application.env_config['action_dispatch.show_exceptions'] = false
begin
example.run
ensure
Rails.application.env_config['action_dispatch.show_detailed_exceptions'] = original_show_detailed_exceptions
Rails.application.env_config['action_dispatch.show_exceptions'] = original_show_exceptions
end
end

it 'pass' do
it 'pass as 400' do
patch '/users/0', params: { nickname: 'willnet' }.to_json, headers: { 'Content-Type': 'application/json', 'Accept' => 'application/json' }
assert_schema_conform(400)
end
Expand All @@ -71,18 +74,18 @@ def response

it 'use default setting' do
post '/users', params: { nickname: 'willnet' }
expect{ assert_schema_conform }.to raise_error(Errno::ENOENT) # not exist doc/schema/schema.json
expect{ assert_schema_conform(200) }.to raise_error(Errno::ENOENT) # not exist doc/schema/schema.json
end
end

context 'when override default setting' do
def committee_options
{ schema_path: Rails.root.join('schema', 'schema.yml').to_s, old_assert_behavior: false }
{ schema_path: Rails.root.join('schema', 'schema.yml').to_s, old_assert_behavior: false, query_hash_key: 'rack.request.query_hash', parse_response_by_content_type: false }
end

it 'use the setting' do
post '/users', params: { nickname: 'willnet' }.to_json, headers: { 'Content-Type' => 'application/json' }
assert_schema_conform
assert_schema_conform(200)
end
end
end
Expand Down