diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-26 21:10:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-26 21:10:35 +0300 |
commit | a56971e97f0385640c2f3568017bd221897b78ef (patch) | |
tree | a22308ba6707f73199e3c80523e88b6363044ca4 /spec/lib | |
parent | d3fafe0995cb26212095568f95de6692ec629157 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
8 files changed, 73 insertions, 30 deletions
diff --git a/spec/lib/banzai/reference_parser/base_parser_spec.rb b/spec/lib/banzai/reference_parser/base_parser_spec.rb index 095500cdc53..4701caa0667 100644 --- a/spec/lib/banzai/reference_parser/base_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/base_parser_spec.rb @@ -247,15 +247,15 @@ RSpec.describe Banzai::ReferenceParser::BaseParser do end end - it 'returns referenceable and visible objects, alongside nodes that are referenceable but not visible' do - expect(subject.gather_references(nodes)).to match( - visible: contain_exactly(6, 8, 10), - not_visible: match_array(nodes.select { |n| n.id.even? && n.id <= 5 }) - ) + it 'returns referenceable and visible objects, alongside all and visible nodes' do + referenceable = nodes.select { |n| n.id.even? } + visible = nodes.select { |n| [6, 8, 10].include?(n.id) } + + expect_gathered_references(subject.gather_references(nodes), [6, 8, 10], referenceable, visible) end it 'is always empty if the input is empty' do - expect(subject.gather_references([])) .to match(visible: be_empty, not_visible: be_empty) + expect_gathered_references(subject.gather_references([]), [], [], []) end end diff --git a/spec/lib/banzai/reference_parser/mentioned_group_parser_spec.rb b/spec/lib/banzai/reference_parser/mentioned_group_parser_spec.rb index 4610da7cbe6..576e629d271 100644 --- a/spec/lib/banzai/reference_parser/mentioned_group_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/mentioned_group_parser_spec.rb @@ -19,7 +19,7 @@ RSpec.describe Banzai::ReferenceParser::MentionedGroupParser do it 'returns empty array' do link['data-group'] = project.group.id.to_s - expect_gathered_references(subject.gather_references([link]), [], 1) + expect_gathered_references(subject.gather_references([link]), [], [link], []) end end @@ -30,7 +30,7 @@ RSpec.describe Banzai::ReferenceParser::MentionedGroupParser do end it 'returns groups' do - expect_gathered_references(subject.gather_references([link]), [group], 0) + expect_gathered_references(subject.gather_references([link]), [group], [link], [link]) end end @@ -38,7 +38,7 @@ RSpec.describe Banzai::ReferenceParser::MentionedGroupParser do it 'returns an empty Array' do link['data-group'] = 'test-non-existing' - expect_gathered_references(subject.gather_references([link]), [], 1) + expect_gathered_references(subject.gather_references([link]), [], [link], []) end end end diff --git a/spec/lib/banzai/reference_parser/mentioned_project_parser_spec.rb b/spec/lib/banzai/reference_parser/mentioned_project_parser_spec.rb index 7eb58ee40d3..983407addce 100644 --- a/spec/lib/banzai/reference_parser/mentioned_project_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/mentioned_project_parser_spec.rb @@ -19,7 +19,7 @@ RSpec.describe Banzai::ReferenceParser::MentionedProjectParser do it 'returns empty Array' do link['data-project'] = project.id.to_s - expect_gathered_references(subject.gather_references([link]), [], 1) + expect_gathered_references(subject.gather_references([link]), [], [link], []) end end @@ -30,7 +30,7 @@ RSpec.describe Banzai::ReferenceParser::MentionedProjectParser do end it 'returns an Array of referenced projects' do - expect_gathered_references(subject.gather_references([link]), [project], 0) + expect_gathered_references(subject.gather_references([link]), [project], [link], [link]) end end @@ -38,7 +38,7 @@ RSpec.describe Banzai::ReferenceParser::MentionedProjectParser do it 'returns an empty Array' do link['data-project'] = 'inexisting-project-id' - expect_gathered_references(subject.gather_references([link]), [], 1) + expect_gathered_references(subject.gather_references([link]), [], [link], []) end end end diff --git a/spec/lib/banzai/reference_parser/mentioned_user_parser_spec.rb b/spec/lib/banzai/reference_parser/mentioned_user_parser_spec.rb index 4be07866db1..f117d796dad 100644 --- a/spec/lib/banzai/reference_parser/mentioned_user_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/mentioned_user_parser_spec.rb @@ -22,7 +22,7 @@ RSpec.describe Banzai::ReferenceParser::MentionedUserParser do end it 'returns empty list of users' do - expect_gathered_references(subject.gather_references([link]), [], 0) + expect_gathered_references(subject.gather_references([link]), [], [link], [link]) end end end @@ -35,7 +35,7 @@ RSpec.describe Banzai::ReferenceParser::MentionedUserParser do end it 'returns empty list of users' do - expect_gathered_references(subject.gather_references([link]), [], 0) + expect_gathered_references(subject.gather_references([link]), [], [link], [link]) end end end @@ -44,7 +44,7 @@ RSpec.describe Banzai::ReferenceParser::MentionedUserParser do it 'returns an Array of users' do link['data-user'] = user.id.to_s - expect_gathered_references(subject.gather_references([link]), [user], 0) + expect_gathered_references(subject.gather_references([link]), [user], [link], [link]) end end end diff --git a/spec/lib/banzai/reference_parser/project_parser_spec.rb b/spec/lib/banzai/reference_parser/project_parser_spec.rb index 6358a04f12a..2c0b6c417b0 100644 --- a/spec/lib/banzai/reference_parser/project_parser_spec.rb +++ b/spec/lib/banzai/reference_parser/project_parser_spec.rb @@ -17,7 +17,7 @@ RSpec.describe Banzai::ReferenceParser::ProjectParser do it 'returns an Array of projects' do link['data-project'] = project.id.to_s - expect_gathered_references(subject.gather_references([link]), [project], 0) + expect_gathered_references(subject.gather_references([link]), [project], [link], [link]) end end @@ -25,7 +25,7 @@ RSpec.describe Banzai::ReferenceParser::ProjectParser do it 'returns an empty Array' do link['data-project'] = '' - expect_gathered_references(subject.gather_references([link]), [], 1) + expect_gathered_references(subject.gather_references([link]), [], [link], []) end end @@ -35,7 +35,7 @@ RSpec.describe Banzai::ReferenceParser::ProjectParser do link['data-project'] = private_project.id.to_s - expect_gathered_references(subject.gather_references([link]), [], 1) + expect_gathered_references(subject.gather_references([link]), [], [link], []) end it 'returns an Array when authorized' do @@ -43,7 +43,7 @@ RSpec.describe Banzai::ReferenceParser::ProjectParser do link['data-project'] = private_project.id.to_s - expect_gathered_references(subject.gather_references([link]), [private_project], 0) + expect_gathered_references(subject.gather_references([link]), [private_project], [link], [link]) end end end diff --git a/spec/lib/gitlab/reference_extractor_spec.rb b/spec/lib/gitlab/reference_extractor_spec.rb index f6e69aa6533..177e9d346b6 100644 --- a/spec/lib/gitlab/reference_extractor_spec.rb +++ b/spec/lib/gitlab/reference_extractor_spec.rb @@ -332,14 +332,59 @@ RSpec.describe Gitlab::ReferenceExtractor do it 'returns visible references of given type' do expect(subject.references(:issue)).to eq([issue]) end + end - it 'does not increase stateful_not_visible_counter' do - expect { subject.references(:issue) }.not_to change { subject.stateful_not_visible_counter } - end + it 'does not return any references' do + expect(subject.references(:issue)).to be_empty + end + end + + describe '#all_visible?' do + let_it_be(:user) { create(:user) } + let_it_be(:project2) { create(:project) } + let_it_be(:issue) { create(:issue, project: project) } + let_it_be(:issue2) { create(:issue, project: project2) } + + let(:text) { "Ref. #{issue.to_reference} and #{issue2.to_reference(project)}" } + + subject { described_class.new(project, user) } + + before do + subject.analyze(text) end - it 'increases stateful_not_visible_counter' do - expect { subject.references(:issue) }.to change { subject.stateful_not_visible_counter }.by(1) + it 'returns true if no references were parsed yet' do + expect(subject.all_visible?).to be_truthy + end + + context 'when references was already called' do + let(:membership) { [] } + + before do + membership.each { |p| p.add_developer(user) } + + subject.references(:issue) + end + + it 'returns false' do + expect(subject.all_visible?).to be_falsey + end + + context 'when user can access only some references' do + let(:membership) { [project] } + + it 'returns false' do + expect(subject.all_visible?).to be_falsey + end + end + + context 'when user can access all references' do + let(:membership) { [project, project2] } + + it 'returns true' do + expect(subject.all_visible?).to be_truthy + end + end end end end diff --git a/spec/lib/gitlab/usage/metric_definition_spec.rb b/spec/lib/gitlab/usage/metric_definition_spec.rb index 1ae8a0881ef..f19e893762f 100644 --- a/spec/lib/gitlab/usage/metric_definition_spec.rb +++ b/spec/lib/gitlab/usage/metric_definition_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Gitlab::Usage::MetricDefinition do value_type: 'string', product_category: 'collection', product_stage: 'growth', - status: 'data_available', + status: 'active', default_generation: 'generation_1', key_path: 'uuid', product_group: 'group::product analytics', @@ -127,9 +127,7 @@ RSpec.describe Gitlab::Usage::MetricDefinition do where(:status, :skip_validation?) do 'deprecated' | true 'removed' | true - 'data_available' | false - 'implemented' | false - 'not_used' | false + 'active' | false end with_them do @@ -191,7 +189,7 @@ RSpec.describe Gitlab::Usage::MetricDefinition do value_type: 'string', product_category: 'collection', product_stage: 'growth', - status: 'data_available', + status: 'active', default_generation: 'generation_1', key_path: 'counter.category.event', product_group: 'group::product analytics', diff --git a/spec/lib/gitlab/usage/metric_spec.rb b/spec/lib/gitlab/usage/metric_spec.rb index d83f59e4a7d..ea8d1a135a6 100644 --- a/spec/lib/gitlab/usage/metric_spec.rb +++ b/spec/lib/gitlab/usage/metric_spec.rb @@ -15,7 +15,7 @@ RSpec.describe Gitlab::Usage::Metric do product_group: "group::plan", product_category: "issue_tracking", value_type: "number", - status: "data_available", + status: "active", time_frame: "all", data_source: "database", instrumentation_class: "CountIssuesMetric", |