summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-07-23 06:08:47 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-07-23 06:08:47 +0000
commitd950ea420a77bc6b27037bd00484f2463e79b4fd (patch)
treeec93e370d6543321bb725e06f331b602e06873ac /spec
parent9d9c8fc2ec2fdfa0bae2f77a5c2bde52a5bf45e2 (diff)
downloadgitlab-ce-d950ea420a77bc6b27037bd00484f2463e79b4fd.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects_controller_spec.rb26
-rw-r--r--spec/experiments/new_project_readme_experiment_spec.rb75
-rw-r--r--spec/features/projects/blobs/blob_show_spec.rb290
-rw-r--r--spec/features/projects/user_creates_project_spec.rb3
-rw-r--r--spec/frontend/pipelines/mock_data.js81
-rw-r--r--spec/frontend/pipelines/pipelines_table_spec.js56
-rw-r--r--spec/models/diff_discussion_spec.rb4
-rw-r--r--spec/models/discussion_spec.rb8
-rw-r--r--spec/models/environment_spec.rb10
-rw-r--r--spec/models/note_spec.rb20
-rw-r--r--spec/requests/projects/merge_requests_discussions_spec.rb24
-rw-r--r--spec/workers/post_receive_spec.rb8
12 files changed, 187 insertions, 418 deletions
diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb
index 46c17d6a6fe..d8a1580ad67 100644
--- a/spec/controllers/projects_controller_spec.rb
+++ b/spec/controllers/projects_controller_spec.rb
@@ -435,32 +435,6 @@ RSpec.describe ProjectsController do
end
end
- describe 'POST create' do
- let!(:project_params) do
- {
- path: 'foo',
- description: 'bar',
- namespace_id: user.namespace.id,
- visibility_level: Gitlab::VisibilityLevel::PUBLIC,
- initialize_with_readme: 1
- }
- end
-
- before do
- sign_in(user)
- end
-
- it 'tracks a created event for the new_project_readme experiment', :experiment do
- expect(experiment(:new_project_readme)).to track(
- :created,
- property: 'blank',
- value: 1
- ).with_context(actor: user).on_next_instance
-
- post :create, params: { project: project_params }
- end
- end
-
describe 'POST #archive' do
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, group: group) }
diff --git a/spec/experiments/new_project_readme_experiment_spec.rb b/spec/experiments/new_project_readme_experiment_spec.rb
deleted file mode 100644
index e5ecc4662f6..00000000000
--- a/spec/experiments/new_project_readme_experiment_spec.rb
+++ /dev/null
@@ -1,75 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe NewProjectReadmeExperiment, :experiment do
- subject { described_class.new(actor: actor) }
-
- let(:actor) { User.new(id: 42, created_at: Time.current) }
-
- describe "exclusions" do
- let(:threshold) { described_class::MAX_ACCOUNT_AGE }
-
- it { is_expected.to exclude(actor: User.new(created_at: (threshold + 1.minute).ago)) }
- it { is_expected.not_to exclude(actor: User.new(created_at: (threshold - 1.minute).ago)) }
- end
-
- describe "the control behavior" do
- subject { described_class.new(actor: actor).run(:control) }
-
- it { is_expected.to be false }
- end
-
- describe "the candidate behavior" do
- subject { described_class.new(actor: actor).run(:candidate) }
-
- it { is_expected.to be true }
- end
-
- context "when tracking initial writes" do
- let!(:project) { create(:project, :repository) }
-
- before do
- stub_experiments(new_project_readme: :control)
- end
-
- it "tracks an event for the first commit on a project with a repository" do
- expect(subject).to receive(:commit_count_for).with(project, default_count: described_class::INITIAL_WRITE_LIMIT, max_count: described_class::INITIAL_WRITE_LIMIT, experiment: 'new_project_readme').and_return(1)
- expect(subject).to receive(:track).with(:write, property: project.created_at.to_s, value: 1).and_call_original
-
- subject.track_initial_writes(project)
- end
-
- it "tracks an event for the second commit on a project with a repository" do
- allow(subject).to receive(:commit_count_for).and_return(2)
-
- expect(subject).to receive(:track).with(:write, property: project.created_at.to_s, value: 2).and_call_original
-
- subject.track_initial_writes(project)
- end
-
- it "doesn't track if the repository has more then 2 commits" do
- allow(subject).to receive(:commit_count_for).and_return(3)
-
- expect(subject).not_to receive(:track)
-
- subject.track_initial_writes(project)
- end
-
- it "doesn't track when we generally shouldn't" do
- allow(subject).to receive(:should_track?).and_return(false)
-
- expect(subject).not_to receive(:track)
-
- subject.track_initial_writes(project)
- end
-
- it "doesn't track if the project is older" do
- expect(project).to receive(:created_at).and_return(described_class::EXPERIMENT_START_DATE - 1.minute)
-
- expect(subject).not_to receive(:track)
-
- subject.track_initial_writes(project)
- end
- end
-end
diff --git a/spec/features/projects/blobs/blob_show_spec.rb b/spec/features/projects/blobs/blob_show_spec.rb
index 595304789a6..677052eebea 100644
--- a/spec/features/projects/blobs/blob_show_spec.rb
+++ b/spec/features/projects/blobs/blob_show_spec.rb
@@ -584,199 +584,205 @@ RSpec.describe 'File blob', :js do
end
end
- describe '.gitlab-ci.yml' do
+ context 'files with auxiliary viewers' do
before do
- project.add_maintainer(project.creator)
-
- Files::CreateService.new(
- project,
- project.creator,
- start_branch: 'master',
- branch_name: 'master',
- commit_message: "Add .gitlab-ci.yml",
- file_path: '.gitlab-ci.yml',
- file_content: File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
- ).execute
-
- visit_blob('.gitlab-ci.yml')
+ stub_feature_flags(refactor_blob_viewer: true)
end
- it 'displays an auxiliary viewer' do
- aggregate_failures do
- # shows that configuration is valid
- expect(page).to have_content('This GitLab CI configuration is valid.')
+ describe '.gitlab-ci.yml' do
+ before do
+ project.add_maintainer(project.creator)
- # shows a learn more link
- expect(page).to have_link('Learn more')
- end
- end
- end
+ Files::CreateService.new(
+ project,
+ project.creator,
+ start_branch: 'master',
+ branch_name: 'master',
+ commit_message: "Add .gitlab-ci.yml",
+ file_path: '.gitlab-ci.yml',
+ file_content: File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
+ ).execute
- describe '.gitlab/route-map.yml' do
- before do
- project.add_maintainer(project.creator)
+ visit_blob('.gitlab-ci.yml')
+ end
- Files::CreateService.new(
- project,
- project.creator,
- start_branch: 'master',
- branch_name: 'master',
- commit_message: "Add .gitlab/route-map.yml",
- file_path: '.gitlab/route-map.yml',
- file_content: <<-MAP.strip_heredoc
- # Team data
- - source: 'data/team.yml'
- public: 'team/'
- MAP
- ).execute
+ it 'displays an auxiliary viewer' do
+ aggregate_failures do
+ # shows that configuration is valid
+ expect(page).to have_content('This GitLab CI configuration is valid.')
- visit_blob('.gitlab/route-map.yml')
+ # shows a learn more link
+ expect(page).to have_link('Learn more')
+ end
+ end
end
- it 'displays an auxiliary viewer' do
- aggregate_failures do
- # shows that map is valid
- expect(page).to have_content('This Route Map is valid.')
+ describe '.gitlab/route-map.yml' do
+ before do
+ project.add_maintainer(project.creator)
+
+ Files::CreateService.new(
+ project,
+ project.creator,
+ start_branch: 'master',
+ branch_name: 'master',
+ commit_message: "Add .gitlab/route-map.yml",
+ file_path: '.gitlab/route-map.yml',
+ file_content: <<-MAP.strip_heredoc
+ # Team data
+ - source: 'data/team.yml'
+ public: 'team/'
+ MAP
+ ).execute
- # shows a learn more link
- expect(page).to have_link('Learn more')
+ visit_blob('.gitlab/route-map.yml')
end
- end
- end
- describe '.gitlab/dashboards/custom-dashboard.yml' do
- before do
- project.add_maintainer(project.creator)
+ it 'displays an auxiliary viewer' do
+ aggregate_failures do
+ # shows that map is valid
+ expect(page).to have_content('This Route Map is valid.')
- Files::CreateService.new(
- project,
- project.creator,
- start_branch: 'master',
- branch_name: 'master',
- commit_message: "Add .gitlab/dashboards/custom-dashboard.yml",
- file_path: '.gitlab/dashboards/custom-dashboard.yml',
- file_content: file_content
- ).execute
+ # shows a learn more link
+ expect(page).to have_link('Learn more')
+ end
+ end
end
- context 'with metrics_dashboard_exhaustive_validations feature flag off' do
+ describe '.gitlab/dashboards/custom-dashboard.yml' do
before do
- stub_feature_flags(metrics_dashboard_exhaustive_validations: false)
- visit_blob('.gitlab/dashboards/custom-dashboard.yml')
+ project.add_maintainer(project.creator)
+
+ Files::CreateService.new(
+ project,
+ project.creator,
+ start_branch: 'master',
+ branch_name: 'master',
+ commit_message: "Add .gitlab/dashboards/custom-dashboard.yml",
+ file_path: '.gitlab/dashboards/custom-dashboard.yml',
+ file_content: file_content
+ ).execute
end
- context 'valid dashboard file' do
- let(:file_content) { File.read(Rails.root.join('config/prometheus/common_metrics.yml')) }
+ context 'with metrics_dashboard_exhaustive_validations feature flag off' do
+ before do
+ stub_feature_flags(metrics_dashboard_exhaustive_validations: false)
+ visit_blob('.gitlab/dashboards/custom-dashboard.yml')
+ end
- it 'displays an auxiliary viewer' do
- aggregate_failures do
- # shows that dashboard yaml is valid
- expect(page).to have_content('Metrics Dashboard YAML definition is valid.')
+ context 'valid dashboard file' do
+ let(:file_content) { File.read(Rails.root.join('config/prometheus/common_metrics.yml')) }
- # shows a learn more link
- expect(page).to have_link('Learn more')
+ it 'displays an auxiliary viewer' do
+ aggregate_failures do
+ # shows that dashboard yaml is valid
+ expect(page).to have_content('Metrics Dashboard YAML definition is valid.')
+
+ # shows a learn more link
+ expect(page).to have_link('Learn more')
+ end
end
end
- end
- context 'invalid dashboard file' do
- let(:file_content) { "dashboard: 'invalid'" }
+ context 'invalid dashboard file' do
+ let(:file_content) { "dashboard: 'invalid'" }
- it 'displays an auxiliary viewer' do
- aggregate_failures do
- # shows that dashboard yaml is invalid
- expect(page).to have_content('Metrics Dashboard YAML definition is invalid:')
- expect(page).to have_content("panel_groups: should be an array of panel_groups objects")
+ it 'displays an auxiliary viewer' do
+ aggregate_failures do
+ # shows that dashboard yaml is invalid
+ expect(page).to have_content('Metrics Dashboard YAML definition is invalid:')
+ expect(page).to have_content("panel_groups: should be an array of panel_groups objects")
- # shows a learn more link
- expect(page).to have_link('Learn more')
+ # shows a learn more link
+ expect(page).to have_link('Learn more')
+ end
end
end
end
- end
- context 'with metrics_dashboard_exhaustive_validations feature flag on' do
- before do
- stub_feature_flags(metrics_dashboard_exhaustive_validations: true)
- visit_blob('.gitlab/dashboards/custom-dashboard.yml')
- end
+ context 'with metrics_dashboard_exhaustive_validations feature flag on' do
+ before do
+ stub_feature_flags(metrics_dashboard_exhaustive_validations: true)
+ visit_blob('.gitlab/dashboards/custom-dashboard.yml')
+ end
- context 'valid dashboard file' do
- let(:file_content) { File.read(Rails.root.join('config/prometheus/common_metrics.yml')) }
+ context 'valid dashboard file' do
+ let(:file_content) { File.read(Rails.root.join('config/prometheus/common_metrics.yml')) }
- it 'displays an auxiliary viewer' do
- aggregate_failures do
- # shows that dashboard yaml is valid
- expect(page).to have_content('Metrics Dashboard YAML definition is valid.')
+ it 'displays an auxiliary viewer' do
+ aggregate_failures do
+ # shows that dashboard yaml is valid
+ expect(page).to have_content('Metrics Dashboard YAML definition is valid.')
- # shows a learn more link
- expect(page).to have_link('Learn more')
+ # shows a learn more link
+ expect(page).to have_link('Learn more')
+ end
end
end
- end
- context 'invalid dashboard file' do
- let(:file_content) { "dashboard: 'invalid'" }
+ context 'invalid dashboard file' do
+ let(:file_content) { "dashboard: 'invalid'" }
- it 'displays an auxiliary viewer' do
- aggregate_failures do
- # shows that dashboard yaml is invalid
- expect(page).to have_content('Metrics Dashboard YAML definition is invalid:')
- expect(page).to have_content("root is missing required keys: panel_groups")
+ it 'displays an auxiliary viewer' do
+ aggregate_failures do
+ # shows that dashboard yaml is invalid
+ expect(page).to have_content('Metrics Dashboard YAML definition is invalid:')
+ expect(page).to have_content("root is missing required keys: panel_groups")
- # shows a learn more link
- expect(page).to have_link('Learn more')
+ # shows a learn more link
+ expect(page).to have_link('Learn more')
+ end
end
end
end
end
- end
- context 'LICENSE' do
- before do
- visit_blob('LICENSE')
- end
+ context 'LICENSE' do
+ before do
+ visit_blob('LICENSE')
+ end
- it 'displays an auxiliary viewer' do
- aggregate_failures do
- # shows license
- expect(page).to have_content('This project is licensed under the MIT License.')
+ it 'displays an auxiliary viewer' do
+ aggregate_failures do
+ # shows license
+ expect(page).to have_content('This project is licensed under the MIT License.')
- # shows a learn more link
- expect(page).to have_link('Learn more', href: 'http://choosealicense.com/licenses/mit/')
+ # shows a learn more link
+ expect(page).to have_link('Learn more', href: 'http://choosealicense.com/licenses/mit/')
+ end
end
end
- end
- context '*.gemspec' do
- before do
- project.add_maintainer(project.creator)
+ context '*.gemspec' do
+ before do
+ project.add_maintainer(project.creator)
- Files::CreateService.new(
- project,
- project.creator,
- start_branch: 'master',
- branch_name: 'master',
- commit_message: "Add activerecord.gemspec",
- file_path: 'activerecord.gemspec',
- file_content: <<-SPEC.strip_heredoc
- Gem::Specification.new do |s|
- s.platform = Gem::Platform::RUBY
- s.name = "activerecord"
- end
- SPEC
- ).execute
+ Files::CreateService.new(
+ project,
+ project.creator,
+ start_branch: 'master',
+ branch_name: 'master',
+ commit_message: "Add activerecord.gemspec",
+ file_path: 'activerecord.gemspec',
+ file_content: <<-SPEC.strip_heredoc
+ Gem::Specification.new do |s|
+ s.platform = Gem::Platform::RUBY
+ s.name = "activerecord"
+ end
+ SPEC
+ ).execute
- visit_blob('activerecord.gemspec')
- end
+ visit_blob('activerecord.gemspec')
+ end
- it 'displays an auxiliary viewer' do
- aggregate_failures do
- # shows names of dependency manager and package
- expect(page).to have_content('This project manages its dependencies using RubyGems.')
+ it 'displays an auxiliary viewer' do
+ aggregate_failures do
+ # shows names of dependency manager and package
+ expect(page).to have_content('This project manages its dependencies using RubyGems.')
- # shows a learn more link
- expect(page).to have_link('Learn more', href: 'https://rubygems.org/')
+ # shows a learn more link
+ expect(page).to have_link('Learn more', href: 'https://rubygems.org/')
+ end
end
end
end
diff --git a/spec/features/projects/user_creates_project_spec.rb b/spec/features/projects/user_creates_project_spec.rb
index a5b51bac747..96051e8d9f9 100644
--- a/spec/features/projects/user_creates_project_spec.rb
+++ b/spec/features/projects/user_creates_project_spec.rb
@@ -8,8 +8,6 @@ RSpec.describe 'User creates a project', :js do
before do
sign_in(user)
create(:personal_key, user: user)
-
- stub_experiments(new_project_readme: :candidate)
end
it 'creates a new project' do
@@ -18,7 +16,6 @@ RSpec.describe 'User creates a project', :js do
find('[data-qa-panel-name="blank_project"]').click
fill_in(:project_name, with: 'Empty')
- # part of the new_project_readme experiment
expect(page).to have_checked_field 'Initialize repository with a README'
uncheck 'Initialize repository with a README'
diff --git a/spec/frontend/pipelines/mock_data.js b/spec/frontend/pipelines/mock_data.js
index 02ec529eb12..7e3c3727c9d 100644
--- a/spec/frontend/pipelines/mock_data.js
+++ b/spec/frontend/pipelines/mock_data.js
@@ -471,84 +471,3 @@ export const mockSearch = [
export const mockBranchesAfterMap = ['branch-1', 'branch-10', 'branch-11'];
export const mockTagsAfterMap = ['tag-3', 'tag-2', 'tag-1', 'main-tag'];
-
-export const triggered = [
- {
- id: 602,
- user: {
- id: 1,
- name: 'Administrator',
- username: 'root',
- state: 'active',
- avatar_url:
- 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
- web_url: 'http://gdk.test:3000/root',
- show_status: false,
- path: '/root',
- },
- active: false,
- coverage: null,
- source: 'pipeline',
- source_job: { name: 'trigger_job_on_mr' },
- path: '/root/job-log-sections/-/pipelines/602',
- details: {
- status: {
- icon: 'status_success',
- text: 'passed',
- label: 'passed',
- group: 'success',
- tooltip: 'passed',
- has_details: true,
- details_path: '/root/job-log-sections/-/pipelines/602',
- illustration: null,
- favicon:
- '/assets/ci_favicons/favicon_status_success-8451333011eee8ce9f2ab25dc487fe24a8758c694827a582f17f42b0a90446a2.png',
- },
- },
- project: {
- id: 36,
- name: 'job-log-sections',
- full_path: '/root/job-log-sections',
- full_name: 'Administrator / job-log-sections',
- },
- },
-];
-
-export const triggeredBy = {
- id: 614,
- user: {
- id: 1,
- name: 'Administrator',
- username: 'root',
- state: 'active',
- avatar_url: 'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
- web_url: 'http://gdk.test:3000/root',
- show_status: false,
- path: '/root',
- },
- active: false,
- coverage: null,
- source: 'web',
- source_job: { name: null },
- path: '/root/trigger-downstream/-/pipelines/614',
- details: {
- status: {
- icon: 'status_success',
- text: 'passed',
- label: 'passed',
- group: 'success',
- tooltip: 'passed',
- has_details: true,
- details_path: '/root/trigger-downstream/-/pipelines/614',
- illustration: null,
- favicon:
- '/assets/ci_favicons/favicon_status_success-8451333011eee8ce9f2ab25dc487fe24a8758c694827a582f17f42b0a90446a2.png',
- },
- },
- project: {
- id: 42,
- name: 'trigger-downstream',
- full_path: '/root/trigger-downstream',
- full_name: 'Administrator / trigger-downstream',
- },
-};
diff --git a/spec/frontend/pipelines/pipelines_table_spec.js b/spec/frontend/pipelines/pipelines_table_spec.js
index 07d9b208776..68b0dfc018e 100644
--- a/spec/frontend/pipelines/pipelines_table_spec.js
+++ b/spec/frontend/pipelines/pipelines_table_spec.js
@@ -12,7 +12,6 @@ import PipelinesTimeago from '~/pipelines/components/pipelines_list/time_ago.vue
import eventHub from '~/pipelines/event_hub';
import CiBadge from '~/vue_shared/components/ci_badge_link.vue';
import CommitComponent from '~/vue_shared/components/commit.vue';
-import { triggeredBy, triggered } from './mock_data';
jest.mock('~/pipelines/event_hub');
@@ -60,8 +59,6 @@ describe('Pipelines Table', () => {
const findStagesTh = () => wrapper.findByTestId('stages-th');
const findTimeAgoTh = () => wrapper.findByTestId('timeago-th');
const findActionsTh = () => wrapper.findByTestId('actions-th');
- const findUpstream = () => wrapper.findByTestId('mini-graph-upstream');
- const findDownstream = () => wrapper.findByTestId('mini-graph-downstream');
beforeEach(() => {
pipeline = createMockPipeline();
@@ -139,8 +136,6 @@ describe('Pipelines Table', () => {
describe('stages cell', () => {
it('should render a pipeline mini graph', () => {
expect(findPipelineMiniGraph().exists()).toBe(true);
- expect(findUpstream().exists()).toBe(false);
- expect(findDownstream().exists()).toBe(false);
});
it('should render the right number of stages', () => {
@@ -178,57 +173,6 @@ describe('Pipelines Table', () => {
expect(eventHub.$emit).toHaveBeenCalledWith('refreshPipelinesTable');
});
-
- describe('upstream linked pipelines', () => {
- beforeEach(() => {
- pipeline = createMockPipeline();
- pipeline.triggered_by = triggeredBy;
-
- createComponent({ pipelines: [pipeline] });
- });
-
- it('should render only a upstream pipeline', () => {
- expect(findUpstream().exists()).toBe(true);
- expect(findDownstream().exists()).toBe(false);
- });
-
- it('should pass an array of the correct data to the linked pipeline component', () => {
- const triggeredByProps = findUpstream().props('triggeredBy');
-
- expect(triggeredByProps).toEqual(expect.any(Array));
- expect(triggeredByProps).toHaveLength(1);
- expect(triggeredByProps[0]).toBe(triggeredBy);
- });
- });
-
- describe('downstream linked pipelines', () => {
- beforeEach(() => {
- pipeline = createMockPipeline();
- pipeline.triggered = triggered;
-
- createComponent({ pipelines: [pipeline] });
- });
-
- it('should render only a downstream pipeline', () => {
- expect(findDownstream().exists()).toBe(true);
- expect(findUpstream().exists()).toBe(false);
- });
- });
-
- describe('upstream and downstream linked pipelines', () => {
- beforeEach(() => {
- pipeline = createMockPipeline();
- pipeline.triggered = triggered;
- pipeline.triggered_by = triggeredBy;
-
- createComponent({ pipelines: [pipeline] });
- });
-
- it('should render both downstream and upstream pipelines', () => {
- expect(findDownstream().exists()).toBe(true);
- expect(findUpstream().exists()).toBe(true);
- });
- });
});
describe('duration cell', () => {
diff --git a/spec/models/diff_discussion_spec.rb b/spec/models/diff_discussion_spec.rb
index 998204626d3..4e2463ab3f3 100644
--- a/spec/models/diff_discussion_spec.rb
+++ b/spec/models/diff_discussion_spec.rb
@@ -129,10 +129,10 @@ RSpec.describe DiffDiscussion do
describe '#cache_key' do
it 'returns the cache key with the position sha' do
- notes_sha = Digest::SHA1.hexdigest("#{diff_note.id}")
+ notes_sha = Digest::SHA1.hexdigest("#{diff_note.post_processed_cache_key}")
position_sha = Digest::SHA1.hexdigest(diff_note.position.to_json)
- expect(subject.cache_key).to eq("#{described_class::CACHE_VERSION}:#{diff_note.latest_cached_markdown_version}:#{subject.id}:#{notes_sha}:#{diff_note.updated_at}::#{position_sha}")
+ expect(subject.cache_key).to eq("#{described_class::CACHE_VERSION}:#{subject.id}:#{notes_sha}::#{position_sha}")
end
end
end
diff --git a/spec/models/discussion_spec.rb b/spec/models/discussion_spec.rb
index 2b33de96e04..212619a1c3d 100644
--- a/spec/models/discussion_spec.rb
+++ b/spec/models/discussion_spec.rb
@@ -53,10 +53,10 @@ RSpec.describe Discussion do
end
describe '#cache_key' do
- let(:notes_sha) { Digest::SHA1.hexdigest("#{first_note.id}:#{second_note.id}:#{third_note.id}") }
+ let(:notes_sha) { Digest::SHA1.hexdigest("#{first_note.post_processed_cache_key}:#{second_note.post_processed_cache_key}:#{third_note.post_processed_cache_key}") }
- it 'returns the cache key with ID and latest updated note updated at' do
- expect(subject.cache_key).to eq("#{described_class::CACHE_VERSION}:#{third_note.latest_cached_markdown_version}:#{subject.id}:#{notes_sha}:#{third_note.updated_at}:")
+ it 'returns the cache key' do
+ expect(subject.cache_key).to eq("#{described_class::CACHE_VERSION}:#{subject.id}:#{notes_sha}:")
end
context 'when discussion is resolved' do
@@ -65,7 +65,7 @@ RSpec.describe Discussion do
end
it 'returns the cache key with resolved at' do
- expect(subject.cache_key).to eq("#{described_class::CACHE_VERSION}:#{third_note.latest_cached_markdown_version}:#{subject.id}:#{notes_sha}:#{third_note.updated_at}:#{subject.resolved_at}")
+ expect(subject.cache_key).to eq("#{described_class::CACHE_VERSION}:#{subject.id}:#{notes_sha}:#{subject.resolved_at}")
end
end
end
diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb
index 18a172b72d7..fae58326f07 100644
--- a/spec/models/environment_spec.rb
+++ b/spec/models/environment_spec.rb
@@ -14,6 +14,7 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
subject(:environment) { create(:environment, project: project) }
it { is_expected.to be_kind_of(ReactiveCaching) }
+ it { is_expected.to nullify_if_blank(:external_url) }
it { is_expected.to belong_to(:project).required }
it { is_expected.to have_many(:deployments) }
@@ -412,15 +413,6 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
end
end
- describe '#nullify_external_url' do
- it 'replaces a blank url with nil' do
- env = build(:environment, external_url: "")
-
- expect(env.save).to be true
- expect(env.external_url).to be_nil
- end
- end
-
describe '#includes_commit?' do
let(:project) { create(:project, :repository) }
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb
index 2afe9a0f29b..d7eddaa4294 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -1538,4 +1538,24 @@ RSpec.describe Note do
expect(attachment).not_to be_exist
end
end
+
+ describe '#post_processed_cache_key' do
+ let(:note) { build(:note) }
+
+ it 'returns cache key by default' do
+ expect(note.post_processed_cache_key).to eq(note.cache_key)
+ end
+
+ context 'when note has redacted_note_html' do
+ let(:redacted_note_html) { 'redacted note html' }
+
+ before do
+ note.redacted_note_html = redacted_note_html
+ end
+
+ it 'returns cache key with redacted_note_html sha' do
+ expect(note.post_processed_cache_key).to eq("#{note.cache_key}:#{Digest::SHA1.hexdigest(redacted_note_html)}")
+ end
+ end
+ end
end
diff --git a/spec/requests/projects/merge_requests_discussions_spec.rb b/spec/requests/projects/merge_requests_discussions_spec.rb
index 595222a9eb2..f2e8377cf23 100644
--- a/spec/requests/projects/merge_requests_discussions_spec.rb
+++ b/spec/requests/projects/merge_requests_discussions_spec.rb
@@ -54,7 +54,8 @@ RSpec.describe 'merge requests discussions' do
end
context 'caching', :use_clean_rails_memory_store_caching do
- let!(:first_note) { create(:diff_note_on_merge_request, noteable: merge_request, project: project) }
+ let(:reference) { create(:issue, project: project) }
+ let!(:first_note) { create(:diff_note_on_merge_request, noteable: merge_request, project: project, note: "reference: #{reference.to_reference}") }
let!(:second_note) { create(:diff_note_on_merge_request, in_reply_to: first_note, noteable: merge_request, project: project) }
let!(:award_emoji) { create(:award_emoji, awardable: first_note) }
@@ -93,6 +94,16 @@ RSpec.describe 'merge requests discussions' do
end
end
+ context 'when a note in a discussion got its reference state updated' do
+ before do
+ reference.close!
+ end
+
+ it_behaves_like 'cache miss' do
+ let(:changed_notes) { [first_note, second_note] }
+ end
+ end
+
context 'when a note in a discussion got resolved' do
before do
travel_to(1.minute.from_now) do
@@ -147,17 +158,6 @@ RSpec.describe 'merge requests discussions' do
end
end
- context 'when cached markdown version gets bump' do
- before do
- settings = Gitlab::CurrentSettings.current_application_settings
- settings.update!(local_markdown_version: settings.local_markdown_version + 1)
- end
-
- it_behaves_like 'cache miss' do
- let(:changed_notes) { [first_note, second_note] }
- end
- end
-
context 'when the diff note position changes' do
before do
# This replicates a position change wherein timestamps aren't updated
diff --git a/spec/workers/post_receive_spec.rb b/spec/workers/post_receive_spec.rb
index 04a38874905..f26b3668653 100644
--- a/spec/workers/post_receive_spec.rb
+++ b/spec/workers/post_receive_spec.rb
@@ -85,14 +85,6 @@ RSpec.describe PostReceive do
perform
end
- it 'tracks an event for the new_project_readme experiment', :experiment do
- expect_next_instance_of(NewProjectReadmeExperiment, :new_project_readme, nil, actor: empty_project.owner) do |e|
- expect(e).to receive(:track_initial_writes).with(empty_project)
- end
-
- perform
- end
-
it 'tracks an event for the empty_repo_upload experiment', :experiment do
expect_next_instance_of(EmptyRepoUploadExperiment) do |e|
expect(e).to receive(:track_initial_write)