Sha256: b133dd42ea692841b5fdd99fdaae5da0d1dbef3e51dc1a494405b1673c95bd4a

Contents?: true

Size: 1.43 KB

Versions: 7

Compression:

Stored size: 1.43 KB

Contents

require 'spec_helper'
use_roles_strategy :roles_string

class User
  include Roles::Generic 
   
  attr_accessor :name
   
  strategy :roles_string, :default

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


describe "Generic RoleStrings 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.roles.first.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.first.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.roles.first.should == :admin           
      @user.has_role?(:admin).should be_true      
    end    
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
roles_generic-0.2.7 spec/roles_generic/roles_string_spec.rb
roles_generic-0.2.6 spec/roles_generic/roles_string_spec.rb
roles_generic-0.2.5 spec/roles_generic/roles_string_spec.rb
roles_generic-0.2.4 spec/roles_generic/roles_string_spec.rb
roles_generic-0.2.3 spec/roles_generic/roles_string_spec.rb
roles_generic-0.2.2 spec/roles_generic/roles_string_spec.rb
roles_generic-0.2.1 spec/roles_generic/roles_string_spec.rb