2016-11-02 7 views
0

更新 - 一般的なユーザーエラー - すべての技術サポートに感謝します! password_reset_controller_testが一度も作成されていないはずです。なんらかの理由で - 私のコントロールは、12.1.1で使用された "--no-test-framework"があったとしても存在します。私は何かを間違って入力したと確信しています&そのチュートリアルには、ユーザーのIDを持っていないのです。要約すると、ソリューションはコントローラーテストを削除していました。後で行う統合テストがあるためです。Michael HartlのRuby on Railsチュートリアル - 経路はありませんが、routes.rbにあります。

私は経路がないと主張している間違いで問題が発生しましたが、rakeルートのroutes.rbファイル&の経路がはっきりとわかります。 Michael HartlのRuby on Railsチュートリアルガイドを使用しています。 12章で、私は失敗したテストを持っています。私はいくつかの部分を取り除いて追加することでこれをテストしました。実際にはコントローラーに表示されますが、アクションが見つからないと主張しています。私は、私の限られた知識でどのように知っているかのように、最高のパラーム問題をチェックしました。

ヒントがあれば幸いです!

おかげで...

ERROR["test_should_get_edit", PasswordResetsControllerTest, 2016-10-20 15:24:37 +0000] 
test_should_get_edit#PasswordResetsControllerTest (1476977077.08s) 
ActionController::UrlGenerationError:   ActionController::UrlGenerationError: No route matches {:action=>"edit", :controller=>"password_resets"} 
      test/controllers/password_resets_controller_test.rb:11:in `block in <class:PasswordResetsControllerTest>' 
     test/controllers/password_resets_controller_test.rb:11:in `block in <class:PasswordResetsControllerTest>' 

    54/54: [=======================================================================] 100% Time: 00:00:03, Time: 00:00:03 

Finished in 3.02339s 
54 tests, 279 assertions, 0 failures, 1 errors, 0 skips 

コントローラテスト

password_resets_controller_test 
    require 'test_helper' 

    class PasswordResetsControllerTest < ActionController::TestCase 

     test "should get new" do 
     get :new 
     assert_response :success 
     end 

     test "should get edit" do 
     get :edit 
     assert_response :success 
     end 
    end 

routes.rbを

Rails.application.routes.draw do 
    root 'static_pages#home' 
    get '/help', to: 'static_pages#help' 
    get '/about', to: 'static_pages#about' 
    get '/contact', to: 'static_pages#contact' 
    get '/signup', to: 'users#new' 
    get '/login', to: 'sessions#new' 
    post '/login', to: 'sessions#create' 
    delete '/logout', to: 'sessions#destroy' 

    resources :users 
    resources :account_activations, only: [:edit] 
    resources :password_resets,  only: [:new, :create, :edit, :update] 
    resources :microposts,   only: [:create, :destroy] 
end 

コントローラは、ファイル

class PasswordResetsController < ApplicationController 
    before_action :get_user,   only: [:edit, :update] 
    before_action :valid_user,  only: [:edit, :update] 
    before_action :check_expiration, only: [:edit, :update] # Case (1) 

    def new 
    end 

    def create 
    @user = User.find_by(email: params[:password_reset][:email].downcase) 
    if @user 
     @user.create_reset_digest 
     @user.send_password_reset_email 
     flash[:info] = "Email sent with password reset instructions" 
     redirect_to root_url 
    else 
     flash.now[:danger] = "Email address not found" 
     render 'new' 
    end 
    end 

    def edit 
    end 

    def update 
    if params[:user][:password].empty? 
     @user.errors.add(:password, "can't be empty") 
     render 'edit' 
    elsif @user.update_attributes(user_params) 
     log_in @user 
     @user.update_attribute(:reset_digest, nil) 
     flash[:success] = "Password has been reset." 
     redirect_to @user 
    else 
     render 'edit' 
    end 
    end 


    private 

    def user_params 
     params.require(:user).permit(:password, :password_confirmation) 
    end 

    # Before filters 

    def get_user 
     @user = User.find_by(email: params[:email]) 
    end 

    # Confirms a valid user. 
    def valid_user 
     unless (@user && @user.activated? && 
       @user.authenticated?(:reset, params[:id])) 
     redirect_to root_url 
     end 
    end 

    # Checks expiration of reset token. 
    def check_expiration 
     if @user.password_reset_expired? 
     flash[:danger] = "Password reset has expired." 
     redirect_to new_password_reset_url 
     end 
    end 
