Commit 9922593f authored by 🙈  jacopo beschi 🙉's avatar 🙈 jacopo beschi 🙉 Committed by Sean McGivern

Resolve "Separate remembering sorting issues/merge requests"

parent c62e9c82
...@@ -107,11 +107,15 @@ module IssuableCollections ...@@ -107,11 +107,15 @@ module IssuableCollections
end end
def set_sort_order_from_cookie def set_sort_order_from_cookie
key = 'issuable_sort' cookies[remember_sorting_key] = params[:sort] if params[:sort].present?
# fallback to legacy cookie value for backward compatibility
cookies[remember_sorting_key] ||= cookies['issuable_sort']
cookies[remember_sorting_key] = update_cookie_value(cookies[remember_sorting_key])
params[:sort] = cookies[remember_sorting_key]
end
cookies[key] = params[:sort] if params[:sort].present? def remember_sorting_key
cookies[key] = update_cookie_value(cookies[key]) @remember_sorting_key ||= "#{collection_type.downcase}_sort"
params[:sort] = cookies[key]
end end
def default_sort_order def default_sort_order
...@@ -140,16 +144,14 @@ module IssuableCollections ...@@ -140,16 +144,14 @@ module IssuableCollections
end end
def finder def finder
strong_memoize(:finder) do @finder ||= issuable_finder_for(finder_type)
issuable_finder_for(finder_type)
end
end end
def collection_type def collection_type
@collection_type ||= case finder @collection_type ||= case finder_type.name
when IssuesFinder when 'IssuesFinder'
'Issue' 'Issue'
when MergeRequestsFinder when 'MergeRequestsFinder'
'MergeRequest' 'MergeRequest'
end end
end end
......
---
title: Split remembering sorting for issues and merge requests
merge_request: 21153
author: Jacopo Beschi @jacopo-beschi
type: fixed
require "spec_helper" require "spec_helper"
describe "User sorts issues" do describe "User sorts issues" do
set(:project) { create(:project_empty_repo, :public) } set(:user) { create(:user) }
set(:group) { create(:group) }
set(:project) { create(:project_empty_repo, :public, group: group) }
set(:issue1) { create(:issue, project: project) } set(:issue1) { create(:issue, project: project) }
set(:issue2) { create(:issue, project: project) } set(:issue2) { create(:issue, project: project) }
set(:issue3) { create(:issue, project: project) } set(:issue3) { create(:issue, project: project) }
...@@ -12,7 +14,29 @@ describe "User sorts issues" do ...@@ -12,7 +14,29 @@ describe "User sorts issues" do
create(:award_emoji, :downvote, awardable: issue1) create(:award_emoji, :downvote, awardable: issue1)
create(:award_emoji, :upvote, awardable: issue2) create(:award_emoji, :upvote, awardable: issue2)
sign_in(user)
visit(project_issues_path(project))
end
it 'keeps the sort option' do
find('button.dropdown-toggle').click
page.within('.content ul.dropdown-menu.dropdown-menu-right li') do
click_link('Milestone')
end
visit(issues_dashboard_path(assignee_id: user.id))
expect(find('.issues-filters a.is-active')).to have_content('Milestone')
visit(project_issues_path(project)) visit(project_issues_path(project))
expect(find('.issues-filters a.is-active')).to have_content('Milestone')
visit(issues_group_path(group))
expect(find('.issues-filters a.is-active')).to have_content('Milestone')
end end
it "sorts by popularity" do it "sorts by popularity" do
......
require 'spec_helper' require 'spec_helper'
describe 'User sorts merge requests' do describe 'User sorts merge requests' do
include CookieHelper
let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) } let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
let!(:merge_request2) do let!(:merge_request2) do
create(:merge_request_with_diffs, source_project: project, target_project: project, source_branch: 'merge-test') create(:merge_request_with_diffs, source_project: project, target_project: project, source_branch: 'merge-test')
end end
let(:project) { create(:project, :public, :repository) } set(:user) { create(:user) }
let(:user) { create(:user) } set(:group) { create(:group) }
set(:group_member) { create(:group_member, :maintainer, user: user, group: group) }
set(:project) { create(:project, :public, group: group) }
before do before do
project.add_maintainer(user)
sign_in(user) sign_in(user)
visit(project_merge_requests_path(project)) visit(project_merge_requests_path(project))
...@@ -19,16 +22,42 @@ describe 'User sorts merge requests' do ...@@ -19,16 +22,42 @@ describe 'User sorts merge requests' do
find('button.dropdown-toggle').click find('button.dropdown-toggle').click
page.within('.content ul.dropdown-menu.dropdown-menu-right li') do page.within('.content ul.dropdown-menu.dropdown-menu-right li') do
click_link('Last updated') click_link('Milestone')
end end
visit(merge_requests_dashboard_path(assignee_id: user.id)) visit(merge_requests_dashboard_path(assignee_id: user.id))
expect(find('.issues-filters')).to have_content('Last updated') expect(find('.issues-filters a.is-active')).to have_content('Milestone')
visit(project_merge_requests_path(project)) visit(project_merge_requests_path(project))
expect(find('.issues-filters')).to have_content('Last updated') expect(find('.issues-filters a.is-active')).to have_content('Milestone')
visit(merge_requests_group_path(group))
expect(find('.issues-filters a.is-active')).to have_content('Milestone')
end
it 'fallbacks to issuable_sort cookie key when remembering the sorting option' do
set_cookie('issuable_sort', 'milestone')
visit(merge_requests_dashboard_path(assignee_id: user.id))
expect(find('.issues-filters a.is-active')).to have_content('Milestone')
end
it 'separates remember sorting with issues' do
create(:issue, project: project)
find('button.dropdown-toggle').click
page.within('.content ul.dropdown-menu.dropdown-menu-right li') do
click_link('Milestone')
end
visit(project_issues_path(project))
expect(find('.issues-filters a.is-active')).not_to have_content('Milestone')
end end
context 'when merge requests have awards' do context 'when merge requests have awards' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment