Commit 7d754c29 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'ee-6539-extract-ee-specific-code' into 'master'

Port Add no-op license helper to CE

See merge request gitlab-org/gitlab-ee!10485
parents 3ea2cfa3 bc4a8443
module EE module EE
module LicenseHelpers module LicenseHelpers
extend ActiveSupport::Concern
# Enable/Disable a feature on the License for a spec. # Enable/Disable a feature on the License for a spec.
# #
# Example: # Example:
...@@ -8,26 +10,29 @@ module EE ...@@ -8,26 +10,29 @@ module EE
# #
# This enables `geo` and disables `deploy_board` features for a spec. # This enables `geo` and disables `deploy_board` features for a spec.
# Other features are still enabled/disabled as defined in the license. # Other features are still enabled/disabled as defined in the license.
def stub_licensed_features(features)
existing_features = License::FEATURES_BY_PLAN.values.flatten.map(&:to_sym)
missing_features = features.keys.map(&:to_sym) - existing_features
if missing_features.any? prepended do
subject = missing_features.join(', ') def stub_licensed_features(features)
noun = 'feature'.pluralize(missing_features.size) existing_features = License::FEATURES_BY_PLAN.values.flatten.map(&:to_sym)
raise ArgumentError, "#{subject} should be defined as licensed #{noun}" missing_features = features.keys.map(&:to_sym) - existing_features
end
if missing_features.any?
subject = missing_features.join(', ')
noun = 'feature'.pluralize(missing_features.size)
raise ArgumentError, "#{subject} should be defined as licensed #{noun}"
end
allow(License).to receive(:feature_available?).and_call_original allow(License).to receive(:feature_available?).and_call_original
features.each do |feature, enabled| features.each do |feature, enabled|
allow(License).to receive(:feature_available?).with(feature) { enabled } allow(License).to receive(:feature_available?).with(feature) { enabled }
end
end end
end
def enable_namespace_license_check! def enable_namespace_license_check!
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false') stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
::Gitlab::CurrentSettings.update!(check_namespace_plan: true) ::Gitlab::CurrentSettings.update!(check_namespace_plan: true)
end
end end
end end
end end
...@@ -16,7 +16,6 @@ describe QuickActions::InterpretService do ...@@ -16,7 +16,6 @@ describe QuickActions::InterpretService do
before do before do
stub_licensed_features(multiple_issue_assignees: false) stub_licensed_features(multiple_issue_assignees: false)
project.add_developer(developer) project.add_developer(developer)
end end
......
...@@ -68,6 +68,7 @@ RSpec.configure do |config| ...@@ -68,6 +68,7 @@ RSpec.configure do |config|
metadata[:type] = match[1].singularize.to_sym if match metadata[:type] = match[1].singularize.to_sym if match
end end
config.include LicenseHelpers
config.include ActiveJob::TestHelper config.include ActiveJob::TestHelper
config.include ActiveSupport::Testing::TimeHelpers config.include ActiveSupport::Testing::TimeHelpers
config.include CycleAnalyticsHelpers config.include CycleAnalyticsHelpers
......
# frozen_string_literal: true
# Placeholder module for EE implementation needed for CE specs to be run in EE codebase
module LicenseHelpers
def stub_licensed_features(features)
# do nothing
end
end
LicenseHelpers.prepend(EE::LicenseHelpers)
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