Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-12-17 14:59:07 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-12-17 14:59:07 +0300
commit8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch)
tree544930fb309b30317ae9797a9683768705d664c4 /spec/lib/feature
parent4b1de649d0168371549608993deac953eb692019 (diff)
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/lib/feature')
-rw-r--r--spec/lib/feature/definition_spec.rb63
1 files changed, 61 insertions, 2 deletions
diff --git a/spec/lib/feature/definition_spec.rb b/spec/lib/feature/definition_spec.rb
index fa0207d829a..21120012927 100644
--- a/spec/lib/feature/definition_spec.rb
+++ b/spec/lib/feature/definition_spec.rb
@@ -64,6 +64,11 @@ RSpec.describe Feature::Definition do
expect { definition.valid_usage!(type_in_code: :development, default_enabled_in_code: false) }
.to raise_error(/The `default_enabled:` of `feature_flag` is not equal to config/)
end
+
+ it 'allows passing `default_enabled: :yaml`' do
+ expect { definition.valid_usage!(type_in_code: :development, default_enabled_in_code: :yaml) }
+ .not_to raise_error
+ end
end
end
@@ -75,7 +80,7 @@ RSpec.describe Feature::Definition do
describe '.load_from_file' do
it 'properly loads a definition from file' do
- expect(File).to receive(:read).with(path) { yaml_content }
+ expect_file_read(path, content: yaml_content)
expect(described_class.send(:load_from_file, path).attributes)
.to eq(definition.attributes)
@@ -93,7 +98,7 @@ RSpec.describe Feature::Definition do
context 'for invalid definition' do
it 'raises exception' do
- expect(File).to receive(:read).with(path) { '{}' }
+ expect_file_read(path, content: '{}')
expect do
described_class.send(:load_from_file, path)
@@ -209,4 +214,58 @@ RSpec.describe Feature::Definition do
end
end
end
+
+ describe '.defaul_enabled?' do
+ subject { described_class.default_enabled?(key) }
+
+ context 'when feature flag exist' do
+ let(:key) { definition.key }
+
+ before do
+ allow(described_class).to receive(:definitions) do
+ { definition.key => definition }
+ end
+ end
+
+ context 'when default_enabled is true' do
+ it 'returns the value from the definition' do
+ expect(subject).to eq(true)
+ end
+ end
+
+ context 'when default_enabled is false' do
+ let(:attributes) do
+ { name: 'feature_flag',
+ type: 'development',
+ default_enabled: false }
+ end
+
+ it 'returns the value from the definition' do
+ expect(subject).to eq(false)
+ end
+ end
+ end
+
+ context 'when feature flag does not exist' do
+ let(:key) { :unknown_feature_flag }
+
+ context 'when on dev or test environment' do
+ it 'raises an error' do
+ expect { subject }.to raise_error(
+ Feature::InvalidFeatureFlagError,
+ "The feature flag YAML definition for 'unknown_feature_flag' does not exist")
+ end
+ end
+
+ context 'when on production environment' do
+ before do
+ allow(Gitlab::ErrorTracking).to receive(:should_raise_for_dev?).and_return(false)
+ end
+
+ it 'returns false' do
+ expect(subject).to eq(false)
+ end
+ end
+ end
+ end
end