Skip to content

Commit

Permalink
Merge pull request #2349 from wairbut-m2c/iagirre-budgets-new-informa…
Browse files Browse the repository at this point in the history
…tion-phase

Budget new "Information" phase
  • Loading branch information
MariaCheca committed Jan 23, 2018
2 parents eee19ad + 4bb872b commit 0dd71e6
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 56 deletions.
3 changes: 2 additions & 1 deletion app/assets/stylesheets/participation.scss
Expand Up @@ -1239,7 +1239,8 @@
text-decoration: none;
}

a {
a,
div {
display: block;
padding: $line-height / 2;

Expand Down
7 changes: 7 additions & 0 deletions app/helpers/budgets_helper.rb
@@ -1,5 +1,12 @@
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
csv_params = params.clone.merge(format: :csv).symbolize_keys
csv_params.delete(:page)
Expand Down
5 changes: 5 additions & 0 deletions app/models/budget.rb
Expand Up @@ -21,6 +21,7 @@ class Budget < ActiveRecord::Base
after_create :generate_phases

scope :drafting, -> { where(phase: "drafting") }
scope :informing, -> { where(phase: "informing") }
scope :accepting, -> { where(phase: "accepting") }
scope :reviewing, -> { where(phase: "reviewing") }
scope :selecting, -> { where(phase: "selecting") }
Expand Down Expand Up @@ -64,6 +65,10 @@ def drafting?
phase == "drafting"
end

def informing?
phase == "informing"
end

def accepting?
phase == "accepting"
end
Expand Down
3 changes: 2 additions & 1 deletion app/models/budget/phase.rb
@@ -1,6 +1,6 @@
class Budget
class Phase < ActiveRecord::Base
PHASE_KINDS = %w(drafting accepting reviewing selecting valuating publishing_prices balloting
PHASE_KINDS = %w(drafting informing accepting reviewing selecting valuating publishing_prices balloting
reviewing_ballots finished).freeze
PUBLISHED_PRICES_PHASES = %w(publishing_prices balloting reviewing_ballots finished).freeze
SUMMARY_MAX_LENGTH = 1000
Expand All @@ -26,6 +26,7 @@ class Phase < ActiveRecord::Base
scope :enabled, -> { where(enabled: true) }
scope :published, -> { enabled.where.not(kind: 'drafting') }
scope :drafting, -> { find_by_kind('drafting') }
scope :informing, -> { find_by_kind('informing') }
scope :accepting, -> { find_by_kind('accepting')}
scope :reviewing, -> { find_by_kind('reviewing')}
scope :selecting, -> { find_by_kind('selecting')}
Expand Down
43 changes: 25 additions & 18 deletions app/views/budgets/index.html.erb
Expand Up @@ -67,32 +67,39 @@
<ul class="no-bullet">
<% group.headings.order_by_group_name.each do |heading| %>
<li class="heading small-12 medium-4 large-2">
<%= link_to budget_investments_path(@budget.id, heading_id: heading.id) do %>
<%= heading.name %>
<span><%= @budget.formatted_heading_price(heading) %></span>
<% unless @budget.informing? %>
<%= link_to budget_investments_path(@budget.id, heading_id: heading.id) do %>
<%= heading_name_and_price_html(heading, @budget) %>
<% end %>
<% else %>
<div>
<%= heading_name_and_price_html(heading, @budget) %>
</div>
<% end %>
</li>
<% end %>
</ul>
<% end %>
</div>

<div id="map">
<h3><%= t("budgets.index.map") %></h3>
<%= render_map(nil, "budgets", false, nil, @budgets_coordinates) %>
</div>
<% unless @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 %>
<small><%= t("budgets.index.investment_proyects") %></small>
<% end %><br>
<%= link_to budget_investments_path(budget_id: @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 %>
<small><%= t("budgets.index.not_selected_investment_proyects") %></small>
<% end %>
</p>
<p>
<%= link_to budget_investments_path(@budget.id) do %>
<small><%= t("budgets.index.investment_proyects") %></small>
<% end %><br>
<%= link_to budget_investments_path(budget_id: @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 %>
<small><%= t("budgets.index.not_selected_investment_proyects") %></small>
<% end %>
</p>
<% end %>

<div id="all_phases">
<h2><%= t("budgets.index.all_phases") %></h2>
Expand Down
1 change: 1 addition & 0 deletions config/locales/en/budgets.yml
Expand Up @@ -30,6 +30,7 @@ en:
unselected: See investments not selected for balloting phase
phase:
drafting: Draft (Not visible to the public)
informing: Informing
accepting: Accepting projects
reviewing: Reviewing projects
selecting: Selecting projects
Expand Down
1 change: 1 addition & 0 deletions config/locales/es/budgets.yml
Expand Up @@ -30,6 +30,7 @@ es:
unselected: Ver las propuestas no seleccionadas para la votación final
phase:
drafting: Borrador (No visible para el público)
informing: Información
accepting: Presentación de proyectos
reviewing: Revisión inicial de proyectos
selecting: Fase de apoyos
Expand Down
@@ -0,0 +1,5 @@
class AddDescriptionInformingToBudgets < ActiveRecord::Migration
def change
add_column :budgets, :description_informing, :text
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180112123641) do
ActiveRecord::Schema.define(version: 20180119073228) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -219,6 +219,7 @@
t.string "slug"
t.text "description_drafting"
t.text "description_publishing_prices"
t.text "description_informing"
end

create_table "campaigns", force: :cascade do |t|
Expand Down
5 changes: 5 additions & 0 deletions spec/factories.rb
Expand Up @@ -224,6 +224,7 @@
currency_symbol "€"
phase 'accepting'
description_drafting "This budget is drafting"
description_informing "This budget is informing"
description_accepting "This budget is accepting"
description_reviewing "This budget is reviewing"
description_selecting "This budget is selecting"
Expand All @@ -237,6 +238,10 @@
phase 'drafting'
end

trait :informing do
phase 'informing'
end

trait :accepting do
phase 'accepting'
end
Expand Down
82 changes: 54 additions & 28 deletions spec/features/budgets/budgets_spec.rb
Expand Up @@ -5,43 +5,69 @@
let(:budget) { create(:budget) }
let(:level_two_user) { create(:user, :level_two) }

scenario 'Index' do
budgets = create_list(:budget, 3)
last_budget = budgets.last
group1 = create(:budget_group, budget: last_budget)
group2 = create(:budget_group, budget: last_budget)
context 'Index' do
let(:budgets) { create_list(:budget, 3) }
let(:last_budget) { budgets.last }

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

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

last_budget.update_attributes(phase: 'informing')

visit budgets_path

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("Actual phase")
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(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")
expect(page).to have_link 'Help with participatory budgets'
expect(page).to have_link 'See all phases'
end

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

within("#budget_heading") do
expect(page).to have_content("Actual phase")
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
end
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)
scenario 'Show informing index without links' do
last_budget.update_attributes(phase: 'informing')
group = create(:budget_group, budget: last_budget)
heading = create(:budget_heading, group: group)

expect(page).to have_content budgets.first.name
expect(page).to have_content budgets[2].name
visit budgets_path

within('#budget_info') do
expect(page).not_to have_link "#{heading.name} €1,000,000"
expect(page).to have_content "#{heading.name} €1,000,000"

expect(page).not_to have_link "List of all investment projects"
expect(page).not_to have_link "List of all unfeasible investment projects"
expect(page).not_to have_link "List of all investment projects not selected for balloting"

expect(page).not_to have_css('div#map')
end
end
end

Expand Down
12 changes: 7 additions & 5 deletions spec/models/budget/phase_spec.rb
Expand Up @@ -4,16 +4,18 @@

let(:budget) { create(:budget) }
let(:first_phase) { budget.phases.drafting }
let(:second_phase) { budget.phases.accepting }
let(:third_phase) { budget.phases.reviewing }
let(:fourth_phase) { budget.phases.selecting }
let(:final_phase) { budget.phases.finished}
let(:second_phase) { budget.phases.informing }
let(:third_phase) { budget.phases.accepting }
let(:fourth_phase) { budget.phases.reviewing }
let(:fifth_phase) { budget.phases.selecting }
let(:final_phase) { budget.phases.finished}

before do
first_phase.update_attributes(starts_at: Date.current - 3.days, ends_at: Date.current - 1.day)
second_phase.update_attributes(starts_at: Date.current - 1.days, ends_at: Date.current + 1.day)
third_phase.update_attributes(starts_at: Date.current + 1.days, ends_at: Date.current + 3.day)
fourth_phase.update_attributes(starts_at: Date.current + 3.days, ends_at: Date.current + 5.day)
fifth_phase.update_attributes(starts_at: Date.current + 5.days, ends_at: Date.current + 7.day)
end

describe "validates" do
Expand Down Expand Up @@ -90,7 +92,7 @@

describe "#next_phase_dates_valid?" do
let(:error) do
"End date must be earlier than the end date of the next enabled phase (Reviewing projects)"
"End date must be earlier than the end date of the next enabled phase (Accepting projects)"
end

it "is invalid when end date is same as next enabled phase end date" do
Expand Down
7 changes: 5 additions & 2 deletions spec/models/budget_spec.rb
Expand Up @@ -192,6 +192,7 @@

describe "#generate_phases" do
let(:drafting_phase) { budget.phases.drafting }
let(:informing_phase) { budget.phases.informing }
let(:accepting_phase) { budget.phases.accepting }
let(:reviewing_phase) { budget.phases.reviewing }
let(:selecting_phase) { budget.phases.selecting }
Expand All @@ -204,7 +205,8 @@
it "generates all phases linked in correct order" do
expect(budget.phases.count).to eq(Budget::Phase::PHASE_KINDS.count)

expect(drafting_phase.next_phase).to eq(accepting_phase)
expect(drafting_phase.next_phase).to eq(informing_phase)
expect(informing_phase.next_phase).to eq(accepting_phase)
expect(accepting_phase.next_phase).to eq(reviewing_phase)
expect(reviewing_phase.next_phase).to eq(selecting_phase)
expect(selecting_phase.next_phase).to eq(valuating_phase)
Expand All @@ -215,7 +217,8 @@
expect(finished_phase.next_phase).to eq(nil)

expect(drafting_phase.prev_phase).to eq(nil)
expect(accepting_phase.prev_phase).to eq(drafting_phase)
expect(informing_phase.prev_phase).to eq(drafting_phase)
expect(accepting_phase.prev_phase).to eq(informing_phase)
expect(reviewing_phase.prev_phase).to eq(accepting_phase)
expect(selecting_phase.prev_phase).to eq(reviewing_phase)
expect(valuating_phase.prev_phase).to eq(selecting_phase)
Expand Down

0 comments on commit 0dd71e6

Please sign in to comment.