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

Ticket #11093: remove_options.diff

File remove_options.diff, 2.4 kB (added by juanjo.bazan, 7 months ago)

patch removing options(and tests)

  • activerecord/lib/active_record/base.rb

    old new  
    22182218        self.attribute_names.each do |name| 
    22192219          attrs[name]=read_attribute(name) 
    22202220        end 
    2221  
    2222         if options.nil? 
    2223           attrs 
    2224         else 
    2225           if except = options[:except] 
    2226             except = Array(except).collect { |attribute| attribute.to_s } 
    2227             except.each { |attribute_name| attrs.delete(attribute_name) } 
    2228             attrs 
    2229           elsif only = options[:only] 
    2230             only = Array(only).collect { |attribute| attribute.to_s } 
    2231             attrs.delete_if { |key, value| !only.include?(key) } 
    2232             attrs 
    2233           else 
    2234             raise ArgumentError, "Options does not specify :except or :only (#{options.keys.inspect})" 
    2235           end 
    2236         end 
     2221        attrs 
    22372222      end 
    22382223 
    22392224      # Returns a hash of attributes before typecasting and deserialization. 
  • activerecord/test/cases/base_test.rb

    old new  
    17781778    assert xml.include?(%(<arbitrary-element>#{value}</arbitrary-element>)) 
    17791779  end 
    17801780 
    1781   def test_except_attributes 
    1782     assert_equal( 
    1783       %w( author_name type id approved replies_count bonus_time written_on content author_email_address parent_id last_read).sort, 
    1784       topics(:first).attributes(:except => :title).keys.sort 
    1785     ) 
    1786  
    1787     assert_equal( 
    1788       %w( replies_count bonus_time written_on content author_email_address parent_id last_read).sort, 
    1789       topics(:first).attributes(:except => [ :title, :id, :type, :approved, :author_name ]).keys.sort 
    1790     ) 
    1791   end 
    1792  
    1793   def test_include_attributes 
    1794     assert_equal(%w( title ), topics(:first).attributes(:only => :title).keys) 
    1795     assert_equal(%w( title author_name type id approved ).sort, topics(:first).attributes(:only => [ :title, :id, :type, :approved, :author_name ]).keys.sort) 
    1796   end 
    1797  
    17981781  def test_type_name_with_module_should_handle_beginning 
    17991782    assert_equal 'ActiveRecord::Person', ActiveRecord::Base.send(:type_name_with_module, 'Person') 
    18001783    assert_equal '::Person', ActiveRecord::Base.send(:type_name_with_module, '::Person')