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.

57 lines
1.9 KiB

  1. require 'rails_helper'
  2. describe AccountFilter do
  3. describe 'with empty params' do
  4. it 'defaults to recent local not-suspended account list' do
  5. filter = described_class.new({})
  6. expect(filter.results).to eq Account.local.without_instance_actor.recent.without_suspended
  7. end
  8. end
  9. describe 'with invalid params' do
  10. it 'raises with key error' do
  11. filter = described_class.new(wrong: true)
  12. expect { filter.results }.to raise_error(/wrong/)
  13. end
  14. end
  15. describe 'with valid params' do
  16. it 'combines filters on Account' do
  17. filter = described_class.new(
  18. by_domain: 'test.com',
  19. silenced: true,
  20. username: 'test',
  21. display_name: 'name',
  22. email: 'user@example.com',
  23. )
  24. allow(Account).to receive(:where).and_return(Account.none)
  25. allow(Account).to receive(:silenced).and_return(Account.none)
  26. allow(Account).to receive(:matches_display_name).and_return(Account.none)
  27. allow(Account).to receive(:matches_username).and_return(Account.none)
  28. allow(User).to receive(:matches_email).and_return(User.none)
  29. filter.results
  30. expect(Account).to have_received(:where).with(domain: 'test.com')
  31. expect(Account).to have_received(:silenced)
  32. expect(Account).to have_received(:matches_username).with('test')
  33. expect(Account).to have_received(:matches_display_name).with('name')
  34. expect(User).to have_received(:matches_email).with('user@example.com')
  35. end
  36. describe 'that call account methods' do
  37. %i(local remote silenced suspended).each do |option|
  38. it "delegates the #{option} option" do
  39. allow(Account).to receive(option).and_return(Account.none)
  40. filter = described_class.new({ option => true })
  41. filter.results
  42. expect(Account).to have_received(option).at_least(1)
  43. end
  44. end
  45. end
  46. end
  47. end