Skip to content

Commit

Permalink
Merge pull request #1426 from AyuntamientoMadrid/fix_admin_investment…
Browse files Browse the repository at this point in the history
…s_default_order

Add default order for admin budget investments list
  • Loading branch information
MariaCheca committed Apr 12, 2018
2 parents e234187 + d22b30e commit c49789e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
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 @@ -149,6 +149,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
10 changes: 10 additions & 0 deletions spec/features/admin/budget_investments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,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('D Fourth 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

0 comments on commit c49789e

Please sign in to comment.