block_spec.rb 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Block do
  4. describe 'validations' do
  5. it 'is invalid without an account' do
  6. block = Fabricate.build(:block, account: nil)
  7. block.valid?
  8. expect(block).to model_have_error_on_field(:account)
  9. end
  10. it 'is invalid without a target_account' do
  11. block = Fabricate.build(:block, target_account: nil)
  12. block.valid?
  13. expect(block).to model_have_error_on_field(:target_account)
  14. end
  15. end
  16. it 'removes blocking cache after creation' do
  17. account = Fabricate(:account)
  18. target_account = Fabricate(:account)
  19. Rails.cache.write("exclude_account_ids_for:#{account.id}", [])
  20. Rails.cache.write("exclude_account_ids_for:#{target_account.id}", [])
  21. described_class.create!(account: account, target_account: target_account)
  22. expect(Rails.cache.exist?("exclude_account_ids_for:#{account.id}")).to be false
  23. expect(Rails.cache.exist?("exclude_account_ids_for:#{target_account.id}")).to be false
  24. end
  25. it 'removes blocking cache after destruction' do
  26. account = Fabricate(:account)
  27. target_account = Fabricate(:account)
  28. block = described_class.create!(account: account, target_account: target_account)
  29. Rails.cache.write("exclude_account_ids_for:#{account.id}", [target_account.id])
  30. Rails.cache.write("exclude_account_ids_for:#{target_account.id}", [account.id])
  31. block.destroy!
  32. expect(Rails.cache.exist?("exclude_account_ids_for:#{account.id}")).to be false
  33. expect(Rails.cache.exist?("exclude_account_ids_for:#{target_account.id}")).to be false
  34. end
  35. end