How do I set cookies in a spec so I can see them in my controller, please?
Conversely, why doesn''t this work...
require File.dirname(__FILE__) + ''/../spec_helper''
class TestApplicationController < ApplicationController
def index
@seen = cookies[''auth_token''] || ''NOT
seen!''
puts cookies.inspect # {"auth_token"=>42}, see below
render :text => ''testing'' # don''t look for
view
end
end
context ''All controllers (via ApplicationController)...'' do
controller_name :test_application
specify ''should see cookie'' do
request.cookies[''auth_token''] = 42
get :index
assigns[''seen''].should eql(42)
end
end
clean$ spec -cfs spec/controllers/
All controllers (via ApplicationController)...
{"auth_token"=>42}
- should allow access to url with proper cookie (FAILED - 1)
1) ''All controllers (via ApplicationController)... should see
cookie'' FAILED
expected 42, got "NOT seen!" (using .eql?)
./spec/controllers/application_controller_spec.rb:17:
Finished in 0.143717 seconds
1 specification, 1 failure
Is it something to do with
http://www.40withegg.com/2007/1/5/rails-cookies-mangles-the-hash-interface
and if so, is there a workaround?
Many thanks,
Jerry