Sha256: 91a3a7e4ac36102cad898371d69906dd49af566da8848663d747cdb71e941bec

Contents?: true

Size: 1.74 KB

Versions: 5

Compression:

Stored size: 1.74 KB

Contents

require 'spec_helper'
module Rolypoly
  describe ControllerRoleDSL do
    let(:example_controller) do
      Class.new do
        include Rolypoly::ControllerRoleDSL
      end
    end
    after { example_controller.instance_variable_set("@rolypoly_gatekeepers", nil) }
    subject { example_controller }
    it { should respond_to :restrict }
    it { should respond_to :allow }

    describe "setting up with DSL" do
      describe "from allow side" do
        let(:controller_instance) { subject.new }
        let(:current_roles) { [:admin] }
        before do
          subject.allow(:admin).to_access(:index)
          subject.publicize(:landing)
          controller_instance.stub current_roles: current_roles, action_name: action_name
        end

        describe "#index" do
          let(:action_name) { "index" }
          it "allows admin access" do
            expect { controller_instance.rolypoly_check_role_access! }
            .not_to raise_error
          end
        end

        describe "#show" do
          let(:action_name) { "show" }
          it "disallows admin access" do
            expect { controller_instance.rolypoly_check_role_access! }
            .to raise_error(Rolypoly::FailedRoleCheckError)
          end
        end

        describe "#landing" do
          let(:action_name) { "landing" }
          it "allows admin access" do
            expect { controller_instance.rolypoly_check_role_access! }
            .not_to raise_error
          end

          describe "with no role" do
            let(:current_roles) { [] }
            it "allows admin access" do
              expect { controller_instance.rolypoly_check_role_access! }
              .not_to raise_error
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rolypoly-0.0.5 spec/lib/rolypoly/controller_role_dsl_spec.rb
rolypoly-0.0.4 spec/lib/rolypoly/controller_role_dsl_spec.rb
rolypoly-0.0.3 spec/lib/rolypoly/controller_role_dsl_spec.rb
rolypoly-0.0.2 spec/lib/rolypoly/controller_role_dsl_spec.rb
rolypoly-0.0.1 spec/lib/rolypoly/controller_role_dsl_spec.rb