diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-30 18:08:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-30 18:08:09 +0300 |
commit | 538fff823de57d1ba5317961aa43091de9dc007f (patch) | |
tree | c741665b338cc0d51ce5f73f5671e5eee8e69349 /spec | |
parent | 3692e9f8a23386c627942ca2a9edd8c00af7e904 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/projects/import_export/import_file_spec.rb | 3 | ||||
-rw-r--r-- | spec/javascripts/boards/issue_card_spec.js | 14 | ||||
-rw-r--r-- | spec/lib/gitlab/snippet_search_results_spec.rb | 15 | ||||
-rw-r--r-- | spec/migrations/backfill_releases_table_updated_at_and_add_not_null_constraints_to_timestamps_spec.rb | 57 | ||||
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 81 | ||||
-rw-r--r-- | spec/models/commit_collection_spec.rb | 45 | ||||
-rw-r--r-- | spec/models/commit_spec.rb | 72 | ||||
-rw-r--r-- | spec/models/commit_with_pipeline_spec.rb | 123 | ||||
-rw-r--r-- | spec/presenters/commit_presenter_spec.rb | 12 | ||||
-rw-r--r-- | spec/support/helpers/select2_helper.rb | 12 | ||||
-rw-r--r-- | spec/support/omniauth_strategy.rb | 2 |
11 files changed, 297 insertions, 139 deletions
diff --git a/spec/features/projects/import_export/import_file_spec.rb b/spec/features/projects/import_export/import_file_spec.rb index a12fc8b18ed..6f96da60a31 100644 --- a/spec/features/projects/import_export/import_file_spec.rb +++ b/spec/features/projects/import_export/import_file_spec.rb @@ -3,7 +3,6 @@ require 'spec_helper' describe 'Import/Export - project import integration test', :js do - include Select2Helper include GitHelpers let(:user) { create(:user) } @@ -31,7 +30,6 @@ describe 'Import/Export - project import integration test', :js do it 'user imports an exported project successfully' do visit new_project_path - select2(namespace.id, from: '#project_namespace_id') fill_in :project_name, with: project_name, visible: true click_import_project_tab click_link 'GitLab export' @@ -78,7 +76,6 @@ describe 'Import/Export - project import integration test', :js do visit new_project_path - select2(user.namespace.id, from: '#project_namespace_id') fill_in :project_name, with: project.name, visible: true click_import_project_tab click_link 'GitLab export' diff --git a/spec/javascripts/boards/issue_card_spec.js b/spec/javascripts/boards/issue_card_spec.js index 8a20911cc66..9b5e8afa4ef 100644 --- a/spec/javascripts/boards/issue_card_spec.js +++ b/spec/javascripts/boards/issue_card_spec.js @@ -42,6 +42,7 @@ describe('Issue card component', () => { assignees: [], reference_path: '#1', real_path: '/test/1', + weight: 1, }); component = new Vue({ @@ -287,8 +288,17 @@ describe('Issue card component', () => { }); describe('weights', () => { - it('not shows weight component', () => { - expect(component.$el.querySelector('.board-card-weight')).toBeNull(); + it('shows weight component is greater than 0', () => { + expect(component.$el.querySelector('.board-card-weight')).not.toBeNull(); + }); + + it('shows weight component when weight is 0', done => { + component.issue.weight = 0; + + Vue.nextTick(() => { + expect(component.$el.querySelector('.board-card-weight')).not.toBeNull(); + done(); + }); }); }); }); diff --git a/spec/lib/gitlab/snippet_search_results_spec.rb b/spec/lib/gitlab/snippet_search_results_spec.rb index d3353b76c15..47f26fdebe2 100644 --- a/spec/lib/gitlab/snippet_search_results_spec.rb +++ b/spec/lib/gitlab/snippet_search_results_spec.rb @@ -6,18 +6,17 @@ describe Gitlab::SnippetSearchResults do include SearchHelpers let!(:snippet) { create(:snippet, content: 'foo', file_name: 'foo') } - - let(:results) { described_class.new(Snippet.all, 'foo') } + let(:results) { described_class.new(snippet.author, 'foo') } describe '#snippet_titles_count' do it 'returns the amount of matched snippet titles' do - expect(results.snippet_titles_count).to eq(1) + expect(results.limited_snippet_titles_count).to eq(1) end end describe '#snippet_blobs_count' do it 'returns the amount of matched snippet blobs' do - expect(results.snippet_blobs_count).to eq(1) + expect(results.limited_snippet_blobs_count).to eq(1) end end @@ -25,10 +24,10 @@ describe Gitlab::SnippetSearchResults do using RSpec::Parameterized::TableSyntax where(:scope, :count_method, :expected) do - 'snippet_titles' | :snippet_titles_count | '1234' - 'snippet_blobs' | :snippet_blobs_count | '1234' - 'projects' | :limited_projects_count | max_limited_count - 'unknown' | nil | nil + 'snippet_titles' | :limited_snippet_titles_count | max_limited_count + 'snippet_blobs' | :limited_snippet_blobs_count | max_limited_count + 'projects' | :limited_projects_count | max_limited_count + 'unknown' | nil | nil end with_them do diff --git a/spec/migrations/backfill_releases_table_updated_at_and_add_not_null_constraints_to_timestamps_spec.rb b/spec/migrations/backfill_releases_table_updated_at_and_add_not_null_constraints_to_timestamps_spec.rb new file mode 100644 index 00000000000..3ca7af8ea37 --- /dev/null +++ b/spec/migrations/backfill_releases_table_updated_at_and_add_not_null_constraints_to_timestamps_spec.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'migrate', '20190920194925_backfill_releases_table_updated_at_and_add_not_null_constraints_to_timestamps.rb') + +describe BackfillReleasesTableUpdatedAtAndAddNotNullConstraintsToTimestamps, :migration do + let(:releases) { table(:releases) } + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + + subject(:migration) { described_class.new } + + it 'fills null updated_at rows with the value of created_at' do + created_at_a = Time.zone.parse('2014-03-11T04:30:00Z') + created_at_b = Time.zone.parse('2019-09-10T12:00:00Z') + namespace = namespaces.create(name: 'foo', path: 'foo') + project = projects.create!(namespace_id: namespace.id) + release_a = releases.create!(project_id: project.id, + released_at: Time.zone.parse('2014-12-10T06:00:00Z'), + created_at: created_at_a) + release_b = releases.create!(project_id: project.id, + released_at: Time.zone.parse('2019-09-11T06:00:00Z'), + created_at: created_at_b) + release_a.update!(updated_at: nil) + release_b.update!(updated_at: nil) + + disable_migrations_output { migrate! } + + release_a.reload + release_b.reload + expect(release_a.updated_at).to eq(created_at_a) + expect(release_b.updated_at).to eq(created_at_b) + end + + it 'does not change updated_at columns with a value' do + created_at_a = Time.zone.parse('2014-03-11T04:30:00Z') + updated_at_a = Time.zone.parse('2015-01-16T10:00:00Z') + created_at_b = Time.zone.parse('2019-09-10T12:00:00Z') + namespace = namespaces.create(name: 'foo', path: 'foo') + project = projects.create!(namespace_id: namespace.id) + release_a = releases.create!(project_id: project.id, + released_at: Time.zone.parse('2014-12-10T06:00:00Z'), + created_at: created_at_a, + updated_at: updated_at_a) + release_b = releases.create!(project_id: project.id, + released_at: Time.zone.parse('2019-09-11T06:00:00Z'), + created_at: created_at_b) + release_b.update!(updated_at: nil) + + disable_migrations_output { migrate! } + + release_a.reload + release_b.reload + expect(release_a.updated_at).to eq(updated_at_a) + expect(release_b.updated_at).to eq(created_at_b) + end +end diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index a00d93ac4ba..3c625784132 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -1966,40 +1966,57 @@ describe Ci::Pipeline, :mailer do end end - describe '.latest_status_per_commit' do + describe '.latest_pipeline_per_commit' do let(:project) { create(:project) } - before do - pairs = [ - %w[success ref1 123], - %w[manual master 123], - %w[failed ref 456] - ] - - pairs.each do |(status, ref, sha)| - create( - :ci_empty_pipeline, - status: status, - ref: ref, - sha: sha, - project: project - ) - end + let!(:commit_123_ref_master) do + create( + :ci_empty_pipeline, + status: 'success', + ref: 'master', + sha: '123', + project: project + ) + end + let!(:commit_123_ref_develop) do + create( + :ci_empty_pipeline, + status: 'success', + ref: 'develop', + sha: '123', + project: project + ) + end + let!(:commit_456_ref_test) do + create( + :ci_empty_pipeline, + status: 'success', + ref: 'test', + sha: '456', + project: project + ) end context 'without a ref' do - it 'returns a Hash containing the latest status per commit for all refs' do - expect(described_class.latest_status_per_commit(%w[123 456])) - .to eq({ '123' => 'manual', '456' => 'failed' }) + it 'returns a Hash containing the latest pipeline per commit for all refs' do + result = described_class.latest_pipeline_per_commit(%w[123 456]) + + expect(result).to match( + '123' => commit_123_ref_develop, + '456' => commit_456_ref_test + ) end - it 'only includes the status of the given commit SHAs' do - expect(described_class.latest_status_per_commit(%w[123])) - .to eq({ '123' => 'manual' }) + it 'only includes the latest pipeline of the given commit SHAs' do + result = described_class.latest_pipeline_per_commit(%w[123]) + + expect(result).to match( + '123' => commit_123_ref_develop + ) end context 'when there are two pipelines for a ref and SHA' do - it 'returns the status of the latest pipeline' do + let!(:commit_123_ref_master_latest) do create( :ci_empty_pipeline, status: 'failed', @@ -2007,17 +2024,25 @@ describe Ci::Pipeline, :mailer do sha: '123', project: project ) + end + + it 'returns the latest pipeline' do + result = described_class.latest_pipeline_per_commit(%w[123]) - expect(described_class.latest_status_per_commit(%w[123])) - .to eq({ '123' => 'failed' }) + expect(result).to match( + '123' => commit_123_ref_master_latest + ) end end end context 'with a ref' do it 'only includes the pipelines for the given ref' do - expect(described_class.latest_status_per_commit(%w[123 456], 'master')) - .to eq({ '123' => 'manual' }) + result = described_class.latest_pipeline_per_commit(%w[123 456], 'master') + + expect(result).to match( + '123' => commit_123_ref_master + ) end end end diff --git a/spec/models/commit_collection_spec.rb b/spec/models/commit_collection_spec.rb index 0bdf83fa90f..a8957bbfdd0 100644 --- a/spec/models/commit_collection_spec.rb +++ b/spec/models/commit_collection_spec.rb @@ -51,6 +51,30 @@ describe CommitCollection do end end + describe '#with_latest_pipeline' do + let!(:pipeline) do + create( + :ci_empty_pipeline, + ref: 'master', + sha: commit.id, + status: 'success', + project: project + ) + end + let(:collection) { described_class.new(project, [commit]) } + + it 'sets the latest pipeline for every commit so no additional queries are necessary' do + commits = collection.with_latest_pipeline('master') + + recorder = ActiveRecord::QueryRecorder.new do + expect(commits.map { |c| c.latest_pipeline('master') }) + .to eq([pipeline]) + end + + expect(recorder.count).to be_zero + end + end + describe 'enrichment methods' do let(:gitaly_commit) { commit } let(:hash_commit) { Commit.from_hash(gitaly_commit.to_hash, project) } @@ -128,27 +152,6 @@ describe CommitCollection do end end - describe '#with_pipeline_status' do - it 'sets the pipeline status for every commit so no additional queries are necessary' do - create( - :ci_empty_pipeline, - ref: 'master', - sha: commit.id, - status: 'success', - project: project - ) - - collection = described_class.new(project, [commit]) - collection.with_pipeline_status - - recorder = ActiveRecord::QueryRecorder.new do - expect(commit.status).to eq('success') - end - - expect(recorder.count).to be_zero - end - end - describe '#respond_to_missing?' do it 'returns true when the underlying Array responds to the message' do collection = described_class.new(project, []) diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb index 5ef824b9950..6e511c9e4ec 100644 --- a/spec/models/commit_spec.rb +++ b/spec/models/commit_spec.rb @@ -462,78 +462,6 @@ eos end end - describe '#last_pipeline' do - let!(:first_pipeline) do - create(:ci_empty_pipeline, - project: project, - sha: commit.sha, - status: 'success') - end - let!(:second_pipeline) do - create(:ci_empty_pipeline, - project: project, - sha: commit.sha, - status: 'success') - end - - it 'returns last pipeline' do - expect(commit.last_pipeline).to eq second_pipeline - end - end - - describe '#status' do - context 'without ref argument' do - before do - %w[success failed created pending].each do |status| - create(:ci_empty_pipeline, - project: project, - sha: commit.sha, - status: status) - end - end - - it 'gives compound status from latest pipelines' do - expect(commit.status).to eq(Ci::Pipeline.latest_status) - expect(commit.status).to eq('pending') - end - end - - context 'when a particular ref is specified' do - let!(:pipeline_from_master) do - create(:ci_empty_pipeline, - project: project, - sha: commit.sha, - ref: 'master', - status: 'failed') - end - - let!(:pipeline_from_fix) do - create(:ci_empty_pipeline, - project: project, - sha: commit.sha, - ref: 'fix', - status: 'success') - end - - it 'gives pipelines from a particular branch' do - expect(commit.status('master')).to eq(pipeline_from_master.status) - expect(commit.status('fix')).to eq(pipeline_from_fix.status) - end - - it 'gives compound status from latest pipelines if ref is nil' do - expect(commit.status(nil)).to eq(pipeline_from_fix.status) - end - end - end - - describe '#set_status_for_ref' do - it 'sets the status for a given reference' do - commit.set_status_for_ref('master', 'failed') - - expect(commit.status('master')).to eq('failed') - end - end - describe '#participants' do let(:user1) { build(:user) } let(:user2) { build(:user) } diff --git a/spec/models/commit_with_pipeline_spec.rb b/spec/models/commit_with_pipeline_spec.rb new file mode 100644 index 00000000000..e0bb29fec7b --- /dev/null +++ b/spec/models/commit_with_pipeline_spec.rb @@ -0,0 +1,123 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe CommitWithPipeline do + let(:project) { create(:project, :public, :repository) } + let(:commit) { described_class.new(project.commit) } + + describe '#last_pipeline' do + let!(:first_pipeline) do + create(:ci_empty_pipeline, + project: project, + sha: commit.sha, + status: 'success') + end + let!(:second_pipeline) do + create(:ci_empty_pipeline, + project: project, + sha: commit.sha, + status: 'success') + end + + it 'returns last pipeline' do + expect(commit.last_pipeline).to eq second_pipeline + end + end + + describe '#latest_pipeline' do + let(:pipeline) { double } + + shared_examples_for 'fetching latest pipeline' do |ref| + it 'returns the latest pipeline for the project' do + expect(commit) + .to receive(:latest_pipeline_for_project) + .with(ref, project) + .and_return(pipeline) + + expect(result).to eq(pipeline) + end + + it "returns the memoized pipeline for the key of #{ref}" do + commit.set_latest_pipeline_for_ref(ref, pipeline) + + expect(commit) + .not_to receive(:latest_pipeline_for_project) + + expect(result).to eq(pipeline) + end + end + + context 'without ref argument' do + let(:result) { commit.latest_pipeline } + + it_behaves_like 'fetching latest pipeline', nil + end + + context 'when a particular ref is specified' do + let(:result) { commit.latest_pipeline('master') } + + it_behaves_like 'fetching latest pipeline', 'master' + end + end + + describe '#latest_pipeline_for_project' do + let(:project_pipelines) { double } + let(:pipeline_project) { double } + let(:pipeline) { double } + let(:ref) { 'master' } + let(:result) { commit.latest_pipeline_for_project(ref, pipeline_project) } + + before do + allow(pipeline_project).to receive(:ci_pipelines).and_return(project_pipelines) + end + + it 'returns the latest pipeline of the commit for the given ref and project' do + expect(project_pipelines) + .to receive(:latest_pipeline_per_commit) + .with(commit.id, ref) + .and_return(commit.id => pipeline) + + expect(result).to eq(pipeline) + end + end + + describe '#set_latest_pipeline_for_ref' do + let(:pipeline) { double } + + it 'sets the latest pipeline for a given reference' do + commit.set_latest_pipeline_for_ref('master', pipeline) + + expect(commit.latest_pipeline('master')).to eq(pipeline) + end + end + + describe "#status" do + it 'returns the status of the latest pipeline for the given ref' do + expect(commit) + .to receive(:latest_pipeline) + .with('master') + .and_return(double(status: 'success')) + + expect(commit.status('master')).to eq('success') + end + + it 'returns nil when latest pipeline is not present for the given ref' do + expect(commit) + .to receive(:latest_pipeline) + .with('master') + .and_return(nil) + + expect(commit.status('master')).to eq(nil) + end + + it 'returns the status of the latest pipeline when no ref is given' do + expect(commit) + .to receive(:latest_pipeline) + .with(nil) + .and_return(double(status: 'success')) + + expect(commit.status).to eq('success') + end + end +end diff --git a/spec/presenters/commit_presenter_spec.rb b/spec/presenters/commit_presenter_spec.rb index 4a0d3a28c32..58179e9a337 100644 --- a/spec/presenters/commit_presenter_spec.rb +++ b/spec/presenters/commit_presenter_spec.rb @@ -17,15 +17,19 @@ describe CommitPresenter do end it 'returns commit status for ref' do - expect(commit).to receive(:status).with('ref').and_return('test') + pipeline = double + status = double - expect(subject).to eq('test') + expect(commit).to receive(:latest_pipeline).with('ref').and_return(pipeline) + expect(pipeline).to receive(:detailed_status).with(user).and_return(status) + + expect(subject).to eq(status) end end context 'when user can not read_commit_status' do - it 'is false' do - is_expected.to eq(false) + it 'is nil' do + is_expected.to eq(nil) end end end diff --git a/spec/support/helpers/select2_helper.rb b/spec/support/helpers/select2_helper.rb index 9c42c2b0d8b..38bf34bdd61 100644 --- a/spec/support/helpers/select2_helper.rb +++ b/spec/support/helpers/select2_helper.rb @@ -24,7 +24,7 @@ module Select2Helper selector = options.fetch(:from) - first(selector, visible: false) + ensure_select2_loaded(selector) if options[:multiple] execute_script("$('#{selector}').select2('val', ['#{value}']).trigger('change');") @@ -34,14 +34,24 @@ module Select2Helper end def open_select2(selector) + ensure_select2_loaded(selector) + execute_script("$('#{selector}').select2('open');") end def close_select2(selector) + ensure_select2_loaded(selector) + execute_script("$('#{selector}').select2('close');") end def scroll_select2_to_bottom(selector) evaluate_script "$('#{selector}').scrollTop($('#{selector}')[0].scrollHeight); $('#{selector}');" end + + private + + def ensure_select2_loaded(selector) + first(selector, visible: :all).sibling('.select2-container') + end end diff --git a/spec/support/omniauth_strategy.rb b/spec/support/omniauth_strategy.rb index eefa04bd9dd..23907b8e450 100644 --- a/spec/support/omniauth_strategy.rb +++ b/spec/support/omniauth_strategy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module StrategyHelpers include Rack::Test::Methods include ActionDispatch::Assertions::ResponseAssertions |