Sha256: b8c0f623f64ef32c6b5f53b5ebbbdffb7569cfc565da46ffe942b220e09c18e3

Contents?: true

Size: 1.75 KB

Versions: 16

Compression:

Stored size: 1.75 KB

Contents

require "spec_helper"

describe CanCan::InheritedResource do
  before(:each) do
    @params = HashWithIndifferentAccess.new(:controller => "projects")
    @controller_class = Class.new
    @controller = @controller_class.new
    @ability = Ability.new(nil)
    stub(@controller).params { @params }
    stub(@controller).current_ability { @ability }
    stub(@controller_class).cancan_skipper { {:authorize => {}, :load => {}} }
  end

  it "show should load resource through @controller.resource" do
    @params.merge!(:action => "show", :id => 123)
    stub(@controller).resource { :project_resource }
    CanCan::InheritedResource.new(@controller).load_resource
    @controller.instance_variable_get(:@project).should == :project_resource
  end

  it "new should load through @controller.build_resource" do
    @params[:action] = "new"
    stub(@controller).build_resource { :project_resource }
    CanCan::InheritedResource.new(@controller).load_resource
    @controller.instance_variable_get(:@project).should == :project_resource
  end

  it "index should load through @controller.association_chain when parent" do
    @params[:action] = "index"
    stub(@controller).association_chain { @controller.instance_variable_set(:@project, :project_resource) }
    CanCan::InheritedResource.new(@controller, :parent => true).load_resource
    @controller.instance_variable_get(:@project).should == :project_resource
  end

  it "index should load through @controller.end_of_association_chain" do
    @params[:action] = "index"
    stub(Project).accessible_by(@ability, :index) { :projects }
    stub(@controller).end_of_association_chain { Project }
    CanCan::InheritedResource.new(@controller).load_resource
    @controller.instance_variable_get(:@projects).should == :projects
  end
end

Version data entries

16 entries across 16 versions & 6 rubygems

Version Path
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/cancan-1.6.7/spec/cancan/inherited_resource_spec.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/cancan-1.6.7/spec/cancan/inherited_resource_spec.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/cancan-1.6.7/spec/cancan/inherited_resource_spec.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/cancan-1.6.7/spec/cancan/inherited_resource_spec.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/cancan-1.6.7/spec/cancan/inherited_resource_spec.rb
cancan-1.6.7 spec/cancan/inherited_resource_spec.rb
codeprimate-cancan-1.6.5 spec/cancan/inherited_resource_spec.rb
corntrace-cancan-1.6.5 spec/cancan/inherited_resource_spec.rb
cancant-0.0.1.beta2 spec/cancan/inherited_resource_spec.rb
cancant-0.0.1.beta1 spec/cancan/inherited_resource_spec.rb
cancat-0.0.1.beta1 spec/cancan/inherited_resource_spec.rb
cancan-1.6.5 spec/cancan/inherited_resource_spec.rb
cancan-1.6.4 spec/cancan/inherited_resource_spec.rb
cancan-1.6.3 spec/cancan/inherited_resource_spec.rb
cancan-1.6.2 spec/cancan/inherited_resource_spec.rb
cancan-1.6.1 spec/cancan/inherited_resource_spec.rb