我试着按照这个答案:https://stackoverflow.com/a/32168734/148844
# Logs in a test user.
def log_in_as(user, options = {})
password = options[:password] || 'password'
remember_me = options[:remember_me] || '1'
if integration_test?
post user_session_path, session: { email: user.email,
password: password,
remember_me: remember_me }
但我得到了这个警告:
DEPRECATION WARNING: Using positional arguments in integration tests has been deprecated,
in favor of keyword arguments, and will be removed in Rails 5.1.
Deprecated style:
get "/profile", { id: 1 }, { "X-Extra-Header" => "123" }
New keyword style:
get "/profile", params: { id: 1 }, headers: { "X-Extra-Header" => "123" }
(called from log_in_as at C:/Users/Chloe/workspace/fortuneempire/test/test_helper.rb:16)
所以我试过
post action: user_session_path, session: { email: user.email,
password: password,
remember_me: remember_me }
它给了
URI::InvalidURIError: bad URI(is not URI?): http://www.example.com:80{:action=>"/users/sign_in", :session=>{:email=>"MyString@example.com", :password=>"password", :remember_me=>"1"}}
test/test_helper.rb:16:in `log_in_as'
老实说,我看不出有什么不妥。 http://api.rubyonrails.org/classes/ActionController/TestCase/Behavior.html#method-i-get
This问题解决方案是标记标头参数,但我没有这样的哈希。
Rails 5.0.2
答案 0 :(得分:0)
post user_session_path, session: { email: user.email,
password: password,
remember_me: remember_me }
变为
post user_session_path, params: { session: { email: user.email,
password: password,
remember_me: remember_me } }