Skip to content

Commit

Permalink
Fix exception super (#2276)
Browse files Browse the repository at this point in the history
* Add super(message) + spec

* Fix rubocop

* Add changelog

* Remove message attr_read

* Add message spec
  • Loading branch information
ericproulx authored Aug 11, 2022
1 parent 362724d commit edc6abe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
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
attr_reader :status, :headers

def initialize(status: nil, message: nil, headers: nil, **_options)
@status = status
@message = message
@headers = headers
super(message)
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

0 comments on commit edc6abe

Please sign in to comment.