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

Ticket #9862: add_arbitrary_attribute_method_names_on_new_active_resource_objects.diff

File add_arbitrary_attribute_method_names_on_new_active_resource_objects.diff, 1.2 kB (added by trek, 9 months ago)
  • test/base_test.rb

    old new  
    334334    assert_equal person, person.reload 
    335335  end 
    336336     
    337  
     337   
     338  def test_new_with_unknown_attributes_returns_nil 
     339    person = Person.new 
     340    assert_equal person.unknow_attribute, nil 
     341     
     342    person = Person.find(:first) 
     343    assert_raise(NoMethodError) { person.unknow_attribute } 
     344  end 
     345   
    338346  def test_create 
    339347    rick = Person.create(:name => 'Rick') 
    340348    assert rick.valid? 
  • lib/active_resource/base.rb

    old new  
    865865          when "?" 
    866866            attributes[method_name.first(-1)] 
    867867          else 
    868             attributes.has_key?(method_name) ? attributes[method_name] : super 
     868            begin 
     869              attributes.has_key?(method_name) ? attributes[method_name] : super 
     870            rescue 
     871              new? ? nil : raise(NoMethodError, "An error occurred: #{$!}") 
     872            end 
    869873        end 
    870874      end 
    871875  end