Skip to content

Commit f82c176

Browse files
committed
expanded :index test for the notifications controller to ensure notifications themselves are validated
1 parent 870bc8e commit f82c176

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

test/controllers/notifications_controller_test.rb

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,26 @@ class NotificationsControllerTest < ActionController::TestCase
55

66
test 'should get index as JSON' do
77
sign_in users(:standard_user)
8-
get :index, params: { format: :json }
9-
assert_not_nil assigns(:notifications)
10-
assert_response(:success)
8+
9+
[:json, :html].each do |format|
10+
try_index(format: format)
11+
12+
assert_response(:success)
13+
14+
if format == :html
15+
@notifications = assigns(:notifications)
16+
assert_not_nil @notifications
17+
else
18+
assert_valid_json_response
19+
notifications = JSON.parse(response.body)
20+
21+
notifications.each do |notification|
22+
assert notification['content'].present?
23+
assert notification['community_name'].present?
24+
end
25+
26+
end
27+
end
1128
end
1229

1330
test 'should mark notification as read' do
@@ -41,4 +58,10 @@ class NotificationsControllerTest < ActionController::TestCase
4158
get :index, params: { format: :json }
4259
assert_response(:unauthorized) # Devise seems to respond 401 for JSON requests.
4360
end
61+
62+
private
63+
64+
def try_index(format: :json)
65+
get :index, params: { format: format }
66+
end
4467
end

0 commit comments

Comments
 (0)