テストでガイドラインが作成されず、その理由がわかりません。
Guidelines_controller_test.rb のテストは
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
Guidelines_controller.rb での私の作成アクションは
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
終わり
テストを実行しようとすると失敗します
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>.
およびtest.logが表示されます(関連するビットをコピーしようとしました)
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
誰でも助けることができますか?