Sha256: d79142f46fc11671c6c384500dc296592052bf9ef113bf4718527ed8f5ed3779

Contents?: true

Size: 1.65 KB

Versions: 4

Compression:

Stored size: 1.65 KB

Contents

require 'spec_helper'
use_roles_strategy :one_role

class User
  include Roles::Generic 
  strategy :one_role, :default

  role_class :role   
    
  attr_accessor :name

  valid_roles_are :admin, :user 
  
  def initialize name, *new_roles
    self.name = name
    self.roles = new_roles
  end 
end


describe "Generic OneRole role strategy" do
  context "default setup" do
  
    before :each do    
      @admin_user = User.new 'Admin user', :admin
      @user = User.new 'User', :user
    end

    it "should have admin user role to :admin" do
      @admin_user.role.should == :admin
      @admin_user.roles.should == [:admin]      
      @admin_user.admin?.should be_true

      @admin_user.has_role?(:user).should be_false

      @admin_user.has_role?(:admin).should be_true
      @admin_user.is?(:admin).should be_true
      @admin_user.has_roles?(:admin).should be_true
      @admin_user.has?(:admin).should be_true      
    end

    it "should have user role to :user" do
      @user.roles.should == [:user]
      @user.admin?.should be_false
      
      @user.has_role?(:user).should be_true    
      @user.has_role?(:admin).should be_false
      @user.is?(:admin).should be_false
      
      @user.has_roles?(:admin).should be_false
      @user.has?(:admin).should be_false
    end
      
    it "should set user role to :admin using roles=" do
      @user.roles = :admin      
      @user.role.should == :admin           
      @user.has_role?(:admin).should be_true      
    end
      
    it "should set user role to :admin using role=" do
      @user.roles = :admin      
      @user.role.should == :admin
      @user.has_role?(:admin).should be_true      
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
roles_generic-0.2.4 spec/roles_generic/one_role_spec.rb
roles_generic-0.2.3 spec/roles_generic/one_role_spec.rb
roles_generic-0.2.2 spec/roles_generic/one_role_spec.rb
roles_generic-0.2.1 spec/roles_generic/one_role_spec.rb