summaryrefslogtreecommitdiff
path: root/spec/lib/banzai/reference_parser
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-02-18 10:34:06 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-02-18 10:34:06 +0000
commit859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch)
treed7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /spec/lib/banzai/reference_parser
parent446d496a6d000c73a304be52587cd9bbc7493136 (diff)
downloadgitlab-ce-859a6fb938bb9ee2a317c46dfa4fcc1af49608f0.tar.gz
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'spec/lib/banzai/reference_parser')
-rw-r--r--spec/lib/banzai/reference_parser/feature_flag_parser_spec.rb53
1 files changed, 53 insertions, 0 deletions
diff --git a/spec/lib/banzai/reference_parser/feature_flag_parser_spec.rb b/spec/lib/banzai/reference_parser/feature_flag_parser_spec.rb
new file mode 100644
index 00000000000..288eb9ae360
--- /dev/null
+++ b/spec/lib/banzai/reference_parser/feature_flag_parser_spec.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Banzai::ReferenceParser::FeatureFlagParser do
+ include ReferenceParserHelpers
+
+ subject { described_class.new(Banzai::RenderContext.new(project, user)) }
+
+ let(:link) { empty_html_link }
+
+ describe '#nodes_visible_to_user' do
+ let(:project) { create(:project, :public) }
+ let(:user) { create(:user) }
+ let(:feature_flag) { create(:operations_feature_flag, project: project) }
+
+ context 'when the link has a data-issue attribute' do
+ before do
+ link['data-feature-flag'] = feature_flag.id.to_s
+ end
+
+ it_behaves_like "referenced feature visibility", "issues", "merge_requests" do
+ before do
+ project.add_developer(user) if enable_user?
+ end
+ end
+ end
+ end
+
+ describe '#referenced_by' do
+ let_it_be(:project) { create(:project, :public) }
+ let_it_be(:user) { create(:user) }
+ let_it_be(:feature_flag) { create(:operations_feature_flag, project: project) }
+
+ describe 'when the link has a data-feature-flag attribute' do
+ context 'using an existing feature flag ID' do
+ it 'returns an Array of feature flags' do
+ link['data-feature-flag'] = feature_flag.id.to_s
+
+ expect(subject.referenced_by([link])).to eq([feature_flag])
+ end
+ end
+
+ context 'using a non-existing feature flag ID' do
+ it 'returns an empty Array' do
+ link['data-feature-flag'] = ''
+
+ expect(subject.referenced_by([link])).to eq([])
+ end
+ end
+ end
+ end
+end