Skip to content

Commit 0a1fe13

Browse files
committed
Merge pull request #586 from kiela/master
Do not repeat the same error messages
2 parents 70db3f7 + 1328a03 commit 0a1fe13

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Next Release
2121

2222
#### Fixes
2323

24+
* [#586](https://github.com/intridea/grape/pull/586): Do not repeat the same validation error messages - [@kiela](https://github.com/kiela)
2425
* [#508](https://github.com/intridea/grape/pull/508): Allow parameters, such as content encoding, in `content_type` - [@dm1try](https://github.com/dm1try).
2526
* [#492](https://github.com/intridea/grape/pull/492): Don't allow to have nil value when a param is required and has a list of allowed values - [@Antti](https://github.com/Antti).
2627
* [#495](https://github.com/intridea/grape/pull/495): Fixed `ParamsScope#params` for parameters nested inside arrays - [@asross](https://github.com/asross).

lib/grape/exceptions/validation_errors.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def each
2727
private
2828

2929
def full_messages
30-
map { |attribute, error| full_message(attribute, error) }
30+
map { |attribute, error| full_message(attribute, error) }.uniq
3131
end
3232

3333
def full_message(attribute, error)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require 'spec_helper'
2+
require 'ostruct'
3+
4+
describe Grape::Exceptions::ValidationErrors do
5+
let(:validation_message) { "FooBar is invalid" }
6+
let(:validation_error) { OpenStruct.new(param: validation_message) }
7+
8+
context "message" do
9+
context "is not repeated" do
10+
let(:error) do
11+
described_class.new(errors: [validation_error, validation_error])
12+
end
13+
subject(:message) { error.message.split(',').map(&:strip) }
14+
15+
it { expect(message).to include validation_message }
16+
it { expect(message.size).to eq 1 }
17+
end
18+
end
19+
end

0 commit comments

Comments
 (0)