diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2007-11-25 22:34:46 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2007-11-25 22:34:46 +0000 |
commit | 18c663eb126c9adc11852dbbc1a1fa2f9e05aa28 (patch) | |
tree | a8faab48687d438c21ff9caf05a7b359a41016e8 | |
parent | 8a59ee921aa00ac7875afb5525d793694b1e8fe8 (diff) | |
download | rails-18c663eb126c9adc11852dbbc1a1fa2f9e05aa28.tar.gz rails-18c663eb126c9adc11852dbbc1a1fa2f9e05aa28.tar.bz2 rails-18c663eb126c9adc11852dbbc1a1fa2f9e05aa28.zip |
Allow validates_acceptance_of to use a real attribute instead of only virtual (so you can record that the acceptance occured) (closes #7457) [ambethia]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8208 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/validations.rb | 6 | ||||
-rwxr-xr-x | activerecord/test/validations_test.rb | 9 |
3 files changed, 14 insertions, 3 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 687aed9874..97132e3fdb 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Allow validates_acceptance_of to use a real attribute instead of only virtual (so you can record that the acceptance occured) #7457 [ambethia] + * DateTimes use Ruby's default calendar reform setting. #10201 [Geoff Buesing] * Dynamic finders on association collections respect association :order and :limit. #10211, #10227 [Patrick Joyce, Rick Olson, Jack Danger Canty] diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index 21d57576f8..bad07dd5c4 100755 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -414,8 +414,8 @@ module ActiveRecord # validates_acceptance_of :eula, :message => "must be abided" # end # - # The terms_of_service attribute is entirely virtual. No database column is needed. This check is performed only if - # terms_of_service is not nil and by default on save. + # If the database column does not exist, the terms_of_service attribute is entirely virtual. This check is + # performed only if terms_of_service is not nil and by default on save. # # Configuration options: # * <tt>message</tt> - A custom error message (default is: "must be accepted") @@ -433,7 +433,7 @@ 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 + attr_accessor *attr_names.reject { |name| column_names.include? name.to_s } validates_each(attr_names,configuration) do |record, attr_name, value| record.errors.add(attr_name, configuration[:message]) unless value == configuration[:accept] diff --git a/activerecord/test/validations_test.rb b/activerecord/test/validations_test.rb index 03d5da4990..263aba7747 100755 --- a/activerecord/test/validations_test.rb +++ b/activerecord/test/validations_test.rb @@ -25,6 +25,10 @@ class UniqueReply < Reply validates_uniqueness_of :content, :scope => 'parent_id' end +class PlagiarizedReply < Reply + validates_acceptance_of :author_name +end + class SillyUniqueReply < UniqueReply end @@ -292,6 +296,11 @@ class ValidationsTest < Test::Unit::TestCase assert t.save end + def test_validates_acceptance_of_as_database_column + reply = PlagiarizedReply.create("author_name" => "Dan Brown") + assert_equal "Dan Brown", reply["author_name"] + end + def test_validate_presences Topic.validates_presence_of(:title, :content) |