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:
parent
58bdf2790b
commit
1f99bdb620
1 changed files with 8 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue