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

Ticket #5380: validations_test.patch

File validations_test.patch, 0.8 kB (added by chris@seagul.co.uk, 2 years ago)
  • activerecord/test/validations_test.rb

    old new  
    777777    r.topic = Topic.find :first 
    778778    assert r.valid? 
    779779  end 
     780   
     781  def test_should_ignore_private_method_with_same_name_as_attribute 
     782    Object.class_eval do 
     783      def title(arg) 'title'; end 
     784      private :title 
     785    end 
     786     
     787    topic_class = Class.new(ActiveRecord::Base) do 
     788      set_table_name :topics 
     789    end 
     790    topic_class.validates_presence_of(:title) 
     791     
     792    topic = topic_class.new 
     793    assert ! topic.valid? 
     794     
     795    topic = topic_class.new(:title => 'title') 
     796    assert topic.valid? 
     797     
     798    Object.class_eval do 
     799      remove_method :title 
     800    end 
     801  end 
     802   
    780803end 
    781804 
    782805