mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
fixing deprecation notice for dynamic finders that use hashes. fixes #2404
This commit is contained in:
@@ -1057,12 +1057,10 @@ module ActiveRecord #:nodoc:
|
||||
if match = DynamicFinderMatch.match(method_id)
|
||||
attribute_names = match.attribute_names
|
||||
super unless all_attributes_exists?(attribute_names)
|
||||
if arguments.size < attribute_names.size
|
||||
ActiveSupport::Deprecation.warn(
|
||||
"Calling dynamic finder with less number of arguments than the number of attributes in " \
|
||||
"method name is deprecated and will raise an ArguementError in the next version of Rails. " \
|
||||
"Please passing `nil' to the argument you want it to be nil."
|
||||
)
|
||||
if !arguments.first.is_a?(Hash) && arguments.size < attribute_names.size
|
||||
ActiveSupport::Deprecation.warn(<<-eowarn)
|
||||
Calling dynamic finder with less number of arguments than the number of attributes in method name is deprecated and will raise an ArguementError in the next version of Rails. Please passing `nil' to the argument you want it to be nil.
|
||||
eowarn
|
||||
end
|
||||
if match.finder?
|
||||
options = arguments.extract_options!
|
||||
|
||||
@@ -661,6 +661,16 @@ class FinderTest < ActiveRecord::TestCase
|
||||
assert_raise(NoMethodError) { Topic.find_or_create_by_title?("Nonexistent Title") }
|
||||
end
|
||||
|
||||
def test_dynamic_finder_with_hash
|
||||
assert_not_deprecated do
|
||||
topic = Topic.find_or_create_by_title_and_author_name(
|
||||
:title => "hi aaron!",
|
||||
:author_name => "Aaron"
|
||||
)
|
||||
assert_equal 'hi aaron!', topic.title
|
||||
end
|
||||
end
|
||||
|
||||
def test_find_by_two_attributes
|
||||
assert_equal topics(:first), Topic.find_by_title_and_author_name("The First Topic", "David")
|
||||
assert_nil Topic.find_by_title_and_author_name("The First Topic", "Mary")
|
||||
|
||||
Reference in New Issue
Block a user