我想在控制器规范中设置auth_token值。我有以下内容:
describe ApiEditController do
before do
session[:auth_token]='abc123' # doesn't work
end
it 'should edit item' do
# lets create a location
#....
end
end
但是当我检查会话时,我没有提到auth_token:
{"format"=>"json", "flash"=>#<ActionDispatch::Flash::FlashHash:0x007fe592813cb8 @used=#<Set: {}>, @closed=false, @flashes={}, @now=nil>}
如果我通过网络界面做同样的事情,我会得到:
{"session_id"=>"f16e0a6a0b4942bcad2fd191b49c9078", "the_last_url"=>"http://localhost:3000/arc/menus/12/edit", "_csrf_token"=>"MuQfgciiZjVpaAYiwrbDHGvcyChf6m0ex2QV8GHzOIs=", "auth_token"=>"vfieGDt_iEmSQjllLL5N6g"}
为什么我的规范请求中没有获取auth_token值?它是否以不同的方式访问Rack :: Middleware?
THX
答案 0 :(得分:1)
使用request.session
代替session