diff options
Diffstat (limited to 'activerecord/test')
-rwxr-xr-x | activerecord/test/cases/validations_test.rb | 35 | ||||
-rwxr-xr-x | activerecord/test/models/topic.rb | 5 |
2 files changed, 20 insertions, 20 deletions
diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb index 1bcd72c71f..97ac22eaf3 100755 --- a/activerecord/test/cases/validations_test.rb +++ b/activerecord/test/cases/validations_test.rb @@ -8,12 +8,15 @@ require 'models/warehouse_thing' # The following methods in Topic are used in test_conditional_validation_* class Topic + has_many :unique_replies, :dependent => :destroy, :foreign_key => "parent_id" + has_many :silly_unique_replies, :dependent => :destroy, :foreign_key => "parent_id" + def condition_is_true - return true + true end def condition_is_true_but_its_not - return false + false end end @@ -34,11 +37,6 @@ end class SillyUniqueReply < UniqueReply end -class Topic < ActiveRecord::Base - has_many :unique_replies, :dependent => :destroy, :foreign_key => "parent_id" - has_many :silly_unique_replies, :dependent => :destroy, :foreign_key => "parent_id" -end - class Wizard < ActiveRecord::Base self.abstract_class = true @@ -55,6 +53,7 @@ end class Thaumaturgist < IneptWizard end + class ValidationsTest < ActiveRecord::TestCase fixtures :topics, :developers, 'warehouse-things' @@ -958,19 +957,22 @@ class ValidationsTest < ActiveRecord::TestCase def test_optionally_validates_length_of_using_within_utf8 with_kcode('UTF8') do - Topic.validates_length_of :title, :content, :within => 3..5, :allow_nil => true + Topic.validates_length_of :title, :within => 3..5, :allow_nil => true - t = Topic.create('title' => '一二三', 'content' => '一二三四五') - assert t.valid? + t = Topic.create(:title => "一二三四五") + assert t.valid?, t.errors.inspect + + t = Topic.create(:title => "一二三") + assert t.valid?, t.errors.inspect t.title = nil - assert t.valid? + assert t.valid?, t.errors.inspect end end def test_optionally_validates_length_of_using_within_on_create_utf8 with_kcode('UTF8') do - Topic.validates_length_of :title, :content, :within => 5..10, :on => :create, :too_long => "長すぎます: %d" + Topic.validates_length_of :title, :within => 5..10, :on => :create, :too_long => "長すぎます: %d" t = Topic.create("title" => "一二三四五六七八九十A", "content" => "whatever") assert !t.save @@ -993,7 +995,7 @@ class ValidationsTest < ActiveRecord::TestCase def test_optionally_validates_length_of_using_within_on_update_utf8 with_kcode('UTF8') do - Topic.validates_length_of :title, :content, :within => 5..10, :on => :update, :too_short => "短すぎます: %d" + Topic.validates_length_of :title, :within => 5..10, :on => :update, :too_short => "短すぎます: %d" t = Topic.create("title" => "一二三4", "content" => "whatever") assert !t.save @@ -1004,12 +1006,11 @@ class ValidationsTest < ActiveRecord::TestCase assert t.errors.on(:title) assert_equal "短すぎます: 5", t.errors[:title] - t.title = "valid" - t.content = "一二三四五六七八九十A" + t.title = "一二三四五六七八九十A" assert !t.save - assert t.errors.on(:content) + assert t.errors.on(:title) - t.content = "一二345" + t.title = "一二345" assert t.save end end diff --git a/activerecord/test/models/topic.rb b/activerecord/test/models/topic.rb index 0ef7be97d3..d2503b78df 100755 --- a/activerecord/test/models/topic.rb +++ b/activerecord/test/models/topic.rb @@ -26,7 +26,7 @@ class Topic < ActiveRecord::Base end named_scope :named_extension, :extend => NamedExtension named_scope :multiple_extensions, :extend => [MultipleExtensionTwo, MultipleExtensionOne] - + has_many :replies, :dependent => :destroy, :foreign_key => "parent_id" serialize :content @@ -42,7 +42,6 @@ class Topic < ActiveRecord::Base id end - protected def approved=(val) @custom_approved = val @@ -62,4 +61,4 @@ class Topic < ActiveRecord::Base self.author_email_address = 'test@test.com' end end -end
\ No newline at end of file +end |