end 

ここにはレーキルートファイルがあります。これを読んだ場合は、そこに編集オプションがあります。また、リソースを削除したときにルートファイルを編集すると、別のエラーメッセージが表示されます。代わりにget :edit

rake routes 
       Prefix Verb URI Pattern        Controller#Action 
        root GET /          static_pages#home 
        help GET /help(.:format)       static_pages#help 
        about GET /about(.:format)      static_pages#about 
       contact GET /contact(.:format)      static_pages#contact 
       signup GET /signup(.:format)      users#new 
        login GET /login(.:format)      sessions#new 
         POST /login(.:format)      sessions#create 
       logout DELETE /logout(.:format)      sessions#destroy 
        users GET /users(.:format)      users#index 
         POST /users(.:format)      users#create 
       new_user GET /users/new(.:format)     users#new 
       edit_user GET /users/:id/edit(.:format)    users#edit 
        user GET /users/:id(.:format)     users#show 
         PATCH /users/:id(.:format)     users#update 
         PUT /users/:id(.:format)     users#update 
         DELETE /users/:id(.:format)     users#destroy 
edit_account_activation GET /account_activations/:id/edit(.:format) account_activations#edit 
     password_resets POST /password_resets(.:format)    password_resets#create 
    new_password_reset GET /password_resets/new(.:format)   password_resets#new 
    edit_password_reset GET /password_resets/:id/edit(.:format)  password_resets#edit 
     password_reset PATCH /password_resets/:id(.:format)   password_resets#update 
         PUT /password_resets/:id(.:format)   password_resets#update 
      microposts POST /microposts(.:format)     microposts#create 
       micropost DELETE /microposts/:id(.:format)    microposts#destroy 
+1

あなたがテストを実行するとき、あなたが見ている障害メッセージを含めることはできますか? – gmcnaughton

+0

よろしくお願いいたします。 – Mirv

+1

@RaptorManパスワードリセット_id_(あなたの 'edit_password_reset'ルートを参照)を提供していないようです。 –

答えて

1

私はあなたが以下のように要求して、必要なパラメータを渡すべきだと思う:

test "should get edit" do 
    get :edit, { id: <id-of-the-resource-for-your-controller> } 
    assert_response :success 
end 
+0

これはソリューションの最適な言い回しでした。エラーは、他の2人が言ったように実際に生成されました - あなたのものが私の周りを回し、私のエラーを最もよく見つけるのを助けました。ありがとうございました。 – Mirv

1

get '/password_resets/new'

は、ルート・パスを確認し、端末にrake routesを実行し、:edit:newアクションのため 同等のパスを参照してみてください。

+0

説明の下部に更新を追加しました...私が見たもの(frustratingly)...作成、新規、編集はすべて存在しますルートで。私はroutes.rbファイルを編集するときにレイクルートをあきらめました - エラーメッセージは違って、ファイルの問題が私の知識を超えているか、routes.rbの実際のルーティングから離れていることを伝えています – Mirv

+1

+あなたがmini_testの代わりにrspecを使うことができたらうれしいです。優れた開発者サポートを手に入れることができます。ところで、michael hartl tutorial-rails 4はデフォルトでrspecを使用しています。:) – Ajay

+0

私は両方のroutes.rbとコントローラのテストで試してみましたが、私は新しいものを試してから編集して、そういうように更新しました... ":get '/ edit': 'password_resets#edit'"これまでの変更はありません。 – Mirv

関連する問題