1
自分のサイトのパスワード変更機能を自分のページに分割しています。実際のユーザーとして手動で実行するとプロセス全体が正常に動作しますが、私のキュウバーテストに合格することはできません。なぜなら、コントローラへの最後の呼び出しで、current_userは不思議なことにnilを返すからです。ユーザーがキュウリ試験の途中でログアウトしました
ユーザーがテストの初めに完全にログインしていて、他の合格テストと同じ手順を踏んでいるので、私は重大なWTFの瞬間を抱えています。それを手で踏んだとき。
Given /^I have a signed in user with email\s*=\s*"([^"]*)" and password\s*=\s*"([^"]*)"$/ do |email, password|
@user = User.new
@user.email = email
@user.password = password
@user.confirm!
@user.save!
visit '/sign_in'
fill_in("Email", :with => @user.email)
fill_in("Password", :with => @user.password)
click_button("Sign in")
end
コントローラのアクション、 "registrations_controller.rb" から:
Scenario: The user should be able to change their password
Given I have a signed in user with email = "[email protected]" and password = "password"
When I am on the change-password page # this hits registrations_controller#change_password
And I fill in "Current password" with "password"
And I fill in "New password" with "new_password"
And I fill in "Re-enter new password" with "new_password"
And I press "Update"
Then I should see "You updated your account successfully"
とログインステップ:ここで
は、問題のテストだdef change_password
# calling "current_user" here retuns the logged-in user as expected
@user = current_user
end
def update_password
# calling "current_user" here returns nil
# error occurs at call to nil.update_with_password
@user = current_user
if @user.update_with_password(params["user"])
redirect_to after_update_path_for(@user)
else
clean_up_passwords(@user)
render_with_scope :change_password
end
end
を今、私たちはdevise(1.1.8)を使用しています。私の推測によれば、私はdeviseルートに間違ったやり方をしています。 "routes.rbを" に
devise_for :users, :controllers => {:confirmations => "confirmations", :sessions => "sessions", :registrations => "registrations"} do
# ...other routes here...
get "/change_password", :to => "registrations#change_password"
put "/update_password", :to => "registrations#update_password"
end
は最後に、完全を期すため、ここでは "change_password.html.haml"
= render :partial => "shared/stats"
#main
= form_for(resource, :as => resource_name, :url => "update_password", :html => { :method => :put, :autocomplete => "off" }) do |f|
= devise_error_messages!
.edit-account-hold
%span Your password
= f.label :current_password, "Current password"
= f.password_field :current_password
= f.label :password, "New password"
= f.password_field :password
= f.label :password_confirmation, "Re-enter new password"
= f.password_field :password_confirmation
= f.submit "Update", :class => "orange-button border-radius"
= link_to "Cancel", account_path, :id => "cancel-link"
:javascript
$(document).ready(function() {
$("#user_current_password").focus();
});
あなたのコントローラに 'before_filter:authenticate_user!'がありますか? – Gazler
うーん、@Gazlerが、私はregistrations_controller.rbの先頭に次き: 'prepend_before_filter:require_no_authentication、:のみ=> [:新しい、:作成] prepend_before_filter:authenticate_scope!:のみ=> [:編集、:update、:destroy] ' 私は嘘をつくつもりはないが、私はこれらの意味が正確にわからない。調査する... –
'authenticate_scope!'は次のようになります: 'def authenticate_scope! send(: "authenticate _#{resource_name}!"); self.resource = resource_class.find(send(: "現在の_#{リソース名}"))。 end' 実際に 'send(:authenticate_user!) 'の呼び出しに解決します このコールバックに':update_proposal'アクションを含めると、Cucumberはこの呼び出しでvomitのように見えますが、なぜ。通常の開発環境では、問題はありません。 S.申し訳ありませんが、私はここでより良いこの書式を設定することはできません... –