Skip to content

Commit 30817e4

Browse files
authored
Merge pull request #1801 from codidact/0valt/notifications-fix
Fix for inbox notifications community_name
2 parents d542bfd + f82c176 commit 30817e4

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

app/controllers/notifications_controller.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ def index
1111
format.html { render :index, layout: 'without_sidebar' }
1212
format.json do
1313
render json: (@notifications.to_a.map do |notif|
14-
notif.as_json.merge(content: helpers.render_pings_text(notif.content))
15-
end), methods: :community_name
14+
notif.as_json.merge(content: helpers.render_pings_text(notif.content),
15+
community_name: notif.community_name)
16+
end)
1617
end
1718
end
1819
end

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)