]> cat aescling's git repositories - mastodon.git/commitdiff
Add specs for AccountTagStat model (#9452)
authorysksn <bluewhale1982@gmail.com>
Fri, 7 Dec 2018 15:37:56 +0000 (00:37 +0900)
committerEugen Rochko <eugen@zeonfederated.com>
Fri, 7 Dec 2018 15:37:56 +0000 (16:37 +0100)
spec/models/account_tag_stat_spec.rb

index f1ebc557834fabd34a982a758612430ef2debc07..6d3057f3555eb808993d763e4f26edafadc2451c 100644 (file)
@@ -1,5 +1,38 @@
+# frozen_string_literal: true
+
 require 'rails_helper'
 
 RSpec.describe AccountTagStat, type: :model do
-  pending "add some examples to (or delete) #{__FILE__}"
+  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