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.

37 lines
1.2 KiB

  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe RelationshipFilter do
  4. let(:account) { Fabricate(:account) }
  5. describe '#results' do
  6. context 'when default params are used' do
  7. let(:subject) do
  8. RelationshipFilter.new(account, 'order' => 'active').results
  9. end
  10. before do
  11. add_following_account_with(last_status_at: 7.days.ago)
  12. add_following_account_with(last_status_at: 1.day.ago)
  13. add_following_account_with(last_status_at: 3.days.ago)
  14. end
  15. it 'returns followings ordered by last activity' do
  16. expected_result = account.following.eager_load(:account_stat).reorder(nil).by_recent_status
  17. expect(subject).to eq expected_result
  18. end
  19. end
  20. end
  21. def add_following_account_with(last_status_at:)
  22. following_account = Fabricate(:account)
  23. Fabricate(:account_stat, account: following_account,
  24. last_status_at: last_status_at,
  25. statuses_count: 1,
  26. following_count: 0,
  27. followers_count: 0)
  28. Fabricate(:follow, account: account, target_account: following_account).account
  29. end
  30. end