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

Ticket #8218: reload_models.patch

File reload_models.patch, 3.9 kB (added by JakeB, 1 year ago)
  • activerecord/test/fixtures/topic.rb

    old new  
    1414    id 
    1515  end 
    1616 
     17  # The following two methods are used in test_conditional_validation_* 
     18  def condition_is_true 
     19    return true 
     20  end 
     21 
     22  def condition_is_true_but_its_not 
     23    return false 
     24  end 
     25 
    1726  protected 
    1827    def default_written_on 
    1928      self.written_on = Time.now unless attribute_present?("written_on") 
  • activerecord/test/validations_test.rb

    old new  
    33require 'fixtures/reply' 
    44require 'fixtures/developer' 
    55 
    6 # The following methods in Topic are used in test_conditional_validation_* 
    7 class Topic 
    8   def condition_is_true 
    9     return true 
    10   end 
    11  
    12   def condition_is_true_but_its_not 
    13     return false 
    14   end 
    15 end 
    16  
    176class ValidationsTest < Test::Unit::TestCase 
    187  fixtures :topics, :developers 
    198 
     
    2110    Topic.write_inheritable_attribute(:validate, nil) 
    2211    Topic.write_inheritable_attribute(:validate_on_create, nil) 
    2312    Topic.write_inheritable_attribute(:validate_on_update, nil) 
     13 
     14    # Reset the model classes used 
     15    [:Reply, :SillyReply, :Topic, :Developer, :DeveloperSalary, :DeveloperWithAggregate, :DeveloperWithBeforeDestroyRaise].each do |c| 
     16      Object.send(:remove_const, c) 
     17    end 
     18    load 'fixtures/topic.rb' 
     19    load 'fixtures/reply.rb' 
     20    load 'fixtures/developer.rb' 
    2421  end 
    2522 
    2623  def test_single_field_validation 
     
    892899  def test_validates_format_of_with_custom_error_using_quotes 
    893900    Developer.validates_format_of :name, :with => /^(A-Z*)$/, :message=> "format 'single' and \"double\" quotes" 
    894901    d = Developer.new 
    895     d.name = d.name_confirmation = "John 32" 
     902    d.name = d.name = "John 32" 
    896903    assert !d.valid? 
    897904    assert_equal "format 'single' and \"double\" quotes", d.errors.on(:name) 
    898905  end 
     
    910917    d = Developer.new 
    911918    d.name = "Jeffrey" 
    912919    assert !d.valid? 
    913     assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:name).first 
     920    assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:name) 
    914921  end 
    915922 
    916923  def test_validates_length_of_with_custom_too_short_using_quotes 
     
    918925    d = Developer.new 
    919926    d.name = "Joe" 
    920927    assert !d.valid? 
    921     assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:name).first 
     928    assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:name) 
    922929  end 
    923930 
    924931  def test_validates_length_of_with_custom_message_using_quotes 
     
    926933    d = Developer.new 
    927934    d.name = "Joe" 
    928935    assert !d.valid? 
    929     assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:name).first 
     936    assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:name) 
    930937  end 
    931938 
    932939  def test_validates_presence_of_with_custom_message_using_quotes 
     
    942949    d = Developer.new 
    943950    d.name = "David" 
    944951    assert !d.valid? 
    945     assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:name).first 
     952    assert_equal "This string contains 'single' and \"double\" quotes", d.errors.on(:name) 
    946953  end 
    947954 
    948955  def test_validates_associated_with_custom_message_using_quotes 
     
    951958    r = Reply.create("title" => "A reply", "content" => "with content!") 
    952959    r.topic = Topic.create("title" => "uhohuhoh") 
    953960    assert !r.valid? 
    954     assert_equal "This string contains 'single' and \"double\" quotes", r.errors.on(:topic).first 
     961    assert_equal "This string contains 'single' and \"double\" quotes", r.errors.on(:topic) 
    955962  end 
    956963 
    957964  def test_conditional_validation_using_method_true