Skip to content
Permalink
Browse files

FIX: Don't update `watching_first_post` notifications when moving fir…

…st post

The first post isn't moved. It gets copied during a move. Notifications of this special type should still link to the original first post.
  • Loading branch information...
gschlager committed Aug 12, 2019
1 parent 5981678 commit 2a95c5c5d6ce62fda41d3d79aa2f9fbba2d0613a
Showing with 26 additions and 0 deletions.
  1. +1 −0 app/models/post_mover.rb
  2. +14 −0 spec/fabricators/notification_fabricator.rb
  3. +11 −0 spec/models/post_mover_spec.rb
@@ -238,6 +238,7 @@ def move_notifications
)) :: JSON
FROM moved_posts mp
WHERE n.topic_id = mp.old_topic_id AND n.post_number = mp.old_post_number
AND n.notification_type <> #{Notification.types[:watching_first_post]}
SQL
end

@@ -72,3 +72,17 @@
}.to_json
end
end

Fabricator(:watching_first_post_notification, from: :notification) do
notification_type Notification.types[:watching_first_post]
data do |attrs|
{
topic_title: attrs[:topic].title,
original_post_id: attrs[:post].id,
original_post_type: attrs[:post].post_type,
original_username: attrs[:post].user.username,
revision_number: nil,
display_username: attrs[:post].user.username
}.to_json
end
end
@@ -312,6 +312,17 @@
expect(n4.post_number).to eq(4)
end

it "doesn't update notifications of type 'watching_first_post'" do
n1 = Fabricate(:watching_first_post_notification, post: p1, user: another_user)

topic.move_posts(user, [p1.id], title: "new testing topic name")

n1.reload
expect(n1.topic_id).to eq(topic.id)
expect(n1.data_hash[:topic_title]).to eq(topic.title)
expect(n1.post_number).to eq(1)
end

it "deletes notifications for users not allowed to see the topic" do
another_admin = Fabricate(:admin)
staff_category = Fabricate(:private_category, group: Group[:staff])

0 comments on commit 2a95c5c

Please sign in to comment.
You can’t perform that action at this time.