Sha256: 9a133f56f63d6207100bf6c6f28009869dca539ec2f919b68993a2dc4f7dc325

Contents?: true

Size: 1.42 KB

Versions: 25

Compression:

Stored size: 1.42 KB

Contents

require 'rails_helper'
Auth = ActiveAdmin::Authorization

describe Admin::PostsController, "Controller Authorization", type: :controller do

  let(:authorization){ controller.send(:active_admin_authorization) }

  before do
    load_defaults!
    # HACK: the AA config is missing, so we throw it in here
    controller.class.active_admin_config = ActiveAdmin.application.namespace(:admin).resources['Post'].controller.active_admin_config
  end

  it "should authorize the index action" do
    expect(authorization).to receive(:authorized?).with(Auth::READ, Post).and_return true
    get :index
    expect(response).to be_success
  end

  it "should authorize the new action" do
    expect(authorization).to receive(:authorized?).with(Auth::CREATE, an_instance_of(Post)).and_return true
    get :new
    expect(response).to be_success
  end

  it "should authorize the create action with the new resource" do
    expect(authorization).to receive(:authorized?).with(Auth::CREATE, an_instance_of(Post)).and_return true
    post :create
    expect(response).to redirect_to action: 'show', id: Post.last.id
  end

  it "should redirect when the user isn't authorized" do
    expect(authorization).to receive(:authorized?).with(Auth::READ, Post).and_return false
    get :index
    expect(response.body).to eq '<html><body>You are being <a href="http://test.host/admin">redirected</a>.</body></html>'
    expect(response).to redirect_to '/admin'
  end

end

Version data entries

25 entries across 25 versions & 4 rubygems

Version Path
activeadmin_addons-1.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/authorization/controller_authorization_spec.rb
activeadmin_addons-1.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/authorization/controller_authorization_spec.rb
yousty-activeadmin-1.0.17.pre spec/unit/authorization/controller_authorization_spec.rb
yousty-activeadmin-1.0.16.pre spec/unit/authorization/controller_authorization_spec.rb
activeadmin_addons-1.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/authorization/controller_authorization_spec.rb
activeadmin_addons-1.0.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/authorization/controller_authorization_spec.rb
activeadmin_addons-1.0.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/authorization/controller_authorization_spec.rb
yousty-activeadmin-1.0.15.pre spec/unit/authorization/controller_authorization_spec.rb
activeadmin-orac-1.0.0.pre4 spec/unit/authorization/controller_authorization_spec.rb
activeadmin-orac-1.0.0 spec/unit/authorization/controller_authorization_spec.rb
activeadmin-orac-1.0.0.pre.orac spec/unit/authorization/controller_authorization_spec.rb
yousty-activeadmin-1.0.14.pre spec/unit/authorization/controller_authorization_spec.rb
yousty-activeadmin-1.0.13.pre spec/unit/authorization/controller_authorization_spec.rb
yousty-activeadmin-1.0.12.pre spec/unit/authorization/controller_authorization_spec.rb
yousty-activeadmin-1.0.11.pre spec/unit/authorization/controller_authorization_spec.rb
yousty-activeadmin-1.0.10.pre spec/unit/authorization/controller_authorization_spec.rb
yousty-activeadmin-1.0.9.pre spec/unit/authorization/controller_authorization_spec.rb
yousty-activeadmin-1.0.8.pre spec/unit/authorization/controller_authorization_spec.rb
activeadmin-1.0.0.pre4 spec/unit/authorization/controller_authorization_spec.rb
activeadmin-1.0.0.pre3 spec/unit/authorization/controller_authorization_spec.rb