My test is not successfully creating a guideline and I cannot work out why.
The test in guidelines_controller_test.rb is
test "should create guideline when logged in" do
sign_in users(:tester)
assert_difference('Guideline.count') do
post :create, guideline: { content: @guideline.content, hospital: @guideline.hospital, title: @guideline.title }
end
My create action in guidelines_controller.rb is
def create
@guideline = Guideline.new(params[:guideline])
respond_to do |format|
if @guideline.save
format.html { redirect_to @guideline, notice: 'Guideline was successfully created.' }
format.json { render json: @guideline, status: :created, location: @guideline }
else
format.html { render action: "new" }
format.json { render json: @guideline.errors, status: :unprocessable_entity }
end
end
end
when I try to run the test it fails
1) Failure:
test_should_create_guideline_when_logged_in(GuidelinesControllerTest) [test/functional/guidelines_controller_test.rb:36]:
"Guideline.count" didn't change by 1.
<4> expected but was
<3>.
and the test.log shows (have tried to copy the relevant bit)
Processing by GuidelinesController#create as HTML
Parameters: {"guideline"=>{"content"=>"www.test.com", "hospital"=>"Test Hospital", "title"=>"Test title"}}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 781720531 LIMIT 1
(0.1ms) SAVEPOINT active_record_1
Guideline Exists (0.3ms) SELECT 1 AS one FROM "guidelines" WHERE (LOWER("guidelines"."title") = LOWER('Test title') AND "guidelines"."hospital" = 'Test Hospital') LIMIT 1
(0.1ms) ROLLBACK TO SAVEPOINT active_record_1
Rendered guidelines/_form.html.erb (256.5ms)
Completed 200 OK in 313ms (Views: 279.2ms | ActiveRecord: 0.8ms)
(0.2ms) SELECT COUNT(*) FROM "guidelines"
(0.1ms) rollback transaction
Can anyone help?