about summary refs log tree commit diff
path: root/spec/models/relationship_filter_spec.rb
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-05-13 23:46:09 +0200
committerGitHub <noreply@github.com>2020-05-13 23:46:09 +0200
commite1d282023432ff4a88cb795f3a9889704314e448 (patch)
tree89f9525142d0bf876a4fb6e0117163c0a76bb78a /spec/models/relationship_filter_spec.rb
parentc6ff4c634caf718adf7280e04909c091d15add1d (diff)
parentd147dd7588502f22ac825780bb1d6e54eb3613e6 (diff)
Merge pull request #1327 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'spec/models/relationship_filter_spec.rb')
-rw-r--r--spec/models/relationship_filter_spec.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/spec/models/relationship_filter_spec.rb b/spec/models/relationship_filter_spec.rb
new file mode 100644
index 000000000..7c0f37a06
--- /dev/null
+++ b/spec/models/relationship_filter_spec.rb
@@ -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