From cdad2d41e18977dd66518efddcb83c2107f0e057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20L=C3=BCtke?= Date: Wed, 6 Dec 2006 00:13:31 +0000 Subject: 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 --- activerecord/test/validations_test.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'activerecord/test') 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 -- cgit v1.2.3