Changeset 241
- Timestamp:
- 12/21/04 23:41:07 (4 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/validations.rb (modified) (4 diffs)
- trunk/activerecord/test/validations_test.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r233 r241 1 1 *SVN* 2 3 * Fixed validates_{confirmation,acceptance}_of to only happen when the virtual attributes are not nil #348 [dpiddy@gmail.com] 2 4 3 5 * Added a require_association hook on const_missing that makes it possible to use any model class without requiring it first. This makes STI look like: trunk/activerecord/lib/active_record/validations.rb
r226 r241 75 75 # 76 76 # The person has to already have a password attribute (a column in the people table), but the password_confirmation is virtual. 77 # It exists only as an in-memory variable for validating the password. This check is performed on save by default. 77 # It exists only as an in-memory variable for validating the password. This check is performed only if password_confirmation 78 # is not nil and by default on save. 78 79 # 79 80 # Configuration options: … … 86 87 for attr_name in attr_names 87 88 attr_accessor "#{attr_name}_confirmation" 88 class_eval(%(#{validation_method(configuration[:on])} %{errors.add('#{attr_name}', "#{configuration[:message]}") unless #{attr_name} == #{attr_name}_confirmation}))89 class_eval(%(#{validation_method(configuration[:on])} %{errors.add('#{attr_name}', "#{configuration[:message]}") unless #{attr_name}_confirmation.nil? or #{attr_name} == #{attr_name}_confirmation})) 89 90 end 90 91 end … … 97 98 # end 98 99 # 99 # The terms_of_service attribute is entirely virtual. No database column is needed. This check is performed on save by default. 100 # The terms_of_service attribute is entirely virtual. No database column is needed. This check is performed only if 101 # terms_of_service is not nil and by default on save. 100 102 # 101 103 # Configuration options: … … 110 112 for attr_name in attr_names 111 113 attr_accessor(attr_name) 112 class_eval(%(#{validation_method(configuration[:on])} %{errors.add('#{attr_name}', '#{configuration[:message]}') unless #{attr_name} == "1"}))114 class_eval(%(#{validation_method(configuration[:on])} %{errors.add('#{attr_name}', '#{configuration[:message]}') unless #{attr_name}.nil? or #{attr_name} == "1"})) 113 115 end 114 116 end trunk/activerecord/test/validations_test.rb
r217 r241 126 126 end 127 127 128 def test_title_confirmation_no_confirm 129 Topic.validates_confirmation_of(:title) 130 131 t = Topic.create("title" => "We should not be confirmed") 132 assert t.save 133 end 134 128 135 def test_title_confirmation 129 136 Topic.validates_confirmation_of(:title) 130 137 131 t = Topic.create("title" => "We should be confirmed" )138 t = Topic.create("title" => "We should be confirmed","title_confirmation" => "") 132 139 assert !t.save 133 140 134 141 t.title_confirmation = "We should be confirmed" 142 assert t.save 143 end 144 145 def test_terms_of_service_agreement_no_acceptance 146 Topic.validates_acceptance_of(:terms_of_service, :on => :create) 147 148 t = Topic.create("title" => "We should not be confirmed") 135 149 assert t.save 136 150 end … … 139 153 Topic.validates_acceptance_of(:terms_of_service, :on => :create) 140 154 141 t = Topic.create("title" => "We should be confirmed" )155 t = Topic.create("title" => "We should be confirmed","terms_of_service" => "") 142 156 assert !t.save 143 157 assert_equal "must be accepted", t.errors.on(:terms_of_service) … … 151 165 Topic.validates_acceptance_of(:eula, :message => "must be abided", :on => :create) 152 166 153 t = Topic.create("title" => "We should be confirmed" )167 t = Topic.create("title" => "We should be confirmed","eula" => "") 154 168 assert !t.save 155 169 assert_equal "must be abided", t.errors.on(:eula)