require "test_helper" class ScoresControllerTest < ActionDispatch::IntegrationTest setup do @tartiflette = tartiflettes(:one) @criterium = scoring_criteria(:one) @score = scores(:one) end test "should get new score form" do get new_tartiflette_score_path(@tartiflette) assert_response :success assert_select "form" assert_select "input[type=number][name=?]", "scores[#{@criterium.id}][value]" 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 "input[type=number][name=?]", "scores[#{@criterium.id}][value]" end test "should update scores for tartiflette" do patch tartiflette_update_scores_path(@tartiflette), params: { scores: { @score.id => { value: 5 } } } assert_redirected_to root_path @score.reload 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, "Score should not be updated with invalid data" end end