我對軌道比較陌生,所以請在回答時記住這一點。 :)'註冊'過程失敗
我已將clearance
gem添加到我的導軌應用程序。我執行rails g clearance:views
,沒有麻煩。接下來我執行了rails g clearance:specs
。所有間隙規格傳遞除了一:
/spec/features/clearance/visitor_signs_up_spec.rb:13 # Visitor signs up with valid email and password
這裏的RSpec的錯誤消息:
Visitor signs up with valid email and password Failure/Error: expect_user_to_be_signed_in expected to find button "Sign out" but there were no matches # ./spec/support/features/clearance_helpers.rb:35:in `expect_user_to_be_signed_in' # ./spec/features/clearance/visitor_signs_up_spec.rb:16:in `block (2 levels) in <top (required)>' # -e:1:in `<main>'
有趣的是,當我嘗試手動遵循規範,註冊過程,但完成它不創建新的會話。換句話說,我必須在註冊後登錄。這似乎與/spec/features/clearance/visitor_signs_up_spec.rb:13
中發生的行爲相符,但根據該規範,這不是預期的行爲。
沒有其他使用相同方法的規格expect_user_to_be_signed_in
有這個問題。
另外,我的Rails服務器日誌沒有顯示任何錯誤。
我不知道在哪裏尋找縮小問題範圍。你怎麼看?
更新:發現錯誤!
Started POST "/users" for ::1 at 2015-10-18 15:15:44 -0600
Processing by UsersController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"[FILTERED]", "user"=>{"first_name"=>"Michael", "last_name"=>"Hargiss", "username"=>"mycargus", "email"=>"[email protected]", "password"=>"[FILTERED]"}, "commit"=>"Sign up"}
Redirected to http://localhost:3000/sign_in
Filter chain halted as :require_login rendered or redirected
Completed 302 Found in 1ms (ActiveRecord: 0.0ms)
更新:我通過在成功保存新用戶後更改重定向url來修復了以前的錯誤。我還必須添加以下內容到我的UsersController
:
before_action :require_login, only: [:index, :show, :edit, :update, :destroy]
任何想法?