board_policy_spec.rb 1.36 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
# frozen_string_literal: true

require 'spec_helper'

describe BoardPolicy do
  let(:user) { create(:user) }
  let(:project) { create(:project, :private) }
  let(:group) { create(:group, :private) }
  let(:group_board) { create(:board, group: group) }
  let(:project_board) { create(:board, project: project) }

  let(:board_permissions) do
    [
      :read_parent,
      :read_milestone,
      :read_issue
    ]
  end

  def expect_allowed(*permissions)
    permissions.each { |p| is_expected.to be_allowed(p) }
  end

  def expect_disallowed(*permissions)
    permissions.each { |p| is_expected.not_to be_allowed(p) }
  end

  context 'group board' do
    subject { described_class.new(user, group_board) }

    context 'user has access' do
      before do
        group.add_developer(user)
      end

      it do
        expect_allowed(*board_permissions)
      end
    end

    context 'user does not have access' do
      it do
        expect_disallowed(*board_permissions)
      end
    end
  end

  context 'project board' do
    subject { described_class.new(user, project_board) }

    context 'user has access' do
      before do
        project.add_developer(user)
      end

      it do
        expect_allowed(*board_permissions)
      end
    end

    context 'user does not have access' do
      it do
        expect_disallowed(*board_permissions)
      end
    end
  end
end