-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathcards_controller_test.rb
More file actions
135 lines (105 loc) · 3.44 KB
/
cards_controller_test.rb
File metadata and controls
135 lines (105 loc) · 3.44 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
require "test_helper"
class CardsControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in_as :kevin
end
test "index" do
get cards_path
assert_response :success
end
test "filtered index" do
get cards_path(filters(:jz_assignments).as_params.merge(term: "haggis"))
assert_response :success
end
test "create a new draft" do
assert_difference -> { Card.count }, 1 do
post board_cards_path(boards(:writebook))
end
card = Card.last
assert card.drafted?
assert_redirected_to card
end
test "create resumes existing draft if it exists" do
draft = boards(:writebook).cards.create!(creator: users(:kevin), status: :drafted)
assert_no_difference -> { Card.count } do
post board_cards_path(boards(:writebook))
end
assert_redirected_to draft
end
test "show" do
get card_path(cards(:logo))
assert_response :success
end
test "edit" do
get edit_card_path(cards(:logo))
assert_response :success
end
test "update" do
patch card_path(cards(:logo)), as: :turbo_stream, params: {
card: {
title: "Logo needs to change",
image: fixture_file_upload("moon.jpg", "image/jpeg"),
description: "Something more in-depth",
tag_ids: [ tags(:mobile).id ] } }
assert_response :success
card = cards(:logo).reload
assert_equal "Logo needs to change", card.title
assert_equal "moon.jpg", card.image.filename.to_s
assert_equal [ tags(:mobile) ], card.tags
assert_equal "Something more in-depth", card.description.to_plain_text.strip
end
test "users can only see cards in boards they have access to" do
get card_path(cards(:logo))
assert_response :success
boards(:writebook).update! all_access: false
boards(:writebook).accesses.revoke_from users(:kevin)
get card_path(cards(:logo))
assert_response :not_found
end
test "admins can see delete button on any card" do
get card_path(cards(:logo))
assert_response :success
assert_match "Delete this card", response.body
end
test "card creators can see delete button on their own cards" do
logout_and_sign_in_as :david
get card_path(cards(:logo))
assert_response :success
assert_match "Delete this card", response.body
end
test "non-admins cannot see delete button on cards they did not create" do
logout_and_sign_in_as :jz
get card_path(cards(:logo))
assert_response :success
assert_no_match "Delete this card", response.body
end
test "non-admins cannot delete cards they did not create" do
logout_and_sign_in_as :jz
assert_no_difference -> { Card.count } do
delete card_path(cards(:logo))
end
assert_response :forbidden
end
test "card creators can delete their own cards" do
logout_and_sign_in_as :david
assert_difference -> { Card.count }, -1 do
delete card_path(cards(:logo))
end
assert_redirected_to boards(:writebook)
end
test "admins can delete any card" do
assert_difference -> { Card.count }, -1 do
delete card_path(cards(:logo))
end
assert_redirected_to boards(:writebook)
end
test "show card with comment containing malformed remote image attachment" do
card = cards(:logo)
card.comments.create!(
creator: users(:kevin),
body: '<action-text-attachment url="image.png" content-type="image/*" presentation="gallery"></action-text-attachment>'
)
get card_path(card)
assert_response :success
end
end