aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/validations/validations_context_test.rb
diff options
context:
space:
mode:
authorJosh Kalderimis <josh.kalderimis@gmail.com>2010-05-08 23:27:49 +0300
committerCarl Lerche <carllerche@mac.com>2010-05-08 23:51:36 +0300
commit66913a76af9969ddf12021992eeb418e270bebe2 (patch)
tree8ff5d8cf518f086979fd4e4b0633c7f8c340323e /activemodel/test/cases/validations/validations_context_test.rb
parent82485068f8b64a49cbb6529d17dd5de27c28e951 (diff)
downloadrails-66913a76af9969ddf12021992eeb418e270bebe2.tar.gz
rails-66913a76af9969ddf12021992eeb418e270bebe2.tar.bz2
rails-66913a76af9969ddf12021992eeb418e270bebe2.zip
removed use of AR in AMo tests and removed testing of scopes (:on) in individual validation tests and moved them to their own test file
Diffstat (limited to 'activemodel/test/cases/validations/validations_context_test.rb')
-rw-r--r--activemodel/test/cases/validations/validations_context_test.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/activemodel/test/cases/validations/validations_context_test.rb b/activemodel/test/cases/validations/validations_context_test.rb
new file mode 100644
index 0000000000..06bd8e7903
--- /dev/null
+++ b/activemodel/test/cases/validations/validations_context_test.rb
@@ -0,0 +1,41 @@
+# encoding: utf-8
+require 'cases/helper'
+require 'cases/tests_database'
+
+require 'models/topic'
+
+class ValidationsContextTest < ActiveRecord::TestCase
+ include ActiveModel::TestsDatabase
+
+ def teardown
+ Topic.reset_callbacks(:validate)
+ Topic._validators.clear
+ end
+
+ ERROR_MESSAGE = "Validation error from validator"
+
+ class ValidatorThatAddsErrors < ActiveModel::Validator
+ def validate(record)
+ record.errors[:base] << ERROR_MESSAGE
+ end
+ end
+
+ test "with a class that adds errors on update and validating a new model with no arguments" do
+ Topic.validates_with(ValidatorThatAddsErrors, :on => :create)
+ topic = Topic.new
+ assert topic.valid?, "Validation doesn't run on create if 'on' is set to update"
+ end
+
+ test "with a class that adds errors on update and validating a new model" do
+ Topic.validates_with(ValidatorThatAddsErrors, :on => :update)
+ topic = Topic.new
+ assert topic.valid?(:create), "Validation doesn't run on create if 'on' is set to update"
+ end
+
+ test "with a class that adds errors on create and validating a new model" do
+ Topic.validates_with(ValidatorThatAddsErrors, :on => :create)
+ topic = Topic.new
+ assert topic.invalid?(:create), "Validation does run on create if 'on' is set to create"
+ assert topic.errors[:base].include?(ERROR_MESSAGE)
+ end
+end \ No newline at end of file