Sha256: 3e48a57044ddff6ee4ad57537df4f8ef124fd81119ec79d6f2eb0fbc43aae14f

Contents?: true

Size: 1.61 KB

Versions: 4

Compression:

Stored size: 1.61 KB

Contents

require 'test_helper'

module ACLQueryMixin
  def self.included base
    base.class_eval do
      setup do
        assert ( @editor = User.create ).has_role! :editor
        assert ( @viewer = User.create ).has_role! :viewer
        assert ( @foo = Foo.first_or_create )
        assert ( @owneroffoo = User.create ).has_role! :owner, @foo

        @controller.before_action
      end

      %i[edit update destroy].each do |meth|
        test "should return true for editor/#{meth}" do
          assert @controller.current_user = @editor
          assert @controller.acl? meth
          assert @controller.acl? meth.to_s
        end

        test "should return false for viewer/#{meth}" do
          assert @controller.current_user = @viewer
          refute @controller.acl? meth
          refute @controller.acl? meth.to_s
        end
      end

      %i[index show].each do |meth|
        test "should return false for editor/#{meth}" do
          assert @controller.current_user = @editor
          refute @controller.acl? meth
          refute @controller.acl? meth.to_s
        end

        test "should return true for viewer/#{meth}" do
          assert @controller.current_user = @viewer
          assert @controller.acl? meth
          assert @controller.acl? meth.to_s
        end
      end

      test "should return false for editor/fooize" do
        assert @controller.current_user = @editor
        refute @controller.acl? :fooize
      end

      test "should return true for foo owner" do
        assert @controller.current_user = @owneroffoo
        assert @controller.acl? :fooize, foo: Foo.first
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
careacademy-acl9-3.4.0 test/controllers/acl_query_mixin.rb
careacademy-acl9-3.3.0 test/controllers/acl_query_mixin.rb
acl9-3.2.0 test/controllers/acl_query_mixin.rb
acl9-3.1.0 test/controllers/acl_query_mixin.rb