You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.0 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe AccountTagStat, type: :model do
  4. key = 'accounts_count'
  5. let(:account_tag_stat) { Fabricate(:tag).account_tag_stat }
  6. describe '#increment_count!' do
  7. it 'calls #update' do
  8. args = { key => account_tag_stat.public_send(key) + 1 }
  9. expect(account_tag_stat).to receive(:update).with(args)
  10. account_tag_stat.increment_count!(key)
  11. end
  12. it 'increments value by 1' do
  13. expect do
  14. account_tag_stat.increment_count!(key)
  15. end.to change { account_tag_stat.accounts_count }.by(1)
  16. end
  17. end
  18. describe '#decrement_count!' do
  19. it 'calls #update' do
  20. args = { key => [account_tag_stat.public_send(key) - 1, 0].max }
  21. expect(account_tag_stat).to receive(:update).with(args)
  22. account_tag_stat.decrement_count!(key)
  23. end
  24. it 'decrements value by 1' do
  25. account_tag_stat.update(key => 1)
  26. expect do
  27. account_tag_stat.decrement_count!(key)
  28. end.to change { account_tag_stat.accounts_count }.by(-1)
  29. end
  30. end
  31. end