mirror of
https://github.com/github/rails.git
synced 2026-02-03 18:55:29 -05:00
Fix that validates_acceptance_of still works for non-existent tables (useful for bootstrapping new databases). Closes #10474 [hasmanyjosh]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8377 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Fix that validates_acceptance_of still works for non-existent tables (useful for bootstrapping new databases). Closes #10474 [hasmanyjosh]
|
||||
|
||||
* Ensure that the :uniq option for has_many :through associations retains the order. #10463 [remvee]
|
||||
|
||||
* Base.exists? doesn't rescue exceptions to avoid hiding SQL errors. #10458 [Michael Klishin]
|
||||
|
||||
@@ -429,7 +429,7 @@ module ActiveRecord
|
||||
configuration = { :message => ActiveRecord::Errors.default_error_messages[:confirmation], :on => :save }
|
||||
configuration.update(attr_names.extract_options!)
|
||||
|
||||
attr_accessor *(attr_names.map { |n| "#{n}_confirmation" })
|
||||
attr_accessor(*(attr_names.map { |n| "#{n}_confirmation" }))
|
||||
|
||||
validates_each(attr_names, configuration) do |record, attr_name, value|
|
||||
record.errors.add(attr_name, configuration[:message]) unless record.send("#{attr_name}_confirmation").nil? or value == record.send("#{attr_name}_confirmation")
|
||||
@@ -462,7 +462,13 @@ module ActiveRecord
|
||||
configuration = { :message => ActiveRecord::Errors.default_error_messages[:accepted], :on => :save, :allow_nil => true, :accept => "1" }
|
||||
configuration.update(attr_names.extract_options!)
|
||||
|
||||
attr_accessor *attr_names.reject { |name| column_names.include? name.to_s }
|
||||
db_cols = begin
|
||||
column_names
|
||||
rescue ActiveRecord::StatementInvalid
|
||||
[]
|
||||
end
|
||||
names = attr_names.reject { |name| db_cols.include?(name.to_s) }
|
||||
attr_accessor(*names)
|
||||
|
||||
validates_each(attr_names,configuration) do |record, attr_name, value|
|
||||
record.errors.add(attr_name, configuration[:message]) unless value == configuration[:accept]
|
||||
|
||||
@@ -301,6 +301,14 @@ class ValidationsTest < Test::Unit::TestCase
|
||||
assert_equal "Dan Brown", reply["author_name"]
|
||||
end
|
||||
|
||||
def test_validates_acceptance_of_with_non_existant_table
|
||||
Object.const_set :IncorporealModel, Class.new(ActiveRecord::Base)
|
||||
|
||||
assert_nothing_raised ActiveRecord::StatementInvalid do
|
||||
IncorporealModel.validates_acceptance_of(:incorporeal_column)
|
||||
end
|
||||
end
|
||||
|
||||
def test_validate_presences
|
||||
Topic.validates_presence_of(:title, :content)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user