moved duplicated code to helper

This commit is contained in:
Raúl Fuentes
2018-01-22 11:09:41 +01:00
committed by iagirre
parent c37496601c
commit 82b750de68
5 changed files with 18 additions and 9 deletions

View File

@@ -1,5 +1,12 @@
module BudgetsHelper module BudgetsHelper
def heading_name_and_price_html(heading, budget)
content_tag :div do
concat(heading.name + ' ')
concat(content_tag(:span, budget.formatted_heading_price(heading)))
end
end
def csv_params def csv_params
csv_params = params.clone.merge(format: :csv).symbolize_keys csv_params = params.clone.merge(format: :csv).symbolize_keys
csv_params.delete(:page) csv_params.delete(:page)

View File

@@ -26,7 +26,7 @@ class Budget
scope :enabled, -> { where(enabled: true) } scope :enabled, -> { where(enabled: true) }
scope :published, -> { enabled.where.not(kind: 'drafting') } scope :published, -> { enabled.where.not(kind: 'drafting') }
scope :drafting, -> { find_by_kind('drafting') } scope :drafting, -> { find_by_kind('drafting') }
scope :informing, -> { find_by_kind('informing') } scope :informing, -> { find_by_kind('informing') }
scope :accepting, -> { find_by_kind('accepting')} scope :accepting, -> { find_by_kind('accepting')}
scope :reviewing, -> { find_by_kind('reviewing')} scope :reviewing, -> { find_by_kind('reviewing')}
scope :selecting, -> { find_by_kind('selecting')} scope :selecting, -> { find_by_kind('selecting')}

View File

@@ -69,13 +69,11 @@
<li class="heading small-12 medium-4 large-2"> <li class="heading small-12 medium-4 large-2">
<% unless @budget.informing? %> <% unless @budget.informing? %>
<%= link_to budget_investments_path(@budget.id, heading_id: heading.id) do %> <%= link_to budget_investments_path(@budget.id, heading_id: heading.id) do %>
<%= heading.name %> <%= heading_name_and_price_html(heading, @budget) %>
<span><%= @budget.formatted_heading_price(heading) %></span>
<% end %> <% end %>
<% else %> <% else %>
<div> <div>
<%= heading.name %> <%= heading_name_and_price_html(heading, @budget) %>
<span><%= @budget.formatted_heading_price(heading) %></span>
</div> </div>
<% end %> <% end %>
</li> </li>

View File

@@ -30,7 +30,7 @@ en:
unselected: See investments not selected for balloting phase unselected: See investments not selected for balloting phase
phase: phase:
drafting: Draft (Not visible to the public) drafting: Draft (Not visible to the public)
informing: Informating informing: Informing
accepting: Accepting projects accepting: Accepting projects
reviewing: Reviewing projects reviewing: Reviewing projects
selecting: Selecting projects selecting: Selecting projects

View File

@@ -16,22 +16,26 @@ feature 'Budgets' do
heading1 = create(:budget_heading, group: group1) heading1 = create(:budget_heading, group: group1)
heading2 = create(:budget_heading, group: group2) heading2 = create(:budget_heading, group: group2)
last_budget.update_attributes(phase: 'informing')
visit budgets_path visit budgets_path
within("#budget_heading") do within("#budget_heading") do
expect(page).to have_content(last_budget.name) expect(page).to have_content(last_budget.name)
expect(page).to have_content(last_budget.description) expect(page).to have_content(last_budget.description)
expect(page).to have_content("Actual phase (2/9)") expect(page).to have_content(I18n.t('budgets.phase.informing'))
expect(page).to have_content("Accepting projects")
expect(page).to have_link 'Help about participatory budgets' expect(page).to have_link 'Help about participatory budgets'
expect(page).to have_link 'See all phases' expect(page).to have_link 'See all phases'
end end
expect(page).to have_content("Accepting projects")
last_budget.update_attributes(phase: 'publishing_prices') last_budget.update_attributes(phase: 'publishing_prices')
visit budgets_path visit budgets_path
within("#budget_heading") do within("#budget_heading") do
expect(page).to have_content("Actual phase (6/9)") expect(page).to have_content(I18n.t('budgets.phase.publishing_prices'))
end end
within('#budget_info') do within('#budget_info') do