about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2023-02-09 12:46:12 +0100
committerClaire <claire.github-309c@sitedethib.com>2023-02-09 12:46:12 +0100
commit85558a5e18a58247606954050a5866e62c877f91 (patch)
tree982808241c0f64c20f8eec9b1ce5651b3c5195da /spec
parent76b4e7727b7497c1b68e06133831701f8950ae19 (diff)
parentc5a4d8c82ddd5265abc830959a58cdaf1f061a43 (diff)
Merge branch 'main' into glitch-soc/merge-upstream
Conflicts:
- `README.md`:
  Minor upstream change, our README is completely different.
  Kept ours.
- `lib/tasks/assets.rake`:
  glitch-soc has extra code to deal with its theming system,
  upstream changed a line that exists in glitch-soc.
  Applied upstream changes.
Diffstat (limited to 'spec')
-rw-r--r--spec/models/concerns/remotable_spec.rb4
-rw-r--r--spec/models/session_activation_spec.rb4
-rw-r--r--spec/rails_helper.rb2
-rw-r--r--spec/workers/scheduler/user_cleanup_scheduler_spec.rb39
4 files changed, 45 insertions, 4 deletions
diff --git a/spec/models/concerns/remotable_spec.rb b/spec/models/concerns/remotable_spec.rb
index 9cc849ded..ca2d65d2d 100644
--- a/spec/models/concerns/remotable_spec.rb
+++ b/spec/models/concerns/remotable_spec.rb
@@ -194,7 +194,9 @@ RSpec.describe Remotable do
           let(:error_class) { error_class }
 
           it 'calls Rails.logger.debug' do
-            expect(Rails.logger).to receive(:debug).with(/^Error fetching remote #{hoge}: /)
+            expect(Rails.logger).to receive(:debug) do |&block|
+              expect(block.call).to match(/^Error fetching remote #{hoge}: /)
+            end
             foo.hoge_remote_url = url
           end
         end
diff --git a/spec/models/session_activation_spec.rb b/spec/models/session_activation_spec.rb
index 450dc1399..8db06c622 100644
--- a/spec/models/session_activation_spec.rb
+++ b/spec/models/session_activation_spec.rb
@@ -118,8 +118,8 @@ RSpec.describe SessionActivation, type: :model do
     let(:id) { '1' }
 
     it 'calls where.destroy_all' do
-      expect(described_class).to receive_message_chain(:where, :destroy_all)
-        .with('session_id != ?', id).with(no_args)
+      expect(described_class).to receive_message_chain(:where, :not, :destroy_all)
+        .with(session_id: id).with(no_args)
 
       described_class.exclusive(id)
     end
diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb
index 02827a388..c197bc007 100644
--- a/spec/rails_helper.rb
+++ b/spec/rails_helper.rb
@@ -1,5 +1,5 @@
 ENV['RAILS_ENV'] ||= 'test'
-require File.expand_path('../../config/environment', __FILE__)
+require File.expand_path('../config/environment', __dir__)
 
 abort("The Rails environment is running in production mode!") if Rails.env.production?
 
diff --git a/spec/workers/scheduler/user_cleanup_scheduler_spec.rb b/spec/workers/scheduler/user_cleanup_scheduler_spec.rb
new file mode 100644
index 000000000..da99f10f9
--- /dev/null
+++ b/spec/workers/scheduler/user_cleanup_scheduler_spec.rb
@@ -0,0 +1,39 @@
+require 'rails_helper'
+
+describe Scheduler::UserCleanupScheduler do
+  subject { described_class.new }
+
+  let!(:new_unconfirmed_user) { Fabricate(:user) }
+  let!(:old_unconfirmed_user) { Fabricate(:user) }
+  let!(:confirmed_user)       { Fabricate(:user) }
+  let!(:moderation_note)      { Fabricate(:account_moderation_note, account: Fabricate(:account), target_account: old_unconfirmed_user.account) }
+
+  describe '#perform' do
+    before do
+      # Need to update the already-existing users because their initialization overrides confirmation_sent_at
+      new_unconfirmed_user.update!(confirmed_at: nil, confirmation_sent_at: Time.now.utc)
+      old_unconfirmed_user.update!(confirmed_at: nil, confirmation_sent_at: 1.week.ago)
+      confirmed_user.update!(confirmed_at: 1.day.ago)
+    end
+
+    it 'deletes the old unconfirmed user' do
+      expect { subject.perform }.to change { User.exists?(old_unconfirmed_user.id) }.from(true).to(false)
+    end
+
+    it "deletes the old unconfirmed user's account" do
+      expect { subject.perform }.to change { Account.exists?(old_unconfirmed_user.account_id) }.from(true).to(false)
+    end
+
+    it 'does not delete the new unconfirmed user or their account' do
+      subject.perform
+      expect(User.exists?(new_unconfirmed_user.id)).to be true
+      expect(Account.exists?(new_unconfirmed_user.account_id)).to be true
+    end
+
+    it 'does not delete the confirmed user or their account' do
+      subject.perform
+      expect(User.exists?(confirmed_user.id)).to be true
+      expect(Account.exists?(confirmed_user.account_id)).to be true
+    end
+  end
+end