logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

account_filter_spec.rb (2343B)


  1. require 'rails_helper'
  2. describe AccountFilter do
  3. describe 'with empty params' do
  4. it 'defaults to alphabetic account list' do
  5. filter = described_class.new({})
  6. expect(filter.results).to eq Account.alphabetic
  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 'when an IP address is provided' do
  16. it 'filters with IP when valid' do
  17. filter = described_class.new(ip: '127.0.0.1')
  18. allow(User).to receive(:with_recent_ip_address).and_return(User.none)
  19. filter.results
  20. expect(User).to have_received(:with_recent_ip_address).with('127.0.0.1')
  21. end
  22. it 'skips IP when invalid' do
  23. filter = described_class.new(ip: '345.678.901.234')
  24. expect(User).not_to receive(:with_recent_ip_address)
  25. filter.results
  26. end
  27. end
  28. describe 'with valid params' do
  29. it 'combines filters on Account' do
  30. filter = described_class.new(
  31. by_domain: 'test.com',
  32. silenced: true,
  33. username: 'test',
  34. display_name: 'name',
  35. email: 'user@example.com',
  36. )
  37. allow(Account).to receive(:where).and_return(Account.none)
  38. allow(Account).to receive(:silenced).and_return(Account.none)
  39. allow(Account).to receive(:matches_display_name).and_return(Account.none)
  40. allow(Account).to receive(:matches_username).and_return(Account.none)
  41. allow(User).to receive(:matches_email).and_return(User.none)
  42. filter.results
  43. expect(Account).to have_received(:where).with(domain: 'test.com')
  44. expect(Account).to have_received(:silenced)
  45. expect(Account).to have_received(:matches_username).with('test')
  46. expect(Account).to have_received(:matches_display_name).with('name')
  47. expect(User).to have_received(:matches_email).with('user@example.com')
  48. end
  49. describe 'that call account methods' do
  50. %i(local remote silenced recent suspended).each do |option|
  51. it "delegates the #{option} option" do
  52. allow(Account).to receive(option).and_return(Account.none)
  53. filter = described_class.new({ option => true })
  54. filter.results
  55. expect(Account).to have_received(option)
  56. end
  57. end
  58. end
  59. end
  60. end