diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-23 15:08:18 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-23 15:08:18 +0300 |
commit | 4aeb8a02c506eaa8f0710ee17edd9e35dd68d280 (patch) | |
tree | 42a0ab818ee72a5f99d017f7ca05b6b6349e142a /spec | |
parent | b8bb2148c282f5ebaf5cd3c83d905285902a1446 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/projects/raw_controller_spec.rb | 13 | ||||
-rw-r--r-- | spec/features/projects/raw/user_interacts_with_raw_endpoint_spec.rb | 2 | ||||
-rw-r--r-- | spec/javascripts/fly_out_nav_spec.js | 4 | ||||
-rw-r--r-- | spec/javascripts/lib/utils/common_utils_spec.js | 2 | ||||
-rw-r--r-- | spec/models/diff_note_spec.rb | 8 | ||||
-rw-r--r-- | spec/requests/api/discussions_spec.rb | 12 | ||||
-rw-r--r-- | spec/support/matchers/graphql_matchers.rb | 2 | ||||
-rw-r--r-- | spec/support/shared_examples/requests/api/diff_discussions.rb | 21 |
8 files changed, 44 insertions, 20 deletions
diff --git a/spec/controllers/projects/raw_controller_spec.rb b/spec/controllers/projects/raw_controller_spec.rb index bdf1c1a84d3..a570db12d94 100644 --- a/spec/controllers/projects/raw_controller_spec.rb +++ b/spec/controllers/projects/raw_controller_spec.rb @@ -56,10 +56,13 @@ describe Projects::RawController do stub_application_setting(raw_blob_request_limit: 5) end - it 'prevents from accessing the raw file' do - execute_raw_requests(requests: 6, project: project, file_path: file_path) + it 'prevents from accessing the raw file', :request_store do + execute_raw_requests(requests: 5, project: project, file_path: file_path) + + expect { execute_raw_requests(requests: 1, project: project, file_path: file_path) } + .to change { Gitlab::GitalyClient.get_request_count }.by(0) - expect(flash[:alert]).to eq(_('You cannot access the raw file. Please wait a minute.')) + expect(response.body).to eq(_('You cannot access the raw file. Please wait a minute.')) expect(response).to have_gitlab_http_status(429) end @@ -109,7 +112,7 @@ describe Projects::RawController do execute_raw_requests(requests: 3, project: project, file_path: modified_path) - expect(flash[:alert]).to eq(_('You cannot access the raw file. Please wait a minute.')) + expect(response.body).to eq(_('You cannot access the raw file. Please wait a minute.')) expect(response).to have_gitlab_http_status(429) end end @@ -137,7 +140,7 @@ describe Projects::RawController do # Accessing downcase version of readme execute_raw_requests(requests: 6, project: project, file_path: file_path) - expect(flash[:alert]).to eq(_('You cannot access the raw file. Please wait a minute.')) + expect(response.body).to eq(_('You cannot access the raw file. Please wait a minute.')) expect(response).to have_gitlab_http_status(429) # Accessing upcase version of readme diff --git a/spec/features/projects/raw/user_interacts_with_raw_endpoint_spec.rb b/spec/features/projects/raw/user_interacts_with_raw_endpoint_spec.rb index 6d587053b4f..673766073a2 100644 --- a/spec/features/projects/raw/user_interacts_with_raw_endpoint_spec.rb +++ b/spec/features/projects/raw/user_interacts_with_raw_endpoint_spec.rb @@ -31,8 +31,6 @@ describe 'Projects > Raw > User interacts with raw endpoint' do visit project_raw_url(project, file_path) end - expect(source).to have_content('You are being redirected') - click_link('redirected') expect(page).to have_content('You cannot access the raw file. Please wait a minute.') end end diff --git a/spec/javascripts/fly_out_nav_spec.js b/spec/javascripts/fly_out_nav_spec.js index 4772f754937..afcf132bea3 100644 --- a/spec/javascripts/fly_out_nav_spec.js +++ b/spec/javascripts/fly_out_nav_spec.js @@ -1,3 +1,4 @@ +import { GlBreakpointInstance } from '@gitlab/ui/dist/utils'; import { calculateTop, showSubLevelItems, @@ -15,7 +16,6 @@ import { subItemsMouseLeave, } from '~/fly_out_nav'; import { SIDEBAR_COLLAPSED_CLASS } from '~/contextual_sidebar'; -import bp from '~/breakpoints'; describe('Fly out sidebar navigation', () => { let el; @@ -26,7 +26,7 @@ describe('Fly out sidebar navigation', () => { el.style.position = 'relative'; document.body.appendChild(el); - spyOn(bp, 'getBreakpointSize').and.callFake(() => breakpointSize); + spyOn(GlBreakpointInstance, 'getBreakpointSize').and.callFake(() => breakpointSize); setOpenMenu(null); }); diff --git a/spec/javascripts/lib/utils/common_utils_spec.js b/spec/javascripts/lib/utils/common_utils_spec.js index 1d91b508b71..504d4a3e01a 100644 --- a/spec/javascripts/lib/utils/common_utils_spec.js +++ b/spec/javascripts/lib/utils/common_utils_spec.js @@ -1,8 +1,8 @@ import MockAdapter from 'axios-mock-adapter'; +import { GlBreakpointInstance as breakpointInstance } from '@gitlab/ui/dist/utils'; import axios from '~/lib/utils/axios_utils'; import * as commonUtils from '~/lib/utils/common_utils'; import { faviconDataUrl, overlayDataUrl, faviconWithOverlayDataUrl } from './mock_data'; -import breakpointInstance from '~/breakpoints'; const PIXEL_TOLERANCE = 0.2; diff --git a/spec/models/diff_note_spec.rb b/spec/models/diff_note_spec.rb index ae493d5c081..b802c8ba506 100644 --- a/spec/models/diff_note_spec.rb +++ b/spec/models/diff_note_spec.rb @@ -5,11 +5,11 @@ require 'spec_helper' describe DiffNote do include RepoHelpers - let!(:merge_request) { create(:merge_request) } - let(:project) { merge_request.project } - let(:commit) { project.commit(sample_commit.id) } + let_it_be(:merge_request) { create(:merge_request) } + let_it_be(:project) { merge_request.project } + let_it_be(:commit) { project.commit(sample_commit.id) } - let(:path) { "files/ruby/popen.rb" } + let_it_be(:path) { "files/ruby/popen.rb" } let(:diff_refs) { merge_request.diff_refs } let!(:position) do diff --git a/spec/requests/api/discussions_spec.rb b/spec/requests/api/discussions_spec.rb index 68f7d407b54..f37a02e7135 100644 --- a/spec/requests/api/discussions_spec.rb +++ b/spec/requests/api/discussions_spec.rb @@ -49,6 +49,18 @@ describe API::Discussions do it_behaves_like 'discussions API', 'projects', 'merge_requests', 'iid', can_reply_to_individual_notes: true it_behaves_like 'diff discussions API', 'projects', 'merge_requests', 'iid' it_behaves_like 'resolvable discussions API', 'projects', 'merge_requests', 'iid' + + context "when position is for a previous commit on the merge request" do + it "returns a 400 bad request error because the line_code is old" do + # SHA taken from an earlier commit listed in spec/factories/merge_requests.rb + position = diff_note.position.to_h.merge(new_line: 'c1acaa58bbcbc3eafe538cb8274ba387047b69f8') + + post api("/projects/#{project.id}/merge_requests/#{noteable['iid']}/discussions", user), + params: { body: 'hi!', position: position } + + expect(response).to have_gitlab_http_status(400) + end + end end context 'when noteable is a Commit' do diff --git a/spec/support/matchers/graphql_matchers.rb b/spec/support/matchers/graphql_matchers.rb index dbf457a9200..282deea4606 100644 --- a/spec/support/matchers/graphql_matchers.rb +++ b/spec/support/matchers/graphql_matchers.rb @@ -8,7 +8,7 @@ end RSpec::Matchers.define :have_graphql_fields do |*expected| def expected_field_names - expected.map { |name| GraphqlHelpers.fieldnamerize(name) } + Array.wrap(expected).map { |name| GraphqlHelpers.fieldnamerize(name) } end match do |kls| diff --git a/spec/support/shared_examples/requests/api/diff_discussions.rb b/spec/support/shared_examples/requests/api/diff_discussions.rb index 76c6c93964a..a7774d17d3c 100644 --- a/spec/support/shared_examples/requests/api/diff_discussions.rb +++ b/spec/support/shared_examples/requests/api/diff_discussions.rb @@ -38,13 +38,24 @@ shared_examples 'diff discussions API' do |parent_type, noteable_type, id_name| expect(json_response['notes'].first['position']).to eq(position.stringify_keys) end - it "returns a 400 bad request error when position is invalid" do - position = diff_note.position.to_h.merge(new_line: '100000') + context "when position is invalid" do + it "returns a 400 bad request error when position is not plausible" do + position = diff_note.position.to_h.merge(new_line: '100000') - post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", user), - params: { body: 'hi!', position: position } + post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", user), + params: { body: 'hi!', position: position } + + expect(response).to have_gitlab_http_status(400) + end + + it "returns a 400 bad request error when the position is not valid for this discussion" do + position = diff_note.position.to_h.merge(new_line: '588440f66559714280628a4f9799f0c4eb880a4a') + + post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", user), + params: { body: 'hi!', position: position } - expect(response).to have_gitlab_http_status(400) + expect(response).to have_gitlab_http_status(400) + end end end |