Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a566ea0f4f | ||
|
|
333ddf1970 | ||
|
|
cd74267364 | ||
|
|
f8631dcc93 |
@@ -1,3 +1,13 @@
|
|||||||
|
1.3.2 (August 7, 2010)
|
||||||
|
|
||||||
|
* Fixing slice error when passing in custom resource name - see issue #112
|
||||||
|
|
||||||
|
|
||||||
|
1.3.1 (August 6, 2010)
|
||||||
|
|
||||||
|
* Fixing protected sanitize_sql error - see issue #111
|
||||||
|
|
||||||
|
|
||||||
1.3.0 (August 6, 2010)
|
1.3.0 (August 6, 2010)
|
||||||
|
|
||||||
* Adding :find_by option to load_resource - see issue #19
|
* Adding :find_by option to load_resource - see issue #19
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = "cancan"
|
s.name = "cancan"
|
||||||
s.version = "1.3.0"
|
s.version = "1.3.2"
|
||||||
s.author = "Ryan Bates"
|
s.author = "Ryan Bates"
|
||||||
s.email = "ryan@railscasts.com"
|
s.email = "ryan@railscasts.com"
|
||||||
s.homepage = "http://github.com/ryanb/cancan"
|
s.homepage = "http://github.com/ryanb/cancan"
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ module CanCan
|
|||||||
# Handle the load and authorization controller logic so we don't clutter up all controllers with non-interface methods.
|
# Handle the load and authorization controller logic so we don't clutter up all controllers with non-interface methods.
|
||||||
# This class is used internally, so you do not need to call methods directly on it.
|
# This class is used internally, so you do not need to call methods directly on it.
|
||||||
class ControllerResource # :nodoc:
|
class ControllerResource # :nodoc:
|
||||||
def self.add_before_filter(controller_class, method, options = {})
|
def self.add_before_filter(controller_class, method, *args)
|
||||||
|
options = args.extract_options!
|
||||||
|
resource_name = args.first
|
||||||
controller_class.before_filter(options.slice(:only, :except)) do |controller|
|
controller_class.before_filter(options.slice(:only, :except)) do |controller|
|
||||||
ControllerResource.new(controller, options.except(:only, :except)).send(method)
|
ControllerResource.new(controller, resource_name, options.except(:only, :except)).send(method)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ module CanCan
|
|||||||
end
|
end
|
||||||
|
|
||||||
def sanitize_sql(conditions)
|
def sanitize_sql(conditions)
|
||||||
@sanitizer.sanitize_sql(conditions)
|
@sanitizer.send(:sanitize_sql, conditions)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Takes two hashes and does a deep merge.
|
# Takes two hashes and does a deep merge.
|
||||||
|
|||||||
@@ -53,19 +53,25 @@ describe CanCan::ControllerAdditions do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "load_and_authorize_resource should setup a before filter which passes call to ControllerResource" do
|
it "load_and_authorize_resource should setup a before filter which passes call to ControllerResource" do
|
||||||
stub(CanCan::ControllerResource).new(@controller, :foo => :bar).mock!.load_and_authorize_resource
|
stub(CanCan::ControllerResource).new(@controller, nil, :foo => :bar).mock!.load_and_authorize_resource
|
||||||
mock(@controller_class).before_filter({}) { |options, block| block.call(@controller) }
|
mock(@controller_class).before_filter({}) { |options, block| block.call(@controller) }
|
||||||
@controller_class.load_and_authorize_resource :foo => :bar
|
@controller_class.load_and_authorize_resource :foo => :bar
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "load_and_authorize_resource should properly pass first argument as the resource name" do
|
||||||
|
stub(CanCan::ControllerResource).new(@controller, :project, :foo => :bar).mock!.load_and_authorize_resource
|
||||||
|
mock(@controller_class).before_filter({}) { |options, block| block.call(@controller) }
|
||||||
|
@controller_class.load_and_authorize_resource :project, :foo => :bar
|
||||||
|
end
|
||||||
|
|
||||||
it "authorize_resource should setup a before filter which passes call to ControllerResource" do
|
it "authorize_resource should setup a before filter which passes call to ControllerResource" do
|
||||||
stub(CanCan::ControllerResource).new(@controller, :foo => :bar).mock!.authorize_resource
|
stub(CanCan::ControllerResource).new(@controller, nil, :foo => :bar).mock!.authorize_resource
|
||||||
mock(@controller_class).before_filter(:except => :show) { |options, block| block.call(@controller) }
|
mock(@controller_class).before_filter(:except => :show) { |options, block| block.call(@controller) }
|
||||||
@controller_class.authorize_resource :foo => :bar, :except => :show
|
@controller_class.authorize_resource :foo => :bar, :except => :show
|
||||||
end
|
end
|
||||||
|
|
||||||
it "load_resource should setup a before filter which passes call to ControllerResource" do
|
it "load_resource should setup a before filter which passes call to ControllerResource" do
|
||||||
stub(CanCan::ControllerResource).new(@controller, :foo => :bar).mock!.load_resource
|
stub(CanCan::ControllerResource).new(@controller, nil, :foo => :bar).mock!.load_resource
|
||||||
mock(@controller_class).before_filter(:only => [:show, :index]) { |options, block| block.call(@controller) }
|
mock(@controller_class).before_filter(:only => [:show, :index]) { |options, block| block.call(@controller) }
|
||||||
@controller_class.load_resource :foo => :bar, :only => [:show, :index]
|
@controller_class.load_resource :foo => :bar, :only => [:show, :index]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,25 +19,29 @@ class Ability
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# this class helps out in testing nesting and SQL conditions
|
# this class helps out in testing SQL conditions
|
||||||
class Person
|
class Person
|
||||||
def self.sanitize_sql(hash_cond)
|
class << self
|
||||||
case hash_cond
|
protected
|
||||||
when Hash
|
|
||||||
sanitize_hash(hash_cond).join(' AND ')
|
def sanitize_sql(hash_cond)
|
||||||
when Array
|
case hash_cond
|
||||||
hash_cond.shift.gsub('?'){"#{hash_cond.shift.inspect}"}
|
when Hash
|
||||||
when String then hash_cond
|
sanitize_hash(hash_cond).join(' AND ')
|
||||||
|
when Array
|
||||||
|
hash_cond.shift.gsub('?'){"#{hash_cond.shift.inspect}"}
|
||||||
|
when String then hash_cond
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def sanitize_hash(hash)
|
||||||
|
hash.map do |name, value|
|
||||||
|
if Hash === value
|
||||||
|
sanitize_hash(value).map{|cond| "#{name}.#{cond}"}
|
||||||
|
else
|
||||||
|
"#{name}=#{value}"
|
||||||
|
end
|
||||||
|
end.flatten
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.sanitize_hash(hash)
|
|
||||||
hash.map do |name, value|
|
|
||||||
if Hash === value
|
|
||||||
sanitize_hash(value).map{|cond| "#{name}.#{cond}"}
|
|
||||||
else
|
|
||||||
"#{name}=#{value}"
|
|
||||||
end
|
|
||||||
end.flatten
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user