parent
6442f25964
commit
1a03de8592
|
@ -23,7 +23,7 @@ class RelationshipFilter
|
||||||
scope = scope_for('relationship', params['relationship'].to_s.strip)
|
scope = scope_for('relationship', params['relationship'].to_s.strip)
|
||||||
|
|
||||||
params.each do |key, value|
|
params.each do |key, value|
|
||||||
next if key.to_s == 'page'
|
next if %w(relationship page).include?(key)
|
||||||
|
|
||||||
scope.merge!(scope_for(key.to_s, value.to_s.strip)) if value.present?
|
scope.merge!(scope_for(key.to_s, value.to_s.strip)) if value.present?
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe RelationshipFilter do
|
||||||
|
let(:account) { Fabricate(:account) }
|
||||||
|
|
||||||
|
describe '#results' do
|
||||||
|
context 'when default params are used' do
|
||||||
|
let(:subject) do
|
||||||
|
RelationshipFilter.new(account, 'order' => 'active').results
|
||||||
|
end
|
||||||
|
|
||||||
|
before do
|
||||||
|
add_following_account_with(last_status_at: 7.days.ago)
|
||||||
|
add_following_account_with(last_status_at: 1.day.ago)
|
||||||
|
add_following_account_with(last_status_at: 3.days.ago)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns followings ordered by last activity' do
|
||||||
|
expected_result = account.following.eager_load(:account_stat).reorder(nil).by_recent_status
|
||||||
|
|
||||||
|
expect(subject).to eq expected_result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_following_account_with(last_status_at:)
|
||||||
|
following_account = Fabricate(:account)
|
||||||
|
Fabricate(:account_stat, account: following_account,
|
||||||
|
last_status_at: last_status_at,
|
||||||
|
statuses_count: 1,
|
||||||
|
following_count: 0,
|
||||||
|
followers_count: 0)
|
||||||
|
Fabricate(:follow, account: account, target_account: following_account).account
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue