Sha256: 34ede73de7ce45fbf0c97becbcbb2d81bc73730bbbf02f56e0384677d6e1ff90

Contents?: true

Size: 1.29 KB

Versions: 3

Compression:

Stored size: 1.29 KB

Contents

require 'spec_helper'

describe "Classes including ReUser" do
  let(:klass) do
    kls = Class.new
    kls.instance_eval do
      include ReUser

      roles do
        role(:admin)
      end
    end
    kls
  end
  subject { klass }

  context ".roles" do
    it "optionally takes a block" do
      lambda { subject.roles { :good } }.should_not raise_error
      lambda { subject.roles }.should_not raise_error
    end

    it "returns an array of role names" do
      subject.roles.should be_kind_of Array
      subject.roles.all? {|el| el.is_a? Symbol}.should be_true
    end
  end

  context ".role" do

    it "takes a symbol" do
      lambda { subject.role(:admin) }.should_not raise_error
    end

    it "returns a ReUser::Role instance" do
      subject.role(:admin).should be_instance_of ReUser::Role
    end

    context "passing in a role that is already defined" do
      it "returns the same role" do
        expected = subject.role(:admin)
        subject.role(:admin).should === expected
      end
    end

    context "passing in a role that is not already defined" do
      it "raises an error" do
        subject.class_eval do
          roles do
            role(:admin)
          end
        end
        lambda { subject.role(:user) }.should raise_error(ReUser::RoleNotDefined)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reuser-3.1.2 spec/reuser/class_spec.rb
reuser-3.1.1 spec/reuser/class_spec.rb
reuser-3.1.0 spec/reuser/class_spec.rb