about summary refs log tree commit diff
path: root/spec/models
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2021-03-19 13:57:15 +0100
committerClaire <claire.github-309c@sitedethib.com>2021-03-19 13:57:15 +0100
commit3ad6ef72cb3a02135a0f395a8a46323e86c4b334 (patch)
treeff1f1d15a80f5420c52afd4d975b44c0afe1194e /spec/models
parentba22398c38067e05f141a0dddeb20bf68913988a (diff)
parent741d0952b174740e70a09fe6db6862624dfe1e44 (diff)
Merge branch 'main' into glitch-soc/merge-upstream
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/account_stat_spec.rb57
-rw-r--r--spec/models/concerns/account_counters_spec.rb60
2 files changed, 60 insertions, 57 deletions
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