Rspec ruby rails -


i'm trying create action set properly.

i keep getting error: argumenterror: unknown keyword: topic

here testing:

require 'rails_helper'  rspec.describe topicscontroller, type: :controller  let(:my_topic) { topic.create!(name: randomdata.random_sentence, description: randomdata.random_paragraph)} describe "post create" "increases number of topics 1"   expect{ post :create, {topic: {name: randomdata.random_sentence, description: randomdata.random_paragraph}}}.to change(topic,:count).by(1) end  "assigns topic.last @topic"   post :create, { topic: {name: randomdata.random_sentence, description: randomdata.random_paragraph}}   expect(assigns(:topic)).to eq topic.last end  "redirects new topic"   post :create, {topic: {name: randomdata.random_sentence, description: randomdata.random_paragraph}}   expect(response).to redirect_to topic.last end end 

here controller:

  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 saved successfully." else   flash.now[:alert] = "error creating topic.  please try again"   render :new end end 

i'm trying figure out i'm missing causing error i've been staring @ hours , have tried edit multiple times no avail. can't figure out. rest of project i've been working on has been okay cannot figure out why can't word topic convert successfully. taking look.

the problem post method takes keyword arguments second argument.

if need specify params, params keyword should used:

post :create, params: { topic: { name: ..., description: ... } } 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -