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
This commit is contained in:
Tobias Lütke
2006-12-06 00:13:31 +00:00
parent 8dea60b0c3
commit cdad2d41e1
5 changed files with 71 additions and 24 deletions

View File

@@ -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