I'm creating an Rspec controller test for a create action that takes parameters for two objects, story and ku. Story validates presence of title and large_cover_url. Not sure why rspec throws an argument error when passing invalid parameters, and could use some insight on this issue.
Here is the error:
Failure/Error: post :create, story: {title: nil, large_cover_url: "present"}, ku: Fabricate.attributes_for(:ku)
ArgumentError:
wrong number of arguments (0 for 2)
# ./app/controllers/stories_controller.rb:18:in `create'
# ./spec/controllers/stories_controller_spec.rb:59:in `block (4 levels) in <top (required)>'
Here is the spec:
context "failed story creation" do
let(:bob) { Fabricate(:user) }
before { sign_in_user(bob) }
it "does not create a new story" do
post :create, story: {title: nil, large_cover_url: "present"}, ku: Fabricate.attributes_for(:ku)
expect(Story.count).to eq(0)
end
end
Here is the controller action:
def create
@story = Story.new(params[:story])
@ku = Ku.new(params[:ku])
if @story.save && @ku.save
@story.update_column(:user_id, current_user.id)
@ku.update_column(:user_id, current_user.id)
@story.kus << @ku
redirect_to story_path(@story), flash: {success: "Your story was published."}
else
flash[:error] = "#{@story.errors.full_message.join(', ')}"
render :new
end
end