2009-03-20 11:07:49 -04:00
|
|
|
# encoding: utf-8
|
|
|
|
require 'cases/helper'
|
2009-03-20 12:02:12 -04:00
|
|
|
require 'cases/tests_database'
|
2009-03-20 11:07:49 -04:00
|
|
|
|
|
|
|
require 'models/topic'
|
|
|
|
require 'models/developer'
|
2009-03-20 18:21:27 -04:00
|
|
|
require 'models/person'
|
2009-03-20 11:07:49 -04:00
|
|
|
|
|
|
|
class ConfirmationValidationTest < ActiveModel::TestCase
|
2009-03-20 12:02:12 -04:00
|
|
|
include ActiveModel::TestsDatabase
|
2009-03-20 11:07:49 -04:00
|
|
|
|
2009-12-23 07:30:58 -05:00
|
|
|
def teardown
|
|
|
|
Topic.reset_callbacks(:validate)
|
|
|
|
end
|
2009-03-20 11:07:49 -04:00
|
|
|
|
|
|
|
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.valid?
|
|
|
|
|
|
|
|
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.create("title" => "We should be confirmed","title_confirmation" => "")
|
|
|
|
assert !t.save
|
|
|
|
|
|
|
|
t.title_confirmation = "We should be confirmed"
|
|
|
|
assert t.save
|
|
|
|
end
|
|
|
|
|
2009-03-20 18:21:27 -04:00
|
|
|
def test_validates_confirmation_of_for_ruby_class
|
2009-12-23 07:30:58 -05:00
|
|
|
Person.validates_confirmation_of :karma
|
2009-03-20 18:21:27 -04:00
|
|
|
|
2009-12-23 07:30:58 -05:00
|
|
|
p = Person.new
|
|
|
|
p.karma_confirmation = "None"
|
|
|
|
assert p.invalid?
|
2009-03-20 18:21:27 -04:00
|
|
|
|
2009-12-23 07:30:58 -05:00
|
|
|
assert_equal ["doesn't match confirmation"], p.errors[:karma]
|
2009-03-20 18:21:27 -04:00
|
|
|
|
2009-12-23 07:30:58 -05:00
|
|
|
p.karma = "None"
|
|
|
|
assert p.valid?
|
|
|
|
ensure
|
|
|
|
Person.reset_callbacks(:validate)
|
2009-03-20 18:21:27 -04:00
|
|
|
end
|
|
|
|
|
2009-03-20 11:07:49 -04:00
|
|
|
end
|