about summary refs log tree commit diff
path: root/spec/models
diff options
context:
space:
mode:
authorStarfall <us@starfall.systems>2021-04-02 15:04:35 -0500
committerStarfall <us@starfall.systems>2021-04-02 15:04:35 -0500
commitaeb0f34cefd88caaaa51e8250e1f6ddde280c4bb (patch)
tree15dafdc2cdfd9e78e72e461440b593c3fc89788e /spec/models
parent0f7be4b48947a9edcbb6fb84d5d0fd9150ee0870 (diff)
parentb7ec2a900251410c65ba214b50c1657209285b07 (diff)
Merge branch 'glitch'
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/account_spec.rb27
-rw-r--r--spec/models/account_stat_spec.rb57
-rw-r--r--spec/models/concerns/account_counters_spec.rb60
-rw-r--r--spec/models/setting_spec.rb11
-rw-r--r--spec/models/user_spec.rb4
5 files changed, 68 insertions, 91 deletions
diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb
index 1d000ed4d..03d6f5fb0 100644
--- a/spec/models/account_spec.rb
+++ b/spec/models/account_spec.rb
@@ -134,18 +134,6 @@ RSpec.describe Account, type: :model do
     end
   end
 
-  describe '#subscribed?' do
-    it 'returns false when no subscription expiration information is present' do
-      account = Fabricate(:account, subscription_expires_at: nil)
-      expect(account.subscribed?).to be false
-    end
-
-    it 'returns true when subscription expiration has been set' do
-      account = Fabricate(:account, subscription_expires_at: 30.days.from_now)
-      expect(account.subscribed?).to be true
-    end
-  end
-
   describe '#possibly_stale?' do
     let(:account) { Fabricate(:account, last_webfingered_at: last_webfingered_at) }
 
@@ -707,21 +695,6 @@ RSpec.describe Account, type: :model do
       end
     end
 
-    describe 'expiring' do
-      it 'returns remote accounts with followers whose subscription expiration date is past or not given' do
-        local = Fabricate(:account, domain: nil)
-        matches = [
-          { domain: 'remote', subscription_expires_at: '2000-01-01T00:00:00Z' },
-        ].map(&method(:Fabricate).curry(2).call(:account))
-        matches.each(&local.method(:follow!))
-        Fabricate(:account, domain: 'remote', subscription_expires_at: nil)
-        local.follow!(Fabricate(:account, domain: 'remote', subscription_expires_at: '2000-01-03T00:00:00Z'))
-        local.follow!(Fabricate(:account, domain: nil, subscription_expires_at: nil))
-
-        expect(Account.expiring('2000-01-02T00:00:00Z').recent).to eq matches.reverse
-      end
-    end
-
     describe 'remote' do
       it 'returns an array of accounts who have a domain' do
         account_1 = Fabricate(:account, domain: nil)
