Sha256: af4b2966137717cefdf0c94b7fd09f007488ff22997cfb213469650e0432c8b0

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

require 'spec_helper'

describe "Instances of a Class including ReUser" do
  let(:klass) do
    kls = Class.new
    kls.instance_eval do
      include ReUser
      attr_accessor :role

      roles do
        role :admin do |admin|
          admin.can :read
          admin.could :write do |language|
            language == "English"
          end
        end
      end
    end
    kls
  end

  subject do
    instance = klass.new
    instance.role = :admin
    instance
  end

  let(:admin_role) do
    klass.role(:admin)
  end

  specify "#can? is delegated to the ReUser::Role" do
    admin_role.should_receive :can?
    subject.can? :read
  end

  specify "#could? is delegated to the ReUser::Role" do
    admin_role.should_receive :could?
    subject.could? :write, 'Farsi'
  end

  specify "#cant? is #can? negated" do
    subject.can?(:write).should == !(subject.cant? :write)
  end

  specify "#couldnt? is #could? negated" do
    subject.could?(:write, 'Farsi').should == !(subject.couldnt? :write, 'Farsi')
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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