From 5c245b91d2dbc0b300e8193310b3f950d0cf6c4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 10 May 2010 12:28:38 +0300 Subject: Make sure valid? preceives the context as in ActiveModel API (ht: Carlos Antonio) --- activerecord/test/cases/validations_test.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb index e1fb911cc9..b873babc36 100644 --- a/activerecord/test/cases/validations_test.rb +++ b/activerecord/test/cases/validations_test.rb @@ -62,6 +62,23 @@ class ValidationsTest < ActiveRecord::TestCase assert_equal ["is Wrong Update"], r.errors[:title], "A reply with a bad content should contain an error" end + def test_error_on_given_context + r = WrongReply.new + assert !r.valid?(:special_case) + assert "Invalid", r.errors[:title].join + + r.title = "secret" + r.content = "Good" + assert r.valid?(:special_case) + + r.title = nil + assert !r.save(:context => :special_case) + assert "Invalid", r.errors[:title].join + + r.title = "secret" + assert r.save(:context => :special_case) + end + def test_invalid_record_exception assert_raise(ActiveRecord::RecordInvalid) { WrongReply.create! } assert_raise(ActiveRecord::RecordInvalid) { WrongReply.new.save! } -- cgit v1.2.3