Note that there are some explanatory texts on larger screens.

plurals
  1. PORspec, Rails - how to test helper method that use params hash?
    primarykey
    data
    text
    <p>I want to implement a tagging system similar to stackoverflow, there is a box with a tags at top right corner, and also I have links to delete tag from params hash. my method works correctly in browser. But I can't find a way to test it.</p> <pre><code>def tags_list_with_destroy_links if params[:tags] li = "" p = params[:tags].split("+") # '/tagged/sea+ship+sun' =&gt; ['sea', 'ship', 'sun'] p.map do |t| remove_link = if p.count &gt;= 3 c = p.reject {|item| item == t } a = c.join("+") {:tags =&gt; a} elsif p.count == 2 c = p.reject {|item| item == t } {tags: c[0]} else questions_url end li &lt;&lt; content_tag(:li) do link_to(t, questions_tags_path(t), class: 'tag') + link_to( '', remove_link , class: 'icon-small icons-cross') end end ul = content_tag(:ul, li.html_safe) ul &lt;&lt; tag(:hr) end end </code></pre> <p>I've tried:</p> <pre><code>it 'return list with selected tags' do #Rails.application.routes.url_helpers.stub(:questions_tags).and_return('/questions/tagged/sea+ship+sun') #helper.request.stub(:path).and_return('/questions/tagged/sea+ship+sun') helper.stub(:url_for, {controller:'questions', action: 'index', tags:'sea+ship+sun'} ).and_return('/questions/tagged/sea+ship+sun') helper.params[:tags] = 'sea+ship+sun' helper.tags_list_with_destroy_links.should == 'list_with_tags' end </code></pre> <p>but it return: </p> <pre><code>&lt;a class=\"tag\" href=\"/questions/tagged/sea+ship+sun\"&gt;sea&lt;/a&gt;&lt;a class=\"icon-small icons-cross\" href=\"/questions/tagged/sea+ship+sun\"&gt;&lt;/a&gt;&lt;/li&gt; </code></pre> <p>and shoud return remove link as </p> <blockquote> <p>href="/questions/tagged/ship+sun" without sea</p> </blockquote> <p>I would appreciate any advice</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload