Skip to content

Commit

Permalink
Merge pull request #16 from willnet/fix-warnings
Browse files Browse the repository at this point in the history
Fix warnings
  • Loading branch information
willnet authored Jul 15, 2022
2 parents abddcb5 + ab908cf commit 273ae15
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
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

0 comments on commit 273ae15

Please sign in to comment.