Factorize policy helpers into PolicyHelpers
Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
parent
1983d05ccd
commit
ce4b70ce18
6 changed files with 12 additions and 32 deletions
|
@ -17,14 +17,6 @@ describe BoardPolicy do
|
||||||
]
|
]
|
||||||
end
|
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
|
context 'group board' do
|
||||||
subject { described_class.new(user, group_board) }
|
subject { described_class.new(user, group_board) }
|
||||||
|
|
||||||
|
|
|
@ -51,14 +51,6 @@ describe GroupPolicy do
|
||||||
|
|
||||||
subject { described_class.new(current_user, group) }
|
subject { described_class.new(current_user, 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
|
|
||||||
|
|
||||||
context 'with no user' do
|
context 'with no user' do
|
||||||
let(:group) { create(:group, :public) }
|
let(:group) { create(:group, :public) }
|
||||||
let(:current_user) { nil }
|
let(:current_user) { nil }
|
||||||
|
|
|
@ -15,14 +15,6 @@ describe ProjectSnippetPolicy do
|
||||||
|
|
||||||
subject { described_class.new(current_user, snippet) }
|
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
|
context 'public snippet' do
|
||||||
let(:snippet_visibility) { :public }
|
let(:snippet_visibility) { :public }
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,7 @@ RSpec.configure do |config|
|
||||||
config.include MigrationsHelpers, :migration
|
config.include MigrationsHelpers, :migration
|
||||||
config.include RedisHelpers
|
config.include RedisHelpers
|
||||||
config.include Rails.application.routes.url_helpers, type: :routing
|
config.include Rails.application.routes.url_helpers, type: :routing
|
||||||
|
config.include PolicyHelpers, type: :policy
|
||||||
|
|
||||||
if ENV['CI']
|
if ENV['CI']
|
||||||
# This includes the first try, i.e. tests will be run 4 times before failing.
|
# This includes the first try, i.e. tests will be run 4 times before failing.
|
||||||
|
|
11
spec/support/helpers/policy_helpers.rb
Normal file
11
spec/support/helpers/policy_helpers.rb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# 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_developer(developer)
|
||||||
project.add_reporter(reporter)
|
project.add_reporter(reporter)
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue