diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-28 21:06:24 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-28 21:06:24 +0000 |
commit | ef326e805ac99222c55e1efd9867045800f01a4b (patch) | |
tree | 201d39fb90a1422cc1f523d95b30b93e95f973f5 /spec | |
parent | 7515ec41c527c62bfd56f46e388cf6d9fe06479f (diff) | |
download | gitlab-ce-ef326e805ac99222c55e1efd9867045800f01a4b.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/projects/releases_controller_spec.rb | 68 | ||||
-rw-r--r-- | spec/features/issues/filtered_search/dropdown_hint_spec.rb | 11 | ||||
-rw-r--r-- | spec/features/issues/filtered_search/dropdown_release_spec.rb | 55 | ||||
-rw-r--r-- | spec/frontend/releases/list/components/release_block_spec.js | 4 | ||||
-rw-r--r-- | spec/frontend/releases/mock_data.js | 2 | ||||
-rw-r--r-- | spec/helpers/search_helper_spec.rb | 1 | ||||
-rw-r--r-- | spec/lib/gitlab/asciidoc_spec.rb | 92 | ||||
-rw-r--r-- | spec/support/helpers/filtered_search_helpers.rb | 4 | ||||
-rw-r--r-- | spec/tasks/gitlab/task_helpers_spec.rb | 27 |
9 files changed, 198 insertions, 66 deletions
diff --git a/spec/controllers/projects/releases_controller_spec.rb b/spec/controllers/projects/releases_controller_spec.rb index 5b9d21d3d5b..63ad633e2fc 100644 --- a/spec/controllers/projects/releases_controller_spec.rb +++ b/spec/controllers/projects/releases_controller_spec.rb @@ -3,10 +3,13 @@ require 'spec_helper' describe Projects::ReleasesController do - let!(:project) { create(:project, :repository, :public) } - let!(:user) { create(:user) } + let!(:project) { create(:project, :repository, :public) } + let!(:private_project) { create(:project, :repository, :private) } + let!(:user) { create(:user) } + let!(:release_1) { create(:release, project: project, released_at: Time.zone.parse('2018-10-18')) } + let!(:release_2) { create(:release, project: project, released_at: Time.zone.parse('2019-10-19')) } - describe 'GET #index' do + shared_examples 'common access controls' do it 'renders a 200' do get_index @@ -14,17 +17,14 @@ describe Projects::ReleasesController do end context 'when the project is private' do - let!(:project) { create(:project, :repository, :private) } - - it 'renders a 302' do - get_index + let(:project) { private_project } - expect(response.status).to eq(302) + before do + sign_in(user) end it 'renders a 200 for a logged in developer' do project.add_developer(user) - sign_in(user) get_index @@ -32,8 +32,6 @@ describe Projects::ReleasesController do end it 'renders a 404 when logged in but not in the project' do - sign_in(user) - get_index expect(response.status).to eq(404) @@ -41,9 +39,55 @@ describe Projects::ReleasesController do end end + describe 'GET #index' do + before do + get_index + end + + context 'as html' do + let(:format) { :html } + + it 'returns a text/html content_type' do + expect(response.content_type).to eq 'text/html' + end + + it_behaves_like 'common access controls' + + context 'when the project is private and the user is not logged in' do + let(:project) { private_project } + + it 'renders a 302' do + expect(response.status).to eq(302) + end + end + end + + context 'as json' do + let(:format) { :json } + + it 'returns an application/json content_type' do + expect(response.content_type).to eq 'application/json' + end + + it "returns the project's releases as JSON, ordered by released_at" do + expect(response.body).to eq([release_2, release_1].to_json) + end + + it_behaves_like 'common access controls' + + context 'when the project is private and the user is not logged in' do + let(:project) { private_project } + + it 'renders a 401' do + expect(response.status).to eq(401) + end + end + end + end + private def get_index - get :index, params: { namespace_id: project.namespace, project_id: project } + get :index, params: { namespace_id: project.namespace, project_id: project, format: format } end end diff --git a/spec/features/issues/filtered_search/dropdown_hint_spec.rb b/spec/features/issues/filtered_search/dropdown_hint_spec.rb index 1c56902a27d..bb57d69148b 100644 --- a/spec/features/issues/filtered_search/dropdown_hint_spec.rb +++ b/spec/features/issues/filtered_search/dropdown_hint_spec.rb @@ -68,7 +68,7 @@ describe 'Dropdown hint', :js do it 'filters with text' do filtered_search.set('a') - expect(find(js_dropdown_hint)).to have_selector('.filter-dropdown .filter-dropdown-item', count: 5) + expect(find(js_dropdown_hint)).to have_selector('.filter-dropdown .filter-dropdown-item', count: 6) end end @@ -104,6 +104,15 @@ describe 'Dropdown hint', :js do expect_filtered_search_input_empty end + it 'opens the release dropdown when you click on release' do + click_hint('release') + + expect(page).to have_css(js_dropdown_hint, visible: false) + expect(page).to have_css('#js-dropdown-release', visible: true) + expect_tokens([{ name: 'Release' }]) + expect_filtered_search_input_empty + end + it 'opens the label dropdown when you click on label' do click_hint('label') diff --git a/spec/features/issues/filtered_search/dropdown_release_spec.rb b/spec/features/issues/filtered_search/dropdown_release_spec.rb new file mode 100644 index 00000000000..eea7f2d7848 --- /dev/null +++ b/spec/features/issues/filtered_search/dropdown_release_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'Dropdown release', :js do + include FilteredSearchHelpers + + let!(:project) { create(:project, :repository) } + let!(:user) { create(:user) } + let!(:release) { create(:release, tag: 'v1.0', project: project) } + let!(:crazy_release) { create(:release, tag: '☺!/"#%&\'{}+,-.<>;=@]_`{|}🚀', project: project) } + + def filtered_search + find('.filtered-search') + end + + def filter_dropdown + find('#js-dropdown-release .filter-dropdown') + end + + before do + project.add_maintainer(user) + sign_in(user) + create(:issue, project: project) + + visit project_issues_path(project) + end + + describe 'behavior' do + before do + filtered_search.set('release:') + end + + def expect_results(count) + expect(filter_dropdown).to have_selector('.filter-dropdown .filter-dropdown-item', count: count) + end + + it 'loads all the releases when opened' do + expect_results(2) + end + + it 'filters by tag name' do + filtered_search.send_keys("☺") + expect_results(1) + end + + it 'fills in the release name when the autocomplete hint is clicked' do + find('#js-dropdown-release .filter-dropdown-item', text: crazy_release.tag).click + + expect(page).to have_css('#js-dropdown-release', visible: false) + expect_tokens([release_token(crazy_release.tag)]) + expect_filtered_search_input_empty + end + end +end diff --git a/spec/frontend/releases/list/components/release_block_spec.js b/spec/frontend/releases/list/components/release_block_spec.js index ac51c3af11a..93f202b2977 100644 --- a/spec/frontend/releases/list/components/release_block_spec.js +++ b/spec/frontend/releases/list/components/release_block_spec.js @@ -73,7 +73,7 @@ describe('Release block', () => { it('renders an edit button that links to the "Edit release" page', () => { expect(editButton().exists()).toBe(true); - expect(editButton().attributes('href')).toBe(release._links.edit); + expect(editButton().attributes('href')).toBe(release._links.edit_url); }); it('renders release name', () => { @@ -180,7 +180,7 @@ describe('Release block', () => { }); }); - it("does not render an edit button if release._links.edit isn't a string", () => { + it("does not render an edit button if release._links.edit_url isn't a string", () => { delete releaseClone._links; return factory(releaseClone).then(() => { diff --git a/spec/frontend/releases/mock_data.js b/spec/frontend/releases/mock_data.js index b2ebf1174d4..32095fd4b78 100644 --- a/spec/frontend/releases/mock_data.js +++ b/spec/frontend/releases/mock_data.js @@ -95,6 +95,6 @@ export const release = { ], }, _links: { - edit: 'http://0.0.0.0:3001/root/release-test/-/releases/v0.3/edit', + edit_url: 'http://0.0.0.0:3001/root/release-test/-/releases/v0.3/edit', }, }; diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb index 561cd085ad1..bef6fbe3d5f 100644 --- a/spec/helpers/search_helper_spec.rb +++ b/spec/helpers/search_helper_spec.rb @@ -167,6 +167,7 @@ describe SearchHelper do expect(search_filter_input_options('')[:data]['runner-tags-endpoint']).to eq(tag_list_admin_runners_path) expect(search_filter_input_options('')[:data]['labels-endpoint']).to eq(project_labels_path(@project)) expect(search_filter_input_options('')[:data]['milestones-endpoint']).to eq(project_milestones_path(@project)) + expect(search_filter_input_options('')[:data]['releases-endpoint']).to eq(project_releases_path(@project)) end it 'includes autocomplete=off flag' do diff --git a/spec/lib/gitlab/asciidoc_spec.rb b/spec/lib/gitlab/asciidoc_spec.rb index 7c65525b8dc..415a6e62374 100644 --- a/spec/lib/gitlab/asciidoc_spec.rb +++ b/spec/lib/gitlab/asciidoc_spec.rb @@ -58,7 +58,7 @@ module Gitlab }, 'image with onerror' => { input: 'image:https://localhost.com/image.png[Alt text" onerror="alert(7)]', - output: "<div>\n<p><span><img src=\"https://localhost.com/image.png\" alt='Alt text\" onerror=\"alert(7)'></span></p>\n</div>" + output: "<div>\n<p><span><a class=\"no-attachment-icon\" href=\"https://localhost.com/image.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img src=\"data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" alt='Alt text\" onerror=\"alert(7)' class=\"lazy\" data-src=\"https://localhost.com/image.png\"></a></span></p>\n</div>" }, 'fenced code with inline script' => { input: '```mypre"><script>alert(3)</script>', @@ -73,6 +73,20 @@ module Gitlab end end + context "images" do + it "does lazy load and link image" do + input = 'image:https://localhost.com/image.png[]' + output = "<div>\n<p><span><a class=\"no-attachment-icon\" href=\"https://localhost.com/image.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img src=\"data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" alt=\"image\" class=\"lazy\" data-src=\"https://localhost.com/image.png\"></a></span></p>\n</div>" + expect(render(input, context)).to include(output) + end + + it "does not automatically link image if link is explicitly defined" do + input = 'image:https://localhost.com/image.png[link=https://gitlab.com]' + output = "<div>\n<p><span><a href=\"https://gitlab.com\" rel=\"nofollow noreferrer noopener\" target=\"_blank\"><img src=\"data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" alt=\"image\" class=\"lazy\" data-src=\"https://localhost.com/image.png\"></a></span></p>\n</div>" + expect(render(input, context)).to include(output) + end + end + context 'with admonition' do it 'preserves classes' do input = <<~ADOC @@ -107,7 +121,7 @@ module Gitlab ADOC output = <<~HTML - <h2>Title</h2> + <h2>Title</h2> HTML expect(render(input, context)).to include(output.strip) @@ -149,15 +163,15 @@ module Gitlab ADOC output = <<~HTML - <div> - <p>This paragraph has a footnote.<sup>[<a id="_footnoteref_1" href="#_footnotedef_1" title="View footnote.">1</a>]</sup></p> - </div> - <div> - <hr> - <div id="_footnotedef_1"> - <a href="#_footnoteref_1">1</a>. This is the text of the footnote. - </div> - </div> + <div> + <p>This paragraph has a footnote.<sup>[<a id="_footnoteref_1" href="#_footnotedef_1" title="View footnote.">1</a>]</sup></p> + </div> + <div> + <hr> + <div id="_footnotedef_1"> + <a href="#_footnoteref_1">1</a>. This is the text of the footnote. + </div> + </div> HTML expect(render(input, context)).to include(output.strip) @@ -183,34 +197,34 @@ module Gitlab ADOC output = <<~HTML - <h1>Title</h1> - <div> - <h2 id="user-content-first-section"> - <a class="anchor" href="#user-content-first-section"></a>First section</h2> - <div> - <div> - <p>This is the first section.</p> - </div> - </div> - </div> - <div> - <h2 id="user-content-second-section"> - <a class="anchor" href="#user-content-second-section"></a>Second section</h2> - <div> - <div> - <p>This is the second section.</p> - </div> - </div> - </div> - <div> - <h2 id="user-content-thunder"> - <a class="anchor" href="#user-content-thunder"></a>Thunder ⚡ !</h2> - <div> - <div> - <p>This is the third section.</p> - </div> - </div> - </div> + <h1>Title</h1> + <div> + <h2 id="user-content-first-section"> + <a class="anchor" href="#user-content-first-section"></a>First section</h2> + <div> + <div> + <p>This is the first section.</p> + </div> + </div> + </div> + <div> + <h2 id="user-content-second-section"> + <a class="anchor" href="#user-content-second-section"></a>Second section</h2> + <div> + <div> + <p>This is the second section.</p> + </div> + </div> + </div> + <div> + <h2 id="user-content-thunder"> + <a class="anchor" href="#user-content-thunder"></a>Thunder ⚡ !</h2> + <div> + <div> + <p>This is the third section.</p> + </div> + </div> + </div> HTML expect(render(input, context)).to include(output.strip) diff --git a/spec/support/helpers/filtered_search_helpers.rb b/spec/support/helpers/filtered_search_helpers.rb index 39c818b1763..5dc87c36931 100644 --- a/spec/support/helpers/filtered_search_helpers.rb +++ b/spec/support/helpers/filtered_search_helpers.rb @@ -114,6 +114,10 @@ module FilteredSearchHelpers create_token('Milestone', milestone_name, symbol) end + def release_token(release_tag = nil) + create_token('Release', release_tag) + end + def label_token(label_name = nil, has_symbol = true) symbol = has_symbol ? '~' : nil create_token('Label', label_name, symbol) diff --git a/spec/tasks/gitlab/task_helpers_spec.rb b/spec/tasks/gitlab/task_helpers_spec.rb index 4b4f7d7c956..4546d3bdfaf 100644 --- a/spec/tasks/gitlab/task_helpers_spec.rb +++ b/spec/tasks/gitlab/task_helpers_spec.rb @@ -20,22 +20,12 @@ describe Gitlab::TaskHelpers do end it 'checkout the version and reset to it' do + expect(subject).to receive(:get_version).with(version).and_call_original expect(subject).to receive(:checkout_version).with(tag, clone_path) subject.checkout_or_clone_version(version: version, repo: repo, target_dir: clone_path) end - context 'with a branch version' do - let(:version) { '=branch_name' } - let(:branch) { 'branch_name' } - - it 'checkout the version and reset to it with a branch name' do - expect(subject).to receive(:checkout_version).with(branch, clone_path) - - subject.checkout_or_clone_version(version: version, repo: repo, target_dir: clone_path) - end - end - context "target_dir doesn't exist" do it 'clones the repo' do expect(subject).to receive(:clone_repo).with(repo, clone_path) @@ -96,4 +86,19 @@ describe Gitlab::TaskHelpers do expect { subject.run_command!(['bash', '-c', 'exit 1']) }.to raise_error Gitlab::TaskFailedError end end + + describe '#get_version' do + using RSpec::Parameterized::TableSyntax + + where(:version, :result) do + '1.1.1' | 'v1.1.1' + 'master' | 'master' + '12.4.0-rc7' | 'v12.4.0-rc7' + '594c3ea3e0e5540e5915bd1c49713a0381459dd6' | '594c3ea3e0e5540e5915bd1c49713a0381459dd6' + end + + with_them do + it { expect(subject.get_version(version)).to eq(result) } + end + end end |