Sha256: 4554ea7dbd5476f3359e10f00c877b7c6caf8004b487c94af7f28d3c52c1cc9e

Contents?: true

Size: 1.47 KB

Versions: 7

Compression:

Stored size: 1.47 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
      create(: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 = create(:permission, :name => 'Permission One', :key => 'permission_one')
      two = create(: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 = create(:role, :name => 'Administrator')
      assert_equal nil, admin_role.permission_keys.index('new_permission')

      permission = Permission.new({ :name => 'New Permission', :key => 'new_permission', :description => 'This is just a test.' }, :without_protection => true)

      assert_difference [ 'Permission.count', 'PermissionRole.count' ], 1 do
        assert permission.save
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
challah-rolls-0.2.0 test/permission_test.rb
challah-rolls-0.1.1 test/permission_test.rb
challah-rolls-0.1.0 test/permission_test.rb
challah-0.6.2 test/permission_test.rb
challah-0.6.1 test/permission_test.rb
challah-0.6.0 test/permission_test.rb
challah-0.5.4 test/permission_test.rb