diff options
Diffstat (limited to 'spec/helpers')
-rw-r--r-- | spec/helpers/application_helper_spec.rb | 37 | ||||
-rw-r--r-- | spec/helpers/blob_helper_spec.rb | 82 | ||||
-rw-r--r-- | spec/helpers/ci_status_helper_spec.rb | 10 | ||||
-rw-r--r-- | spec/helpers/diff_helper_spec.rb | 110 | ||||
-rw-r--r-- | spec/helpers/emails_helper_spec.rb | 12 | ||||
-rw-r--r-- | spec/helpers/events_helper_spec.rb | 16 | ||||
-rw-r--r-- | spec/helpers/gitlab_markdown_helper_spec.rb | 20 | ||||
-rw-r--r-- | spec/helpers/graph_helper_spec.rb | 2 | ||||
-rw-r--r-- | spec/helpers/groups_helper_spec.rb | 4 | ||||
-rw-r--r-- | spec/helpers/issuables_helper_spec.rb | 16 | ||||
-rw-r--r-- | spec/helpers/issues_helper_spec.rb | 117 | ||||
-rw-r--r-- | spec/helpers/members_helper_spec.rb | 48 | ||||
-rw-r--r-- | spec/helpers/notes_helper_spec.rb | 60 | ||||
-rw-r--r-- | spec/helpers/page_layout_helper_spec.rb | 9 | ||||
-rw-r--r-- | spec/helpers/projects_helper_spec.rb | 38 | ||||
-rw-r--r-- | spec/helpers/search_helper_spec.rb | 2 | ||||
-rw-r--r-- | spec/helpers/submodule_helper_spec.rb | 28 | ||||
-rw-r--r-- | spec/helpers/time_helper_spec.rb | 26 | ||||
-rw-r--r-- | spec/helpers/tree_helper_spec.rb | 4 |
19 files changed, 341 insertions, 300 deletions
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index bb28866f010..73f5470cf35 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -54,7 +54,7 @@ describe ApplicationHelper do describe 'project_icon' do let(:avatar_file_path) { File.join(Rails.root, 'spec', 'fixtures', 'banana_sample.gif') } - it 'should return an url for the avatar' do + it 'returns an url for the avatar' do project = create(:project, avatar: File.open(avatar_file_path)) avatar_url = "http://localhost/uploads/project/avatar/#{project.id}/banana_sample.gif" @@ -62,7 +62,7 @@ describe ApplicationHelper do to eq "<img src=\"#{avatar_url}\" alt=\"Banana sample\" />" end - it 'should give uploaded icon when present' do + it 'gives uploaded icon when present' do project = create(:project) allow_any_instance_of(Project).to receive(:avatar_in_git).and_return(true) @@ -76,14 +76,14 @@ describe ApplicationHelper do describe 'avatar_icon' do let(:avatar_file_path) { File.join(Rails.root, 'spec', 'fixtures', 'banana_sample.gif') } - it 'should return an url for the avatar' do + it 'returns an url for the avatar' do user = create(:user, avatar: File.open(avatar_file_path)) expect(helper.avatar_icon(user.email).to_s). to match("/uploads/user/avatar/#{user.id}/banana_sample.gif") end - it 'should return an url for the avatar with relative url' do + it 'returns an url for the avatar with relative url' do stub_config_setting(relative_url_root: '/gitlab') # Must be stubbed after the stub above, and separately stub_config_setting(url: Settings.send(:build_gitlab_url)) @@ -94,14 +94,14 @@ describe ApplicationHelper do to match("/gitlab/uploads/user/avatar/#{user.id}/banana_sample.gif") end - it 'should call gravatar_icon when no User exists with the given email' do + it 'calls gravatar_icon when no User exists with the given email' do expect(helper).to receive(:gravatar_icon).with('foo@example.com', 20, 2) helper.avatar_icon('foo@example.com', 20, 2) end describe 'using a User' do - it 'should return an URL for the avatar' do + it 'returns an URL for the avatar' do user = create(:user, avatar: File.open(avatar_file_path)) expect(helper.avatar_icon(user).to_s). @@ -146,7 +146,7 @@ describe ApplicationHelper do to match('https://secure.gravatar.com') end - it 'should return custom gravatar path when gravatar_url is set' do + it 'returns custom gravatar path when gravatar_url is set' do stub_gravatar_setting(plain_url: 'http://example.local/?s=%{size}&hash=%{hash}') expect(gravatar_icon(user_email, 20)). @@ -218,12 +218,12 @@ describe ApplicationHelper do end it 'includes a default js-timeago class' do - expect(element.attr('class')).to eq 'time_ago js-timeago js-timeago-pending' + expect(element.attr('class')).to eq 'js-timeago js-timeago-pending' end it 'accepts a custom html_class' do expect(element(html_class: 'custom_class').attr('class')). - to eq 'custom_class js-timeago js-timeago-pending' + to eq 'js-timeago custom_class js-timeago-pending' end it 'accepts a custom tooltip placement' do @@ -244,6 +244,19 @@ describe ApplicationHelper do it 'converts to Time' do expect { helper.time_ago_with_tooltip(Date.today) }.not_to raise_error end + + it 'add class for the short format and includes inline script' do + timeago_element = element(short_format: 'short') + expect(timeago_element.attr('class')).to eq 'js-short-timeago js-timeago-pending' + script_element = timeago_element.next_element + expect(script_element.name).to eq 'script' + end + + it 'add class for the short format and does not include inline script' do + timeago_element = element(short_format: 'short', skip_js: true) + expect(timeago_element.attr('class')).to eq 'js-short-timeago' + expect(timeago_element.next_element).to eq nil + end end describe 'render_markup' do @@ -253,19 +266,19 @@ describe ApplicationHelper do allow(helper).to receive(:current_user).and_return(user) end - it 'should preserve encoding' do + it 'preserves encoding' do expect(content.encoding.name).to eq('UTF-8') expect(helper.render_markup('foo.rst', content).encoding.name).to eq('UTF-8') end - it "should delegate to #markdown when file name corresponds to Markdown" do + it "delegates to #markdown when file name corresponds to Markdown" do expect(helper).to receive(:gitlab_markdown?).with('foo.md').and_return(true) expect(helper).to receive(:markdown).and_return('NOEL') expect(helper.render_markup('foo.md', content)).to eq('NOEL') end - it "should delegate to #asciidoc when file name corresponds to AsciiDoc" do + it "delegates to #asciidoc when file name corresponds to AsciiDoc" do expect(helper).to receive(:asciidoc?).with('foo.adoc').and_return(true) expect(helper).to receive(:asciidoc).and_return('NOEL') diff --git a/spec/helpers/blob_helper_spec.rb b/spec/helpers/blob_helper_spec.rb index 6d1c02db297..a43a7238c70 100644 --- a/spec/helpers/blob_helper_spec.rb +++ b/spec/helpers/blob_helper_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' describe BlobHelper do + include TreeHelper + let(:blob_name) { 'test.lisp' } let(:no_context_content) { ":type \"assem\"))" } let(:blob_content) { "(make-pathname :defaults name\n#{no_context_content}" } @@ -15,20 +17,20 @@ describe BlobHelper do end describe '#highlight' do - it 'should return plaintext for unknown lexer context' do - result = helper.highlight(blob_name, no_context_content, nowrap: true) - expect(result).to eq('<span id="LC1" class="line">:type "assem"))</span>') + it 'returns plaintext for unknown lexer context' do + result = helper.highlight(blob_name, no_context_content) + expect(result).to eq(%[<pre class="code highlight"><code><span id="LC1" class="line">:type "assem"))</span></code></pre>]) end - it 'should highlight single block' do - expected = %Q[<span id="LC1" class="line"><span class="p">(</span><span class="nb">make-pathname</span> <span class="ss">:defaults</span> <span class="nv">name</span></span> -<span id="LC2" class="line"><span class="ss">:type</span> <span class="s">"assem"</span><span class="p">))</span></span>] + it 'highlights single block' do + expected = %Q[<pre class="code highlight"><code><span id="LC1" class="line"><span class="p">(</span><span class="nb">make-pathname</span> <span class="ss">:defaults</span> <span class="nv">name</span></span> +<span id="LC2" class="line"><span class="ss">:type</span> <span class="s">"assem"</span><span class="p">))</span></span></code></pre>] - expect(helper.highlight(blob_name, blob_content, nowrap: true)).to eq(expected) + expect(helper.highlight(blob_name, blob_content)).to eq(expected) end - it 'should highlight multi-line comments' do - result = helper.highlight(blob_name, multiline_content, nowrap: true) + it 'highlights multi-line comments' do + result = helper.highlight(blob_name, multiline_content) html = Nokogiri::HTML(result) lines = html.search('.s') expect(lines.count).to eq(3) @@ -41,42 +43,66 @@ describe BlobHelper do let(:blob_name) { 'test.diff' } let(:blob_content) { "+aaa\n+bbb\n- ccc\n ddd\n"} let(:expected) do - %q(<span id="LC1" class="line"><span class="gi">+aaa</span></span> + %q(<pre class="code highlight"><code><span id="LC1" class="line"><span class="gi">+aaa</span></span> <span id="LC2" class="line"><span class="gi">+bbb</span></span> <span id="LC3" class="line"><span class="gd">- ccc</span></span> -<span id="LC4" class="line"> ddd</span>) +<span id="LC4" class="line"> ddd</span></code></pre>) end - it 'should highlight each line properly' do - result = helper.highlight(blob_name, blob_content, nowrap: true) + it 'highlights each line properly' do + result = helper.highlight(blob_name, blob_content) expect(result).to eq(expected) end end end - describe "#highlighter" do - it 'should highlight continued blocks' do - # Both lines have LC1 as ID since formatter doesn't support continue at the moment - expected = [ - '<span id="LC1" class="line"><span class="p">(</span><span class="nb">make-pathname</span> <span class="ss">:defaults</span> <span class="nv">name</span></span>', - '<span id="LC1" class="line"><span class="ss">:type</span> <span class="s">"assem"</span><span class="p">))</span></span>' - ] - - highlighter = helper.highlighter(blob_name, blob_content, nowrap: true) - result = split_content.map{ |content| highlighter.highlight(content) } - expect(result).to eq(expected) - end - end - describe "#sanitize_svg" do let(:input_svg_path) { File.join(Rails.root, 'spec', 'fixtures', 'unsanitized.svg') } let(:data) { open(input_svg_path).read } let(:expected_svg_path) { File.join(Rails.root, 'spec', 'fixtures', 'sanitized.svg') } let(:expected) { open(expected_svg_path).read } - it 'should retain essential elements' do + it 'retains essential elements' do blob = OpenStruct.new(data: data) expect(sanitize_svg(blob).data).to eq(expected) end end + + describe "#edit_blob_link" do + let(:namespace) { create(:namespace, name: 'gitlab' )} + let(:project) { create(:project, namespace: namespace) } + + before do + allow(self).to receive(:current_user).and_return(double) + allow(self).to receive(:can_collaborate_with_project?).and_return(true) + end + + it 'verifies blob is text' do + expect(helper).not_to receive(:blob_text_viewable?) + + button = edit_blob_link(project, 'refs/heads/master', 'README.md') + + expect(button).to start_with('<button') + end + + it 'uses the passed blob instead retrieve from repository' do + blob = project.repository.blob_at('refs/heads/master', 'README.md') + + expect(project.repository).not_to receive(:blob_at) + + edit_blob_link(project, 'refs/heads/master', 'README.md', blob: blob) + end + + it 'returns a link with the proper route' do + link = edit_blob_link(project, 'master', 'README.md') + + expect(Capybara.string(link).find_link('Edit')[:href]).to eq('/gitlab/gitlabhq/edit/master/README.md') + end + + it 'returns a link with the passed link_opts on the expected route' do + link = edit_blob_link(project, 'master', 'README.md', link_opts: { mr_id: 10 }) + + expect(Capybara.string(link).find_link('Edit')[:href]).to eq('/gitlab/gitlabhq/edit/master/README.md?mr_id=10') + end + end end diff --git a/spec/helpers/ci_status_helper_spec.rb b/spec/helpers/ci_status_helper_spec.rb index 45199d0f09d..637b02d9388 100644 --- a/spec/helpers/ci_status_helper_spec.rb +++ b/spec/helpers/ci_status_helper_spec.rb @@ -7,7 +7,13 @@ describe CiStatusHelper do let(:failed_commit) { double("Ci::Pipeline", status: 'failed') } describe 'ci_icon_for_status' do - it { expect(helper.ci_icon_for_status(success_commit.status)).to include('fa-check') } - it { expect(helper.ci_icon_for_status(failed_commit.status)).to include('fa-close') } + it 'renders to correct svg on success' do + expect(helper).to receive(:render).with('shared/icons/icon_status_success.svg', anything) + helper.ci_icon_for_status(success_commit.status) + end + it 'renders the correct svg on failure' do + expect(helper).to receive(:render).with('shared/icons/icon_status_failed.svg', anything) + helper.ci_icon_for_status(failed_commit.status) + end end end diff --git a/spec/helpers/diff_helper_spec.rb b/spec/helpers/diff_helper_spec.rb index e2db33d8345..9c7c79f57c6 100644 --- a/spec/helpers/diff_helper_spec.rb +++ b/spec/helpers/diff_helper_spec.rb @@ -6,7 +6,7 @@ describe DiffHelper do let(:project) { create(:project) } let(:repository) { project.repository } let(:commit) { project.commit(sample_commit.id) } - let(:diffs) { commit.diffs } + let(:diffs) { commit.raw_diffs } let(:diff) { diffs.first } let(:diff_refs) { [commit.parent, commit] } let(:diff_file) { Gitlab::Diff::File.new(diff, diff_refs: diff_refs, repository: repository) } @@ -15,70 +15,56 @@ describe DiffHelper do it 'returns a valid value when cookie is set' do helper.request.cookies[:diff_view] = 'parallel' - expect(helper.diff_view).to eq 'parallel' + expect(helper.diff_view).to eq :parallel end it 'returns a default value when cookie is invalid' do helper.request.cookies[:diff_view] = 'invalid' - expect(helper.diff_view).to eq 'inline' + expect(helper.diff_view).to eq :inline end it 'returns a default value when cookie is nil' do expect(helper.request.cookies).to be_empty - expect(helper.diff_view).to eq 'inline' - end - end - - describe 'diff_hard_limit_enabled?' do - it 'should return true if param is provided' do - allow(controller).to receive(:params) { { force_show_diff: true } } - expect(diff_hard_limit_enabled?).to be_truthy - end - - it 'should return false if param is not provided' do - expect(diff_hard_limit_enabled?).to be_falsey + expect(helper.diff_view).to eq :inline end end describe 'diff_options' do - it 'should return hard limit for a diff if force diff is true' do - allow(controller).to receive(:params) { { force_show_diff: true } } - expect(diff_options).to include(Commit.max_diff_options) + it 'returns no collapse false' do + expect(diff_options).to include(no_collapse: false) end - it 'should return safe limit for a diff if force diff is false' do - expect(diff_options).not_to include(:max_lines, :max_files) + it 'returns no collapse true if expand_all_diffs' do + allow(controller).to receive(:params) { { expand_all_diffs: true } } + expect(diff_options).to include(no_collapse: true) end - end - describe 'unfold_bottom_class' do - it 'should return empty string when bottom line shouldnt be unfolded' do - expect(unfold_bottom_class(false)).to eq('') + it 'returns no collapse true if action name diff_for_path' do + allow(controller).to receive(:action_name) { 'diff_for_path' } + expect(diff_options).to include(no_collapse: true) end - it 'should return js class when bottom lines should be unfolded' do - expect(unfold_bottom_class(true)).to eq('js-unfold-bottom') + it 'returns paths if action name diff_for_path and param old path' do + allow(controller).to receive(:params) { { old_path: 'lib/wadus.rb' } } + allow(controller).to receive(:action_name) { 'diff_for_path' } + expect(diff_options[:paths]).to include('lib/wadus.rb') end - end - describe 'unfold_class' do - it 'returns empty on false' do - expect(unfold_class(false)).to eq('') - end - - it 'returns a class on true' do - expect(unfold_class(true)).to eq('unfold js-unfold') + it 'returns paths if action name diff_for_path and param new path' do + allow(controller).to receive(:params) { { new_path: 'lib/wadus.rb' } } + allow(controller).to receive(:action_name) { 'diff_for_path' } + expect(diff_options[:paths]).to include('lib/wadus.rb') end end describe '#diff_line_content' do - it 'should return non breaking space when line is empty' do + it 'returns non breaking space when line is empty' do expect(diff_line_content(nil)).to eq(' ') end - it 'should return the line itself' do + it 'returns the line itself' do expect(diff_line_content(diff_file.diff_lines.first.text)). to eq('@@ -6,12 +6,18 @@ module Popen') expect(diff_line_content(diff_file.diff_lines.first.type)).to eq('match') @@ -99,4 +85,56 @@ describe DiffHelper do expect(marked_new_line).to be_html_safe end end + + describe "#diff_match_line" do + let(:old_pos) { 40 } + let(:new_pos) { 50 } + let(:text) { 'some_text' } + + it "should generate foldable top match line for inline view with empty text by default" do + output = diff_match_line old_pos, new_pos + + expect(output).to be_html_safe + expect(output).to have_css "td:nth-child(1):not(.js-unfold-bottom).diff-line-num.unfold.js-unfold.old_line[data-linenumber='#{old_pos}']", text: '...' + expect(output).to have_css "td:nth-child(2):not(.js-unfold-bottom).diff-line-num.unfold.js-unfold.new_line[data-linenumber='#{new_pos}']", text: '...' + expect(output).to have_css 'td:nth-child(3):not(.parallel).line_content.match', text: '' + end + + it "should allow to define text and bottom option" do + output = diff_match_line old_pos, new_pos, text: text, bottom: true + + expect(output).to be_html_safe + expect(output).to have_css "td:nth-child(1).diff-line-num.unfold.js-unfold.js-unfold-bottom.old_line[data-linenumber='#{old_pos}']", text: '...' + expect(output).to have_css "td:nth-child(2).diff-line-num.unfold.js-unfold.js-unfold-bottom.new_line[data-linenumber='#{new_pos}']", text: '...' + expect(output).to have_css 'td:nth-child(3):not(.parallel).line_content.match', text: text + end + + it "should generate match line for parallel view" do + output = diff_match_line old_pos, new_pos, text: text, view: :parallel + + expect(output).to be_html_safe + expect(output).to have_css "td:nth-child(1):not(.js-unfold-bottom).diff-line-num.unfold.js-unfold.old_line[data-linenumber='#{old_pos}']", text: '...' + expect(output).to have_css 'td:nth-child(2).line_content.match.parallel', text: text + expect(output).to have_css "td:nth-child(3):not(.js-unfold-bottom).diff-line-num.unfold.js-unfold.new_line[data-linenumber='#{new_pos}']", text: '...' + expect(output).to have_css 'td:nth-child(4).line_content.match.parallel', text: text + end + + it "should allow to generate only left match line for parallel view" do + output = diff_match_line old_pos, nil, text: text, view: :parallel + + expect(output).to be_html_safe + expect(output).to have_css "td:nth-child(1):not(.js-unfold-bottom).diff-line-num.unfold.js-unfold.old_line[data-linenumber='#{old_pos}']", text: '...' + expect(output).to have_css 'td:nth-child(2).line_content.match.parallel', text: text + expect(output).not_to have_css 'td:nth-child(3)' + end + + it "should allow to generate only right match line for parallel view" do + output = diff_match_line nil, new_pos, text: text, view: :parallel + + expect(output).to be_html_safe + expect(output).to have_css "td:nth-child(1):not(.js-unfold-bottom).diff-line-num.unfold.js-unfold.new_line[data-linenumber='#{new_pos}']", text: '...' + expect(output).to have_css 'td:nth-child(2).line_content.match.parallel', text: text + expect(output).not_to have_css 'td:nth-child(3)' + end + end end diff --git a/spec/helpers/emails_helper_spec.rb b/spec/helpers/emails_helper_spec.rb index 7a3e38d7e63..3223556e1d3 100644 --- a/spec/helpers/emails_helper_spec.rb +++ b/spec/helpers/emails_helper_spec.rb @@ -8,37 +8,37 @@ describe EmailsHelper do end context 'when time limit is less than 2 hours' do - it 'should display the time in hours using a singular unit' do + it 'displays the time in hours using a singular unit' do validate_time_string(1.hour, '1 hour') end end context 'when time limit is 2 or more hours' do - it 'should display the time in hours using a plural unit' do + it 'displays the time in hours using a plural unit' do validate_time_string(2.hours, '2 hours') end end context 'when time limit contains fractions of an hour' do - it 'should round down to the nearest hour' do + it 'rounds down to the nearest hour' do validate_time_string(96.minutes, '1 hour') end end context 'when time limit is 24 or more hours' do - it 'should display the time in days using a singular unit' do + it 'displays the time in days using a singular unit' do validate_time_string(24.hours, '1 day') end end context 'when time limit is 2 or more days' do - it 'should display the time in days using a plural unit' do + it 'displays the time in days using a plural unit' do validate_time_string(2.days, '2 days') end end context 'when time limit contains fractions of a day' do - it 'should round down to the nearest day' do + it 'rounds down to the nearest day' do validate_time_string(57.hours, '2 days') end end diff --git a/spec/helpers/events_helper_spec.rb b/spec/helpers/events_helper_spec.rb index c0d2be98e85..022aba0c0d0 100644 --- a/spec/helpers/events_helper_spec.rb +++ b/spec/helpers/events_helper_spec.rb @@ -6,34 +6,34 @@ describe EventsHelper do allow(helper).to receive(:current_user).and_return(double) end - it 'should display one line of plain text without alteration' do + it 'displays one line of plain text without alteration' do input = 'A short, plain note' expect(helper.event_note(input)).to match(input) expect(helper.event_note(input)).not_to match(/\.\.\.\z/) end - it 'should display inline code' do + it 'displays inline code' do input = 'A note with `inline code`' expected = 'A note with <code>inline code</code>' expect(helper.event_note(input)).to match(expected) end - it 'should truncate a note with multiple paragraphs' do + it 'truncates a note with multiple paragraphs' do input = "Paragraph 1\n\nParagraph 2" expected = 'Paragraph 1...' expect(helper.event_note(input)).to match(expected) end - it 'should display the first line of a code block' do + it 'displays the first line of a code block' do input = "```\nCode block\nwith two lines\n```" expected = %r{<pre.+><code>Code block\.\.\.</code></pre>} expect(helper.event_note(input)).to match(expected) end - it 'should truncate a single long line of text' do + it 'truncates a single long line of text' do text = 'The quick brown fox jumped over the lazy dog twice' # 50 chars input = text * 4 expected = (text * 2).sub(/.{3}/, '...') @@ -41,7 +41,7 @@ describe EventsHelper do expect(helper.event_note(input)).to match(expected) end - it 'should preserve a link href when link text is truncated' do + it 'preserves a link href when link text is truncated' do text = 'The quick brown fox jumped over the lazy dog' # 44 chars input = "#{text}#{text}#{text} " # 133 chars link_url = 'http://example.com/foo/bar/baz' # 30 chars @@ -52,12 +52,12 @@ describe EventsHelper do expect(helper.event_note(input)).to match(expected_link_text) end - it 'should preserve code color scheme' do + it 'preserves code color scheme' do input = "```ruby\ndef test\n 'hello world'\nend\n```" expected = '<pre class="code highlight js-syntax-highlight ruby">' \ "<code><span class=\"k\">def</span> <span class=\"nf\">test</span>\n" \ " <span class=\"s1\">\'hello world\'</span>\n" \ - "<span class=\"k\">end</span>" \ + "<span class=\"k\">end</span>\n" \ '</code></pre>' expect(helper.event_note(input)).to eq(expected) end diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb index ade5c3b02d9..5368e5fab06 100644 --- a/spec/helpers/gitlab_markdown_helper_spec.rb +++ b/spec/helpers/gitlab_markdown_helper_spec.rb @@ -26,17 +26,17 @@ describe GitlabMarkdownHelper do describe "referencing multiple objects" do let(:actual) { "#{merge_request.to_reference} -> #{commit.to_reference} -> #{issue.to_reference}" } - it "should link to the merge request" do + it "links to the merge request" do expected = namespace_project_merge_request_path(project.namespace, project, merge_request) expect(helper.markdown(actual)).to match(expected) end - it "should link to the commit" do + it "links to the commit" do expected = namespace_project_commit_path(project.namespace, project, commit) expect(helper.markdown(actual)).to match(expected) end - it "should link to the issue" do + it "links to the issue" do expected = namespace_project_issue_path(project.namespace, project, issue) expect(helper.markdown(actual)).to match(expected) end @@ -47,7 +47,7 @@ describe GitlabMarkdownHelper do let(:second_project) { create(:project, :public) } let(:second_issue) { create(:issue, project: second_project) } - it 'should link to the issue' do + it 'links to the issue' do expected = namespace_project_issue_path(second_project.namespace, second_project, second_issue) expect(markdown(actual, project: second_project)).to match(expected) end @@ -58,7 +58,7 @@ describe GitlabMarkdownHelper do let(:commit_path) { namespace_project_commit_path(project.namespace, project, commit) } let(:issues) { create_list(:issue, 2, project: project) } - it 'should handle references nested in links with all the text' do + it 'handles references nested in links with all the text' do actual = helper.link_to_gfm("This should finally fix #{issues[0].to_reference} and #{issues[1].to_reference} for real", commit_path) doc = Nokogiri::HTML.parse(actual) @@ -88,7 +88,7 @@ describe GitlabMarkdownHelper do expect(doc.css('a')[4].text).to eq ' for real' end - it 'should forward HTML options' do + it 'forwards HTML options' do actual = helper.link_to_gfm("Fixed in #{commit.id}", commit_path, class: 'foo') doc = Nokogiri::HTML.parse(actual) @@ -110,7 +110,7 @@ describe GitlabMarkdownHelper do expect(act).to eq %Q(<a href="/foo">#{issues[0].to_reference}</a>) end - it 'should replace commit message with emoji to link' do + it 'replaces commit message with emoji to link' do actual = link_to_gfm(':book:Book', '/foo') expect(actual). to eq %Q(<img class="emoji" title=":book:" alt=":book:" src="http://localhost/assets/1F4D6.png" height="20" width="20" align="absmiddle"><a href="/foo">Book</a>) @@ -125,7 +125,7 @@ describe GitlabMarkdownHelper do helper.instance_variable_set(:@project_wiki, @wiki) end - it "should use Wiki pipeline for markdown files" do + it "uses Wiki pipeline for markdown files" do allow(@wiki).to receive(:format).and_return(:markdown) expect(helper).to receive(:markdown).with('wiki content', pipeline: :wiki, project_wiki: @wiki, page_slug: "nested/page") @@ -133,7 +133,7 @@ describe GitlabMarkdownHelper do helper.render_wiki_content(@wiki) end - it "should use Asciidoctor for asciidoc files" do + it "uses Asciidoctor for asciidoc files" do allow(@wiki).to receive(:format).and_return(:asciidoc) expect(helper).to receive(:asciidoc).with('wiki content') @@ -141,7 +141,7 @@ describe GitlabMarkdownHelper do helper.render_wiki_content(@wiki) end - it "should use the Gollum renderer for all other file types" do + it "uses the Gollum renderer for all other file types" do allow(@wiki).to receive(:format).and_return(:rdoc) formatted_content_stub = double('formatted_content') expect(formatted_content_stub).to receive(:html_safe) diff --git a/spec/helpers/graph_helper_spec.rb b/spec/helpers/graph_helper_spec.rb index 4acf38771b7..51c49f0e587 100644 --- a/spec/helpers/graph_helper_spec.rb +++ b/spec/helpers/graph_helper_spec.rb @@ -6,7 +6,7 @@ describe GraphHelper do let(:commit) { project.commit("master") } let(:graph) { Network::Graph.new(project, 'master', commit, '') } - it 'filter our refs used by GitLab' do + it 'filters our refs used by GitLab' do allow(commit).to receive(:ref_names).and_return(['refs/merge-requests/abc', 'master', 'refs/tmp/xyz']) self.instance_variable_set(:@graph, graph) refs = get_refs(project.repository, commit) diff --git a/spec/helpers/groups_helper_spec.rb b/spec/helpers/groups_helper_spec.rb index 4ea90a80a92..0807534720a 100644 --- a/spec/helpers/groups_helper_spec.rb +++ b/spec/helpers/groups_helper_spec.rb @@ -4,7 +4,7 @@ describe GroupsHelper do describe 'group_icon' do avatar_file_path = File.join(Rails.root, 'spec', 'fixtures', 'banana_sample.gif') - it 'should return an url for the avatar' do + it 'returns an url for the avatar' do group = create(:group) group.avatar = File.open(avatar_file_path) group.save! @@ -12,7 +12,7 @@ describe GroupsHelper do to match("/uploads/group/avatar/#{group.id}/banana_sample.gif") end - it 'should give default avatar_icon when no avatar is present' do + it 'gives default avatar_icon when no avatar is present' do group = create(:group) group.save! expect(group_icon(group.path)).to match('group_avatar.png') diff --git a/spec/helpers/issuables_helper_spec.rb b/spec/helpers/issuables_helper_spec.rb new file mode 100644 index 00000000000..2dd2eab0524 --- /dev/null +++ b/spec/helpers/issuables_helper_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' + +describe IssuablesHelper do + let(:label) { build_stubbed(:label) } + let(:label2) { build_stubbed(:label) } + + context 'label tooltip' do + it 'returns label text' do + expect(issuable_labels_tooltip([label])).to eq(label.title) + end + + it 'returns label text' do + expect(issuable_labels_tooltip([label, label2], limit: 1)).to eq("#{label.title}, and 1 more") + end + end +end diff --git a/spec/helpers/issues_helper_spec.rb b/spec/helpers/issues_helper_spec.rb index 831ae7fb69c..67bac782591 100644 --- a/spec/helpers/issues_helper_spec.rb +++ b/spec/helpers/issues_helper_spec.rb @@ -5,69 +5,24 @@ describe IssuesHelper do let(:issue) { create :issue, project: project } let(:ext_project) { create :redmine_project } - describe "url_for_project_issues" do - let(:project_url) { ext_project.external_issue_tracker.project_url } - let(:ext_expected) { project_url.gsub(':project_id', ext_project.id.to_s) } - let(:int_expected) { polymorphic_path([@project.namespace, project]) } - - it "should return internal path if used internal tracker" do - @project = project - expect(url_for_project_issues).to match(int_expected) - end - - it "should return path to external tracker" do - @project = ext_project - - expect(url_for_project_issues).to match(ext_expected) - end - - it "should return empty string if project nil" do - @project = nil - - expect(url_for_project_issues).to eq "" - end - - it 'returns an empty string if project_url is invalid' do - expect(project).to receive_message_chain('issues_tracker.project_url') { 'javascript:alert("foo");' } - - expect(url_for_project_issues(project)).to eq '' - end - - it 'returns an empty string if project_path is invalid' do - expect(project).to receive_message_chain('issues_tracker.project_path') { 'javascript:alert("foo");' } - - expect(url_for_project_issues(project, only_path: true)).to eq '' - end - - describe "when external tracker was enabled and then config removed" do - before do - @project = ext_project - allow(Gitlab.config).to receive(:issues_tracker).and_return(nil) - end - - it "should return path to external tracker" do - expect(url_for_project_issues).to match(ext_expected) - end - end - end - describe "url_for_issue" do let(:issues_url) { ext_project.external_issue_tracker.issues_url} let(:ext_expected) { issues_url.gsub(':id', issue.iid.to_s).gsub(':project_id', ext_project.id.to_s) } let(:int_expected) { polymorphic_path([@project.namespace, project, issue]) } - it "should return internal path if used internal tracker" do + it "returns internal path if used internal tracker" do @project = project + expect(url_for_issue(issue.iid)).to match(int_expected) end - it "should return path to external tracker" do + it "returns path to external tracker" do @project = ext_project expect(url_for_issue(issue.iid)).to match(ext_expected) end - it "should return empty string if project nil" do + it "returns empty string if project nil" do @project = nil expect(url_for_issue(issue.iid)).to eq "" @@ -91,66 +46,46 @@ describe IssuesHelper do allow(Gitlab.config).to receive(:issues_tracker).and_return(nil) end - it "should return external path" do + it "returns external path" do expect(url_for_issue(issue.iid)).to match(ext_expected) end end end - describe 'url_for_new_issue' do - let(:issues_url) { ext_project.external_issue_tracker.new_issue_url } - let(:ext_expected) { issues_url.gsub(':project_id', ext_project.id.to_s) } - let(:int_expected) { new_namespace_project_issue_path(project.namespace, project) } - - it "should return internal path if used internal tracker" do - @project = project - expect(url_for_new_issue).to match(int_expected) + describe "merge_requests_sentence" do + subject { merge_requests_sentence(merge_requests)} + let(:merge_requests) do + [ build(:merge_request, iid: 1), build(:merge_request, iid: 2), + build(:merge_request, iid: 3)] end - it "should return path to external tracker" do - @project = ext_project - - expect(url_for_new_issue).to match(ext_expected) - end + it { is_expected.to eq("!1, !2, or !3") } + end - it "should return empty string if project nil" do - @project = nil + describe '#award_user_list' do + let!(:awards) { build_list(:award_emoji, 15) } - expect(url_for_new_issue).to eq "" + it "returns a comma seperated list of 1-9 users" do + expect(award_user_list(awards.first(9), nil)).to eq(awards.first(9).map { |a| a.user.name }.to_sentence) end - it 'returns an empty string if issue_url is invalid' do - expect(project).to receive_message_chain('issues_tracker.new_issue_url') { 'javascript:alert("foo");' } - - expect(url_for_new_issue(project)).to eq '' + it "displays the current user's name as 'You'" do + expect(award_user_list(awards.first(1), awards[0].user)).to eq('You') end - it 'returns an empty string if issue_path is invalid' do - expect(project).to receive_message_chain('issues_tracker.new_issue_path') { 'javascript:alert("foo");' } - - expect(url_for_new_issue(project, only_path: true)).to eq '' + it "truncates lists of larger than 9 users" do + expect(award_user_list(awards, nil)).to eq(awards.first(9).map { |a| a.user.name }.join(', ') + ", and 6 more.") end - describe "when external tracker was enabled and then config removed" do - before do - @project = ext_project - allow(Gitlab.config).to receive(:issues_tracker).and_return(nil) - end - - it "should return internal path" do - expect(url_for_new_issue).to match(ext_expected) - end + it "displays the current user in front of 0-9 other users" do + expect(award_user_list(awards, awards[0].user)). + to eq("You, " + awards[1..9].map { |a| a.user.name }.join(', ') + ", and 5 more.") end - end - describe "merge_requests_sentence" do - subject { merge_requests_sentence(merge_requests)} - let(:merge_requests) do - [ build(:merge_request, iid: 1), build(:merge_request, iid: 2), - build(:merge_request, iid: 3)] + it "displays the current user in front regardless of position in the list" do + expect(award_user_list(awards, awards[12].user)). + to eq("You, " + awards[0..8].map { |a| a.user.name }.join(', ') + ", and 5 more.") end - - it { is_expected.to eq("!1, !2, or !3") } end describe '#award_active_class' do diff --git a/spec/helpers/members_helper_spec.rb b/spec/helpers/members_helper_spec.rb index f75fdb739f6..7998209b7b0 100644 --- a/spec/helpers/members_helper_spec.rb +++ b/spec/helpers/members_helper_spec.rb @@ -9,54 +9,6 @@ describe MembersHelper do it { expect(action_member_permission(:admin, group_member)).to eq :admin_group_member } end - describe '#default_show_roles' do - let(:user) { double } - let(:member) { build(:project_member) } - - before do - allow(helper).to receive(:current_user).and_return(user) - allow(helper).to receive(:can?).with(user, :update_project_member, member).and_return(false) - allow(helper).to receive(:can?).with(user, :destroy_project_member, member).and_return(false) - allow(helper).to receive(:can?).with(user, :admin_project_member, member.source).and_return(false) - end - - context 'when the current cannot update, destroy or admin the passed member' do - it 'returns false' do - expect(helper.default_show_roles(member)).to be_falsy - end - end - - context 'when the current can update the passed member' do - before do - allow(helper).to receive(:can?).with(user, :update_project_member, member).and_return(true) - end - - it 'returns true' do - expect(helper.default_show_roles(member)).to be_truthy - end - end - - context 'when the current can destroy the passed member' do - before do - allow(helper).to receive(:can?).with(user, :destroy_project_member, member).and_return(true) - end - - it 'returns true' do - expect(helper.default_show_roles(member)).to be_truthy - end - end - - context 'when the current can admin the passed member source' do - before do - allow(helper).to receive(:can?).with(user, :admin_project_member, member.source).and_return(true) - end - - it 'returns true' do - expect(helper.default_show_roles(member)).to be_truthy - end - end - end - describe '#remove_member_message' do let(:requester) { build(:user) } let(:project) { create(:project) } diff --git a/spec/helpers/notes_helper_spec.rb b/spec/helpers/notes_helper_spec.rb index 08a93503258..9c577501f00 100644 --- a/spec/helpers/notes_helper_spec.rb +++ b/spec/helpers/notes_helper_spec.rb @@ -1,37 +1,30 @@ require "spec_helper" describe NotesHelper do - describe "#notes_max_access_for_users" do - let(:owner) { create(:owner) } - let(:group) { create(:group) } - let(:project) { create(:empty_project, namespace: group) } - let(:master) { create(:user) } - let(:reporter) { create(:user) } - let(:guest) { create(:user) } - - let(:owner_note) { create(:note, author: owner, project: project) } - let(:master_note) { create(:note, author: master, project: project) } - let(:reporter_note) { create(:note, author: reporter, project: project) } - let!(:notes) { [owner_note, master_note, reporter_note] } + let(:owner) { create(:owner) } + let(:group) { create(:group) } + let(:project) { create(:empty_project, namespace: group) } + let(:master) { create(:user) } + let(:reporter) { create(:user) } + let(:guest) { create(:user) } - before do - group.add_owner(owner) - project.team << [master, :master] - project.team << [reporter, :reporter] - project.team << [guest, :guest] - end + let(:owner_note) { create(:note, author: owner, project: project) } + let(:master_note) { create(:note, author: master, project: project) } + let(:reporter_note) { create(:note, author: reporter, project: project) } + let!(:notes) { [owner_note, master_note, reporter_note] } - it 'return human access levels' do - original_method = project.team.method(:human_max_access) - expect_any_instance_of(ProjectTeam).to receive(:human_max_access).exactly(3).times do |*args| - original_method.call(args[1]) - end + before do + group.add_owner(owner) + project.team << [master, :master] + project.team << [reporter, :reporter] + project.team << [guest, :guest] + end + describe "#notes_max_access_for_users" do + it 'returns human access levels' do expect(helper.note_max_access_for_user(owner_note)).to eq('Owner') expect(helper.note_max_access_for_user(master_note)).to eq('Master') expect(helper.note_max_access_for_user(reporter_note)).to eq('Reporter') - # Call it again to ensure value is cached - expect(helper.note_max_access_for_user(owner_note)).to eq('Owner') end it 'handles access in different projects' do @@ -43,4 +36,21 @@ describe NotesHelper do expect(helper.note_max_access_for_user(other_note)).to eq('Reporter') end end + + describe '#preload_max_access_for_authors' do + before do + # This method reads cache from RequestStore, so make sure it's clean. + RequestStore.clear! + end + + it 'loads multiple users' do + expected_access = { + owner.id => Gitlab::Access::OWNER, + master.id => Gitlab::Access::MASTER, + reporter.id => Gitlab::Access::REPORTER + } + + expect(helper.preload_max_access_for_authors(notes, project)).to eq(expected_access) + end + end end diff --git a/spec/helpers/page_layout_helper_spec.rb b/spec/helpers/page_layout_helper_spec.rb index cf632f594c7..dc07657e101 100644 --- a/spec/helpers/page_layout_helper_spec.rb +++ b/spec/helpers/page_layout_helper_spec.rb @@ -97,5 +97,14 @@ describe PageLayoutHelper do expect(tags).to include %q(<meta property="twitter:data1" content="bar" />) end end + + it 'escapes content' do + allow(helper).to receive(:page_card_attributes) + .and_return(foo: %q{foo" http-equiv="refresh}.html_safe) + + tags = helper.page_card_meta_tags + + expect(tags).to include(%q{content="foo" http-equiv="refresh"}) + end end end diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index 604204cca0a..284b58d8d5c 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -136,4 +136,42 @@ describe ProjectsHelper do expect(sanitize_repo_path(project, import_error)).to eq('Could not clone [REPOS PATH]/namespace/test.git') end end + + describe '#last_push_event' do + let(:user) { double(:user, fork_of: nil) } + let(:project) { double(:project, id: 1) } + + before do + allow(helper).to receive(:current_user).and_return(user) + helper.instance_variable_set(:@project, project) + end + + context 'when there is no current_user' do + let(:user) { nil } + + it 'returns nil' do + expect(helper.last_push_event).to eq(nil) + end + end + + it 'returns recent push on the current project' do + event = double(:event) + expect(user).to receive(:recent_push).with([project.id]).and_return(event) + + expect(helper.last_push_event).to eq(event) + end + + context 'when current user has a fork of the current project' do + let(:fork) { double(:fork, id: 2) } + + it 'returns recent push considering fork events' do + expect(user).to receive(:fork_of).with(project).and_return(fork) + + event_on_fork = double(:event) + expect(user).to receive(:recent_push).with([project.id, fork.id]).and_return(event_on_fork) + + expect(helper.last_push_event).to eq(event_on_fork) + end + end + end end diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb index 601b6915e27..b0bb991539b 100644 --- a/spec/helpers/search_helper_spec.rb +++ b/spec/helpers/search_helper_spec.rb @@ -42,7 +42,7 @@ describe SearchHelper do expect(search_autocomplete_opts(project.name).size).to eq(1) end - it "should not include the public group" do + it "does not include the public group" do group = create(:group) expect(search_autocomplete_opts(group.name).size).to eq(0) end diff --git a/spec/helpers/submodule_helper_spec.rb b/spec/helpers/submodule_helper_spec.rb index 10121759132..37ac6a2699d 100644 --- a/spec/helpers/submodule_helper_spec.rb +++ b/spec/helpers/submodule_helper_spec.rb @@ -17,35 +17,35 @@ describe SubmoduleHelper do allow(Gitlab.config.gitlab).to receive(:protocol).and_return('http') # set this just to be sure end - it 'should detect ssh on standard port' do + it 'detects ssh on standard port' do allow(Gitlab.config.gitlab_shell).to receive(:ssh_port).and_return(22) # set this just to be sure allow(Gitlab.config.gitlab_shell).to receive(:ssh_path_prefix).and_return(Settings.send(:build_gitlab_shell_ssh_path_prefix)) stub_url([ config.user, '@', config.host, ':gitlab-org/gitlab-ce.git' ].join('')) expect(submodule_links(submodule_item)).to eq([ namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash') ]) end - it 'should detect ssh on non-standard port' do + it 'detects ssh on non-standard port' do allow(Gitlab.config.gitlab_shell).to receive(:ssh_port).and_return(2222) allow(Gitlab.config.gitlab_shell).to receive(:ssh_path_prefix).and_return(Settings.send(:build_gitlab_shell_ssh_path_prefix)) stub_url([ 'ssh://', config.user, '@', config.host, ':2222/gitlab-org/gitlab-ce.git' ].join('')) expect(submodule_links(submodule_item)).to eq([ namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash') ]) end - it 'should detect http on standard port' do + it 'detects http on standard port' do allow(Gitlab.config.gitlab).to receive(:port).and_return(80) allow(Gitlab.config.gitlab).to receive(:url).and_return(Settings.send(:build_gitlab_url)) stub_url([ 'http://', config.host, '/gitlab-org/gitlab-ce.git' ].join('')) expect(submodule_links(submodule_item)).to eq([ namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash') ]) end - it 'should detect http on non-standard port' do + it 'detects http on non-standard port' do allow(Gitlab.config.gitlab).to receive(:port).and_return(3000) allow(Gitlab.config.gitlab).to receive(:url).and_return(Settings.send(:build_gitlab_url)) stub_url([ 'http://', config.host, ':3000/gitlab-org/gitlab-ce.git' ].join('')) expect(submodule_links(submodule_item)).to eq([ namespace_project_path('gitlab-org', 'gitlab-ce'), namespace_project_tree_path('gitlab-org', 'gitlab-ce', 'hash') ]) end - it 'should work with relative_url_root' do + it 'works with relative_url_root' do allow(Gitlab.config.gitlab).to receive(:port).and_return(80) # set this just to be sure allow(Gitlab.config.gitlab).to receive(:relative_url_root).and_return('/gitlab/root') allow(Gitlab.config.gitlab).to receive(:url).and_return(Settings.send(:build_gitlab_url)) @@ -55,22 +55,22 @@ describe SubmoduleHelper do end context 'submodule on github.com' do - it 'should detect ssh' do + it 'detects ssh' do stub_url('git@github.com:gitlab-org/gitlab-ce.git') expect(submodule_links(submodule_item)).to eq([ 'https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash' ]) end - it 'should detect http' do + it 'detects http' do stub_url('http://github.com/gitlab-org/gitlab-ce.git') expect(submodule_links(submodule_item)).to eq([ 'https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash' ]) end - it 'should detect https' do + it 'detects https' do stub_url('https://github.com/gitlab-org/gitlab-ce.git') expect(submodule_links(submodule_item)).to eq([ 'https://github.com/gitlab-org/gitlab-ce', 'https://github.com/gitlab-org/gitlab-ce/tree/hash' ]) end - it 'should return original with non-standard url' do + it 'returns original with non-standard url' do stub_url('http://github.com/gitlab-org/gitlab-ce') expect(submodule_links(submodule_item)).to eq([ repo.submodule_url_for, nil ]) @@ -80,22 +80,22 @@ describe SubmoduleHelper do end context 'submodule on gitlab.com' do - it 'should detect ssh' do + it 'detects ssh' do stub_url('git@gitlab.com:gitlab-org/gitlab-ce.git') expect(submodule_links(submodule_item)).to eq([ 'https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash' ]) end - it 'should detect http' do + it 'detects http' do stub_url('http://gitlab.com/gitlab-org/gitlab-ce.git') expect(submodule_links(submodule_item)).to eq([ 'https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash' ]) end - it 'should detect https' do + it 'detects https' do stub_url('https://gitlab.com/gitlab-org/gitlab-ce.git') expect(submodule_links(submodule_item)).to eq([ 'https://gitlab.com/gitlab-org/gitlab-ce', 'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash' ]) end - it 'should return original with non-standard url' do + it 'returns original with non-standard url' do stub_url('http://gitlab.com/gitlab-org/gitlab-ce') expect(submodule_links(submodule_item)).to eq([ repo.submodule_url_for, nil ]) @@ -105,7 +105,7 @@ describe SubmoduleHelper do end context 'submodule on unsupported' do - it 'should return original' do + it 'returns original' do stub_url('http://mygitserver.com/gitlab-org/gitlab-ce') expect(submodule_links(submodule_item)).to eq([ repo.submodule_url_for, nil ]) diff --git a/spec/helpers/time_helper_spec.rb b/spec/helpers/time_helper_spec.rb index 3f62527c5bb..21f35585367 100644 --- a/spec/helpers/time_helper_spec.rb +++ b/spec/helpers/time_helper_spec.rb @@ -1,36 +1,34 @@ require 'spec_helper' describe TimeHelper do - describe "#duration_in_words" do + describe "#time_interval_in_words" do it "returns minutes and seconds" do intervals_in_words = { 100 => "1 minute 40 seconds", + 100.32 => "1 minute 40 seconds", 121 => "2 minutes 1 second", 3721 => "62 minutes 1 second", 0 => "0 seconds" } intervals_in_words.each do |interval, expectation| - expect(duration_in_words(Time.now + interval, Time.now)).to eq(expectation) + expect(time_interval_in_words(interval)).to eq(expectation) end end - - it "calculates interval from now if there is no finished_at" do - expect(duration_in_words(nil, Time.now - 5)).to eq("5 seconds") - end end - describe "#time_interval_in_words" do + describe "#duration_in_numbers" do it "returns minutes and seconds" do - intervals_in_words = { - 100 => "1 minute 40 seconds", - 121 => "2 minutes 1 second", - 3721 => "62 minutes 1 second", - 0 => "0 seconds" + durations_and_expectations = { + 100 => "01:40", + 121 => "02:01", + 3721 => "01:02:01", + 0 => "00:00", + 42 => "00:42" } - intervals_in_words.each do |interval, expectation| - expect(time_interval_in_words(interval)).to eq(expectation) + durations_and_expectations.each do |duration, expectation| + expect(duration_in_numbers(duration)).to eq(expectation) end end end diff --git a/spec/helpers/tree_helper_spec.rb b/spec/helpers/tree_helper_spec.rb index c70dd8076e0..8d6537ba4b5 100644 --- a/spec/helpers/tree_helper_spec.rb +++ b/spec/helpers/tree_helper_spec.rb @@ -12,7 +12,7 @@ describe TreeHelper do context "on a directory containing more than one file/directory" do let(:tree_item) { double(name: "files", path: "files") } - it "should return the directory name" do + it "returns the directory name" do expect(flatten_tree(tree_item)).to match('files') end end @@ -20,7 +20,7 @@ describe TreeHelper do context "on a directory containing only one directory" do let(:tree_item) { double(name: "foo", path: "foo") } - it "should return the flattened path" do + it "returns the flattened path" do expect(flatten_tree(tree_item)).to match('foo/bar') end end |