在我的应用程序控制器中,我在 3 个地方设置了 cookie。在过滤器之前...
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 => current_user.id, :expires => 1.year.from_now }
else
Abingo.identity = cookies[:abingo_identity] ||=
{ :value => rand(10 ** 10), :expires => 1.year.from_now }
end
end
...并有两种方法...
def remember_visit url
20.times do |i|
# Add cookie to referrer list
name = "referrer#{i}"
if cookies[name].blank?
cookies[name] = {:value => url, :expires => Time.now + 1.year }
break
elsif cookies[name] == url
break # skip
end
end
end
... 和这个...
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 => affiliate.id.to_s, :expires => Time.now + 1.year }
end
if offer.blank? && affiliate.offer? && !affiliate.expired?
cookies[offer_name] = { :value => affiliate.id.to_s, :expires => Time.now + 1.year }
end
end
end
return affiliate
end
在调试器中单步执行,我在之前的过滤器中看到,cookies["abingo_identity"]
已设置。然后在 remember_visit() 中,它和cookies["referrer0"]
都被设置,然后在 set_referral_cookie() 中,所有 3 都被设置。
但是当我回到我的功能测试时,只有cookies["abingo_identity"]
设置。
cookies["abingo_identity"] 部分是新的,当我将其注释掉时,其他 cookie 仍然存在。
这段代码有什么问题?
更新:它们没有被删除,但它们并没有全部复制到测试用例的@response.cookies