diff options
author | ysksn <bluewhale1982@gmail.com> | 2018-12-08 00:37:56 +0900 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2018-12-07 16:37:56 +0100 |
commit | 51cbd045dab531725b448311ea52d0aec215a8f8 (patch) | |
tree | 5a546e3a6304ee6ee42e8c616f49e00020211114 /spec/models | |
parent | ecd303c097bf20aa971628ba8420a9f17f3dd1f7 (diff) |
Add specs for AccountTagStat model (#9452)
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/account_tag_stat_spec.rb | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/spec/models/account_tag_stat_spec.rb b/spec/models/account_tag_stat_spec.rb index f1ebc5578..6d3057f35 100644 --- a/spec/models/account_tag_stat_spec.rb +++ b/spec/models/account_tag_stat_spec.rb @@ -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 |