aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorPaul McMahon <paul@mobalean.com>2012-01-28 10:42:44 +0900
committerPaul McMahon <paul@mobalean.com>2012-01-28 10:42:44 +0900
commitfe12497e4d8ad292ffbcb4486a26b8802c19d65d (patch)
treeb8ce366c6a691a9f51cf7ad4d9d5de54a9b03eef /activerecord/lib
parent1be248e246948c43867e1d512502cbfdfcae3dd6 (diff)
downloadrails-fe12497e4d8ad292ffbcb4486a26b8802c19d65d.tar.gz
rails-fe12497e4d8ad292ffbcb4486a26b8802c19d65d.tar.bz2
rails-fe12497e4d8ad292ffbcb4486a26b8802c19d65d.zip
Move argument validation into match
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/dynamic_finder_match.rb8
-rw-r--r--activerecord/lib/active_record/dynamic_matchers.rb2
-rw-r--r--activerecord/lib/active_record/dynamic_scope_match.rb4
3 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/dynamic_finder_match.rb b/activerecord/lib/active_record/dynamic_finder_match.rb
index 0cdc49ae14..2b4f1bbf92 100644
--- a/activerecord/lib/active_record/dynamic_finder_match.rb
+++ b/activerecord/lib/active_record/dynamic_finder_match.rb
@@ -36,6 +36,10 @@ module ActiveRecord
def bang?
false
end
+
+ def valid_arguments?(arguments)
+ arguments.size >= @attribute_names.size
+ end
end
class FindBy < DynamicFinderMatch
@@ -65,5 +69,9 @@ module ActiveRecord
new(:first, $2, $1 == 'initialize' ? :new : :create)
end
end
+
+ def valid_arguments?(arguments)
+ arguments.size == 1 && arguments.first.is_a?(Hash) || super
+ end
end
end
diff --git a/activerecord/lib/active_record/dynamic_matchers.rb b/activerecord/lib/active_record/dynamic_matchers.rb
index b6b8e24436..60ce3dd4f1 100644
--- a/activerecord/lib/active_record/dynamic_matchers.rb
+++ b/activerecord/lib/active_record/dynamic_matchers.rb
@@ -25,7 +25,7 @@ module ActiveRecord
if match = (DynamicFinderMatch.match(method_id) || DynamicScopeMatch.match(method_id))
attribute_names = match.attribute_names
super unless all_attributes_exists?(attribute_names)
- if !(match.is_a?(DynamicFinderMatch) && match.instantiator? && arguments.first.is_a?(Hash)) && arguments.size < attribute_names.size
+ unless match.valid_arguments?(arguments)
method_trace = "#{__FILE__}:#{__LINE__}:in `#{method_id}'"
backtrace = [method_trace] + caller
raise ArgumentError, "wrong number of arguments (#{arguments.size} for #{attribute_names.size})", backtrace
diff --git a/activerecord/lib/active_record/dynamic_scope_match.rb b/activerecord/lib/active_record/dynamic_scope_match.rb
index c832e927d6..a502155aac 100644
--- a/activerecord/lib/active_record/dynamic_scope_match.rb
+++ b/activerecord/lib/active_record/dynamic_scope_match.rb
@@ -19,5 +19,9 @@ module ActiveRecord
attr_reader :scope, :attribute_names
alias :scope? :scope
+
+ def valid_arguments?(arguments)
+ arguments.size >= @attribute_names.size
+ end
end
end