Skip to content

Commit

Permalink
Fix group mentions in notifications (#8598)
Browse files Browse the repository at this point in the history
* Fix group mention in notifications

* Remove loading group unused code

* Refact notification factory trait
  • Loading branch information
quinHD committed Dec 16, 2021
1 parent 5bf0dec commit 45f3bce
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
Expand Up @@ -56,7 +56,7 @@ def notify_mentioned_groups
affected_users = group.accepted_users - already_notified_users
@already_notified_users += affected_users

notify(:user_group_mentioned, affected_users: affected_users, extra: { group: group })
notify(:user_group_mentioned, affected_users: affected_users, extra: { group_id: group.id })
end
end

Expand Down
Expand Up @@ -10,7 +10,7 @@
let(:extra) do
{
comment_id: comment.id,
group: group
group_id: group.id
}
end

Expand Down
Expand Up @@ -146,7 +146,7 @@
affected_users: a_collection_containing_exactly(*affected_group_users),
extra: {
comment_id: comment.id,
group: group
group_id: group.id
}
)
expect(Decidim::EventsManager)
Expand Down Expand Up @@ -198,7 +198,7 @@
affected_users: a_collection_containing_exactly(*affected_group_users),
extra: {
comment_id: comment.id,
group: group
group_id: group.id
}
)
expect(Decidim::EventsManager)
Expand Down Expand Up @@ -232,7 +232,7 @@
affected_users: a_collection_containing_exactly(*affected_group_users),
extra: {
comment_id: comment.id,
group: group
group_id: group.id
}
)

Expand Down
4 changes: 1 addition & 3 deletions decidim-core/lib/decidim/events/user_group_event.rb
Expand Up @@ -35,9 +35,7 @@ def group_presenter
end

def group
return unless extra[:group].is_a?(Decidim::UserGroup)

extra[:group]
@group ||= Decidim::UserGroup.find_by(id: extra[:group_id]) if extra[:group_id]
end
end
end
Expand Down
19 changes: 19 additions & 0 deletions decidim-core/spec/system/notifications_spec.rb
Expand Up @@ -111,4 +111,23 @@
end
end
end

context "with user group mentioned notifications" do
let(:event_class) { "Decidim::Comments::UserGroupMentionedEvent" }
let(:event_name) { "decidim.events.comments.user_group_mentioned" }
let(:extra) { { comment_id: create(:comment).id, group_id: create(:user_group).id } }
let!(:notification) { create :notification, user: user, event_class: event_class, event_name: event_name, extra: extra }

before do
page.visit decidim.notifications_path
end

it "shows the notification with the group mentioned" do
group = Decidim::UserGroup.find(notification.extra["group_id"])
element = page.find(".card-data__item--expand")
notification_text = element.text

expect(notification_text).to end_with("as a member of #{group.name} @#{group.nickname}")
end
end
end

0 comments on commit 45f3bce

Please sign in to comment.