From 539938ba593b92e43194f22f7fe46ab799caf111 Mon Sep 17 00:00:00 2001 From: Natalie Tay Date: Wed, 9 Apr 2025 14:14:38 +0800 Subject: [PATCH] FIX: Solutions directory item was using post creation instead of solved creation (#361) Earlier on in the migration, the update of the user directory query was erroneously switched to use post creation date instead of the date the post was solved. This commit fixes that. --- plugin.rb | 2 +- spec/models/directory_item_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin.rb b/plugin.rb index 5a849cf..13f51a0 100644 --- a/plugin.rb +++ b/plugin.rb @@ -295,7 +295,7 @@ after_initialize do FROM discourse_solved_solved_topics AS st JOIN posts AS p ON p.id = st.answer_post_id - AND COALESCE(p.created_at, :since) > :since + AND COALESCE(st.created_at, :since) > :since AND p.deleted_at IS NULL JOIN topics AS t ON t.id = st.topic_id diff --git a/spec/models/directory_item_spec.rb b/spec/models/directory_item_spec.rb index 357987e..7e2034c 100644 --- a/spec/models/directory_item_spec.rb +++ b/spec/models/directory_item_spec.rb @@ -6,10 +6,10 @@ describe DirectoryItem, type: :model do fab!(:admin) fab!(:topic1) { Fabricate(:topic, archetype: "regular", user:) } - fab!(:topic_post1) { Fabricate(:post, topic: topic1, user:) } + fab!(:topic_post1) { Fabricate(:post, topic: topic1, user:, created_at: 10.years.ago) } fab!(:topic2) { Fabricate(:topic, archetype: "regular", user:) } - fab!(:topic_post2) { Fabricate(:post, topic: topic2, user:) } + fab!(:topic_post2) { Fabricate(:post, topic: topic2, user:, created_at: 10.years.ago) } fab!(:pm) { Fabricate(:topic, archetype: "private_message", user:, category_id: nil) } fab!(:pm_post) { Fabricate(:post, topic: pm, user:) } @@ -97,7 +97,7 @@ describe DirectoryItem, type: :model do expect( DirectoryItem.find_by( user_id: user.id, - period_type: DirectoryItem.period_types[:all], + period_type: DirectoryItem.period_types[:daily], ).solutions, ).to eq(1) end