diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-03 18:06:11 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-03 18:06:11 +0000 |
commit | 25521def84a6987fe9d4265b560e930bfb32c195 (patch) | |
tree | 711e001ea65f76a9c2eb034c4531bda325af84f3 /spec | |
parent | 9a1c5456747a7b5b218b8b44e4b43396bf7fd705 (diff) | |
download | gitlab-ce-25521def84a6987fe9d4265b560e930bfb32c195.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/projects/branches_spec.rb | 1 | ||||
-rw-r--r-- | spec/features/projects/compare_spec.rb | 34 | ||||
-rw-r--r-- | spec/frontend/repository/components/__snapshots__/last_commit_spec.js.snap | 105 | ||||
-rw-r--r-- | spec/frontend/repository/components/last_commit_spec.js | 6 | ||||
-rw-r--r-- | spec/graphql/resolvers/last_commit_resolver_spec.rb | 41 | ||||
-rw-r--r-- | spec/graphql/types/commit_type_spec.rb | 7 | ||||
-rw-r--r-- | spec/lib/banzai/filter/video_link_filter_spec.rb | 94 | ||||
-rw-r--r-- | spec/presenters/commit_presenter_spec.rb | 13 | ||||
-rw-r--r-- | spec/rubocop/cop/line_break_around_conditional_block_spec.rb | 13 |
9 files changed, 277 insertions, 37 deletions
diff --git a/spec/features/projects/branches_spec.rb b/spec/features/projects/branches_spec.rb index b35067d0f4d..18e2723ff8e 100644 --- a/spec/features/projects/branches_spec.rb +++ b/spec/features/projects/branches_spec.rb @@ -246,7 +246,6 @@ describe 'Branches' do end expect(page).to have_content 'Commits' - expect(page).to have_link 'Create merge request' end end diff --git a/spec/features/projects/compare_spec.rb b/spec/features/projects/compare_spec.rb index 2674617bcfc..34bde29c8da 100644 --- a/spec/features/projects/compare_spec.rb +++ b/spec/features/projects/compare_spec.rb @@ -12,6 +12,23 @@ describe "Compare", :js do end describe "branches" do + shared_examples 'compares branches' do + it 'compares branches' do + visit project_compare_index_path(project, from: 'master', to: 'master') + + select_using_dropdown 'from', 'feature' + expect(find('.js-compare-from-dropdown .dropdown-toggle-text')).to have_content('feature') + + select_using_dropdown 'to', 'binary-encoding' + expect(find('.js-compare-to-dropdown .dropdown-toggle-text')).to have_content('binary-encoding') + + click_button 'Compare' + + expect(page).to have_content 'Commits' + expect(page).to have_link 'Create merge request' + end + end + it "pre-populates fields" do visit project_compare_index_path(project, from: "master", to: "master") @@ -19,19 +36,14 @@ describe "Compare", :js do expect(find(".js-compare-to-dropdown .dropdown-toggle-text")).to have_content("master") end - it "compares branches" do - visit project_compare_index_path(project, from: "master", to: "master") - - select_using_dropdown "from", "feature" - expect(find(".js-compare-from-dropdown .dropdown-toggle-text")).to have_content("feature") - - select_using_dropdown "to", "binary-encoding" - expect(find(".js-compare-to-dropdown .dropdown-toggle-text")).to have_content("binary-encoding") + it_behaves_like 'compares branches' - click_button "Compare" + context 'on a read-only instance' do + before do + allow(Gitlab::Database).to receive(:read_only?).and_return(true) + end - expect(page).to have_content "Commits" - expect(page).to have_link 'Create merge request' + it_behaves_like 'compares branches' end it 'renders additions info when click unfold diff' do diff --git a/spec/frontend/repository/components/__snapshots__/last_commit_spec.js.snap b/spec/frontend/repository/components/__snapshots__/last_commit_spec.js.snap index cd8372a8800..0e04487cb20 100644 --- a/spec/frontend/repository/components/__snapshots__/last_commit_spec.js.snap +++ b/spec/frontend/repository/components/__snapshots__/last_commit_spec.js.snap @@ -60,6 +60,111 @@ exports[`Repository last commit component renders commit widget 1`] = ` <div class="commit-actions flex-row" > + <!----> + + <gllink-stub + class="js-commit-pipeline" + data-original-title="Commit: failed" + href="https://test.com/pipeline" + title="" + > + <ciicon-stub + aria-label="Commit: failed" + cssclasses="" + size="24" + status="[object Object]" + /> + </gllink-stub> + + <div + class="commit-sha-group d-flex" + > + <div + class="label label-monospace monospace" + > + + 12345678 + + </div> + + <clipboardbutton-stub + cssclass="btn-default" + text="123456789" + title="Copy commit SHA to clipboard" + tooltipplacement="bottom" + /> + </div> + </div> + </div> +</div> +`; + +exports[`Repository last commit component renders the signature HTML as returned by the backend 1`] = ` +<div + class="info-well d-none d-sm-flex project-last-commit commit p-3" +> + <useravatarlink-stub + class="avatar-cell" + imgalt="" + imgcssclasses="" + imgsize="40" + imgsrc="https://test.com" + linkhref="https://test.com/test" + tooltipplacement="top" + tooltiptext="" + username="" + /> + + <div + class="commit-detail flex-list" + > + <div + class="commit-content qa-commit-content" + > + <gllink-stub + class="commit-row-message item-title" + href="https://test.com/commit/123" + > + + Commit title + + </gllink-stub> + + <!----> + + <div + class="committer" + > + <gllink-stub + class="commit-author-link js-user-link" + href="https://test.com/test" + > + + Test + + </gllink-stub> + + authored + + <timeagotooltip-stub + cssclass="" + time="2019-01-01" + tooltipplacement="bottom" + /> + </div> + + <!----> + </div> + + <div + class="commit-actions flex-row" + > + <div> + <button> + Verified + </button> + </div> + <gllink-stub class="js-commit-pipeline" data-original-title="Commit: failed" diff --git a/spec/frontend/repository/components/last_commit_spec.js b/spec/frontend/repository/components/last_commit_spec.js index 14479f3c3a4..01b56d453e6 100644 --- a/spec/frontend/repository/components/last_commit_spec.js +++ b/spec/frontend/repository/components/last_commit_spec.js @@ -107,4 +107,10 @@ describe('Repository last commit component', () => { expect(vm.find('.commit-row-description').isVisible()).toBe(true); expect(vm.find('.text-expander').classes('open')).toBe(true); }); + + it('renders the signature HTML as returned by the backend', () => { + factory(createCommitData({ signatureHtml: '<button>Verified</button>' })); + + expect(vm.element).toMatchSnapshot(); + }); }); diff --git a/spec/graphql/resolvers/last_commit_resolver_spec.rb b/spec/graphql/resolvers/last_commit_resolver_spec.rb new file mode 100644 index 00000000000..15b09b77a10 --- /dev/null +++ b/spec/graphql/resolvers/last_commit_resolver_spec.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Resolvers::LastCommitResolver do + include GraphqlHelpers + + let(:repository) { create(:project, :repository).repository } + let(:tree) { repository.tree(ref, path) } + + let(:commit) { resolve(described_class, obj: tree) } + + describe '#resolve' do + context 'last commit is a merge commit' do + let(:ref) { 'master' } + let(:path) { '/' } + + it 'resolves to the merge commit' do + expect(commit).to eq(repository.commits(ref, limit: 1).last) + end + end + + context 'last commit for a different branch and path' do + let(:ref) { 'fix' } + let(:path) { 'files' } + + it 'resolves commit' do + expect(commit).to eq(repository.commits(ref, path: path, limit: 1).last) + end + end + + context 'last commit does not exist' do + let(:ref) { 'master' } + let(:path) { 'does-not-exist' } + + it 'returns nil' do + expect(commit).to be_nil + end + end + end +end diff --git a/spec/graphql/types/commit_type_spec.rb b/spec/graphql/types/commit_type_spec.rb index 5d8edcf254c..1ff1c97f8db 100644 --- a/spec/graphql/types/commit_type_spec.rb +++ b/spec/graphql/types/commit_type_spec.rb @@ -7,5 +7,10 @@ describe GitlabSchema.types['Commit'] do it { expect(described_class).to require_graphql_authorizations(:download_code) } - it { expect(described_class).to have_graphql_fields(:id, :sha, :title, :description, :message, :authored_date, :author, :web_url, :latest_pipeline) } + it 'contains attributes related to commit' do + expect(described_class).to have_graphql_fields( + :id, :sha, :title, :description, :message, :authored_date, + :author, :web_url, :latest_pipeline, :signature_html + ) + end end diff --git a/spec/lib/banzai/filter/video_link_filter_spec.rb b/spec/lib/banzai/filter/video_link_filter_spec.rb index b5be204d680..332817d6585 100644 --- a/spec/lib/banzai/filter/video_link_filter_spec.rb +++ b/spec/lib/banzai/filter/video_link_filter_spec.rb @@ -12,52 +12,98 @@ describe Banzai::Filter::VideoLinkFilter do end def link_to_image(path) - %(<img src="#{path}" />) + return '<img/>' if path.nil? + + %(<img src="#{path}"/>) end let(:project) { create(:project, :repository) } - context 'when the element src has a video extension' do - UploaderHelper::SAFE_VIDEO_EXT.each do |ext| - it "replaces the image tag 'path/video.#{ext}' with a video tag" do - container = filter(link_to_image("/path/video.#{ext}")).children.first + shared_examples 'a video element' do + let(:image) { link_to_image(src) } - expect(container.name).to eq 'div' - expect(container['class']).to eq 'video-container' + it 'replaces the image tag with a video tag' do + container = filter(image).children.first - video, paragraph = container.children + expect(container.name).to eq 'div' + expect(container['class']).to eq 'video-container' - expect(video.name).to eq 'video' - expect(video['src']).to eq "/path/video.#{ext}" + video, paragraph = container.children - expect(paragraph.name).to eq 'p' + expect(video.name).to eq 'video' + expect(video['src']).to eq src - link = paragraph.children.first + expect(paragraph.name).to eq 'p' - expect(link.name).to eq 'a' - expect(link['href']).to eq "/path/video.#{ext}" - expect(link['target']).to eq '_blank' - end + link = paragraph.children.first + + expect(link.name).to eq 'a' + expect(link['href']).to eq src + expect(link['target']).to eq '_blank' end end - context 'when the element src is an image' do + shared_examples 'an unchanged element' do |ext| it 'leaves the document unchanged' do - element = filter(link_to_image('/path/my_image.jpg')).children.first + element = filter(link_to_image(src)).children.first expect(element.name).to eq 'img' - expect(element['src']).to eq '/path/my_image.jpg' + expect(element['src']).to eq src end end - context 'when asset proxy is enabled' do - it 'uses the correct src' do - stub_asset_proxy_setting(enabled: true) + context 'when the element src has a video extension' do + Gitlab::FileTypeDetection::SAFE_VIDEO_EXT.each do |ext| + it_behaves_like 'a video element' do + let(:src) { "/path/video.#{ext}" } + end + + it_behaves_like 'a video element' do + let(:src) { "/path/video.#{ext.upcase}" } + end + end + end + + context 'when the element has no src attribute' do + let(:src) { nil } + + it_behaves_like 'an unchanged element' + end + + context 'when the element src is an image' do + let(:src) { '/path/my_image.jpg' } + + it_behaves_like 'an unchanged element' + end + + context 'when the element src has an invalid file extension' do + let(:src) { '/path/my_video.somemp4' } + + it_behaves_like 'an unchanged element' + end + + context 'when data-canonical-src is empty' do + let(:image) { %(<img src="#{src}" data-canonical-src=""/>) } + context 'and src is a video' do + let(:src) { '/path/video.mp4' } + + it_behaves_like 'a video element' + end + + context 'and src is an image' do + let(:src) { '/path/my_image.jpg' } + + it_behaves_like 'an unchanged element' + end + end + + context 'when data-canonical-src is set' do + it 'uses the correct src' do proxy_src = 'https://assets.example.com/6d8b63' canonical_src = 'http://example.com/test.mp4' - image = %(<img src="#{proxy_src}" data-canonical-src="#{canonical_src}" />) - container = filter(image, asset_proxy_enabled: true).children.first + image = %(<img src="#{proxy_src}" data-canonical-src="#{canonical_src}"/>) + container = filter(image).children.first expect(container['class']).to eq 'video-container' diff --git a/spec/presenters/commit_presenter_spec.rb b/spec/presenters/commit_presenter_spec.rb index 58179e9a337..bc749acfa3a 100644 --- a/spec/presenters/commit_presenter_spec.rb +++ b/spec/presenters/commit_presenter_spec.rb @@ -55,4 +55,17 @@ describe CommitPresenter do end end end + + describe '#signature_html' do + let(:signature) { 'signature' } + + before do + expect(commit).to receive(:has_signature?).and_return(true) + allow(ApplicationController.renderer).to receive(:render).and_return(signature) + end + + it 'renders html for displaying signature' do + expect(presenter.signature_html).to eq(signature) + end + end end diff --git a/spec/rubocop/cop/line_break_around_conditional_block_spec.rb b/spec/rubocop/cop/line_break_around_conditional_block_spec.rb index 892b393c307..cc933ce12c8 100644 --- a/spec/rubocop/cop/line_break_around_conditional_block_spec.rb +++ b/spec/rubocop/cop/line_break_around_conditional_block_spec.rb @@ -132,6 +132,19 @@ describe RuboCop::Cop::LineBreakAroundConditionalBlock do expect(cop.offenses).to be_empty end + it "doesn't flag violation for #{conditional} preceded by a block definition with a comment" do + source = <<~RUBY + on_block(param_a) do |item| # a short comment + #{conditional} condition + do_something + end + end + RUBY + inspect_source(source) + + expect(cop.offenses).to be_empty + end + it "doesn't flag violation for #{conditional} preceded by a block definition using brackets" do source = <<~RUBY on_block(param_a) { |item| |