Skip to content

Commit edc6abe

Browse files
authored
Fix exception super (#2276)
* Add super(message) + spec * Fix rubocop * Add changelog * Remove message attr_read * Add message spec
1 parent 362724d commit edc6abe

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* [#2267](https://github.com/ruby-grape/grape/pull/2267): Standardized English error messages - [@dblock](https://github.com/dblock).
1212
* [#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).
1313
* [#2274](https://github.com/ruby-grape/grape/pull/2274): Error middleware support using rack util's symbols as status - [@dhruvCW](https://github.com/dhruvCW).
14+
* [#2276](https://github.com/ruby-grape/grape/pull/2276): Fix exception super - [@ericproulx](https://github.com/ericproulx).
1415
* Your contribution here.
1516

1617
#### Fixes

lib/grape/exceptions/base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ class Base < StandardError
77
BASE_ATTRIBUTES_KEY = 'grape.errors.attributes'
88
FALLBACK_LOCALE = :en
99

10-
attr_reader :status, :message, :headers
10+
attr_reader :status, :headers
1111

1212
def initialize(status: nil, message: nil, headers: nil, **_options)
1313
@status = status
14-
@message = message
1514
@headers = headers
15+
super(message)
1616
end
1717

1818
def [](index)

lib/grape/exceptions/validation.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ def initialize(params:, message: nil, **args)
2121
def as_json(*_args)
2222
to_s
2323
end
24-
25-
def to_s
26-
message
27-
end
2824
end
2925
end
3026
end

spec/grape/exceptions/base_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
# frozen_string_literal: true
22

33
describe Grape::Exceptions::Base do
4+
describe '#to_s' do
5+
subject { described_class.new(message: message).to_s }
6+
7+
let(:message) { 'a_message' }
8+
9+
it { is_expected.to eq(message) }
10+
end
11+
12+
describe '#message' do
13+
subject { described_class.new(message: message).message }
14+
15+
let(:message) { 'a_message' }
16+
17+
it { is_expected.to eq(message) }
18+
end
19+
420
describe '#compose_message' do
521
subject { described_class.new.send(:compose_message, key, **attributes) }
622

0 commit comments

Comments
 (0)