fcc534ed76
This will render the error message on :#{attribute}_confirmation instead of on attribute itself. When rendering confirmation errors inline on the form with form builders such as SimpleForm and Formtastic it is confusing to the ender user to see the confirmation error message on the attribute element. Instead it makes more sense to have this validation error render on the confirmation field instead. The i18n message has been updated for the confirmation validator error message to include the original attribute name.
56 lines
1.1 KiB
Ruby
56 lines
1.1 KiB
Ruby
# encoding: utf-8
|
|
require 'cases/helper'
|
|
|
|
require 'models/topic'
|
|
require 'models/person'
|
|
|
|
class ConfirmationValidationTest < ActiveModel::TestCase
|
|
|
|
def teardown
|
|
Topic.reset_callbacks(:validate)
|
|
end
|
|
|
|
def test_no_title_confirmation
|
|
Topic.validates_confirmation_of(:title)
|
|
|
|
t = Topic.new(:author_name => "Plutarch")
|
|
assert t.valid?
|
|
|
|
t.title_confirmation = "Parallel Lives"
|
|
assert t.invalid?
|
|
|
|
t.title_confirmation = nil
|
|
t.title = "Parallel Lives"
|
|
assert t.valid?
|
|
|
|
t.title_confirmation = "Parallel Lives"
|
|
assert t.valid?
|
|
end
|
|
|
|
def test_title_confirmation
|
|
Topic.validates_confirmation_of(:title)
|
|
|
|
t = Topic.new("title" => "We should be confirmed","title_confirmation" => "")
|
|
assert t.invalid?
|
|
|
|
t.title_confirmation = "We should be confirmed"
|
|
assert t.valid?
|
|
end
|
|
|
|
def test_validates_confirmation_of_for_ruby_class
|
|
Person.validates_confirmation_of :karma
|
|
|
|
p = Person.new
|
|
p.karma_confirmation = "None"
|
|
assert p.invalid?
|
|
|
|
assert_equal ["doesn't match karma"], p.errors[:karma_confirmation]
|
|
|
|
p.karma = "None"
|
|
assert p.valid?
|
|
ensure
|
|
Person.reset_callbacks(:validate)
|
|
end
|
|
|
|
end
|