diff --git a/spec/models/account_stat_spec.rb b/spec/models/account_stat_spec.rb
deleted file mode 100644
index 8adc0d1d6..000000000
--- a/spec/models/account_stat_spec.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-require 'rails_helper'
-
-RSpec.describe AccountStat, type: :model do
-  describe '#increment_count!' do
-    it 'increments the count' do
-      account_stat = AccountStat.create(account: Fabricate(:account))
-      expect(account_stat.followers_count).to eq 0
-      account_stat.increment_count!(:followers_count)
-      expect(account_stat.followers_count).to eq 1
-    end
-
-    it 'increments the count in multi-threaded an environment' do
-      account_stat   = AccountStat.create(account: Fabricate(:account), statuses_count: 0)
-      increment_by   = 15
-      wait_for_start = true
-
-      threads = Array.new(increment_by) do
-        Thread.new do
-          true while wait_for_start
-          AccountStat.find(account_stat.id).increment_count!(:statuses_count)
-        end
-      end
-
-      wait_for_start = false
-      threads.each(&:join)
-
-      expect(account_stat.reload.statuses_count).to eq increment_by
-    end
-  end
-
-  describe '#decrement_count!' do
-    it 'decrements the count' do
-      account_stat = AccountStat.create(account: Fabricate(:account), followers_count: 15)
-      expect(account_stat.followers_count).to eq 15
-      account_stat.decrement_count!(:followers_count)
-      expect(account_stat.followers_count).to eq 14
-    end
-
-    it 'decrements the count in multi-threaded an environment' do
-      account_stat   = AccountStat.create(account: Fabricate(:account), statuses_count: 15)
-      decrement_by   = 10
-      wait_for_start = true
-
-      threads = Array.new(decrement_by) do
-        Thread.new do
-          true while wait_for_start
-          AccountStat.find(account_stat.id).decrement_count!(:statuses_count)
-        end
-      end
-
-      wait_for_start = false
-      threads.each(&:join)
-
-      expect(account_stat.reload.statuses_count).to eq 5
-    end
-  end
-end
diff --git a/spec/models/concerns/account_counters_spec.rb b/spec/models/concerns/account_counters_spec.rb
new file mode 100644
index 000000000..4350496e7
--- /dev/null
+++ b/spec/models/concerns/account_counters_spec.rb
@@ -0,0 +1,60 @@
+require 'rails_helper'
+
+describe AccountCounters do
+  let!(:account) { Fabricate(:account) }
+
+  describe '#increment_count!' do
+    it 'increments the count' do
+      expect(account.followers_count).to eq 0
+      account.increment_count!(:followers_count)
+      expect(account.followers_count).to eq 1
+    end
+
+    it 'increments the count in multi-threaded an environment' do
+      increment_by   = 15
+      wait_for_start = true
+
+      threads = Array.new(increment_by) do
+        Thread.new do
+          true while wait_for_start
+          account.increment_count!(:statuses_count)
+        end
+      end
+
+      wait_for_start = false
+      threads.each(&:join)
+
+      expect(account.statuses_count).to eq increment_by
+    end
+  end
+
+  describe '#decrement_count!' do
+    it 'decrements the count' do
+      account.followers_count = 15
+      account.save!
+      expect(account.followers_count).to eq 15
+      account.decrement_count!(:followers_count)
+      expect(account.followers_count).to eq 14
+    end
+
+    it 'decrements the count in multi-threaded an environment' do
+      decrement_by   = 10
+      wait_for_start = true
+
+      account.statuses_count = 15
+      account.save!
+
+      threads = Array.new(decrement_by) do
+        Thread.new do
+          true while wait_for_start
+          account.decrement_count!(:statuses_count)
+        end
+      end
+
+      wait_for_start = false
+      threads.each(&:join)
+
+      expect(account.statuses_count).to eq 5
+    end
+  end
+end
diff --git a/spec/models/setting_spec.rb b/spec/models/setting_spec.rb
index 1cc528674..3ccc21d6c 100644
--- a/spec/models/setting_spec.rb
+++ b/spec/models/setting_spec.rb
@@ -99,11 +99,12 @@ RSpec.describe Setting, type: :model do
         end
 
         it 'does not query the database' do
-          expect do |callback|
-            ActiveSupport::Notifications.subscribed callback, 'sql.active_record' do
-              described_class[key]
-            end
-          end.not_to yield_control
+          callback = double
+          allow(callback).to receive(:call)
+          ActiveSupport::Notifications.subscribed callback, 'sql.active_record' do
+            described_class[key]
+          end
+          expect(callback).not_to have_received(:call)
         end
 
         it 'returns the cached value' do
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index cded4c99b..5db249be2 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -175,7 +175,7 @@ RSpec.describe User, type: :model do
       user = Fabricate(:user)
       ActiveJob::Base.queue_adapter = :test
 
-      expect { user.send_confirmation_instructions }.to have_enqueued_job(ActionMailer::DeliveryJob)
+      expect { user.send_confirmation_instructions }.to have_enqueued_job(ActionMailer::MailDeliveryJob)
     end
   end
 
@@ -206,7 +206,7 @@ RSpec.describe User, type: :model do
 
   describe 'whitelist' do
     around(:each) do |example|
-      old_whitelist = Rails.configuration.x.email_whitelist
+      old_whitelist = Rails.configuration.x.email_domains_whitelist
 
       Rails.configuration.x.email_domains_whitelist = 'mastodon.space'