diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index afe8b8c0d0..6c8df8ef16 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -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! diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index 528ee0ce0a..868cf88ead 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -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")