Skip to content

Commit c54cd8f

Browse files
stjhimydblock
authored andcommitted
Store message_key on Grape::Exceptions::Validation.
1 parent f8e20a2 commit c54cd8f

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
0.14.1 (Next)
22
=============
33

4-
* Your contribution here.
5-
64
* [#1216](https://github.com/ruby-grape/grape/pull/1142): Fix JSON error response when calling `error!` with non-Strings - [@jrforrest](https://github.com/jrforrest).
75
* [#1225](https://github.com/ruby-grape/grape/pull/1225): Fix `given` with nested params not returning correct declared params - [@JanStevens](https://github.com/JanStevens).
6+
* [#1227](https://github.com/ruby-grape/grape/pull/1227): Store `message_key` on Grape::Exceptions::Validation - [@stjhimy](https://github.com/sthimy).
7+
* Your contribution here.
88

99
0.14.0 (12/07/2015)
1010
===================

lib/grape/exceptions/validation.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ module Grape
44
module Exceptions
55
class Validation < Grape::Exceptions::Base
66
attr_accessor :params
7+
attr_accessor :message_key
78

89
def initialize(args = {})
910
fail 'Params are missing:' unless args.key? :params
1011
@params = args[:params]
12+
@message_key = args[:message_key]
1113
args[:message] = translate_message(args[:message_key]) if args.key? :message_key
1214
super
1315
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'spec_helper'
2+
3+
describe Grape::Exceptions::Validation do
4+
it 'fails when params are missing' do
5+
expect { Grape::Exceptions::Validation.new(message_key: 'presence') }.to raise_error(RuntimeError, 'Params are missing:')
6+
end
7+
8+
it 'store message_key' do
9+
expect(Grape::Exceptions::Validation.new(params: ['id'], message_key: 'presence').message_key).to eq('presence')
10+
end
11+
end

0 commit comments

Comments
 (0)