From 75ab5498ca90bc3e3b4fecd3103dec2c0c089039 Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Wed, 1 Jan 2025 17:56:38 +0100 Subject: Updated tests. --- test/controllers/scores_controller_test.rb | 45 ++++++++---------------------- 1 file changed, 12 insertions(+), 33 deletions(-) (limited to 'test/controllers') diff --git a/test/controllers/scores_controller_test.rb b/test/controllers/scores_controller_test.rb index 8fb4cb8..6a6bc9a 100644 --- a/test/controllers/scores_controller_test.rb +++ b/test/controllers/scores_controller_test.rb @@ -2,9 +2,9 @@ require "test_helper" class ScoresControllerTest < ActionDispatch::IntegrationTest setup do - @tartiflette = Tartiflette.create!(scoring_id: 1) - @criterium = ScoringCriterium.create!(name: "Taste", category: "Flavor") - @score = Score.create!(tartiflette: @tartiflette, scoring_criterium: @criterium, value: 4) + @tartiflette = tartiflettes(:one) + @criterium = scoring_criteria(:one) + @score = scores(:one) end test "should get new score form" do @@ -14,26 +14,6 @@ class ScoresControllerTest < ActionDispatch::IntegrationTest assert_select "select[name=?]", "scores[#{@criterium.id}][value]" end - test "should create scores for tartiflette" do - assert_difference("Score.count", 1) do - post tartiflette_scores_path(@tartiflette), params: { - scores: { @criterium.id => { value: 5 } } - } - end - assert_redirected_to root_path - end - - # test "should not create scores if already scored" do - # session = { :scored_tartiflettes => [ @tartiflette.id ] } - # assert_no_difference("Score.count") do - # post tartiflette_scores_path(@tartiflette), params: { - # scores: { @criterium.id => { value: 5 } } - # } - # end - # assert_redirected_to root_path - # assert_match /Vous avez déja noté cette tartiflette/, flash[:alert] - # end - test "should not create scores with invalid data" do assert_no_difference("Score.count") do post tartiflette_scores_path(@tartiflette), params: { @@ -52,19 +32,18 @@ class ScoresControllerTest < ActionDispatch::IntegrationTest test "should update scores for tartiflette" do patch tartiflette_update_scores_path(@tartiflette), params: { - scores: { @score.id => { value: 3 } } + scores: { @score.id => { value: 5 } } } assert_redirected_to root_path @score.reload - assert_equal 3, @score.value + assert_equal 5, @score.value, "Score value should be updated to 5" end - # test "should not update scores with invalid data" do - # patch tartiflette_update_scores_path(@tartiflette), params: { - # scores: { @score.id => { value: nil } } - # } - # @score.reload - # assert_not_equal nil, @score.value - # assert_redirected_to tartiflette_edit_scores_path(@tartiflette) - # end + test "should not update scores with invalid data" do + patch tartiflette_update_scores_path(@tartiflette), params: { + scores: { @score.id => { value: nil } } + } + @score.reload + assert_not_equal nil, @score.value, "Score should not be updated with invalid data" + end end -- cgit v1.2.3