FIX: do not expire policy accepted after renew at date (#10)

FIX: do not expire policy accepted after renew at date (#10)

diff --git a/jobs/scheduled/check_policy.rb b/jobs/scheduled/check_policy.rb
index 6ea15e5..ca267ab 100644
--- a/jobs/scheduled/check_policy.rb
+++ b/jobs/scheduled/check_policy.rb
@@ -40,7 +40,7 @@ module Jobs
       end
 
       PostPolicy.where("next_renew_at < ?", Time.zone.now).find_each do |policy|
-        policy.policy_users.accepted.update_all(expired_at: Time.zone.now)
+        policy.policy_users.accepted.where("accepted_at < ?", policy.next_renew_at).update_all(expired_at: Time.zone.now)
         next_renew = policy.renew_start
         if policy.renew_days < 1
           Rails.logger.warn("Invalid policy on post #{policy.post_id}")
diff --git a/spec/lib/check_policy_spec.rb b/spec/lib/check_policy_spec.rb
index 2baf717..6f1d9d7 100644
--- a/spec/lib/check_policy_spec.rb
+++ b/spec/lib/check_policy_spec.rb
@@ -140,10 +140,12 @@ describe DiscoursePolicy::CheckPolicy do
 
     freeze_time (Time.utc(2020, 10, 17) + 101.days)
 
+    PolicyUser.add!(user2, post.post_policy)
+
     DiscoursePolicy::CheckPolicy.new.execute
 
     post.reload
-    expect(post.post_policy.accepted_by.sort).to eq([])
+    expect(post.post_policy.accepted_by.sort).to eq([user2])
   end
 
   it "will correctly notify users" do

GitHub sha: 1d3de0f2

This commit appears in #10 which was merged by SamSaffron.