Sha256: 4074af4c47e37a363a15b8303042f969579bf6f4b8c4c7124275215a356ffaea

Contents?: true

Size: 1.31 KB

Versions: 5

Compression:

Stored size: 1.31 KB

Contents

require 'test_helper'

module Guts
  class AuthorizationTest < ActiveSupport::TestCase
    test 'should create a authorization' do
      auth = Authorization.new(
        subject_class: 'Guts::Type',
        action: 'manage'
      )

      assert auth.save
    end

    test 'should create a authorization with subject_id' do
      auth = Authorization.new(
        subject_class: 'Guts::Type',
        action: 'manage',
        subject_id: 3
      )

      assert auth.save
    end

    test 'should not create authorization with validation issues' do
      # Missing class
      auth1 = Authorization.new(
        action: 'manage',
        subject_id: 3
      )

      # Missing action
      auth2 = Authorization.new(
        subject_class: 'Guts::Type',
        subject_id: 3
      )

      # Invalid subject_id
      auth3 = Authorization.new(
        subject_class: 'Guts::Type',
        action: 'manage',
        subject_id: 'whoops'
      )

      assert_equal false, auth1.save
      assert_equal false, auth2.save
      assert_equal false, auth3.save
    end

    test 'should format class and action' do
      auth = guts_authorizations :type_authorization

      assert_equal 'Guts::Type (manage) for ID: 3', auth.class_with_action
      assert_equal 'Type (Manage) For Id: 3', auth.class_with_action_cleaner
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
guts-2.1.0 test/models/guts/authorization_test.rb
guts-2.0.2 test/models/guts/authorization_test.rb
guts-2.0.1 test/models/guts/authorization_test.rb
guts-2.0.0 test/models/guts/authorization_test.rb
guts-1.4.0 test/models/guts/authorization_test.rb