Skip to content

Commit

Permalink
Merge pull request #3151 from consul/backport-fix_admin_investments_d…
Browse files Browse the repository at this point in the history
…efault_order

Add default order for admin budget investments list
  • Loading branch information
javierm committed Jan 9, 2019
2 parents 3733dc7 + 7c06320 commit 90a6623
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
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

0 comments on commit 90a6623

Please sign in to comment.