Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #785: validates_confirmation_of_ticket_785.diff

File validates_confirmation_of_ticket_785.diff, 1.6 kB (added by z@wzph.com, 2 years ago)
  • rails/activerecord/test/validations_test.rb

    old new  
    172172    assert developer.save 
    173173  end 
    174174 
    175   def test_title_confirmation_no_confirm 
     175  def test_no_title_confirmation 
    176176    Topic.validates_confirmation_of(:title) 
    177177 
    178     t = Topic.create("title" => "We should not be confirmed") 
     178    t = Topic.create( "author_name" => "Plutarch") 
    179179    assert t.save 
     180 
     181    t.title_confirmation = "Parallel Lives" 
     182    assert t.save 
     183 
     184    t.title_confirmation = nil 
     185    t.title = "Parallel Lives" 
     186    assert !t.save 
     187 
     188    t.title_confirmation = "Parallel Lives" 
     189    assert t.save 
    180190  end 
    181191 
    182192  def test_title_confirmation 
  • rails/activerecord/lib/active_record/validations.rb

    old new  
    333333        attr_accessor *(attr_names.map { |n| "#{n}_confirmation" }) 
    334334 
    335335        validates_each(attr_names, configuration) do |record, attr_name, value| 
    336           record.errors.add(attr_name, configuration[:message]) unless record.send("#{attr_name}_confirmation").nil? or value == record.send("#{attr_name}_confirmation") 
     336          record.errors.add(attr_name, configuration[:message]) unless record.send( attr_name ).nil? or value == record.send("#{attr_name}_confirmation") 
    337337        end 
    338338      end 
    339339