Я пытаюсь проверить мои Post_comments # создать действие в спецификации контроллера с RSpec и я получаю сообщение об ошибке:POST: создать Rspec тестирования ошибки контроллера, неверное число аргументов 2 для 0
Failure/Error: post :create, :post_id => post.to_param, :post_comment => attributes_for(:post_comment, comment: "New")
ArgumentError:
wrong number of arguments (2 for 0)
# ./spec/controllers/post_comments_controller_spec.rb:95:in `block (4 levels) in <top (required)>'
Мой пост Комментарии контроллер:
class PostCommentsController < ApplicationController
before_action :find_todo_list
def index
@post_comment = @post.post_comments.all
end
def show
@post_comment = @post.post_comments.find(params[:id])
end
def new
@post_comment = @post.post_comments.new
end
def edit
@post_comment = @post.post_comments.find(params[:id])
end
def create
@post_comment = @post.post_comments.new(post_comment_params)
if
@post_comment.save
redirect_to post_post_comments_path
flash[:success] = "Comment added successfully!"
else
flash.now[:error] = "Comment could not be saved"
render 'new'
end
end
def update
@post_comment = @post.post_comments.find(params[:id])
if
@post_comment.update(post_comment_params)
redirect_to post_post_comment_path
flash[:success] = "Comment successfully updated"
else
flash.now[:error] = "Comment could not be updated"
render 'edit'
end
end
def destroy
@post_comment = @post.post_comments.find(params[:id])
@post_comment.destroy
redirect_to post_post_comments_path
flash[:success] = "The comment was successfully deleted"
end
end
private
def find_todo_list
@post = Post.find_by(params[:post_id])
end
def post_comment_params
params.require(:post_comment).permit(:comment)
end
Мой контроллер спецификации, которая держит неудачу:
describe "POST #create" do
context "flash messages" do
let(:post) {create(:post)}
it "sets flash success" do
post :create, :post_id => post.to_param, :post_comment => attributes_for(:post_comment, comment: "New")
expect(flash[:success]).to eq("Comment added successfully!")
end
end
конца
Я использую заводскую девочку так вот моя фабрика для почтовых комментариев, которая имеет belongs_to ассоциации с постом ... Дух
factory :post_comment do
comment "Post comment"
post
end
Любой помощь будет действительно помочь мне, спасибо!
Большое вам спасибо! Это была проблема. @zetetic – AdamG