diff --git a/lib/cancan/controller_resource.rb b/lib/cancan/controller_resource.rb index 702fbcfb..d3211f4d 100644 --- a/lib/cancan/controller_resource.rb +++ b/lib/cancan/controller_resource.rb @@ -216,14 +216,24 @@ def name def resource_params if @options[:class] params_key = extract_key(@options[:class]) - return @params[params_key] if @params[params_key] + if params = fetch_params(params_key) + return params + end end resource_params_by_namespaced_name end def resource_params_by_namespaced_name - @params[extract_key(namespaced_name)] + fetch_params extract_key(namespaced_name) + end + + def fetch_params(key) + @controller.respond_to?(params_method(key), true) ? @controller.send(params_method(key)) : @params[key] + end + + def params_method(key) + "#{key}_params".to_sym end def namespace diff --git a/lib/cancan/matchers.rb b/lib/cancan/matchers.rb index 4a4fb947..c246bc51 100644 --- a/lib/cancan/matchers.rb +++ b/lib/cancan/matchers.rb @@ -4,11 +4,11 @@ ability.can?(*args) end - failure_message_for_should do |ability| + failure_message do |ability| "expected to be able to #{args.map(&:inspect).join(" ")}" end - failure_message_for_should_not do |ability| + failure_message_when_negated do |ability| "expected not to be able to #{args.map(&:inspect).join(" ")}" end end diff --git a/lib/cancan/rule.rb b/lib/cancan/rule.rb index c0415de8..ac79fbab 100644 --- a/lib/cancan/rule.rb +++ b/lib/cancan/rule.rb @@ -111,7 +111,7 @@ def matches_conditions_hash?(subject, conditions = @conditions) else attribute = subject.send(name) if value.kind_of?(Hash) - if attribute.kind_of? Array + if attribute.kind_of?(Array) || attribute.kind_of?(ActiveRecord::Relation) attribute.any? { |element| matches_conditions_hash? element, value } else !attribute.nil? && matches_conditions_hash?(attribute, value)