Skip to content

Commit 642da85

Browse files
fcheunglifo
authored andcommitted
Deprecate AR::Base#attributes argument
Signed-off-by: Pratik Naik <[email protected]>
1 parent 63edc02 commit 642da85

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

activerecord/lib/active_record/base.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,7 @@ def attributes(options = nil)
21452145
if options.nil?
21462146
attributes
21472147
else
2148+
ActiveSupport::Deprecation.warn "Passing options to Base#attributes is deprecated and will be removed in Rails 2.1. Please use Hash#slice or Hash#except instead"
21482149
if except = options[:except]
21492150
except = Array(except).collect { |attribute| attribute.to_s }
21502151
except.each { |attribute_name| attributes.delete(attribute_name) }

activerecord/test/base_test.rb

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,20 +1706,24 @@ def test_to_xml_with_block
17061706
end
17071707

17081708
def test_except_attributes
1709-
assert_equal(
1710-
%w( author_name type id approved replies_count bonus_time written_on content author_email_address parent_id last_read),
1711-
topics(:first).attributes(:except => :title).keys
1712-
)
1709+
assert_deprecated do
1710+
assert_equal(
1711+
%w( author_name type id approved replies_count bonus_time written_on content author_email_address parent_id last_read),
1712+
topics(:first).attributes(:except => :title).keys
1713+
)
17131714

1714-
assert_equal(
1715-
%w( replies_count bonus_time written_on content author_email_address parent_id last_read),
1716-
topics(:first).attributes(:except => [ :title, :id, :type, :approved, :author_name ]).keys
1717-
)
1715+
assert_equal(
1716+
%w( replies_count bonus_time written_on content author_email_address parent_id last_read),
1717+
topics(:first).attributes(:except => [ :title, :id, :type, :approved, :author_name ]).keys
1718+
)
1719+
end
17181720
end
17191721

17201722
def test_include_attributes
1721-
assert_equal(%w( title ), topics(:first).attributes(:only => :title).keys)
1722-
assert_equal(%w( title author_name type id approved ), topics(:first).attributes(:only => [ :title, :id, :type, :approved, :author_name ]).keys)
1723+
assert_deprecated do
1724+
assert_equal(%w( title ), topics(:first).attributes(:only => :title).keys)
1725+
assert_equal(%w( title author_name type id approved ), topics(:first).attributes(:only => [ :title, :id, :type, :approved, :author_name ]).keys)
1726+
end
17231727
end
17241728

17251729
def test_type_name_with_module_should_handle_beginning

0 commit comments

Comments
 (0)