about summary refs log tree commit diff
path: root/spec/models/account_tag_stat_spec.rb
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2018-12-09 13:28:09 +0100
committerThibaut Girka <thib@sitedethib.com>2018-12-09 16:08:04 +0100
commite7f1bfdc2d528f137299ba0c3ab2a30f2f91f53c (patch)
tree2693ffce4d340a9b77a7ca52c856aaae7af8c913 /spec/models/account_tag_stat_spec.rb
parente3682c9c1750e5e7e5d2f817e29f6760a18400ca (diff)
parent81bda7d67c984c9bfcb5bca94e50cec6405b492e (diff)
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts:
- app/javascript/packs/public.js
- app/models/user.rb
- config/settings.yml
- db/schema.rb

Moved public.js changes to settings.js.
Diffstat (limited to 'spec/models/account_tag_stat_spec.rb')
-rw-r--r--spec/models/account_tag_stat_spec.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/spec/models/account_tag_stat_spec.rb b/spec/models/account_tag_stat_spec.rb
new file mode 100644
index 000000000..6d3057f35
--- /dev/null
+++ b/spec/models/account_tag_stat_spec.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+RSpec.describe AccountTagStat, type: :model do
+  key = 'accounts_count'
+  let(:account_tag_stat) { Fabricate(:tag).account_tag_stat }
+
+  describe '#increment_count!' do
+    it 'calls #update' do
+      args = { key => account_tag_stat.public_send(key) + 1 }
+      expect(account_tag_stat).to receive(:update).with(args)
+      account_tag_stat.increment_count!(key)
+    end
+
+    it 'increments value by 1' do
+      expect do
+        account_tag_stat.increment_count!(key)
+      end.to change { account_tag_stat.accounts_count }.by(1)
+    end
+  end
+
+  describe '#decrement_count!' do
+    it 'calls #update' do
+      args = { key => [account_tag_stat.public_send(key) - 1, 0].max }
+      expect(account_tag_stat).to receive(:update).with(args)
+      account_tag_stat.decrement_count!(key)
+    end
+
+    it 'decrements value by 1' do
+      account_tag_stat.update(key => 1)
+
+      expect do
+        account_tag_stat.decrement_count!(key)
+      end.to change { account_tag_stat.accounts_count }.by(-1)
+    end
+  end
+end