0
임 댓글 컨트롤러의 사후 조치에 대한 테스트를 작성하지만,이 오류가 점점 계속 노력 : 나는 시험에 주위에 몇 가지 변경을 시도했습니다RSpec에 액티브 :: AssociationTypeMismatch
Failure/Error: @comment = @outlet.comments.build(comment_params)
ActiveRecord::AssociationTypeMismatch:
Outlet(#70273695598160) expected, got String(#70273689026640)
을하지만 점점 계속 같은 오류.
다음describe 'create' do
context 'with valid attributes' do
before :each do
@outlet = FactoryGirl.create(:outlet)
@outlet_id = @outlet.id
@user = FactoryGirl.create(:user)
@user_id = @user.id
@comment_params = { body: "This is a comment", outlet: @outlet_id, user: @user_id }
end
let(:create) { post :create, params: { outlet_id: @outlet_id, user_id: @user_id, comment: @comment_params } }
it "creates new comment" do
puts @outlet.class
puts @user.class
expect { create }.to change { Comment.count }.by 1
end
end
end
내 의견 컨트롤러 : 여기
을 시도 할 그 밖의 무엇 확실하지 내 테스트입니다 당신은 사용자와 출구 IDS 전달
class CommentsController < ApplicationController
def new
@comment = Comment.new
end
def create
@outlet = Outlet.find(params[:outlet_id])
@user = User.find(params[:user_id])
@comment = @outlet.comments.build(comment_params)
if @comment.save!
redirect_to(@outlet)
end
end
private
def comment_params
params.require(:comment).permit(:body, :outlet, :user)
end
end
당신이 실패 라인 전에 중단 점을 넣고'comment_params'의 모습을 검사 할 수 있습니다 :
는에 테스트를 변경:
하고 컨트롤러를 변경? –