Skip to content

Commit f0335c4

Browse files
committed
AO3-5573 Fix sorting on user collected works page
1 parent fd5046c commit f0335c4

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

app/views/works/_collection_filters.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%= form_for @search,
1+
<%= form_for @search, as: :work_search,
22
url: collected_user_works_path(@user),
33
html: {
44
method: :get,
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Feature: Search collected works
2+
As a creator of collected works
3+
I want to filter for works across all those collections
4+
5+
Scenario: Works that are collected show up in the creator's
6+
collected works page
7+
Given I am logged in as "author"
8+
And I create the collection "Author Collection"
9+
And I create the collection "Other Collection"
10+
And I post the work "Old Title" to the collection "Author Collection"
11+
And I post the work "Revised Title" to the collection "Author Collection"
12+
And I post the work "New Title" to the collection "Other Collection"
13+
And I post a chapter for the work "Revised Title"
14+
When I go to author's user page
15+
And I follow "Works (3)"
16+
And I follow "Works in Collections"
17+
Then I should see "Works in Challenges/Collections"
18+
And "Revised Title" should appear before "New Title"
19+
And "New Title" should appear before "Old Title"
20+
When I select "Title" from "Sort by"
21+
And I press "Sort and Filter"
22+
Then I should see "Works in Challenges/Collections"
23+
And "New Title" should appear before "Old Title"
24+
And "Old Title" should appear before "Revised Title"

spec/controllers/works/default_rails_actions_spec.rb

+45
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,51 @@ def call_with_params(params)
815815
expect(assigns(:works)).to include(work, unrevealed_work)
816816
end
817817
end
818+
819+
context "with sorting options" do
820+
let!(:new_work) do
821+
create(:work,
822+
title: "New Title",
823+
authors: [collected_user.default_pseud],
824+
collection_names: collection.name,
825+
created_at: 3.days.ago,
826+
revised_at: 3.days.ago)
827+
end
828+
829+
let!(:old_work) do
830+
create(:work,
831+
title: "Old Title",
832+
authors: [collected_user.default_pseud],
833+
collection_names: collection.name,
834+
created_at: 30.days.ago,
835+
revised_at: 30.days.ago)
836+
end
837+
838+
let!(:revised_work) do
839+
create(:work,
840+
title: "Revised Title",
841+
authors: [collected_user.default_pseud],
842+
collection_names: collection.name,
843+
created_at: 20.days.ago,
844+
revised_at: 2.days.ago)
845+
end
846+
847+
before { run_all_indexing_jobs }
848+
849+
it "sorts by date" do
850+
get :collected, params: { user_id: collected_user.login }
851+
expect(assigns(:works).map(&:title)).to eq([revised_work, new_work, old_work].map(&:title))
852+
get :collected, params: { user_id: collected_user.login, work_search: { sort_direction: "asc" } }
853+
expect(assigns(:works).map(&:title)).to eq([old_work, new_work, revised_work].map(&:title))
854+
end
855+
856+
it "sorts by title" do
857+
get :collected, params: { user_id: collected_user.login, work_search: { sort_column: "title_to_sort_on" } }
858+
expect(assigns(:works).map(&:title)).to eq([new_work, old_work, revised_work].map(&:title))
859+
get :collected, params: { user_id: collected_user.login, work_search: { sort_column: "title_to_sort_on", sort_direction: "desc" } }
860+
expect(assigns(:works).map(&:title)).to eq([revised_work, old_work, new_work].map(&:title))
861+
end
862+
end
818863
end
819864

820865
describe "destroy" do

0 commit comments

Comments
 (0)