1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
|