Skip to content

Commit

Permalink
Merge pull request #1138 from AyuntamientoMadrid/invert_budget_groups…
Browse files Browse the repository at this point in the history
…_order

Invert budget groups order at investment form
  • Loading branch information
bertocq authored Jan 22, 2018
2 parents 6342241 + 3ee5f09 commit 2578e12
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 13 deletions.
4 changes: 4 additions & 0 deletions app/models/budget/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ class Group < ActiveRecord::Base
def to_param
name.parameterize
end

def single_heading_group?
headings.count == 1
end
end
end
6 changes: 4 additions & 2 deletions app/models/budget/heading.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ class Heading < ActiveRecord::Base

delegate :budget, :budget_id, to: :group, allow_nil: true

scope :order_by_group_name, -> { includes(:group).order('budget_groups.name', 'budget_headings.name') }
scope :order_by_group_name, -> do
includes(:group).order('budget_groups.name DESC', 'budget_headings.name')
end

def name_scoped_by_group
"#{group.name}: #{name}"
group.single_heading_group? ? name : "#{group.name}: #{name}"
end

def to_param
Expand Down
2 changes: 1 addition & 1 deletion app/views/budgets/investments/_banners.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% if @heading.present? %>
<% if @heading.group.headings.count == 1 %>
<% if @heading.group.single_heading_group? %>
<%= render "banner_city" %>
<% else %>
<%= render "banner_district" %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/budgets/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<% @budget.groups.each do |group| %>
<tr>
<td>
<% if group.headings.count == 1 %>
<% if group.single_heading_group? %>
<%= link_to group.name,
custom_budget_investments_path(@budget, group,
heading_id: group.headings.first.to_param,
Expand Down
22 changes: 19 additions & 3 deletions spec/features/budgets/investments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def investments_order
login_as(author)
visit new_budget_investment_path(budget_id: budget.id)

select 'Health: More hospitals', from: 'budget_investment_heading_id'
select heading.name, from: 'budget_investment_heading_id'
fill_in 'budget_investment_title', with: 'I am a bot'
fill_in 'budget_investment_subtitle', with: 'This is the honeypot'
fill_in 'budget_investment_description', with: 'This is the description'
Expand All @@ -308,7 +308,7 @@ def investments_order
login_as(author)
visit new_budget_investment_path(budget_id: budget.id)

select 'Health: More hospitals', from: 'budget_investment_heading_id'
select heading.name, from: 'budget_investment_heading_id'
fill_in 'budget_investment_title', with: 'I am a bot'
fill_in 'budget_investment_description', with: 'This is the description'
check 'budget_investment_terms_of_service'
Expand All @@ -324,7 +324,7 @@ def investments_order

visit new_budget_investment_path(budget_id: budget.id)

select 'Health: More hospitals', from: 'budget_investment_heading_id'
select heading.name, from: 'budget_investment_heading_id'
fill_in 'budget_investment_title', with: 'Build a skyscraper'
fill_in 'budget_investment_description', with: 'I want to live in a high tower over the clouds'
fill_in 'budget_investment_location', with: 'City center'
Expand Down Expand Up @@ -415,6 +415,22 @@ def investments_order
expect(page).not_to have_content('My ballot')
end
end

scenario "Heading options are correctly ordered" do
city_group = create(:budget_group, name: "Toda la ciudad", budget: budget)
create(:budget_heading, name: "Toda la ciudad", price: 333333, group: city_group)
create(:budget_heading, name: "More health professionals", price: 999999, group: group)

login_as(author)

visit new_budget_investment_path(budget_id: budget.id)

select_options = find('#budget_investment_heading_id').all('option').collect(&:text)
expect(select_options.first).to eq('')
expect(select_options.second).to eq('Toda la ciudad')
expect(select_options.third).to eq('Health: More health professionals')
expect(select_options.fourth).to eq('Health: More hospitals')
end
end

scenario "Show" do
Expand Down
12 changes: 6 additions & 6 deletions spec/features/tags/budget_investments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

visit new_budget_investment_path(budget_id: budget.id)

select "#{group.name}: #{heading.name}", from: 'budget_investment_heading_id'
select heading.name, from: 'budget_investment_heading_id'
fill_in 'budget_investment_title', with: 'Build a skyscraper'
fill_in 'budget_investment_description', with: 'I want to live in a high tower over the clouds'
check 'budget_investment_terms_of_service'
Expand All @@ -84,7 +84,7 @@

visit new_budget_investment_path(budget_id: budget.id)

select "#{group.name}: #{heading.name}", from: 'budget_investment_heading_id'
select heading.name, from: 'budget_investment_heading_id'
fill_in 'budget_investment_title', with: 'Build a skyscraper'
fill_in_ckeditor 'budget_investment_description', with: 'If I had a gym near my place I could go do Zumba'
check 'budget_investment_terms_of_service'
Expand All @@ -109,7 +109,7 @@
visit budget_path(budget)
click_link "Create a budget investment"

select 'Health: More hospitals', from: 'budget_investment_heading_id'
select heading.name, from: 'budget_investment_heading_id'
fill_in 'budget_investment_title', with: 'Build a skyscraper'
fill_in_ckeditor 'budget_investment_description', with: 'If I had a gym near my place I could go do Zumba'
check 'budget_investment_terms_of_service'
Expand All @@ -134,7 +134,7 @@
visit budget_investments_path(budget, heading_id: heading.id)
click_link "Create a budget investment"

select 'Health: More hospitals', from: 'budget_investment_heading_id'
select heading.name, from: 'budget_investment_heading_id'
fill_in 'budget_investment_title', with: 'Build a skyscraper'
fill_in_ckeditor 'budget_investment_description', with: 'If I had a gym near my place I could go do Zumba'
check 'budget_investment_terms_of_service'
Expand All @@ -155,7 +155,7 @@

visit new_budget_investment_path(budget_id: budget.id)

select "#{group.name}: #{heading.name}", from: 'budget_investment_heading_id'
select heading.name, from: 'budget_investment_heading_id'
fill_in 'budget_investment_title', with: 'Build a skyscraper'
fill_in 'budget_investment_description', with: 'I want to live in a high tower over the clouds'
check 'budget_investment_terms_of_service'
Expand All @@ -173,7 +173,7 @@

visit new_budget_investment_path(budget_id: budget.id)

select "#{group.name}: #{heading.name}", from: 'budget_investment_heading_id'
select heading.name, from: 'budget_investment_heading_id'
fill_in 'budget_investment_title', with: 'Build a skyscraper'
fill_in 'budget_investment_description', with: 'I want to live in a high tower over the clouds'
check 'budget_investment_terms_of_service'
Expand Down

0 comments on commit 2578e12

Please sign in to comment.