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 exception super #2276

Merged
merged 5 commits into from
Aug 11, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* [#2267](https://github.com/ruby-grape/grape/pull/2267): Standardized English error messages - [@dblock](https://github.com/dblock).
* [#2272](https://github.com/ruby-grape/grape/pull/2272): Added error on param init when provided type does not have `[]` coercion method, previously validation silently failed for any value - [@vasfed](https://github.com/Vasfed).
* [#2274](https://github.com/ruby-grape/grape/pull/2274): Error middleware support using rack util's symbols as status - [@dhruvCW](https://github.com/dhruvCW).
* [#2276](https://github.com/ruby-grape/grape/pull/2276): Fix exception super - [@ericproulx](https://github.com/ericproulx).
* Your contribution here.

#### Fixes
Expand Down
4 changes: 2 additions & 2 deletions lib/grape/exceptions/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ class Base < StandardError
BASE_ATTRIBUTES_KEY = 'grape.errors.attributes'
FALLBACK_LOCALE = :en

attr_reader :status, :message, :headers
ericproulx marked this conversation as resolved.
Show resolved Hide resolved
attr_reader :status, :headers

def initialize(status: nil, message: nil, headers: nil, **_options)
@status = status
@message = message
@headers = headers
super(message)
ericproulx marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be two lines above :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it matter? If you think it does, PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end

def [](index)
Expand Down
4 changes: 0 additions & 4 deletions lib/grape/exceptions/validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ def initialize(params:, message: nil, **args)
def as_json(*_args)
to_s
end

def to_s
message
end
end
end
end
16 changes: 16 additions & 0 deletions spec/grape/exceptions/base_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
# frozen_string_literal: true

describe Grape::Exceptions::Base do
describe '#to_s' do
subject { described_class.new(message: message).to_s }

let(:message) { 'a_message' }

it { is_expected.to eq(message) }
end

describe '#message' do
subject { described_class.new(message: message).message }

let(:message) { 'a_message' }

it { is_expected.to eq(message) }
end

describe '#compose_message' do
subject { described_class.new.send(:compose_message, key, **attributes) }

Expand Down