1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Add test case for interpolation with passing of data along with record attribute in error message, where a proc is passed.

This commit is contained in:
Vipul A M 2016-04-05 14:18:44 +05:30
parent 58bdf2790b
commit 1f99bdb620

View file

@ -452,4 +452,12 @@ class ValidationsTest < ActiveModel::TestCase
assert t.invalid?
assert_equal ["You have failed me for the last time, Admiral."], t.errors[:title]
end
def test_validation_with_message_as_proc_that_takes_record_and_data_as_a_parameters
Topic.validates_presence_of(:title, message: proc { |record, data| "#{data[:attribute]} is missing. You have failed me for the last time, #{record.author_name}." })
t = Topic.new(author_name: 'Admiral')
assert t.invalid?
assert_equal ["Title is missing. You have failed me for the last time, Admiral."], t.errors[:title]
end
end