diff options
author | Phil Hughes <me@iamphill.com> | 2018-04-19 08:36:54 +0100 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2018-04-19 08:36:54 +0100 |
commit | 9392ff6ba98f961bf90caf22db7c1ea00a4c631b (patch) | |
tree | 52b5eef249edf859ea7d68b0ac61ec8676e4ebcf /spec | |
parent | 5eb7ed7509dd8654b30aa62905e81c6856035ff5 (diff) | |
parent | ffde69d71e3c77dd39f955bbf5c562271ba7963a (diff) | |
download | gitlab-ce-9392ff6ba98f961bf90caf22db7c1ea00a4c631b.tar.gz |
Merge branch 'master' into ide-staged-changes
Diffstat (limited to 'spec')
19 files changed, 415 insertions, 139 deletions
diff --git a/spec/controllers/projects/jobs_controller_spec.rb b/spec/controllers/projects/jobs_controller_spec.rb index b9a979044fe..f677cec3408 100644 --- a/spec/controllers/projects/jobs_controller_spec.rb +++ b/spec/controllers/projects/jobs_controller_spec.rb @@ -190,7 +190,10 @@ describe Projects::JobsController do expect(response).to have_gitlab_http_status(:ok) expect(json_response['id']).to eq job.id expect(json_response['status']).to eq job.status - expect(json_response['html']).to be_nil + end + + it 'returns no job log message' do + expect(json_response['html']).to eq('No job log') end end diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb index 33de637ff7d..4acc008ed38 100644 --- a/spec/factories/ci/builds.rb +++ b/spec/factories/ci/builds.rb @@ -243,5 +243,10 @@ FactoryBot.define do failed failure_reason 1 end + + trait :api_failure do + failed + failure_reason 2 + end end end diff --git a/spec/features/boards/sidebar_spec.rb b/spec/features/boards/sidebar_spec.rb index d4c44c1adf9..4d31123a699 100644 --- a/spec/features/boards/sidebar_spec.rb +++ b/spec/features/boards/sidebar_spec.rb @@ -237,6 +237,22 @@ describe 'Issue Boards', :js do end context 'labels' do + it 'shows current labels when editing' do + click_card(card) + + page.within('.labels') do + click_link 'Edit' + + wait_for_requests + + page.within('.value') do + expect(page).to have_selector('.label', count: 2) + expect(page).to have_content(development.title) + expect(page).to have_content(stretch.title) + end + end + end + it 'adds a single label' do click_card(card) @@ -296,7 +312,9 @@ describe 'Issue Boards', :js do wait_for_requests - click_link stretch.title + within('.dropdown-menu-labels') do + click_link stretch.title + end wait_for_requests diff --git a/spec/features/issues/issue_sidebar_spec.rb b/spec/features/issues/issue_sidebar_spec.rb index 27551bb70ee..830c794376d 100644 --- a/spec/features/issues/issue_sidebar_spec.rb +++ b/spec/features/issues/issue_sidebar_spec.rb @@ -5,9 +5,9 @@ feature 'Issue Sidebar' do let(:group) { create(:group, :nested) } let(:project) { create(:project, :public, namespace: group) } - let(:issue) { create(:issue, project: project) } let!(:user) { create(:user)} let!(:label) { create(:label, project: project, title: 'bug') } + let(:issue) { create(:labeled_issue, project: project, labels: [label]) } let!(:xss_label) { create(:label, project: project, title: '<script>alert("xss");</script>') } before do @@ -112,11 +112,18 @@ feature 'Issue Sidebar' do context 'editing issue labels', :js do before do + issue.update_attributes(labels: [label]) page.within('.block.labels') do find('.edit-link').click end end + it 'shows the current set of labels' do + page.within('.issuable-show-labels') do + expect(page).to have_content label.title + end + end + it 'shows option to create a project label' do page.within('.block.labels') do expect(page).to have_content 'Create project' diff --git a/spec/features/projects/jobs_spec.rb b/spec/features/projects/jobs_spec.rb index a460024542c..a00db6dd161 100644 --- a/spec/features/projects/jobs_spec.rb +++ b/spec/features/projects/jobs_spec.rb @@ -491,16 +491,18 @@ feature 'Jobs' do end end - describe "POST /:project/jobs/:id/retry" do + describe "POST /:project/jobs/:id/retry", :js do context "Job from project", :js do before do job.run! + job.cancel! visit project_job_path(project, job) - find('.js-cancel-job').click() + wait_for_requests + find('.js-retry-button').click end - it 'shows the right status and buttons', :js do + it 'shows the right status and buttons' do page.within('aside.right-sidebar') do expect(page).to have_content 'Cancel' end diff --git a/spec/finders/group_descendants_finder_spec.rb b/spec/finders/group_descendants_finder_spec.rb index 375bcc9087e..796d40cb625 100644 --- a/spec/finders/group_descendants_finder_spec.rb +++ b/spec/finders/group_descendants_finder_spec.rb @@ -35,15 +35,6 @@ describe GroupDescendantsFinder do expect(finder.execute).to contain_exactly(project) end - it 'does not include projects shared with the group' do - project = create(:project, namespace: group) - other_project = create(:project) - other_project.project_group_links.create(group: group, - group_access: ProjectGroupLink::MASTER) - - expect(finder.execute).to contain_exactly(project) - end - context 'when archived is `true`' do let(:params) { { archived: 'true' } } diff --git a/spec/javascripts/jobs/header_spec.js b/spec/javascripts/jobs/header_spec.js index 0961605ce5c..4f861c39d3f 100644 --- a/spec/javascripts/jobs/header_spec.js +++ b/spec/javascripts/jobs/header_spec.js @@ -36,14 +36,28 @@ describe('Job details header', () => { }, isLoading: false, }; - - vm = mountComponent(HeaderComponent, props); }); afterEach(() => { vm.$destroy(); }); + describe('job reason', () => { + it('should not render the reason when reason is absent', () => { + vm = mountComponent(HeaderComponent, props); + + expect(vm.shouldRenderReason).toBe(false); + }); + + it('should render the reason when reason is present', () => { + props.job.callout_message = 'There is an unknown failure, please try again'; + + vm = mountComponent(HeaderComponent, props); + + expect(vm.shouldRenderReason).toBe(true); + }); + }); + describe('triggered job', () => { beforeEach(() => { vm = mountComponent(HeaderComponent, props); @@ -51,14 +65,17 @@ describe('Job details header', () => { it('should render provided job information', () => { expect( - vm.$el.querySelector('.header-main-content').textContent.replace(/\s+/g, ' ').trim(), + vm.$el + .querySelector('.header-main-content') + .textContent.replace(/\s+/g, ' ') + .trim(), ).toEqual('failed Job #123 triggered 3 weeks ago by Foo'); }); it('should render new issue link', () => { - expect( - vm.$el.querySelector('.js-new-issue').getAttribute('href'), - ).toEqual(props.job.new_issue_path); + expect(vm.$el.querySelector('.js-new-issue').getAttribute('href')).toEqual( + props.job.new_issue_path, + ); }); }); @@ -68,7 +85,10 @@ describe('Job details header', () => { vm = mountComponent(HeaderComponent, props); expect( - vm.$el.querySelector('.header-main-content').textContent.replace(/\s+/g, ' ').trim(), + vm.$el + .querySelector('.header-main-content') + .textContent.replace(/\s+/g, ' ') + .trim(), ).toEqual('failed Job #123 created 3 weeks ago by Foo'); }); }); diff --git a/spec/javascripts/jobs/sidebar_details_block_spec.js b/spec/javascripts/jobs/sidebar_details_block_spec.js index 602dae514b1..6b397c22fb9 100644 --- a/spec/javascripts/jobs/sidebar_details_block_spec.js +++ b/spec/javascripts/jobs/sidebar_details_block_spec.js @@ -31,10 +31,25 @@ describe('Sidebar details block', () => { }); }); + describe("when user can't retry", () => { + it('should not render a retry button', () => { + vm = new SidebarComponent({ + propsData: { + job: {}, + canUserRetry: false, + isLoading: true, + }, + }).$mount(); + + expect(vm.$el.querySelector('.js-retry-job')).toBeNull(); + }); + }); + beforeEach(() => { vm = new SidebarComponent({ propsData: { job, + canUserRetry: true, isLoading: false, }, }).$mount(); @@ -42,7 +57,9 @@ describe('Sidebar details block', () => { describe('actions', () => { it('should render link to new issue', () => { - expect(vm.$el.querySelector('.js-new-issue').getAttribute('href')).toEqual(job.new_issue_path); + expect(vm.$el.querySelector('.js-new-issue').getAttribute('href')).toEqual( + job.new_issue_path, + ); expect(vm.$el.querySelector('.js-new-issue').textContent.trim()).toEqual('New issue'); }); @@ -57,43 +74,35 @@ describe('Sidebar details block', () => { describe('information', () => { it('should render merge request link', () => { - expect( - trimWhitespace(vm.$el.querySelector('.js-job-mr')), - ).toEqual('Merge Request: !2'); + expect(trimWhitespace(vm.$el.querySelector('.js-job-mr'))).toEqual('Merge Request: !2'); - expect( - vm.$el.querySelector('.js-job-mr a').getAttribute('href'), - ).toEqual(job.merge_request.path); + expect(vm.$el.querySelector('.js-job-mr a').getAttribute('href')).toEqual( + job.merge_request.path, + ); }); it('should render job duration', () => { - expect( - trimWhitespace(vm.$el.querySelector('.js-job-duration')), - ).toEqual('Duration: 6 seconds'); + expect(trimWhitespace(vm.$el.querySelector('.js-job-duration'))).toEqual( + 'Duration: 6 seconds', + ); }); it('should render erased date', () => { - expect( - trimWhitespace(vm.$el.querySelector('.js-job-erased')), - ).toEqual('Erased: 3 weeks ago'); + expect(trimWhitespace(vm.$el.querySelector('.js-job-erased'))).toEqual('Erased: 3 weeks ago'); }); it('should render finished date', () => { - expect( - trimWhitespace(vm.$el.querySelector('.js-job-finished')), - ).toEqual('Finished: 3 weeks ago'); + expect(trimWhitespace(vm.$el.querySelector('.js-job-finished'))).toEqual( + 'Finished: 3 weeks ago', + ); }); it('should render queued date', () => { - expect( - trimWhitespace(vm.$el.querySelector('.js-job-queued')), - ).toEqual('Queued: 9 seconds'); + expect(trimWhitespace(vm.$el.querySelector('.js-job-queued'))).toEqual('Queued: 9 seconds'); }); it('should render runner ID', () => { - expect( - trimWhitespace(vm.$el.querySelector('.js-job-runner')), - ).toEqual('Runner: #1'); + expect(trimWhitespace(vm.$el.querySelector('.js-job-runner'))).toEqual('Runner: #1'); }); it('should render timeout information', () => { @@ -103,15 +112,11 @@ describe('Sidebar details block', () => { }); it('should render coverage', () => { - expect( - trimWhitespace(vm.$el.querySelector('.js-job-coverage')), - ).toEqual('Coverage: 20%'); + expect(trimWhitespace(vm.$el.querySelector('.js-job-coverage'))).toEqual('Coverage: 20%'); }); it('should render tags', () => { - expect( - trimWhitespace(vm.$el.querySelector('.js-job-tags')), - ).toEqual('Tags: tag'); + expect(trimWhitespace(vm.$el.querySelector('.js-job-tags'))).toEqual('Tags: tag'); }); }); }); diff --git a/spec/javascripts/vue_shared/components/callout_spec.js b/spec/javascripts/vue_shared/components/callout_spec.js new file mode 100644 index 00000000000..e62bd86f4ca --- /dev/null +++ b/spec/javascripts/vue_shared/components/callout_spec.js @@ -0,0 +1,45 @@ +import Vue from 'vue'; +import callout from '~/vue_shared/components/callout.vue'; +import createComponent from 'spec/helpers/vue_mount_component_helper'; + +describe('Callout Component', () => { + let CalloutComponent; + let vm; + const exampleMessage = 'This is a callout message!'; + + beforeEach(() => { + CalloutComponent = Vue.extend(callout); + }); + + afterEach(() => { + vm.$destroy(); + }); + + it('should render the appropriate variant of callout', () => { + vm = createComponent(CalloutComponent, { + category: 'info', + message: exampleMessage, + }); + + expect(vm.$el.getAttribute('class')).toEqual('bs-callout bs-callout-info'); + + expect(vm.$el.tagName).toEqual('DIV'); + }); + + it('should render accessibility attributes', () => { + vm = createComponent(CalloutComponent, { + message: exampleMessage, + }); + + expect(vm.$el.getAttribute('role')).toEqual('alert'); + expect(vm.$el.getAttribute('aria-live')).toEqual('assertive'); + }); + + it('should render the provided message', () => { + vm = createComponent(CalloutComponent, { + message: exampleMessage, + }); + + expect(vm.$el.innerHTML.trim()).toEqual(exampleMessage); + }); +}); diff --git a/spec/lib/gitlab/git/wiki_spec.rb b/spec/lib/gitlab/git/wiki_spec.rb index 761f7732036..722d697c28e 100644 --- a/spec/lib/gitlab/git/wiki_spec.rb +++ b/spec/lib/gitlab/git/wiki_spec.rb @@ -30,7 +30,7 @@ describe Gitlab::Git::Wiki do end def commit_details(name) - Gitlab::Git::Wiki::CommitDetails.new(user.name, user.email, "created page #{name}") + Gitlab::Git::Wiki::CommitDetails.new(user.id, user.username, user.name, user.email, "created page #{name}") end def destroy_page(title, dir = '') diff --git a/spec/lib/gitlab/view/presenter/base_spec.rb b/spec/lib/gitlab/view/presenter/base_spec.rb index 32a946ca034..4eca53032a2 100644 --- a/spec/lib/gitlab/view/presenter/base_spec.rb +++ b/spec/lib/gitlab/view/presenter/base_spec.rb @@ -48,4 +48,11 @@ describe Gitlab::View::Presenter::Base do end end end + + describe '#present' do + it 'returns self' do + presenter = presenter_class.new(build_stubbed(:project)) + expect(presenter.present).to eq(presenter) + end + end end diff --git a/spec/lib/gitlab/wiki/committer_with_hooks_spec.rb b/spec/lib/gitlab/wiki/committer_with_hooks_spec.rb new file mode 100644 index 00000000000..830fb8a8598 --- /dev/null +++ b/spec/lib/gitlab/wiki/committer_with_hooks_spec.rb @@ -0,0 +1,154 @@ +require 'spec_helper' + +describe Gitlab::Wiki::CommitterWithHooks, seed_helper: true do + shared_examples 'calling wiki hooks' do + let(:project) { create(:project) } + let(:user) { project.owner } + let(:project_wiki) { ProjectWiki.new(project, user) } + let(:wiki) { project_wiki.wiki } + let(:options) do + { + id: user.id, + username: user.username, + name: user.name, + email: user.email, + message: 'commit message' + } + end + + subject { described_class.new(wiki, options) } + + before do + project_wiki.create_page('home', 'test content') + end + + shared_examples 'failing pre-receive hook' do + before do + expect_any_instance_of(Gitlab::Git::HooksService).to receive(:run_hook).with('pre-receive').and_return([false, '']) + expect_any_instance_of(Gitlab::Git::HooksService).not_to receive(:run_hook).with('update') + expect_any_instance_of(Gitlab::Git::HooksService).not_to receive(:run_hook).with('post-receive') + end + + it 'raises exception' do + expect { subject.commit }.to raise_error(Gitlab::Git::Wiki::OperationError) + end + + it 'does not create a new commit inside the repository' do + current_rev = find_current_rev + + expect { subject.commit }.to raise_error(Gitlab::Git::Wiki::OperationError) + + expect(current_rev).to eq find_current_rev + end + end + + shared_examples 'failing update hook' do + before do + expect_any_instance_of(Gitlab::Git::HooksService).to receive(:run_hook).with('pre-receive').and_return([true, '']) + expect_any_instance_of(Gitlab::Git::HooksService).to receive(:run_hook).with('update').and_return([false, '']) + expect_any_instance_of(Gitlab::Git::HooksService).not_to receive(:run_hook).with('post-receive') + end + + it 'raises exception' do + expect { subject.commit }.to raise_error(Gitlab::Git::Wiki::OperationError) + end + + it 'does not create a new commit inside the repository' do + current_rev = find_current_rev + + expect { subject.commit }.to raise_error(Gitlab::Git::Wiki::OperationError) + + expect(current_rev).to eq find_current_rev + end + end + + shared_examples 'failing post-receive hook' do + before do + expect_any_instance_of(Gitlab::Git::HooksService).to receive(:run_hook).with('pre-receive').and_return([true, '']) + expect_any_instance_of(Gitlab::Git::HooksService).to receive(:run_hook).with('update').and_return([true, '']) + expect_any_instance_of(Gitlab::Git::HooksService).to receive(:run_hook).with('post-receive').and_return([false, '']) + end + + it 'does not raise exception' do + expect { subject.commit }.not_to raise_error + end + + it 'creates the commit' do + current_rev = find_current_rev + + subject.commit + + expect(current_rev).not_to eq find_current_rev + end + end + + shared_examples 'when hooks call succceeds' do + let(:hook) { double(:hook) } + + it 'calls the three hooks' do + expect(Gitlab::Git::Hook).to receive(:new).exactly(3).times.and_return(hook) + expect(hook).to receive(:trigger).exactly(3).times.and_return([true, nil]) + + subject.commit + end + + it 'creates the commit' do + current_rev = find_current_rev + + subject.commit + + expect(current_rev).not_to eq find_current_rev + end + end + + context 'when creating a page' do + before do + project_wiki.create_page('index', 'test content') + end + + it_behaves_like 'failing pre-receive hook' + it_behaves_like 'failing update hook' + it_behaves_like 'failing post-receive hook' + it_behaves_like 'when hooks call succceeds' + end + + context 'when updating a page' do + before do + project_wiki.update_page(find_page('home'), content: 'some other content', format: :markdown) + end + + it_behaves_like 'failing pre-receive hook' + it_behaves_like 'failing update hook' + it_behaves_like 'failing post-receive hook' + it_behaves_like 'when hooks call succceeds' + end + + context 'when deleting a page' do + before do + project_wiki.delete_page(find_page('home')) + end + + it_behaves_like 'failing pre-receive hook' + it_behaves_like 'failing update hook' + it_behaves_like 'failing post-receive hook' + it_behaves_like 'when hooks call succceeds' + end + + def find_current_rev + wiki.gollum_wiki.repo.commits.first&.sha + end + + def find_page(name) + wiki.page(title: name) + end + end + + # TODO: Uncomment once Gitaly updates the ruby vendor code + # context 'when Gitaly is enabled' do + # it_behaves_like 'calling wiki hooks' + # end + + context 'when Gitaly is disabled', :skip_gitaly_mock do + it_behaves_like 'calling wiki hooks' + end +end diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index d7075d4a6b4..451b038e9a6 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1472,7 +1472,7 @@ describe Ci::Build do { key: 'CI_REPOSITORY_URL', value: build.repo_url, public: false }, { key: 'CI', value: 'true', public: true }, { key: 'GITLAB_CI', value: 'true', public: true }, - { key: 'GITLAB_FEATURES', value: project.namespace.features.join(','), public: true }, + { key: 'GITLAB_FEATURES', value: project.licensed_features.join(','), public: true }, { key: 'CI_SERVER_NAME', value: 'GitLab', public: true }, { key: 'CI_SERVER_VERSION', value: Gitlab::VERSION, public: true }, { key: 'CI_SERVER_REVISION', value: Gitlab::REVISION, public: true }, diff --git a/spec/models/concerns/group_descendant_spec.rb b/spec/models/concerns/group_descendant_spec.rb index c163fb01a81..28352d8c961 100644 --- a/spec/models/concerns/group_descendant_spec.rb +++ b/spec/models/concerns/group_descendant_spec.rb @@ -79,9 +79,24 @@ describe GroupDescendant, :nested_groups do expect(described_class.build_hierarchy(groups)).to eq(expected_hierarchy) end + it 'tracks the exception when a parent was not preloaded' do + expect(Gitlab::Sentry).to receive(:track_exception).and_call_original + + expect { GroupDescendant.build_hierarchy([subsub_group]) }.to raise_error(ArgumentError) + end + + it 'recovers if a parent was not reloaded by querying for the parent' do + expected_hierarchy = { parent => { subgroup => subsub_group } } + + # this does not raise in production, so stubbing it here. + allow(Gitlab::Sentry).to receive(:track_exception) + + expect(GroupDescendant.build_hierarchy([subsub_group])).to eq(expected_hierarchy) + end + it 'raises an error if not all elements were preloaded' do expect { described_class.build_hierarchy([subsub_group]) } - .to raise_error('parent was not preloaded') + .to raise_error(/was not preloaded/) end end end diff --git a/spec/models/project_wiki_spec.rb b/spec/models/project_wiki_spec.rb index 374a157bec0..4e83f4353cf 100644 --- a/spec/models/project_wiki_spec.rb +++ b/spec/models/project_wiki_spec.rb @@ -377,7 +377,7 @@ describe ProjectWiki do end def commit_details - Gitlab::Git::Wiki::CommitDetails.new(user.name, user.email, "test commit") + Gitlab::Git::Wiki::CommitDetails.new(user.id, user.username, user.name, user.email, "test commit") end def create_page(name, content) diff --git a/spec/models/wiki_page_spec.rb b/spec/models/wiki_page_spec.rb index b2b7721674c..90b7e7715a8 100644 --- a/spec/models/wiki_page_spec.rb +++ b/spec/models/wiki_page_spec.rb @@ -561,7 +561,7 @@ describe WikiPage do end def commit_details - Gitlab::Git::Wiki::CommitDetails.new(user.name, user.email, "test commit") + Gitlab::Git::Wiki::CommitDetails.new(user.id, user.username, user.name, user.email, "test commit") end def create_page(name, content) diff --git a/spec/presenters/ci/build_presenter_spec.rb b/spec/presenters/ci/build_presenter_spec.rb index cc16d0f156b..4bc005df2fc 100644 --- a/spec/presenters/ci/build_presenter_spec.rb +++ b/spec/presenters/ci/build_presenter_spec.rb @@ -217,4 +217,39 @@ describe Ci::BuildPresenter do end end end + + describe '#callout_failure_message' do + let(:build) { create(:ci_build, :failed, :script_failure) } + + it 'returns a verbose failure reason' do + description = subject.callout_failure_message + expect(description).to eq('There has been a script failure. Check the job log for more information') + end + end + + describe '#recoverable?' do + let(:build) { create(:ci_build, :failed, :script_failure) } + + context 'when is a script or missing dependency failure' do + let(:failure_reasons) { %w(script_failure missing_dependency_failure) } + + it 'should return false' do + failure_reasons.each do |failure_reason| + build.update_attribute(:failure_reason, failure_reason) + expect(presenter.recoverable?).to be_falsy + end + end + end + + context 'when is any other failure type' do + let(:failure_reasons) { %w(unknown_failure api_failure stuck_or_timeout_failure runner_system_failure) } + + it 'should return true' do + failure_reasons.each do |failure_reason| + build.update_attribute(:failure_reason, failure_reason) + expect(presenter.recoverable?).to be_truthy + end + end + end + end end diff --git a/spec/rubocop/cop/gitlab/has_many_through_scope_spec.rb b/spec/rubocop/cop/gitlab/has_many_through_scope_spec.rb deleted file mode 100644 index 6d769c8e6fd..00000000000 --- a/spec/rubocop/cop/gitlab/has_many_through_scope_spec.rb +++ /dev/null @@ -1,74 +0,0 @@ -require 'spec_helper' - -require 'rubocop' -require 'rubocop/rspec/support' - -require_relative '../../../../rubocop/cop/gitlab/has_many_through_scope' - -describe RuboCop::Cop::Gitlab::HasManyThroughScope do # rubocop:disable RSpec/FilePath - include CopHelper - - subject(:cop) { described_class.new } - - context 'in a model file' do - before do - allow(cop).to receive(:in_model?).and_return(true) - end - - context 'when the model does not use has_many :through' do - it 'does not register an offense' do - expect_no_offenses(<<-RUBY) - class User < ActiveRecord::Base - has_many :tags, source: 'UserTag' - end - RUBY - end - end - - context 'when the model uses has_many :through' do - context 'when the association has no scope defined' do - it 'registers an offense on the association' do - expect_offense(<<-RUBY) - class User < ActiveRecord::Base - has_many :tags, through: :user_tags - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG} - end - RUBY - end - end - - context 'when the association has a scope defined' do - context 'when the scope does not disable auto-loading' do - it 'registers an offense on the scope' do - expect_offense(<<-RUBY) - class User < ActiveRecord::Base - has_many :tags, -> { where(active: true) }, through: :user_tags - ^^^^^^^^^^^^^^^^^^^^^^^^^^ #{described_class::MSG} - end - RUBY - end - end - - context 'when the scope has auto_include(false)' do - it 'does not register an offense' do - expect_no_offenses(<<-RUBY) - class User < ActiveRecord::Base - has_many :tags, -> { where(active: true).auto_include(false).reorder(nil) }, through: :user_tags - end - RUBY - end - end - end - end - end - - context 'outside of a migration spec file' do - it 'does not register an offense' do - expect_no_offenses(<<-RUBY) - class User < ActiveRecord::Base - has_many :tags, through: :user_tags - end - RUBY - end - end -end diff --git a/spec/serializers/job_entity_spec.rb b/spec/serializers/job_entity_spec.rb index 24a6f1a2a8a..c90396ebb28 100644 --- a/spec/serializers/job_entity_spec.rb +++ b/spec/serializers/job_entity_spec.rb @@ -133,22 +133,65 @@ describe JobEntity do context 'when job failed' do let(:job) { create(:ci_build, :script_failure) } - describe 'status' do - it 'should contain the failure reason inside label' do - expect(subject[:status]).to include :icon, :favicon, :text, :label, :tooltip - expect(subject[:status][:label]).to eq('failed') - expect(subject[:status][:tooltip]).to eq('failed <br> (script failure)') - end + it 'contains details' do + expect(subject[:status]).to include :icon, :favicon, :text, :label, :tooltip + end + + it 'states that it failed' do + expect(subject[:status][:label]).to eq('failed') + end + + it 'should indicate the failure reason on tooltip' do + expect(subject[:status][:tooltip]).to eq('failed <br> (script failure)') + end + + it 'should include a callout message with a verbose output' do + expect(subject[:callout_message]).to eq('There has been a script failure. Check the job log for more information') + end + + it 'should state that it is not recoverable' do + expect(subject[:recoverable]).to be_falsy + end + end + + context 'when job is allowed to fail' do + let(:job) { create(:ci_build, :allowed_to_fail, :script_failure) } + + it 'contains details' do + expect(subject[:status]).to include :icon, :favicon, :text, :label, :tooltip + end + + it 'states that it failed' do + expect(subject[:status][:label]).to eq('failed (allowed to fail)') + end + + it 'should indicate the failure reason on tooltip' do + expect(subject[:status][:tooltip]).to eq('failed <br> (script failure) (allowed to fail)') + end + + it 'should include a callout message with a verbose output' do + expect(subject[:callout_message]).to eq('There has been a script failure. Check the job log for more information') + end + + it 'should state that it is not recoverable' do + expect(subject[:recoverable]).to be_falsy + end + end + + context 'when job failed and is recoverable' do + let(:job) { create(:ci_build, :api_failure) } + + it 'should state it is recoverable' do + expect(subject[:recoverable]).to be_truthy end end context 'when job passed' do let(:job) { create(:ci_build, :success) } - describe 'status' do - it 'should not contain the failure reason inside label' do - expect(subject[:status][:label]).to eq('passed') - end + it 'should not include callout message or recoverable keys' do + expect(subject).not_to include('callout_message') + expect(subject).not_to include('recoverable') end end end |