Skip to content

Do not repeat the same error messages #586

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

Merged
merged 3 commits into from
Mar 5, 2014
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 @@ -21,6 +21,7 @@ Next Release

#### Fixes

* [#586](https://github.com/intridea/grape/pull/586): Do not repeat the same validation error messages - [@kiela](https://github.com/kiela)
* [#508](https://github.com/intridea/grape/pull/508): Allow parameters, such as content encoding, in `content_type` - [@dm1try](https://github.com/dm1try).
* [#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).
* [#495](https://github.com/intridea/grape/pull/495): Fixed `ParamsScope#params` for parameters nested inside arrays - [@asross](https://github.com/asross).
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/exceptions/validation_errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def each
private

def full_messages
map { |attribute, error| full_message(attribute, error) }
map { |attribute, error| full_message(attribute, error) }.uniq
end

def full_message(attribute, error)
Expand Down
19 changes: 19 additions & 0 deletions spec/grape/exceptions/validation_errors_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'spec_helper'
require 'ostruct'

describe Grape::Exceptions::ValidationErrors do
let(:validation_message) { "FooBar is invalid" }
let(:validation_error) { OpenStruct.new(param: validation_message) }

context "message" do
context "is not repeated" do
let(:error) do
described_class.new(errors: [validation_error, validation_error])
end
subject(:message) { error.message.split(',').map(&:strip) }

it { expect(message).to include validation_message }
it { expect(message.size).to eq 1 }
end
end
end