Sha256: 074b856e683bc54573935712217d6f19224dd4c65d92b4b820b7bbc96878bc37

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

require "spec_helper"

describe Shamu::Security::Roles do

  describe "#role" do
    it "adds a role" do
      klass = Class.new do
        include Shamu::Security::Roles

        role :admin
      end

      expect( klass.roles ).to have_key :admin
      expect( klass.roles[:admin] ).to be_a Hash
    end
  end

  describe "#expand_roles" do
    let( :klass ) do
      Class.new do
        include Shamu::Security::Roles

        role :admin, inherits: :manager
        role :manager, inherits: :user
        role :user
      end
    end

    it "returns all roles for :all" do
      expect( klass.expand_roles( :all ) ).to eq [ :admin, :manager, :user ]
    end

    it "includes base roles" do
      expect( klass.expand_roles( :user ) ).to include :user
    end

    it "excludes unknown roles" do
      expect( klass.expand_roles( :magician ) ).to be_empty
    end

    it "includes inherited roles" do
      expect( klass.expand_roles( :manager ) ).to include :user
    end

    it "includes inherited inherited roles" do
      expect( klass.expand_roles( :admin ) ).to include :manager
      expect( klass.expand_roles( :admin ) ).to include :user
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
shamu-0.0.24 spec/lib/shamu/security/roles_spec.rb
shamu-0.0.21 spec/lib/shamu/security/roles_spec.rb
shamu-0.0.20 spec/lib/shamu/security/roles_spec.rb