Show city heading in first position on executions list
This commit is contained in:
@@ -16,6 +16,8 @@ module Budgets
|
||||
if params[:status].present?
|
||||
@headings = @headings.where(filter_investment_by_latest_milestone, params[:status])
|
||||
end
|
||||
|
||||
@headings = reorder_with_city_heading_first(@headings)
|
||||
end
|
||||
|
||||
private
|
||||
@@ -30,5 +32,19 @@ module Budgets
|
||||
WHERE investment_id = budget_investments.id ORDER BY publication_date DESC LIMIT 1) = ?
|
||||
SQL
|
||||
end
|
||||
|
||||
def reorder_with_city_heading_first(original_headings)
|
||||
headings = original_headings.to_a.dup
|
||||
|
||||
city_heading_index = headings.find_index do |heading|
|
||||
heading.name == "Toda la ciudad"
|
||||
end
|
||||
|
||||
if city_heading_index
|
||||
headings.insert(0, headings.delete_at(city_heading_index))
|
||||
else
|
||||
headings
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -181,4 +181,31 @@ feature 'Executions' do
|
||||
end
|
||||
end
|
||||
|
||||
context 'Heading Order' do
|
||||
|
||||
def create_heading_with_investment_with_milestone(group:, name:)
|
||||
heading = create(:budget_heading, group: group, name: name)
|
||||
investment = create(:budget_investment, :winner, heading: heading)
|
||||
milestone = create(:budget_investment_milestone, investment: investment)
|
||||
heading
|
||||
end
|
||||
|
||||
scenario 'City heading is displayed first' do
|
||||
heading.destroy!
|
||||
other_heading1 = create_heading_with_investment_with_milestone(group: group, name: 'Other 1')
|
||||
city_heading = create_heading_with_investment_with_milestone(group: group, name: 'Toda la ciudad')
|
||||
other_heading2 = create_heading_with_investment_with_milestone(group: group, name: 'Other 2')
|
||||
|
||||
visit budget_path(budget)
|
||||
click_link 'See results'
|
||||
|
||||
expect(page).to have_link('Milestones')
|
||||
|
||||
click_link 'Milestones'
|
||||
|
||||
expect(page).to have_css('.budget-execution', count: 3)
|
||||
expect(city_heading.name).to appear_before(other_heading1.name)
|
||||
expect(city_heading.name).to appear_before(other_heading2.name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user