Skip to content

Commit

Permalink
Only editors can reorder by load or score
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanxu committed Jun 7, 2023
1 parent 2ca9871 commit 1bb1d09
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/controllers/reviewers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def create
private

def order_by
params[:sort] = nil unless current_editor
order_direction = params[:direction].presence == "asc" ? :asc : :desc
if params[:sort].presence == "load"
"stats.active_reviews #{order_direction.to_s.upcase}, users.feedback_score_last_3 DESC, users.updated_at DESC, users.github ASC"
Expand Down
41 changes: 39 additions & 2 deletions spec/system/search_reviewers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
click_on "Load"
expect(page).to have_content([@reviewer3_data, @reviewer1_data, @reviewer2_data]*" ")

click_on "Load"
visit search_reviewers_path(sort: "load", direction: "desc")
expect(page).to have_content([@reviewer2_data, @reviewer1_data, @reviewer3_data]*" ")
end

Expand All @@ -221,10 +221,47 @@
click_on "Score"
expect(page).to have_content([@reviewer1_data, @reviewer2_data, @reviewer3_data]*" ")

click_on "Score"
visit search_reviewers_path(sort: "score", direction: "desc")
expect(page).to have_content([@reviewer3_data, @reviewer2_data, @reviewer1_data]*" ")
end

scenario "reorder by load or score is only available to editors" do
reviewer1_visible_data = "TesterUser33 @other-tester-33 Python big trees, oceans"
reviewer2_visible_data = "TesterUser21 @tester21 Julia astroplanetary science"
reviewer3_visible_data = "TesterUser42 @biouser Ruby cell biology, oceanography"

login_as create(:user)
@reviewer_3.touch
@reviewer_2.touch
visit search_reviewers_path
expect(page).to have_content([reviewer2_visible_data, reviewer3_visible_data, reviewer1_visible_data]*" ")

visit search_reviewers_path(sort: "score", direction: "desc")
expect(page).to have_content([reviewer2_visible_data, reviewer3_visible_data, reviewer1_visible_data]*" ")
visit search_reviewers_path(sort: "score", direction: "asc")
expect(page).to have_content([reviewer2_visible_data, reviewer3_visible_data, reviewer1_visible_data]*" ")

visit search_reviewers_path(sort: "load", direction: "desc")
expect(page).to have_content([reviewer2_visible_data, reviewer3_visible_data, reviewer1_visible_data]*" ")

visit search_reviewers_path(sort: "load", direction: "desc")
expect(page).to have_content([reviewer2_visible_data, reviewer3_visible_data, reviewer1_visible_data]*" ")

visit reviewers_path
expect(page).to have_content([reviewer2_visible_data, reviewer3_visible_data, reviewer1_visible_data]*" ")

visit reviewers_path(sort: "score", direction: "desc")
expect(page).to have_content([reviewer2_visible_data, reviewer3_visible_data, reviewer1_visible_data]*" ")
visit reviewers_path(sort: "score", direction: "asc")
expect(page).to have_content([reviewer2_visible_data, reviewer3_visible_data, reviewer1_visible_data]*" ")

visit reviewers_path(sort: "load", direction: "desc")
expect(page).to have_content([reviewer2_visible_data, reviewer3_visible_data, reviewer1_visible_data]*" ")

visit reviewers_path(sort: "load", direction: "desc")
expect(page).to have_content([reviewer2_visible_data, reviewer3_visible_data, reviewer1_visible_data]*" ")
end

scenario "works in the index page too" do
visit reviewers_path

Expand Down

0 comments on commit 1bb1d09

Please sign in to comment.