Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Remove rr dependency for Ruby 1.9 and 2.0 compatibility #900

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
rvm:
- 1.8.7
- 1.9.2
- 1.9.3
- 2.0.0
- ree
notifications:
recipients:
Expand Down
2 changes: 1 addition & 1 deletion cancan.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Gem::Specification.new do |s|
s.require_path = "lib"

s.add_development_dependency 'rspec', '~> 2.6.0'
s.add_development_dependency 'rspec-mocks', '~> 2.6.0'
s.add_development_dependency 'rails', '~> 3.0.9'
s.add_development_dependency 'rr', '~> 0.10.11' # 1.0.0 has respond_to? issues: http://github.com/btakita/rr/issues/issue/43
s.add_development_dependency 'supermodel', '~> 0.1.4'

s.rubyforge_project = s.name
Expand Down
13 changes: 8 additions & 5 deletions spec/cancan/ability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,18 @@
end

it "should accept a set as a condition value" do
mock(object_with_foo_2 = Object.new).foo { 2 }
mock(object_with_foo_3 = Object.new).foo { 3 }
object_with_foo_2 = Object.new
object_with_foo_2.should_receive(:foo).and_return(2)
object_with_foo_3 = Object.new
object_with_foo_3.should_receive(:foo).and_return(3)
@ability.can :read, Object, :foo => [1, 2, 5].to_set
@ability.can?(:read, object_with_foo_2).should be_true
@ability.can?(:read, object_with_foo_3).should be_false
end

it "should not match subjects return nil for methods that must match nested a nested conditions hash" do
mock(object_with_foo = Object.new).foo { :bar }
object_with_foo = Object.new
object_with_foo.should_receive(:foo).and_return(:bar)
@ability.can :read, Array, :first => { :foo => :bar }
@ability.can?(:read, [object_with_foo]).should be_true
@ability.can?(:read, []).should be_false
Expand Down Expand Up @@ -387,8 +390,8 @@ class Container < Hash; end
it "should determine model adapter class by asking AbstractAdapter" do
model_class = Object.new
adapter_class = Object.new
stub(CanCan::ModelAdapters::AbstractAdapter).adapter_class(model_class) { adapter_class }
stub(adapter_class).new(model_class, []) { :adapter_instance }
CanCan::ModelAdapters::AbstractAdapter.stub(:adapter_class).with(model_class).and_return(adapter_class)
adapter_class.stub(:new).with(model_class, []).and_return(:adapter_instance)
@ability.model_adapter(model_class, :read).should == :adapter_instance
end

Expand Down
50 changes: 29 additions & 21 deletions spec/cancan/controller_additions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
before(:each) do
@controller_class = Class.new
@controller = @controller_class.new
stub(@controller).params { {} }
stub(@controller).current_user { :current_user }
mock(@controller_class).helper_method(:can?, :cannot?, :current_ability)
@controller.stub(:params).and_return({})
@controller.stub(:current_user).and_return(:current_user)
@controller_class.should_receive(:helper_method).with(:can?, :cannot?, :current_ability)
@controller_class.send(:include, CanCan::ControllerAdditions)
end

Expand All @@ -15,7 +15,7 @@
end

it "authorize! should assign @_authorized instance variable and pass args to current ability" do
mock(@controller.current_ability).authorize!(:foo, :bar)
@controller.current_ability.should_receive(:authorize!).with(:foo, :bar)
@controller.authorize!(:foo, :bar)
@controller.instance_variable_get(:@_authorized).should be_true
end
Expand All @@ -31,66 +31,74 @@
end

it "load_and_authorize_resource should setup a before filter which passes call to ControllerResource" do
stub(CanCan::ControllerResource).new(@controller, nil, :foo => :bar).mock!.load_and_authorize_resource
mock(@controller_class).before_filter({}) { |options, block| block.call(@controller) }
new_return_value = double
CanCan::ControllerResource.stub(:new).with(@controller, nil, :foo => :bar) { new_return_value }
new_return_value.should_receive(:load_and_authorize_resource)
@controller_class.should_receive(:before_filter).with({}) { |options, block| block.call(@controller) }
@controller_class.load_and_authorize_resource :foo => :bar
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) }
new_return_value = double
CanCan::ControllerResource.stub(:new).with(@controller, :project, :foo => :bar) { new_return_value }
new_return_value.should_receive(:load_and_authorize_resource)
@controller_class.should_receive(:before_filter).with({}) { |options, block| block.call(@controller) }
@controller_class.load_and_authorize_resource :project, :foo => :bar
end

