diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-14 00:08:55 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-14 00:08:55 +0300 |
commit | a5650b86b5a809d3b7c754afd5ff5671e9bcc584 (patch) | |
tree | 6a53414f01dae4b5716a94c8d33136616c8b3eb1 /spec/helpers | |
parent | e689e858ede41a34b1e9132eba6a602632e6885e (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/markup_helper_spec.rb | 39 | ||||
-rw-r--r-- | spec/helpers/projects_helper_spec.rb | 42 |
2 files changed, 37 insertions, 44 deletions
diff --git a/spec/helpers/markup_helper_spec.rb b/spec/helpers/markup_helper_spec.rb index 33347f20de8..b2df543d651 100644 --- a/spec/helpers/markup_helper_spec.rb +++ b/spec/helpers/markup_helper_spec.rb @@ -95,12 +95,13 @@ describe MarkupHelper do context 'when text contains a relative link to an image in the repository' do let(:image_file) { "logo-white.png" } let(:text_with_relative_path) { "![](./#{image_file})\n" } - let(:generated_html) { helper.markdown(text_with_relative_path, requested_path: requested_path) } + let(:generated_html) { helper.markdown(text_with_relative_path, requested_path: requested_path, ref: ref) } subject { Nokogiri::HTML.parse(generated_html) } - context 'when requested_path is provided in the context' do + context 'when requested_path is provided, but ref isn\'t' do let(:requested_path) { 'files/images/README.md' } + let(:ref) { nil } it 'returns the correct HTML for the image' do expanded_path = "/#{project.full_path}/-/raw/master/files/images/#{image_file}" @@ -110,13 +111,43 @@ describe MarkupHelper do end end - context 'when requested_path parameter is not provided' do + context 'when requested_path and ref parameters are both provided' do + let(:requested_path) { 'files/images/README.md' } + let(:ref) { 'other_branch' } + + it 'returns the correct HTML for the image' do + project.repository.create_branch('other_branch') + + expanded_path = "/#{project.full_path}/-/raw/#{ref}/files/images/#{image_file}" + + expect(subject.css('a')[0].attr('href')).to eq(expanded_path) + expect(subject.css('img')[0].attr('data-src')).to eq(expanded_path) + end + end + + context 'when ref is provided, but requested_path isn\'t' do + let(:ref) { 'other_branch' } + let(:requested_path) { nil } + + it 'returns the correct HTML for the image' do + project.repository.create_branch('other_branch') + + expanded_path = "/#{project.full_path}/-/blob/#{ref}/./#{image_file}" + + expect(subject.css('a')[0].attr('href')).to eq(expanded_path) + expect(subject.css('img')[0].attr('data-src')).to eq(expanded_path) + end + end + + context 'when neither requested_path, nor ref parameter is provided' do + let(:ref) { nil } let(:requested_path) { nil } - it 'returns the link to the image path as a relative path' do + it 'returns the correct HTML for the image' do expanded_path = "/#{project.full_path}/-/blob/master/./#{image_file}" expect(subject.css('a')[0].attr('href')).to eq(expanded_path) + expect(subject.css('img')[0].attr('data-src')).to eq(expanded_path) end end end diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index 17e3f8f9c06..189ab1a8354 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -719,11 +719,7 @@ describe ProjectsHelper do end describe '#show_merge_request_count' do - context 'when the feature flag is enabled' do - before do - stub_feature_flags(project_list_show_mr_count: true) - end - + context 'enabled flag' do it 'returns true if compact mode is disabled' do expect(helper.show_merge_request_count?).to be_truthy end @@ -733,22 +729,7 @@ describe ProjectsHelper do end end - context 'when the feature flag is disabled' do - before do - stub_feature_flags(project_list_show_mr_count: false) - end - - it 'always returns false' do - expect(helper.show_merge_request_count?(disabled: false)).to be_falsy - expect(helper.show_merge_request_count?(disabled: true)).to be_falsy - end - end - context 'disabled flag' do - before do - stub_feature_flags(project_list_show_mr_count: true) - end - it 'returns false if disabled flag is true' do expect(helper.show_merge_request_count?(disabled: true)).to be_falsey end @@ -760,11 +741,7 @@ describe ProjectsHelper do end describe '#show_issue_count?' do - context 'when the feature flag is enabled' do - before do - stub_feature_flags(project_list_show_issue_count: true) - end - + context 'enabled flag' do it 'returns true if compact mode is disabled' do expect(helper.show_issue_count?).to be_truthy end @@ -774,22 +751,7 @@ describe ProjectsHelper do end end - context 'when the feature flag is disabled' do - before do - stub_feature_flags(project_list_show_issue_count: false) - end - - it 'always returns false' do - expect(helper.show_issue_count?(disabled: false)).to be_falsy - expect(helper.show_issue_count?(disabled: true)).to be_falsy - end - end - context 'disabled flag' do - before do - stub_feature_flags(project_list_show_issue_count: true) - end - it 'returns false if disabled flag is true' do expect(helper.show_issue_count?(disabled: true)).to be_falsey end |