Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport] Add default order for admin budget investments list #3151

Merged
merged 3 commits into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/admin/budget_investments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def resource_name

def load_investments
@investments = Budget::Investment.scoped_filter(params, @current_filter)
@investments = @investments.order_filter(params[:sort_by]) if params[:sort_by].present?
.order_filter(params[:sort_by])
@investments = @investments.page(params[:page]) unless request.format.csv?
end

Expand Down
2 changes: 2 additions & 0 deletions app/models/budget/investment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def self.advanced_filters(params, results)
def self.order_filter(sorting_param)
if sorting_param.present? && SORTING_OPTIONS.include?(sorting_param)
send("sort_by_#{sorting_param}")
else
order(cached_votes_up: :desc).order(id: :desc)
end
end

Expand Down
30 changes: 22 additions & 8 deletions spec/features/admin/budget_investments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,16 @@
create(:budget_investment, title: 'C Third Investment', cached_votes_up: 10, budget: budget)
end

scenario "Default sorting" do
create(:budget_investment, title: 'D Fourth Investment', cached_votes_up: 50, budget: budget)

visit admin_budget_budget_investments_path(budget)

expect('D Fourth Investment').to appear_before('B First Investment')
expect('B First Investment').to appear_before('A Second Investment')
expect('A Second Investment').to appear_before('C Third Investment')
end

scenario 'Sort by ID' do
visit admin_budget_budget_investments_path(budget, sort_by: 'id')

Expand Down Expand Up @@ -1116,18 +1126,22 @@
end
end

scenario "Pagination after unselecting an investment", :js do
create_list(:budget_investment, 30, budget: budget)
feature "Pagination" do
background { selected_bi.update(cached_votes_up: 50) }

visit admin_budget_budget_investments_path(budget)
scenario "After unselecting an investment", :js do
create_list(:budget_investment, 30, budget: budget)

within("#budget_investment_#{selected_bi.id}") do
click_link('Selected')
end
visit admin_budget_budget_investments_path(budget)

click_link('Next')
within("#budget_investment_#{selected_bi.id}") do
click_link('Selected')
end

click_link('Next')

expect(page).to have_link('Previous')
expect(page).to have_link('Previous')
end
end
end

Expand Down