Commit 39e8ac1a authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'pl-gitlab-edition-memoize' into 'master'

Memoize GitlabEdition.ee? and GitlabEdition.jh?

See merge request gitlab-org/gitlab!80600
parents e6addfb6 b304c357
......@@ -18,7 +18,11 @@ module GitlabEdition
end
def self.ee?
@is_ee ||=
# To reduce dependencies in QA image we are not using
# `Gitlab::Utils::StrongMemoize` but reimplementing its functionality.
return @is_ee if defined?(@is_ee)
@is_ee =
# We use this method when the Rails environment is not loaded. This
# means that checking the presence of the License class could result in
# this method returning `false`, even for an EE installation.
......@@ -34,7 +38,9 @@ module GitlabEdition
end
def self.jh?
@is_jh ||=
return @is_jh if defined?(@is_jh)
@is_jh =
ee? &&
root.join('jh').exist? &&
!%w[true 1].include?(ENV['EE_ONLY'].to_s)
......
......@@ -3,18 +3,22 @@
require 'spec_helper'
RSpec.describe GitlabEdition do
def remove_instance_variable(ivar)
described_class.remove_instance_variable(ivar) if described_class.instance_variable_defined?(ivar)
end
before do
# Make sure the ENV is clean
stub_env('FOSS_ONLY', nil)
stub_env('EE_ONLY', nil)
described_class.instance_variable_set(:@is_ee, nil)
described_class.instance_variable_set(:@is_jh, nil)
remove_instance_variable(:@is_ee)
remove_instance_variable(:@is_jh)
end
after do
described_class.instance_variable_set(:@is_ee, nil)
described_class.instance_variable_set(:@is_jh, nil)
remove_instance_variable(:@is_ee)
remove_instance_variable(:@is_jh)
end
describe '.root' do
......@@ -51,7 +55,7 @@ RSpec.describe GitlabEdition do
allow(described_class).to receive(:ee?).and_return(false)
end
it 'returns the exyensions according to the current edition' do
it 'returns the extensions according to the current edition' do
expect(described_class.extensions).to be_empty
end
end
......@@ -77,7 +81,7 @@ RSpec.describe GitlabEdition do
end
describe '.ee?' do
context 'for EE' do
context 'when EE' do
before do
stub_path('ee/app/models/license.rb', exist?: true)
end
......@@ -109,7 +113,7 @@ RSpec.describe GitlabEdition do
end
end
context 'for CE' do
context 'when CE' do
before do
stub_path('ee/app/models/license.rb', exist?: false)
end
......@@ -121,12 +125,9 @@ RSpec.describe GitlabEdition do
end
describe '.jh?' do
context 'for JH' do
context 'when JH' do
before do
stub_path(
'ee/app/models/license.rb',
'jh',
exist?: true)
stub_path('ee/app/models/license.rb', 'jh', exist?: true)
end
context 'when using default FOSS_ONLY and EE_ONLY' do
......
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