diff options
Diffstat (limited to 'test/controllers')
-rw-r--r-- | test/controllers/.keep | 0 | ||||
-rw-r--r-- | test/controllers/home_controller_test.rb | 16 | ||||
-rw-r--r-- | test/controllers/scores_controller_test.rb | 70 |
3 files changed, 86 insertions, 0 deletions
diff --git a/test/controllers/.keep b/test/controllers/.keep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/controllers/.keep diff --git a/test/controllers/home_controller_test.rb b/test/controllers/home_controller_test.rb new file mode 100644 index 0000000..aab02bb --- /dev/null +++ b/test/controllers/home_controller_test.rb @@ -0,0 +1,16 @@ +require "test_helper" + +class HomeControllerTest < ActionDispatch::IntegrationTest + test "should get index" do + get root_url + assert_response :success + assert_select "h1", "World Tartiflette Tour 2024" + end + + test "should list tartiflettes in the index" do + tartiflette = Tartiflette.create!(scoring_id: 1) + get root_url + assert_response :success + assert_select "li", tartiflette.scoring_id.to_s + end +end diff --git a/test/controllers/scores_controller_test.rb b/test/controllers/scores_controller_test.rb new file mode 100644 index 0000000..8fb4cb8 --- /dev/null +++ b/test/controllers/scores_controller_test.rb @@ -0,0 +1,70 @@ +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) + end + + test "should get new score form" do + get new_tartiflette_score_path(@tartiflette) + assert_response :success + assert_select "form" + 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: { + scores: { @criterium.id => { value: nil } } + } + end + assert_response :unprocessable_entity + end + + test "should get edit scores form" do + get tartiflette_edit_scores_path(@tartiflette) + assert_response :success + assert_select "form" + assert_select "select[name=?]", "scores[#{@criterium.id}][value]" + end + + test "should update scores for tartiflette" do + patch tartiflette_update_scores_path(@tartiflette), params: { + scores: { @score.id => { value: 3 } } + } + assert_redirected_to root_path + @score.reload + assert_equal 3, @score.value + 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 +end |