Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly show finished budgets at budget index #2369

Merged
merged 8 commits into from
Jan 30, 2018
3 changes: 1 addition & 2 deletions app/controllers/budgets_controller.rb
Expand Up @@ -14,8 +14,7 @@ def show
end

def index
@budgets = @budgets.order(created_at: :desc)
@budget = current_budget
@finished_budgets = @budgets.finished.order(created_at: :desc)
@budgets_coordinates = current_budget_map_locations
end

Expand Down
4 changes: 2 additions & 2 deletions app/views/budgets/_phases.html.erb
@@ -1,6 +1,6 @@
<ul class="no-bullet budget-timeline">
<% @budget.published_phases.each do |phase| %>
<li class="phase <%= 'active' if phase == @budget.current_phase %>">
<% current_budget.published_phases.each do |phase| %>
<li class="phase <%= 'active' if phase == current_budget.current_phase %>">
<h3><%= t("budgets.phase.#{phase.kind}") %></h3>
<span>
<%= l(phase.starts_at.to_date, format: :long) if phase.starts_at.present? %>
Expand Down
64 changes: 32 additions & 32 deletions app/views/budgets/index.html.erb
Expand Up @@ -7,9 +7,9 @@
<div class="row" data-equalizer data-equalizer-on="medium">
<div class="small-12 medium-9 column padding" data-equalizer-watch>

<h1><%= @budget.name %></h1>
<h1><%= current_budget.name %></h1>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing some instance variables @current_budget 😱

<div class="description">
<%= safe_html_with_links(@budget.description) %>
<%= safe_html_with_links(current_budget.description) %>
</div>
<p>
<%= link_to t("budgets.index.section_header.help"), "#section_help" %>
Expand All @@ -19,11 +19,11 @@
<p>
<strong><%= t('budgets.show.phase') %></strong>
</p>
<h2><%= t("budgets.phase.#{@budget.phase}") %></h2>
<h2><%= t("budgets.phase.#{current_budget.phase}") %></h2>

<%= link_to t("budgets.index.section_header.all_phases"), "#all_phases" %>

<% if @budget.accepting? %>
<% if current_budget.accepting? %>
<% if current_user %>
<% if current_user.level_two_or_three_verified? %>
<%= link_to t("budgets.investments.index.sidebar.create"),
Expand All @@ -48,9 +48,9 @@
<% end %>


<% if @budget.finished? || (@budget.balloting? && can?(:read_results, @budget)) %>
<% if current_budget.finished? || (current_budget.balloting? && can?(:read_results, current_budget)) %>
<%= link_to t("budgets.show.see_results"),
budget_results_path(@budget, heading_id: @budget.headings.first),
budget_results_path(current_budget, heading_id: current_budget.headings.first),
class: "button margin-top expanded" %>
<% end %>
</div>
Expand All @@ -62,18 +62,18 @@
<div class="small-12 column">

<div id="groups_and_headings" class="groups-and-headings">
<% @budget.groups.each do |group| %>
<% current_budget.groups.each do |group| %>
<h2><%= group.name %></h2>
<ul class="no-bullet">
<% group.headings.order_by_group_name.each do |heading| %>
<li class="heading small-12 medium-4 large-2">
<% unless @budget.informing? %>
<%= link_to budget_investments_path(@budget.id, heading_id: heading.id) do %>
<%= heading_name_and_price_html(heading, @budget) %>
<% unless current_budget.informing? %>
<%= link_to budget_investments_path(current_budget.id, heading_id: heading.id) do %>
<%= heading_name_and_price_html(heading, current_budget) %>
<% end %>
<% else %>
<div>
<%= heading_name_and_price_html(heading, @budget) %>
<%= heading_name_and_price_html(heading, current_budget) %>
</div>
<% end %>
</li>
Expand All @@ -82,47 +82,47 @@
<% end %>
</div>

<% unless @budget.informing? %>
<% unless current_budget.informing? %>
<div id="map">
<h3><%= t("budgets.index.map") %></h3>
<%= render_map(nil, "budgets", false, nil, @budgets_coordinates) %>
</div>

<p>
<%= link_to budget_investments_path(@budget.id) do %>
<%= link_to budget_investments_path(current_budget.id) do %>
<small><%= t("budgets.index.investment_proyects") %></small>
<% end %><br>
<%= link_to budget_investments_path(budget_id: @budget.id, filter: 'unfeasible') do %>
<%= link_to budget_investments_path(budget_id: current_budget.id, filter: 'unfeasible') do %>
<small><%= t("budgets.index.unfeasible_investment_proyects") %></small>
<% end %><br>
<%= link_to budget_investments_path(budget_id: @budget.id, filter: 'unselected') do %>
<%= link_to budget_investments_path(budget_id: current_budget.id, filter: 'unselected') do %>
<small><%= t("budgets.index.not_selected_investment_proyects") %></small>
<% end %>
</p>
<% end %>