it "load_and_authorize_resource with :prepend should prepend the before filter" do
mock(@controller_class).prepend_before_filter({})
@controller_class.should_receive(:prepend_before_filter).with({})
@controller_class.load_and_authorize_resource :foo => :bar, :prepend => true
end

it "authorize_resource should setup a before filter which passes call to ControllerResource" do
stub(CanCan::ControllerResource).new(@controller, nil, :foo => :bar).mock!.authorize_resource
mock(@controller_class).before_filter(:except => :show, :if => true) { |options, block| block.call(@controller) }
new_return_value = double
CanCan::ControllerResource.stub(:new).with(@controller, nil, :foo => :bar) { new_return_value }
new_return_value.should_receive(:authorize_resource)
@controller_class.should_receive(:before_filter).with(:except => :show, :if => true) { |options, block| block.call(@controller) }
@controller_class.authorize_resource :foo => :bar, :except => :show, :if => true
end

it "load_resource should setup a before filter which passes call to ControllerResource" do
stub(CanCan::ControllerResource).new(@controller, nil, :foo => :bar).mock!.load_resource
mock(@controller_class).before_filter(:only => [:show, :index], :unless => false) { |options, block| block.call(@controller) }
new_return_value = double
CanCan::ControllerResource.stub(:new).with(@controller, nil, :foo => :bar) { new_return_value }
new_return_value.should_receive(:load_resource)
@controller_class.should_receive(:before_filter).with(:only => [:show, :index], :unless => false) { |options, block| block.call(@controller) }
@controller_class.load_resource :foo => :bar, :only => [:show, :index], :unless => false
end

it "skip_authorization_check should set up a before filter which sets @_authorized to true" do
mock(@controller_class).before_filter(:filter_options) { |options, block| block.call(@controller) }
@controller_class.should_receive(:before_filter).with(:filter_options) { |options, block| block.call(@controller) }
@controller_class.skip_authorization_check(:filter_options)
@controller.instance_variable_get(:@_authorized).should be_true
end

it "check_authorization should trigger AuthorizationNotPerformed in after filter" do
mock(@controller_class).after_filter(:only => [:test]) { |options, block| block.call(@controller) }
@controller_class.should_receive(:after_filter).with(:only => [:test]) { |options, block| block.call(@controller) }
lambda {
@controller_class.check_authorization(:only => [:test])
}.should raise_error(CanCan::AuthorizationNotPerformed)
end

it "check_authorization should not trigger AuthorizationNotPerformed when :if is false" do
stub(@controller).check_auth? { false }
mock(@controller_class).after_filter({}) { |options, block| block.call(@controller) }
@controller.stub(:check_auth?).and_return(false)
@controller_class.should_receive(:after_filter).with({}) { |options, block| block.call(@controller) }
lambda {
@controller_class.check_authorization(:if => :check_auth?)
}.should_not raise_error(CanCan::AuthorizationNotPerformed)
end

it "check_authorization should not trigger AuthorizationNotPerformed when :unless is true" do
stub(@controller).engine_controller? { true }
mock(@controller_class).after_filter({}) { |options, block| block.call(@controller) }
@controller.stub(:engine_controller?).and_return(true)
@controller_class.should_receive(:after_filter).with({}) { |options, block| block.call(@controller) }
lambda {
@controller_class.check_authorization(:unless => :engine_controller?)
}.should_not raise_error(CanCan::AuthorizationNotPerformed)
end

it "check_authorization should not raise error when @_authorized is set" do
@controller.instance_variable_set(:@_authorized, true)
mock(@controller_class).after_filter(:only => [:test]) { |options, block| block.call(@controller) }
@controller_class.should_receive(:after_filter).with(:only => [:test]) { |options, block| block.call(@controller) }
lambda {
@controller_class.check_authorization(:only => [:test])
}.should_not raise_error(CanCan::AuthorizationNotPerformed)
Expand All @@ -101,7 +109,7 @@
end

it "cancan_resource_class should be InheritedResource when class includes InheritedResources::Actions" do
stub(@controller.class).ancestors { ["InheritedResources::Actions"] }
@controller.class.stub(:ancestors).and_return(["InheritedResources::Actions"])
@controller.class.cancan_resource_class.should == CanCan::InheritedResource
end

Expand Down
Loading