Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy are Rails cookies disappearing in Functional Tests
    primarykey
    data
    text
    <p>In my Application Controller I am setting cookies in 3 places. In a before filter...</p> <pre><code>def set_abingo_identity # skip bots if request.user_agent =~ /#{@robot_regular_expression}/i Abingo.identity = "robot" elsif current_user Abingo.identity = cookies[:abingo_identity] ||= { :value =&gt; current_user.id, :expires =&gt; 1.year.from_now } else Abingo.identity = cookies[:abingo_identity] ||= { :value =&gt; rand(10 ** 10), :expires =&gt; 1.year.from_now } end end </code></pre> <p>... and in two methods...</p> <pre><code>def remember_visit url 20.times do |i| # Add cookie to referrer list name = "referrer#{i}" if cookies[name].blank? cookies[name] = {:value =&gt; url, :expires =&gt; Time.now + 1.year } break elsif cookies[name] == url break # skip end end end </code></pre> <p>... and this one...</p> <pre><code>def set_referral_cookie val ref_name = "referral_id" offer_name = "offer_id" cur = cookies[ref_name] offer = cookies[offer_name] affiliate = Affiliate.find_by_name val if cur.blank? || offer.blank? if affiliate if cur.blank? cookies[ref_name] = { :value =&gt; affiliate.id.to_s, :expires =&gt; Time.now + 1.year } end if offer.blank? &amp;&amp; affiliate.offer? &amp;&amp; !affiliate.expired? cookies[offer_name] = { :value =&gt; affiliate.id.to_s, :expires =&gt; Time.now + 1.year } end end end return affiliate end </code></pre> <p>Stepping through in the debugger, I see in the before filter, <code>cookies["abingo_identity"]</code> is set. Then in remember_visit(), both it and <code>cookies["referrer0"]</code> are set, and then in set_referral_cookie(), all 3 are set.</p> <p>But when I get back to my functional test, only <code>cookies["abingo_identity"]</code> is set. </p> <p>The cookies["abingo_identity"] part is new, and when I comment it out, the other cookies persist.</p> <p>What is wrong with this code?</p> <p>Update: They are not getting deleted, but they are not all copied to the test case's @response.cookies</p>
    singulars
    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