Commit 30e11d4c authored by Rémy Coutable's avatar Rémy Coutable

Factorize policy helpers into PolicyHelpers

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 9ee5229b
......@@ -148,15 +148,5 @@ describe Ci::BuildPolicy do
it_behaves_like 'forbidden access'
end
end
def expect_allowed(*permissions)
permissions.each { |p| is_expected.to be_allowed(p) }
end
def expect_disallowed(*permissions)
permissions.each do |p|
is_expected.not_to be_allowed(p)
end
end
end
end
......@@ -449,14 +449,6 @@ describe GroupPolicy do
describe 'private nested group use the highest access level from the group and inherited permissions', :nested_groups do
let(:nested_group) { create(:group, :private, parent: group) }
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
before do
nested_group.add_guest(guest)
nested_group.add_guest(reporter)
......
......@@ -15,14 +15,6 @@ describe ProjectSnippetPolicy do
subject { described_class.new(current_user, snippet) }
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 'private snippet' do
let(:snippet_visibility) { :private }
......
......@@ -17,14 +17,6 @@ describe BoardPolicy do
]
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) }
......
......@@ -3,14 +3,6 @@ require 'spec_helper'
describe GroupPolicy do
include_context 'GroupPolicy context'
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 'with no user' do
let(:group) { create(:group, :public) }
let(:current_user) { nil }
......
......@@ -15,14 +15,6 @@ describe ProjectSnippetPolicy do
subject { described_class.new(current_user, snippet) }
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 'public snippet' do
let(:snippet_visibility) { :public }
......
......@@ -98,6 +98,7 @@ RSpec.configure do |config|
config.include MigrationsHelpers, :migration
config.include RedisHelpers
config.include Rails.application.routes.url_helpers, type: :routing
config.include PolicyHelpers, type: :policy
if ENV['CI']
# This includes the first try, i.e. tests will be run 4 times before failing.
......
# frozen_string_literal: true
module PolicyHelpers
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
end
......@@ -85,12 +85,4 @@ RSpec.shared_context 'ProjectPolicy context' do
project.add_developer(developer)
project.add_reporter(reporter)
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
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment