Skip to content

Commit 51e3022

Browse files
committed
Store message key on validation exception
1 parent a00b2d8 commit 51e3022

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'spec_helper'
2+
3+
describe Grape::Exceptions::Validation do
4+
it 'store message_key' do
5+
expect(Grape::Exceptions::Validation.new(params: ['id'], message_key: 'presence').message_key).to eq('presence')
6+
end
7+
end

0 commit comments

Comments
 (0)