【发布时间】:2017-08-20 06:21:47
【问题描述】:
我正在尝试正确设置创建操作。
我不断收到错误消息:ArgumentError: Unknown keyword: topic
这里是测试:
require 'rails_helper'
RSpec.describe TopicsController, type: :controller do
let(:my_topic) { Topic.create!(name: RandomData.random_sentence, description: RandomData.random_paragraph)}
describe "POST create" do
it "increases the number of topics by 1" do
expect{ post :create, {topic: {name: RandomData.random_sentence, description: RandomData.random_paragraph}}}.to change(Topic,:count).by(1)
end
it "assigns Topic.last to @topic" do
post :create, { topic: {name: RandomData.random_sentence, description: RandomData.random_paragraph}}
expect(assigns(:topic)).to eq Topic.last
end
it "redirects to the new topic" do
post :create, {topic: {name: RandomData.random_sentence, description: RandomData.random_paragraph}}
expect(response).to redirect_to Topic.last
end
end
这里是控制器:
def create
@topic = Topic.new
@topic.name = params[:topic][:name]
@topic.description = params[:topic][:description]
@topic.public = params[:topic][:public]
if @topic.save
redirect_to @topic, notice: "Topic was saved successfully."
else
flash.now[:alert] = "Error creating topic. Please try again"
render :new
end
end
我正在尝试找出导致此错误的原因,我已经盯着它看了好几个小时,并尝试多次对其进行编辑但无济于事。我想不通。我一直在从事的项目的其余部分还可以,但是我无法弄清楚为什么我无法成功转换主题这个词。感谢您的观看。
【问题讨论】:
标签: ruby-on-rails ruby rspec rspec-rails ruby-on-rails-5.1