diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-21 03:08:37 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-21 03:08:37 +0000 |
commit | 2399724614f3c4dcf3059038d997193830de93ee (patch) | |
tree | 3315c4453ef3efb5c1162911753436cad4f3e57d /spec/support/shared_examples/lib/banzai/reference_parser_shared_examples.rb | |
parent | 6755df108b123ecc8ae330d7c7bf2f04fbf36a81 (diff) | |
download | gitlab-ce-2399724614f3c4dcf3059038d997193830de93ee.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support/shared_examples/lib/banzai/reference_parser_shared_examples.rb')
-rw-r--r-- | spec/support/shared_examples/lib/banzai/reference_parser_shared_examples.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/spec/support/shared_examples/lib/banzai/reference_parser_shared_examples.rb b/spec/support/shared_examples/lib/banzai/reference_parser_shared_examples.rb new file mode 100644 index 00000000000..d903c0f10e0 --- /dev/null +++ b/spec/support/shared_examples/lib/banzai/reference_parser_shared_examples.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +RSpec.shared_examples "referenced feature visibility" do |*related_features| + let(:feature_fields) do + related_features.map { |feature| (feature + "_access_level").to_sym } + end + + before do + link['data-project'] = project.id.to_s + end + + context "when feature is disabled" do + it "does not create reference" do + set_features_fields_to(ProjectFeature::DISABLED) + expect(subject.nodes_visible_to_user(user, [link])).to eq([]) + end + end + + context "when feature is enabled only for team members" do + before do + set_features_fields_to(ProjectFeature::PRIVATE) + end + + it "does not create reference for non member" do + non_member = create(:user) + + expect(subject.nodes_visible_to_user(non_member, [link])).to eq([]) + end + + it "creates reference for member" do + project.add_developer(user) + + expect(subject.nodes_visible_to_user(user, [link])).to eq([link]) + end + end + + context "when feature is enabled" do + # The project is public + it "creates reference" do + set_features_fields_to(ProjectFeature::ENABLED) + + expect(subject.nodes_visible_to_user(user, [link])).to eq([link]) + end + end + + def set_features_fields_to(visibility_level) + feature_fields.each { |field| project.project_feature.update_attribute(field, visibility_level) } + end +end |