Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: better notification level on assign #601

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/assigner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,15 +312,15 @@ def assign(
publish_assignment(assignment, assign_to, note, status)

if assignment.assigned_to_user?
if !TopicUser.exists?(
user_id: assign_to.id,
topic_id: topic.id,
notification_level: TopicUser.notification_levels[:watching],
)
notification_level =
assign_to.user_option&.notification_level_when_replying ||
TopicUser.notification_levels[:watching]

if !TopicUser.exists?(user_id: assign_to.id, topic_id: topic.id, notification_level:)
TopicUser.change(
assign_to.id,
topic.id,
notification_level: TopicUser.notification_levels[:watching],
notification_level:,
notifications_reason_id: TopicUser.notification_reasons[:plugin_changed],
)
end
Expand Down
42 changes: 30 additions & 12 deletions spec/lib/assigner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,34 @@
[topic],
)

expect(TopicUser.find_by(user: moderator).notification_level).to eq(
TopicUser.notification_levels[:watching],
)
notification_level = moderator.user_option.notification_level_when_replying

expect(TopicUser.find_by(user: moderator).notification_level).to eq(notification_level)

expect_enqueued_with(job: :unassign_notification) { assigner.unassign }

expect(TopicQuery.new(moderator, assigned: moderator.username).list_latest.topics).to eq([])

expect(TopicUser.find_by(user: moderator).notification_level).to eq(notification_level)
end

it "uses the notification_level_when_replying of the assignee" do
moderator.user_option.update!(
notification_level_when_replying: TopicUser.notification_levels[:regular],
)

assigner.assign(moderator)

expect(TopicUser.find_by(user: moderator).notification_level).to eq(
TopicUser.notification_levels[:regular],
)
end

it "defaults the notification level to watching" do
moderator.user_option.update!(notification_level_when_replying: nil)

assigner.assign(moderator)

expect(TopicUser.find_by(user: moderator).notification_level).to eq(
TopicUser.notification_levels[:watching],
)
Expand Down Expand Up @@ -111,28 +131,26 @@
end

it "does not update notification level if already watching" do
TopicUser.change(
moderator.id,
topic.id,
notification_level: TopicUser.notification_levels[:watching],
)
notification_level = moderator.user_option.notification_level_when_replying

TopicUser.change(moderator.id, topic.id, notification_level:)

expect do assigner_self.assign(moderator) end.to_not change {
TopicUser.last.notifications_reason_id
}
end

it "does not update notification level when unassigned" do
notification_level = moderator.user_option.notification_level_when_replying

assigner.assign(moderator)

expect(TopicUser.find_by(user: moderator).notification_level).to eq(
TopicUser.notification_levels[:watching],
)
expect(TopicUser.find_by(user: moderator).notification_level).to eq(notification_level)

assigner.unassign

expect(TopicUser.find_by(user: moderator, topic: topic).notification_level).to eq(
TopicUser.notification_levels[:watching],
notification_level,
)
end

Expand Down