<div id="all_phases">
<h2><%= t("budgets.index.all_phases") %></h2>
<%= render "phases" %>
<%= render "phases", budget: current_budget %>
</div>
</div>
</div>

<div class="row margin-top">
<div class="small-12 medium-9 column">
<ul class="no-bullet submenu">
<li class="inline-block">
<%= link_to "#other_budgets", class: "active" do %>
<h2>
<%= t("budgets.index.finished_budgets") %>
</h2>
<% end %>
</li>
</ul>
<% if @finished_budgets.present? %>
<div class="row margin-top">
<div class="small-12 medium-9 column">
<ul class="no-bullet submenu">
<li class="inline-block">
<%= link_to "#other_budgets", class: "active" do %>
<h2>
<%= t("budgets.index.finished_budgets") %>
</h2>
<% end %>
</li>
</ul>

<div class="budget-investments-list">
<% @budgets.each do |budget| %>
<% if budget_published?(budget) %>
<div id="finished_budgets" class="budget-investments-list">
<% @finished_budgets.each do |budget| %>
<div class="budget-investment clear">
<div class="panel past-budgets">
<div class="row" data-equalizer data-equalizer-on="medium">
Expand All @@ -142,10 +142,10 @@
</div>
</div>
<% end %>
<% end %>
</div>
</div>
</div>
</div>
<% end %>

<div class="row">
<div class="small-12 column">
Expand Down
126 changes: 59 additions & 67 deletions spec/features/budgets/budgets_spec.rb
Expand Up @@ -6,54 +6,60 @@
let(:level_two_user) { create(:user, :level_two) }

context 'Index' do
let(:budgets) { create_list(:budget, 3) }
let(:last_budget) { budgets.last }

scenario 'Show normal index with links' do
group1 = create(:budget_group, budget: last_budget)
group2 = create(:budget_group, budget: last_budget)

group1 = create(:budget_group, budget: budget)
group2 = create(:budget_group, budget: budget)
heading1 = create(:budget_heading, group: group1)
heading2 = create(:budget_heading, group: group2)

last_budget.update_attributes(phase: 'informing')
budget.update_attributes(phase: 'informing')

visit budgets_path


within("#budget_heading") do
expect(page).to have_content(last_budget.name)
expect(page).to have_content(last_budget.description)
expect(page).to have_content(budget.name)
expect(page).to have_content(budget.description)
expect(page).to have_content("Actual phase")
expect(page).to have_content(I18n.t('budgets.phase.informing'))
expect(page).to have_link 'Help with participatory budgets'
expect(page).to have_link 'See all phases'
end

expect(page).to have_content("Accepting projects")

last_budget.update_attributes(phase: 'publishing_prices')
budget.update_attributes(phase: 'publishing_prices')
visit budgets_path

within("#budget_heading") do
expect(page).to have_content(I18n.t('budgets.phase.publishing_prices'))
end

within('#budget_info') do
expect(page).to have_content group1.name
expect(page).to have_content group2.name
expect(page).to have_content heading1.name
expect(page).to have_content last_budget.formatted_heading_price(heading1)
expect(page).to have_content heading2.name
expect(page).to have_content last_budget.formatted_heading_price(heading2)

expect(page).to have_content budgets.first.name
expect(page).to have_content budgets[2].name
expect(page).to have_content(group1.name)
expect(page).to have_content(group2.name)
expect(page).to have_content(heading1.name)
expect(page).to have_content(budget.formatted_heading_price(heading1))
expect(page).to have_content(heading2.name)
expect(page).to have_content(budget.formatted_heading_price(heading2))
end

expect(page).not_to have_content("#finished_budgets")
end

scenario 'Show finished budgets list' do
finished_budget = create(:budget, :finished)
drafting_budget = create(:budget, :drafting)
visit budgets_path

within("#finished_budgets") do
expect(page).to have_content(finished_budget.name)
expect(page).not_to have_content(budget.name)
expect(page).not_to have_content(drafting_budget.name)
end
end

scenario 'Show informing index without links' do
last_budget.update_attributes(phase: 'informing')
group = create(:budget_group, budget: last_budget)
budget.update_attributes(phase: 'informing')
group = create(:budget_group, budget: budget)
heading = create(:budget_heading, group: group)

