diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/javascripts/zen_mode_spec.js | 2 | ||||
-rw-r--r-- | spec/lib/quality/test_level_spec.rb | 28 | ||||
-rw-r--r-- | spec/mailers/emails/pipelines_spec.rb | 69 | ||||
-rw-r--r-- | spec/requests/api/group_labels_spec.rb | 94 | ||||
-rw-r--r-- | spec/requests/api/labels_spec.rb | 201 | ||||
-rw-r--r-- | spec/support/helpers/javascript_fixtures_helpers.rb | 2 | ||||
-rw-r--r-- | spec/support/shared_examples/ci/pipeline_email_examples.rb | 20 | ||||
-rw-r--r-- | spec/views/notify/pipeline_failed_email.html.haml_spec.rb | 2 | ||||
-rw-r--r-- | spec/views/notify/pipeline_failed_email.text.erb_spec.rb | 2 | ||||
-rw-r--r-- | spec/views/notify/pipeline_success_email.html.haml_spec.rb | 2 | ||||
-rw-r--r-- | spec/views/notify/pipeline_success_email.text.erb_spec.rb | 26 |
11 files changed, 339 insertions, 109 deletions
diff --git a/spec/javascripts/zen_mode_spec.js b/spec/javascripts/zen_mode_spec.js index 8f662c71c7a..5dee11b3810 100644 --- a/spec/javascripts/zen_mode_spec.js +++ b/spec/javascripts/zen_mode_spec.js @@ -2,6 +2,7 @@ import $ from 'jquery'; import Dropzone from 'dropzone'; import Mousetrap from 'mousetrap'; import ZenMode from '~/zen_mode'; +import initNotes from '~/init_notes'; describe('ZenMode', () => { let zen; @@ -28,6 +29,7 @@ describe('ZenMode', () => { beforeEach(() => { loadFixtures(fixtureName); + initNotes(); dropzoneForElementSpy = spyOn(Dropzone, 'forElement').and.callFake(() => ({ enable: () => true, diff --git a/spec/lib/quality/test_level_spec.rb b/spec/lib/quality/test_level_spec.rb index 59870ce44a7..4db188bd8f2 100644 --- a/spec/lib/quality/test_level_spec.rb +++ b/spec/lib/quality/test_level_spec.rb @@ -4,6 +4,20 @@ require 'fast_spec_helper' RSpec.describe Quality::TestLevel do describe '#pattern' do + context 'when level is all' do + it 'returns a pattern' do + expect(subject.pattern(:all)) + .to eq("spec/**{,/**/}*_spec.rb") + end + end + + context 'when level is geo' do + it 'returns a pattern' do + expect(subject.pattern(:geo)) + .to eq("spec/**{,/**/}*_spec.rb") + end + end + context 'when level is unit' do it 'returns a pattern' do expect(subject.pattern(:unit)) @@ -44,6 +58,20 @@ RSpec.describe Quality::TestLevel do end describe '#regexp' do + context 'when level is all' do + it 'returns a regexp' do + expect(subject.regexp(:all)) + .to eq(%r{spec/}) + end + end + + context 'when level is geo' do + it 'returns a regexp' do + expect(subject.regexp(:geo)) + .to eq(%r{spec/}) + end + end + context 'when level is unit' do it 'returns a regexp' do expect(subject.regexp(:unit)) diff --git a/spec/mailers/emails/pipelines_spec.rb b/spec/mailers/emails/pipelines_spec.rb new file mode 100644 index 00000000000..8d4afe9f00f --- /dev/null +++ b/spec/mailers/emails/pipelines_spec.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +require 'spec_helper' +require 'email_spec' + +describe Emails::Pipelines do + include EmailSpec::Matchers + + set(:project) { create(:project, :repository) } + + shared_examples_for 'correct pipeline information' do + it 'has a correct information' do + expect(subject) + .to have_subject "#{project.name} | Pipeline ##{pipeline.id} has " \ + "#{status} for #{pipeline.source_ref} | " \ + "#{pipeline.short_sha}".to_s + + expect(subject).to have_body_text pipeline.source_ref + expect(subject).to have_body_text status_text + end + + context 'when pipeline for merge requests' do + let(:pipeline) { merge_request.all_pipelines.first } + + let(:merge_request) do + create(:merge_request, :with_detached_merge_request_pipeline, + source_project: project, + target_project: project) + end + + it 'has a correct information with merge request link' do + expect(subject) + .to have_subject "#{project.name} | Pipeline ##{pipeline.id} has " \ + "#{status} for #{pipeline.source_ref} | " \ + "#{pipeline.short_sha} in !#{merge_request.iid}".to_s + + expect(subject).to have_body_text merge_request.to_reference + expect(subject).to have_body_text pipeline.source_ref + expect(subject).not_to have_body_text pipeline.ref + end + end + end + + describe '#pipeline_success_email' do + subject { Notify.pipeline_success_email(pipeline, pipeline.user.try(:email)) } + + let(:pipeline) { create(:ci_pipeline, project: project, ref: ref, sha: sha) } + let(:ref) { 'master' } + let(:sha) { project.commit(ref).sha } + + it_behaves_like 'correct pipeline information' do + let(:status) { 'succeeded' } + let(:status_text) { 'Your pipeline has passed.' } + end + end + + describe '#pipeline_failed_email' do + subject { Notify.pipeline_failed_email(pipeline, pipeline.user.try(:email)) } + + let(:pipeline) { create(:ci_pipeline, project: project, ref: ref, sha: sha) } + let(:ref) { 'master' } + let(:sha) { project.commit(ref).sha } + + it_behaves_like 'correct pipeline information' do + let(:status) { 'failed' } + let(:status_text) { 'Your pipeline has failed.' } + end + end +end diff --git a/spec/requests/api/group_labels_spec.rb b/spec/requests/api/group_labels_spec.rb index 3ac394b57c5..f7994b55efa 100644 --- a/spec/requests/api/group_labels_spec.rb +++ b/spec/requests/api/group_labels_spec.rb @@ -65,6 +65,17 @@ describe API::GroupLabels do end end + describe 'GET :id/labels/:label_id' do + it 'returns a single label for the group' do + get api("/groups/#{group.id}/labels/#{group_label1.name}", user) + + expect(response).to have_gitlab_http_status(200) + expect(json_response['name']).to eq(group_label1.name) + expect(json_response['color']).to eq(group_label1.color) + expect(json_response['description']).to eq(group_label1.description) + end + end + describe 'POST /groups/:id/labels' do it 'returns created label when all params are given' do post api("/groups/#{group.id}/labels", user), @@ -117,7 +128,7 @@ describe API::GroupLabels do end end - describe 'DELETE /groups/:id/labels' do + describe 'DELETE /groups/:id/labels (deprecated)' do it 'returns 204 for existing label' do delete api("/groups/#{group.id}/labels", user), params: { name: group_label1.name } @@ -154,7 +165,37 @@ describe API::GroupLabels do end end - describe 'PUT /groups/:id/labels' do + describe 'DELETE /groups/:id/labels/:label_id' do + it 'returns 204 for existing label' do + delete api("/groups/#{group.id}/labels/#{group_label1.name}", user) + + expect(response).to have_gitlab_http_status(204) + end + + it 'returns 404 for non existing label' do + delete api("/groups/#{group.id}/labels/not_exists", user) + + expect(response).to have_gitlab_http_status(404) + expect(json_response['message']).to eq('404 Label Not Found') + end + + it "does not delete parent's group labels" do + subgroup = create(:group, parent: group) + subgroup_label = create(:group_label, title: 'feature', group: subgroup) + + delete api("/groups/#{subgroup.id}/labels/#{subgroup_label.name}", user) + + expect(response).to have_gitlab_http_status(204) + expect(subgroup.labels.size).to eq(0) + expect(group.labels).to include(group_label1) + end + + it_behaves_like '412 response' do + let(:request) { api("/groups/#{group.id}/labels/#{group_label1.name}", user) } + end + end + + describe 'PUT /groups/:id/labels (deprecated)' do it 'returns 200 if name and colors and description are changed' do put api("/groups/#{group.id}/labels", user), params: { @@ -199,7 +240,7 @@ describe API::GroupLabels do put api("/groups/#{group.id}/labels", user), params: { new_name: group_label1.name } expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('name is missing') + expect(json_response['error']).to eq('label_id, name are missing, exactly one parameter must be provided') end it 'returns 400 if no new parameters given' do @@ -211,6 +252,53 @@ describe API::GroupLabels do end end + describe 'PUT /groups/:id/labels/:label_id' do + it 'returns 200 if name and colors and description are changed' do + put api("/groups/#{group.id}/labels/#{group_label1.name}", user), + params: { + new_name: 'New Label', + color: '#FFFFFF', + description: 'test' + } + + expect(response).to have_gitlab_http_status(200) + expect(json_response['name']).to eq('New Label') + expect(json_response['color']).to eq('#FFFFFF') + expect(json_response['description']).to eq('test') + end + + it "does not update parent's group label" do + subgroup = create(:group, parent: group) + subgroup_label = create(:group_label, title: 'feature', group: subgroup) + + put api("/groups/#{subgroup.id}/labels/#{subgroup_label.name}", user), + params: { + new_name: 'New Label' + } + + expect(response).to have_gitlab_http_status(200) + expect(subgroup.labels[0].name).to eq('New Label') + expect(group_label1.name).to eq('feature') + end + + it 'returns 404 if label does not exist' do + put api("/groups/#{group.id}/labels/not_exists", user), + params: { + new_name: 'label3' + } + + expect(response).to have_gitlab_http_status(404) + end + + it 'returns 400 if no new parameters given' do + put api("/groups/#{group.id}/labels/#{group_label1.name}", user) + + expect(response).to have_gitlab_http_status(400) + expect(json_response['error']).to eq('new_name, color, description are missing, '\ + 'at least one parameter must be provided') + end + end + describe 'POST /groups/:id/labels/:label_id/subscribe' do context 'when label_id is a label title' do it 'subscribes to the label' do diff --git a/spec/requests/api/labels_spec.rb b/spec/requests/api/labels_spec.rb index 4f8233a9110..7089da3d351 100644 --- a/spec/requests/api/labels_spec.rb +++ b/spec/requests/api/labels_spec.rb @@ -1,139 +1,122 @@ require 'spec_helper' describe API::Labels do + def put_labels_api(route_type, user, spec_params, request_params = {}) + if route_type == :deprecated + put api("/projects/#{project.id}/labels", user), + params: request_params.merge(spec_params) + else + label_id = spec_params[:name] || spec_params[:label_id] + + put api("/projects/#{project.id}/labels/#{label_id}", user), + params: request_params.merge(spec_params.except(:name, :id)) + end + end + let(:user) { create(:user) } let(:project) { create(:project, creator_id: user.id, namespace: user.namespace) } let!(:label1) { create(:label, title: 'label1', project: project) } let!(:priority_label) { create(:label, title: 'bug', project: project, priority: 3) } - shared_examples 'label update API' do - it 'returns 200 if name is changed' do - request_params = { - new_name: 'New Label' - }.merge(spec_params) - - put api("/projects/#{project.id}/labels", user), - params: request_params + route_types = [:deprecated, :rest] - expect(response).to have_gitlab_http_status(200) - expect(json_response['name']).to eq('New Label') - expect(json_response['color']).to eq(label1.color) - end - - it 'returns 200 if colors is changed' do - request_params = { - color: '#FFFFFF' - }.merge(spec_params) + shared_examples 'label update API' do + route_types.each do |route_type| + it "returns 200 if name is changed (#{route_type} route)" do + put_labels_api(route_type, user, spec_params, new_name: 'New Label') - put api("/projects/#{project.id}/labels", user), - params: request_params + expect(response).to have_gitlab_http_status(200) + expect(json_response['name']).to eq('New Label') + expect(json_response['color']).to eq(label1.color) + end - expect(response).to have_gitlab_http_status(200) - expect(json_response['name']).to eq(label1.name) - expect(json_response['color']).to eq('#FFFFFF') - end + it "returns 200 if colors is changed (#{route_type} route)" do + put_labels_api(route_type, user, spec_params, color: '#FFFFFF') - it 'returns 200 if a priority is added' do - request_params = { - priority: 3 - }.merge(spec_params) + expect(response).to have_gitlab_http_status(200) + expect(json_response['name']).to eq(label1.name) + expect(json_response['color']).to eq('#FFFFFF') + end - put api("/projects/#{project.id}/labels", user), - params: request_params + it "returns 200 if a priority is added (#{route_type} route)" do + put_labels_api(route_type, user, spec_params, priority: 3) - expect(response.status).to eq(200) - expect(json_response['name']).to eq(label1.name) - expect(json_response['priority']).to eq(3) - end - - it 'returns 400 if no new parameters given' do - put api("/projects/#{project.id}/labels", user), params: spec_params + expect(response.status).to eq(200) + expect(json_response['name']).to eq(label1.name) + expect(json_response['priority']).to eq(3) + end - expect(response).to have_gitlab_http_status(400) - expect(json_response['error']).to eq('new_name, color, description, priority are missing, '\ - 'at least one parameter must be provided') - end + it "returns 400 if no new parameters given (#{route_type} route)" do + put_labels_api(route_type, user, spec_params) - it 'returns 400 when color code is too short' do - request_params = { - color: '#FF' - }.merge(spec_params) + expect(response).to have_gitlab_http_status(400) + expect(json_response['error']).to eq('new_name, color, description, priority are missing, '\ + 'at least one parameter must be provided') + end - put api("/projects/#{project.id}/labels", user), - params: request_params + it "returns 400 when color code is too short (#{route_type} route)" do + put_labels_api(route_type, user, spec_params, color: '#FF') - expect(response).to have_gitlab_http_status(400) - expect(json_response['message']['color']).to eq(['must be a valid color code']) - end + expect(response).to have_gitlab_http_status(400) + expect(json_response['message']['color']).to eq(['must be a valid color code']) + end - it 'returns 400 for too long color code' do - request_params = { - color: '#FFAAFFFF' - }.merge(spec_params) + it "returns 400 for too long color code (#{route_type} route)" do + put_labels_api(route_type, user, spec_params, color: '#FFAAFFFF') - put api("/projects/#{project.id}/labels", user), - params: request_params + expect(response).to have_gitlab_http_status(400) + expect(json_response['message']['color']).to eq(['must be a valid color code']) + end - expect(response).to have_gitlab_http_status(400) - expect(json_response['message']['color']).to eq(['must be a valid color code']) - end + it "returns 400 for invalid priority (#{route_type} route)" do + put_labels_api(route_type, user, spec_params, priority: 'foo') - it 'returns 400 for invalid priority' do - request_params = { - priority: 'foo' - }.merge(spec_params) + expect(response).to have_gitlab_http_status(400) + end - put api("/projects/#{project.id}/labels", user), - params: request_params + it "returns 200 if name and colors and description are changed (#{route_type} route)" do + put_labels_api(route_type, user, spec_params, new_name: 'New Label', color: '#FFFFFF', description: 'test') - expect(response).to have_gitlab_http_status(400) - end + expect(response).to have_gitlab_http_status(200) + expect(json_response['name']).to eq('New Label') + expect(json_response['color']).to eq('#FFFFFF') + expect(json_response['description']).to eq('test') + end - it 'returns 200 if name and colors and description are changed' do - request_params = { - new_name: 'New Label', - color: '#FFFFFF', - description: 'test' - }.merge(spec_params) + it "returns 400 for invalid name (#{route_type} route)" do + put_labels_api(route_type, user, spec_params, new_name: ',', color: '#FFFFFF') - put api("/projects/#{project.id}/labels", user), - params: request_params + expect(response).to have_gitlab_http_status(400) + expect(json_response['message']['title']).to eq(['is invalid']) + end - expect(response).to have_gitlab_http_status(200) - expect(json_response['name']).to eq('New Label') - expect(json_response['color']).to eq('#FFFFFF') - expect(json_response['description']).to eq('test') - end + it "returns 200 if description is changed (#{route_type} route)" do + put_labels_api(route_type, user, spec_params, description: 'test') - it 'returns 400 for invalid name' do - request_params = { - new_name: ',', - color: '#FFFFFF' - }.merge(spec_params) + expect(response).to have_gitlab_http_status(200) + expect(json_response['id']).to eq(expected_response_label_id) + expect(json_response['description']).to eq('test') + end - put api("/projects/#{project.id}/labels", user), - params: request_params + it "returns 200 if priority is changed (#{route_type} route)" do + put_labels_api(route_type, user, spec_params, priority: 10) - expect(response).to have_gitlab_http_status(400) - expect(json_response['message']['title']).to eq(['is invalid']) + expect(response.status).to eq(200) + expect(json_response['id']).to eq(expected_response_label_id) + expect(json_response['priority']).to eq(10) + end end - it 'returns 200 if description is changed' do - request_params = { - description: 'test' - }.merge(spec_params) + it 'returns 200 if a priority is removed (deprecated route)' do + label = find_by_spec_params(spec_params) - put api("/projects/#{project.id}/labels", user), - params: request_params + expect(label).not_to be_nil - expect(response).to have_gitlab_http_status(200) - expect(json_response['id']).to eq(expected_response_label_id) - expect(json_response['description']).to eq('test') - end + label.priorities.create(project: label.project, priority: 1) + label.save! - it 'returns 200 if priority is changed' do request_params = { - priority: 10 + priority: nil }.merge(spec_params) put api("/projects/#{project.id}/labels", user), @@ -141,21 +124,22 @@ describe API::Labels do expect(response.status).to eq(200) expect(json_response['id']).to eq(expected_response_label_id) - expect(json_response['priority']).to eq(10) + expect(json_response['priority']).to be_nil end - it 'returns 200 if a priority is removed' do + it 'returns 200 if a priority is removed (rest route)' do label = find_by_spec_params(spec_params) expect(label).not_to be_nil + label_id = spec_params[:name] || spec_params[:label_id] label.priorities.create(project: label.project, priority: 1) label.save! request_params = { priority: nil - }.merge(spec_params) + }.merge(spec_params.except(:name, :id)) - put api("/projects/#{project.id}/labels", user), + put api("/projects/#{project.id}/labels/#{label_id}", user), params: request_params expect(response.status).to eq(200) @@ -173,11 +157,18 @@ describe API::Labels do end shared_examples 'label delete API' do - it 'returns 204 for existing label' do + it 'returns 204 for existing label (deprecated route)' do delete api("/projects/#{project.id}/labels", user), params: spec_params expect(response).to have_gitlab_http_status(204) end + + it 'returns 204 for existing label (rest route)' do + label_id = spec_params[:name] || spec_params[:label_id] + delete api("/projects/#{project.id}/labels/#{label_id}", user), params: spec_params.except(:name, :label_id) + + expect(response).to have_gitlab_http_status(204) + end end before do diff --git a/spec/support/helpers/javascript_fixtures_helpers.rb b/spec/support/helpers/javascript_fixtures_helpers.rb index 7ec65318ec5..fd5ad9451f7 100644 --- a/spec/support/helpers/javascript_fixtures_helpers.rb +++ b/spec/support/helpers/javascript_fixtures_helpers.rb @@ -69,7 +69,7 @@ module JavaScriptFixturesHelpers link_tags = doc.css('link') link_tags.remove - scripts = doc.css("script:not([type='text/template']):not([type='text/x-template'])") + scripts = doc.css("script:not([type='text/template']):not([type='text/x-template']):not([type='application/json'])") scripts.remove fixture = doc.to_html diff --git a/spec/support/shared_examples/ci/pipeline_email_examples.rb b/spec/support/shared_examples/ci/pipeline_email_examples.rb new file mode 100644 index 00000000000..f72d8af3c65 --- /dev/null +++ b/spec/support/shared_examples/ci/pipeline_email_examples.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +shared_examples_for 'correct pipeline information for pipelines for merge requests' do + context 'when pipeline for merge request' do + let(:pipeline) { merge_request.all_pipelines.first } + + let(:merge_request) do + create(:merge_request, :with_detached_merge_request_pipeline, + source_project: project, + target_project: project) + end + + it 'renders a source ref of the pipeline' do + render + + expect(rendered).to have_content pipeline.source_ref + expect(rendered).not_to have_content pipeline.ref + end + end +end diff --git a/spec/views/notify/pipeline_failed_email.html.haml_spec.rb b/spec/views/notify/pipeline_failed_email.html.haml_spec.rb index bf633a118ca..28f8203fd8f 100644 --- a/spec/views/notify/pipeline_failed_email.html.haml_spec.rb +++ b/spec/views/notify/pipeline_failed_email.html.haml_spec.rb @@ -33,6 +33,8 @@ describe 'notify/pipeline_failed_email.html.haml' do expect(rendered).to have_content "##{pipeline.id}" expect(rendered).to have_content pipeline.user.name end + + it_behaves_like 'correct pipeline information for pipelines for merge requests' end context 'pipeline without user' do diff --git a/spec/views/notify/pipeline_failed_email.text.erb_spec.rb b/spec/views/notify/pipeline_failed_email.text.erb_spec.rb index 060274eb56a..d15969acf83 100644 --- a/spec/views/notify/pipeline_failed_email.text.erb_spec.rb +++ b/spec/views/notify/pipeline_failed_email.text.erb_spec.rb @@ -36,4 +36,6 @@ describe 'notify/pipeline_failed_email.text.erb' do expect(rendered).to have_content(pipeline.user.name) expect(rendered).to have_content("/-/jobs/#{job.id}/raw") end + + it_behaves_like 'correct pipeline information for pipelines for merge requests' end diff --git a/spec/views/notify/pipeline_success_email.html.haml_spec.rb b/spec/views/notify/pipeline_success_email.html.haml_spec.rb index 46a6c908863..79beca79724 100644 --- a/spec/views/notify/pipeline_success_email.html.haml_spec.rb +++ b/spec/views/notify/pipeline_success_email.html.haml_spec.rb @@ -33,6 +33,8 @@ describe 'notify/pipeline_success_email.html.haml' do expect(rendered).to have_content "##{pipeline.id}" expect(rendered).to have_content pipeline.user.name end + + it_behaves_like 'correct pipeline information for pipelines for merge requests' end context 'pipeline without user' do diff --git a/spec/views/notify/pipeline_success_email.text.erb_spec.rb b/spec/views/notify/pipeline_success_email.text.erb_spec.rb new file mode 100644 index 00000000000..ba4633bc346 --- /dev/null +++ b/spec/views/notify/pipeline_success_email.text.erb_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'notify/pipeline_success_email.text.erb' do + let(:user) { create(:user, developer_projects: [project]) } + let(:project) { create(:project, :repository) } + let(:merge_request) { create(:merge_request, :simple, source_project: project) } + + let(:pipeline) do + create(:ci_pipeline, + :success, + project: project, + user: user, + ref: project.default_branch, + sha: project.commit.sha) + end + + before do + assign(:project, project) + assign(:pipeline, pipeline) + assign(:merge_request, merge_request) + end + + it_behaves_like 'correct pipeline information for pipelines for merge requests' +end |