From c37a4492e218d2046e5a18984632dcea89fcea66 Mon Sep 17 00:00:00 2001 From: Grzegorz Derebecki Date: Sat, 16 Mar 2013 11:42:22 +0100 Subject: [PATCH 1/4] Add Support for Strong Parameters --- lib/cancan/controller_resource.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/cancan/controller_resource.rb b/lib/cancan/controller_resource.rb index 670b30c3..672a7e35 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 From 48f6946a8d521cb8abc1bc480a1e83fc3b823103 Mon Sep 17 00:00:00 2001 From: Marcin Chrost Date: Tue, 13 Aug 2013 08:16:12 +0200 Subject: [PATCH 2/4] treat ActiveRecord::Relation as Array --- lib/cancan/rule.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cancan/rule.rb b/lib/cancan/rule.rb index f86296f1..10c26a0c 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) From 5e2c6ecd10125d974fb1a80aff2fb4ebb43b84bf Mon Sep 17 00:00:00 2001 From: Marcin Chrost Date: Tue, 13 Aug 2013 08:16:12 +0200 Subject: [PATCH 3/4] treat ActiveRecord::Relation as Array --- lib/cancan/rule.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From aebd42e23203fc1f175dc6f8a69eaea665ba5bc4 Mon Sep 17 00:00:00 2001 From: Grzegorz Derebecki Date: Mon, 24 Feb 2014 11:44:37 +0100 Subject: [PATCH 4/4] make gem compatible with rspec 3.x --- lib/cancan/matchers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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