0
私はこのテストを実行するときにルーティングエラーが発生する理由を理解しようとしているチェスアプリケーション&を構築しているグループプロジェクトに取り組んでいます。 作品を移動した後にリダイレクトするように、私の作品のコントローラで更新アクションをテストしようとしています。私はテストを始めたばかりで、これを書いた方法に問題があると推測しています。本当に立ち往生し、私が逃しているものの説明を使用することができます。Rspecに問題があります。ルーティングエラーを取得する
コントローラ:
class PiecesController < ApplicationController
before_action :authenticate_user!, only: [:show, :update]
def show
#show the board again
@game = Game.find(params[:id])
@pieces = @game.pieces
end
def update
@piece = Piece.find(params[:id])
@game = @piece.game
if @piece.update_attributes(piece_params)
redirect_to game_path(@game)
end
end
private
def piece_params
params.require(:piece).permit(:x_position, :y_position)
end
end
スペック:
require 'rails_helper'
RSpec.describe PiecesController, type: :controller do
describe 'update action' do
it 'should redirect to game path when piece is moved' do
user1 = FactoryGirl.create(:user)
game = FactoryGirl.create(:game, white_user_id: user1.id)
piece = FactoryGirl.create(:piece, game: game, user_id: user1.id, x_position: 0, y_position: 0)
put :update, params: {x_position: 1, y_position: 1}
expect(response).to redirect_to game_path(game)
end
end
end
路線:
Rails.application.routes.draw do
devise_for :users
root 'static_pages#index'
resources :games do
member do
patch :join
end
resources :pieces, only: [:show, :update]
end
end
を、しかし私はまだ方法エラーの失敗を取得していませんよ。何が適切に定義されていないか把握しようとしています。 – Belder
おっと - それは 'ピース'で、 '@ピース'ではありません。私は例を更新しました – gwcodes
ありがとうございます。これは元の失敗を修正し、現在は作品IDを割り当てています。 URLGenerationError経路が一致しません... – Belder