block_spec.rb 1.6 KB

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