aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/validations_test.rb
diff options
context:
space:
mode:
authorTobias Lütke <tobias.luetke@gmail.com>2006-12-06 00:13:31 +0000
committerTobias Lütke <tobias.luetke@gmail.com>2006-12-06 00:13:31 +0000
commitcdad2d41e18977dd66518efddcb83c2107f0e057 (patch)
treebc7b29ec491f534cd2ca91385658d404e3382452 /activerecord/test/validations_test.rb
parent8dea60b0c3a965c169127e0f1f4777bfbbc5e16d (diff)
downloadrails-cdad2d41e18977dd66518efddcb83c2107f0e057.tar.gz
rails-cdad2d41e18977dd66518efddcb83c2107f0e057.tar.bz2
rails-cdad2d41e18977dd66518efddcb83c2107f0e057.zip
Consolidated different create and create! versions to call through to the base class with scope. This fixes inconsistencies, especially related to protected attribtues.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5684 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/validations_test.rb')
-rwxr-xr-xactiverecord/test/validations_test.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/activerecord/test/validations_test.rb b/activerecord/test/validations_test.rb
index 92a11778ef..f193261eb8 100755
--- a/activerecord/test/validations_test.rb
+++ b/activerecord/test/validations_test.rb
@@ -1,6 +1,7 @@
require 'abstract_unit'
require 'fixtures/topic'
require 'fixtures/reply'
+require 'fixtures/person'
require 'fixtures/developer'
# The following methods in Topic are used in test_conditional_validation_*
@@ -14,6 +15,12 @@ class Topic
end
end
+class ProtectedPerson < ActiveRecord::Base
+ set_table_name 'people'
+ attr_accessor :addon
+ attr_protected :first_name
+end
+
class ValidationsTest < Test::Unit::TestCase
fixtures :topics, :developers
@@ -94,6 +101,24 @@ class ValidationsTest < Test::Unit::TestCase
end
end
+ def test_create_with_exceptions_using_scope_for_protected_attributes
+ assert_nothing_raised do
+ ProtectedPerson.with_scope( :create => { :first_name => "Mary" } ) do
+ person = ProtectedPerson.create! :addon => "Addon"
+ assert_equal person.first_name, "Mary", "scope should ignore attr_protected"
+ end
+ end
+ end
+
+ def test_create_with_exceptions_using_scope_and_empty_attributes
+ assert_nothing_raised do
+ ProtectedPerson.with_scope( :create => { :first_name => "Mary" } ) do
+ person = ProtectedPerson.create!
+ assert_equal person.first_name, "Mary", "should be ok when no attributes are passed to create!"
+ end
+ end
+ end
+
def test_single_error_per_attr_iteration
r = Reply.new
r.save