-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpuzzles_controller_test.rb
More file actions
54 lines (44 loc) · 1.29 KB
/
puzzles_controller_test.rb
File metadata and controls
54 lines (44 loc) · 1.29 KB
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
require "test_helper"
class PuzzlesControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
sign_in
get puzzles_path
assert_response :success
end
test "unauthenticated request renders login page" do
get puzzles_path
assert_response :success
assert_match "login", response.body.downcase
end
test "should show error message when editing puzzle with invalid data" do
puzzle = puzzles(:one)
sign_in
patch puzzle_path(puzzle), params: {
puzzle: {
question: "",
answer: "rails",
explanation: "Updated explanation",
link: "https://example.com"
}
}, as: :turbo_stream
assert_response :unprocessable_entity
assert_select "div.field-error", "can't be blank"
assert_select "textarea.error"
end
test "should successfully update puzzle with valid data" do
puzzle = puzzles(:one)
sign_in
patch puzzle_path(puzzle), params: {
puzzle: {
question: "Updated question",
answer: "rails",
explanation: "Updated explanation",
link: "https://example.com"
}
}, as: :turbo_stream
assert_response :success
puzzle.reload
assert_equal "Updated question", puzzle.question
assert_equal "Updated explanation", puzzle.explanation
end
end