Sha256: e7432efc88a58ec8bb23ad4250417d2fa3c328c6b6e94e972e640fa98ea55978

Contents?: true

Size: 1.52 KB

Versions: 13

Compression:

Stored size: 1.52 KB

Contents

require 'helper'

class PermissionTest < ActiveSupport::TestCase
  should validate_presence_of :name
  should validate_presence_of :key
  
  should have_many :roles
  should have_many :users
  should have_many :permission_roles
  should have_many :permission_users
  
  context "With existing permissions" do
    setup do
      Factory(:permission)
    end
    
    should validate_uniqueness_of :name
    should validate_uniqueness_of :key
  end
  
  context "The Permission class" do
    should "load with the brackets shortcut" do
      one = Factory(:permission, :name => 'Permission One', :key => 'permission_one')
      two = Factory(:permission, :name => 'Permission Two', :key => 'permission_two')

      assert_equal one, Permission[:permission_one]
      assert_equal one, Permission[:Permission_One]
      assert_equal two, Permission['Permission Two']
      assert_equal two, Permission[' permission two  ']
      assert_equal nil, Permission[:no_permission_exists]
    end
  end
  
  context "A Permission instance" do    
    should "get added to the admin role on create" do
      admin_role = Factory(:role, :name => 'Administrator')
      assert_equal nil, admin_role.permission_keys.index('new_permission')
      
      #Role.stubs(:admin).returns(admin_role)
      
      permission = Permission.new(:name => 'New Permission', :key => 'new_permission', :description => 'This is just a test.')
      
      assert_difference [ 'Permission.count', 'PermissionRole.count' ], 1 do
        assert permission.save
      end      
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
challah-0.5.2 test/permission_test.rb
challah-0.5.1 test/permission_test.rb
challah-0.5.0 test/permission_test.rb
challah-0.4.1 test/permission_test.rb
challah-0.4.0 test/permission_test.rb
challah-0.3.5 test/permission_test.rb
challah-0.3.4 test/permission_test.rb
challah-0.3.3 test/permission_test.rb
challah-0.3.2 test/permission_test.rb
challah-0.3.1 test/permission_test.rb
challah-0.3.0 test/permission_test.rb
challah-0.2.1 test/permission_test.rb
challah-0.2.0 test/permission_test.rb