Ticket #11093: remove_options.diff
| File remove_options.diff, 2.4 kB (added by juanjo.bazan, 7 months ago) |
|---|
-
activerecord/lib/active_record/base.rb
old new 2218 2218 self.attribute_names.each do |name| 2219 2219 attrs[name]=read_attribute(name) 2220 2220 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 2237 2222 end 2238 2223 2239 2224 # Returns a hash of attributes before typecasting and deserialization. -
activerecord/test/cases/base_test.rb
old new 1778 1778 assert xml.include?(%(<arbitrary-element>#{value}</arbitrary-element>)) 1779 1779 end 1780 1780 1781 def test_except_attributes1782 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.sort1785 )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.sort1790 )1791 end1792 1793 def test_include_attributes1794 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 end1797 1798 1781 def test_type_name_with_module_should_handle_beginning 1799 1782 assert_equal 'ActiveRecord::Person', ActiveRecord::Base.send(:type_name_with_module, 'Person') 1800 1783 assert_equal '::Person', ActiveRecord::Base.send(:type_name_with_module, '::Person')