File tree Expand file tree Collapse file tree 3 files changed +17
-1
lines changed Expand file tree Collapse file tree 3 files changed +17
-1
lines changed Original file line number Diff line number Diff line change 3
3
4
4
* Your contribution here.
5
5
6
+ #### Features
7
+ * [ #1366 ] ( https://github.com/ruby-grape/grape/pull/1366 ) : Store ` message_key ` on ` Grape::Exceptions::Validation ` - [ @mkou ] ( https://github.com/mkou ) .
8
+
6
9
0.16.2 (4/12/2016)
7
10
==================
8
11
Original file line number Diff line number Diff line change @@ -9,7 +9,10 @@ class Validation < Grape::Exceptions::Base
9
9
def initialize ( args = { } )
10
10
fail 'Params are missing:' unless args . key? :params
11
11
@params = args [ :params ]
12
- args [ :message ] = translate_message ( args [ :message ] ) if args . key? :message
12
+ if args . key? ( :message )
13
+ @message_key = args [ :message ] if args [ :message ] . is_a? ( Symbol )
14
+ args [ :message ] = translate_message ( args [ :message ] )
15
+ end
13
16
super
14
17
end
15
18
Original file line number Diff line number Diff line change 4
4
it 'fails when params are missing' do
5
5
expect { Grape ::Exceptions ::Validation . new ( message : 'presence' ) } . to raise_error ( RuntimeError , 'Params are missing:' )
6
6
end
7
+ context 'when message is a symbol' do
8
+ it 'stores message_key' do
9
+ expect ( Grape ::Exceptions ::Validation . new ( params : [ 'id' ] , message : :presence ) . message_key ) . to eq ( :presence )
10
+ end
11
+ end
12
+ context 'when message is a String' do
13
+ it 'does not store the message_key' do
14
+ expect ( Grape ::Exceptions ::Validation . new ( params : [ 'id' ] , message : 'presence' ) . message_key ) . to eq ( nil )
15
+ end
16
+ end
7
17
end
You can’t perform that action at this time.
0 commit comments