-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathsteps_controller_test.rb
More file actions
120 lines (94 loc) · 3.66 KB
/
Copy pathsteps_controller_test.rb
File metadata and controls
120 lines (94 loc) · 3.66 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
require "test_helper"
class Cards::StepsControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in_as :kevin
end
test "create" do
card = cards(:logo)
assert_difference -> { card.steps.count }, +1 do
assert_changes -> { card.reload.last_active_at } do
post card_steps_path(card), params: { step: { content: "Research alternatives" } }, as: :turbo_stream
assert_turbo_stream action: :before, target: dom_id(card, :new_step)
end
end
assert_equal "Research alternatives", card.steps.last.content
end
test "update" do
card = cards(:logo)
step = card.steps.create!(content: "Original content")
assert_changes -> { step.reload.content }, from: "Original content", to: "Updated content" do
assert_changes -> { card.reload.last_active_at } do
put card_step_path(card, step), params: { step: { content: "Updated content" } }, as: :turbo_stream
assert_turbo_stream action: :replace, target: dom_id(step)
end
end
end
test "destroy" do
card = cards(:logo)
step = card.steps.create!(content: "Step to delete")
assert_difference -> { card.steps.count }, -1 do
assert_changes -> { card.reload.last_active_at } do
delete card_step_path(card, step), as: :turbo_stream
assert_turbo_stream action: :remove, target: dom_id(step)
end
end
end
test "toggle completion" do
card = cards(:logo)
step = card.steps.create!(content: "Test step", completed: false)
# Toggle to completed
assert_changes -> { step.reload.completed? }, from: false, to: true do
assert_changes -> { card.reload.last_active_at } do
put card_step_path(card, step), params: { step: { completed: "1" } }, as: :turbo_stream
assert_turbo_stream action: :replace, target: dom_id(step)
end
end
# Toggle back to incomplete
assert_changes -> { step.reload.completed? }, from: true, to: false do
put card_step_path(card, step), params: { step: { completed: "0" } }, as: :turbo_stream
assert_turbo_stream action: :replace, target: dom_id(step)
end
end
test "index as JSON" do
card = cards(:logo)
card.steps.create!(content: "Step one")
card.steps.create!(content: "Step two", completed: true)
get card_steps_path(card), as: :json
assert_response :success
body = @response.parsed_body
assert_equal 2, body.size
assert_equal "Step one", body.first["content"]
end
test "create as JSON" do
card = cards(:logo)
assert_difference -> { card.steps.count }, +1 do
post card_steps_path(card), params: { step: { content: "New step" } }, as: :json
end
assert_response :created
assert_equal card_step_path(card, Step.last, format: :json), @response.headers["Location"]
assert_equal "New step", @response.parsed_body["content"]
end
test "show as JSON" do
card = cards(:logo)
step = card.steps.create!(content: "Test step")
get card_step_path(card, step), as: :json
assert_response :success
assert_equal step.id, @response.parsed_body["id"]
assert_equal "Test step", @response.parsed_body["content"]
end
test "update as JSON" do
card = cards(:logo)
step = card.steps.create!(content: "Original")
put card_step_path(card, step), params: { step: { content: "Updated" } }, as: :json
assert_response :success
assert_equal "Updated", step.reload.content
assert_equal "Updated", @response.parsed_body["content"]
end
test "destroy as JSON" do
card = cards(:logo)
step = card.steps.create!(content: "To delete")
delete card_step_path(card, step), as: :json
assert_response :no_content
assert_not Step.exists?(step.id)
end
end