1
0

block_spec.rb 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Block do
  4. describe 'Associations' do
  5. it { is_expected.to belong_to(:account).required }
  6. it { is_expected.to belong_to(:target_account).required }
  7. end
  8. describe '#local?' do
  9. it { is_expected.to_not be_local }
  10. end
  11. describe 'Callbacks' do
  12. describe 'Setting a URI' do
  13. context 'when URI exists' do
  14. subject { Fabricate.build :block, uri: 'https://uri/value' }
  15. it 'does not change' do
  16. expect { subject.save }
  17. .to not_change(subject, :uri)
  18. end
  19. end
  20. context 'when URI is blank' do
  21. subject { Fabricate.build :follow, uri: nil }
  22. it 'populates the value' do
  23. expect { subject.save }
  24. .to change(subject, :uri).to(be_present)
  25. end
  26. end
  27. end
  28. end
  29. it 'removes blocking cache after creation' do
  30. account = Fabricate(:account)
  31. target_account = Fabricate(:account)
  32. Rails.cache.write("exclude_account_ids_for:#{account.id}", [])
  33. Rails.cache.write("exclude_account_ids_for:#{target_account.id}", [])
  34. described_class.create!(account: account, target_account: target_account)
  35. expect(Rails.cache.exist?("exclude_account_ids_for:#{account.id}")).to be false
  36. expect(Rails.cache.exist?("exclude_account_ids_for:#{target_account.id}")).to be false
  37. end
  38. it 'removes blocking cache after destruction' do
  39. account = Fabricate(:account)
  40. target_account = Fabricate(:account)
  41. block = described_class.create!(account: account, target_account: target_account)
  42. Rails.cache.write("exclude_account_ids_for:#{account.id}", [target_account.id])
  43. Rails.cache.write("exclude_account_ids_for:#{target_account.id}", [account.id])
  44. block.destroy!
  45. expect(Rails.cache.exist?("exclude_account_ids_for:#{account.id}")).to be false
  46. expect(Rails.cache.exist?("exclude_account_ids_for:#{target_account.id}")).to be false
  47. end
  48. end