visit budgets_path
Expand All @@ -74,42 +80,42 @@
scenario 'Index shows only published phases' do

budget.update(phase: :finished)
phases = budget.phases
phases.drafting.update(starts_at: '30-12-2017', ends_at: '31-12-2017', enabled: true,
description: 'Description of drafting phase',
summary: '<p>This is the summary for drafting phase</p>')

budget.phases.drafting.update(starts_at: '30-12-2017', ends_at: '31-12-2017', enabled: true,
description: 'Description of drafting phase',
summary: '<p>This is the summary for drafting phase</p>')
phases.accepting.update(starts_at: '01-01-2018', ends_at: '10-01-2018', enabled: true,
description: 'Description of accepting phase',
summary: 'This is the summary for accepting phase')

budget.phases.accepting.update(starts_at: '01-01-2018', ends_at: '10-01-2018', enabled: true,
description: 'Description of accepting phase',
summary: 'This is the summary for accepting phase')
phases.reviewing.update(starts_at: '11-01-2018', ends_at: '20-01-2018', enabled: false,
description: 'Description of reviewing phase',
summary: 'This is the summary for reviewing phase')

budget.phases.reviewing.update(starts_at: '11-01-2018', ends_at: '20-01-2018', enabled: false,
description: 'Description of reviewing phase',
summary: 'This is the summary for reviewing phase')
phases.selecting.update(starts_at: '21-01-2018', ends_at: '01-02-2018', enabled: true,
description: 'Description of selecting phase',
summary: 'This is the summary for selecting phase')

budget.phases.selecting.update(starts_at: '21-01-2018', ends_at: '01-02-2018', enabled: true,
description: 'Description of selecting phase',
summary: 'This is the summary for selecting phase')
phases.valuating.update(starts_at: '10-02-2018', ends_at: '20-02-2018', enabled: false,
description: 'Description of valuating phase',
summary: 'This is the summary for valuating phase')

budget.phases.valuating.update(starts_at: '10-02-2018', ends_at: '20-02-2018', enabled: false,
description: 'Description of valuating phase',
summary: 'This is the summary for valuating phase')
phases.publishing_prices.update(starts_at: '21-02-2018', ends_at: '01-03-2018', enabled: false,
description: 'Description of publishing prices phase',
summary: 'This is the summary for publishing_prices phase')

budget.phases.publishing_prices.update(starts_at: '21-02-2018', ends_at: '01-03-2018', enabled: false,
description: 'Description of publishing prices phase',
summary: 'This is the summary for publishing_prices phase')
phases.balloting.update(starts_at: '02-03-2018', ends_at: '10-03-2018', enabled: true,
description: 'Description of balloting phase',
summary: 'This is the summary for balloting phase')

budget.phases.balloting.update(starts_at: '02-03-2018', ends_at: '10-03-2018', enabled: true,
description: 'Description of balloting phase',
summary: 'This is the summary for balloting phase')
phases.reviewing_ballots.update(starts_at: '11-03-2018', ends_at: '20-03-2018', enabled: false,
description: 'Description of reviewing ballots phase',
summary: 'This is the summary for reviewing_ballots phase')

budget.phases.reviewing_ballots.update(starts_at: '11-03-2018', ends_at: '20-03-2018', enabled: false,
description: 'Description of reviewing ballots phase',
summary: 'This is the summary for reviewing_ballots phase')

budget.phases.finished.update(starts_at: '21-03-2018', ends_at: '30-03-2018', enabled: true,
description: 'Description of finished phase',
summary: 'This is the summary for finished phase')
phases.finished.update(starts_at: '21-03-2018', ends_at: '30-03-2018', enabled: true,
description: 'Description of finished phase',
summary: 'This is the summary for finished phase')

visit budgets_path

Expand Down Expand Up @@ -199,25 +205,11 @@
end

context "Listed" do
scenario "Not listed to guest users at the public budgets list" do
visit budgets_path

expect(page).not_to have_content(budget.name)
end

scenario "Not listed to logged users at the public budgets list" do
login_as(level_two_user)
scenario "Not listed at public budgets list" do
visit budgets_path

expect(page).not_to have_content(budget.name)
end

scenario "Is listed to admins at the public budgets list" do
login_as(admin)
visit budgets_path

expect(page).to have_content(budget.name)
end
end

context "Shown" do
Expand Down Expand Up @@ -269,7 +261,7 @@
scenario "user not logged in" do
visit budget_path(budget)

expect(page).to have_content "To create a new budget investment you must sign in or sign up."
expect(page).to have_content "To create a new budget investment you must sign in or sign up"
end

end
Expand Down