Merge pull request #1279 from consul/budgets-management

Budgets management
This commit is contained in:
Juanjo Bazán
2016-12-08 12:08:59 +01:00
committed by GitHub
58 changed files with 777 additions and 485 deletions

View File

@@ -20,11 +20,11 @@ module Budgets
#@ballot.set_geozone(@geozone)
#@current_user.update(representative_id: nil)
if request.get?
redirect_to @spending_proposal, notice: t('spending_proposals.notice.voted')
redirect_to @investment, notice: t('budget_investments.notice.voted')
end
else
if request.get?
redirect_to @spending_proposal, notice: t('spending_proposals.notice.could_not_vote')
redirect_to @investment, notice: t('budget_investments.notice.could_not_vote')
else
render :new
end
@@ -74,4 +74,4 @@ module Budgets
end
end
end
end

View File

@@ -1,79 +0,0 @@
class Management::BudgetInvestmentsController < Management::BaseController
before_action :only_verified_users, except: :print
before_action :set_budget_investment, only: [:vote, :show]
before_action :load_budget
def index
@budget_investments = apply_filters_and_search(Budget::Investment).order(cached_votes_up: :desc).page(params[:page]).for_render
set_budget_investment_votes(@budget_investments)
end
def new
@investment = Budget::Investment.new
end
def create
@budget_investment = Budget::Investment.new(budget_investment_params)
@budget_investment.author = managed_user
if @budget_investment.save
redirect_to management_budget_investment_path(@budget_investment), notice: t('flash.actions.create.notice', resource_name: t("activerecord.models.budget_investment", count: 1))
else
render :new
end
end
def show
set_budget_investment_votes(@budget_investment)
end
def vote
@budget_investment.register_vote(managed_user, 'yes')
set_budget_investment_votes(@budget_investment)
end
def print
params[:geozone] ||= 'all'
@budget_investments = apply_filters_and_search(Budget::Investment).order(cached_votes_up: :desc).for_render.limit(15)
set_budget_investment_votes(@budget_investments)
end
private
def set_budget_investment
@budget_investment = Budget::Investment.find(params[:id])
end
def budget_investment_params
params.require(:budget_investment).permit(:title, :description, :external_url, :geozone_id, :terms_of_service)
end
def only_verified_users
check_verified_user t("management.budget_investments.alert.unverified_user")
end
# This should not be necessary. Maybe we could create a specific show view for managers.
def set_budget_investment_votes(budget_investments)
@budget_investment_votes = managed_user ? managed_user.budget_investment_votes(budget_investments) : {}
end
def set_geozone_name
if params[:geozone] == 'all'
@geozone_name = t('geozones.none')
else
@geozone_name = Geozone.find(params[:geozone]).name
end
end
def apply_filters_and_search(target)
target = params[:unfeasible].present? ? target.unfeasible : target.not_unfeasible
if params[:geozone].present?
target = target.by_geozone(params[:geozone])
set_geozone_name
end
target = target.search(params[:search]) if params[:search].present?
target
end
end

View File

@@ -0,0 +1,66 @@
class Management::Budgets::InvestmentsController < Management::BaseController
load_resource :budget
load_resource :investment, through: :budget, class: 'Budget::Investment'
before_action :only_verified_users, except: :print
def index
@investments = apply_filters_and_search(@investments).page(params[:page])
set_investment_votes(@investments)
end
def new
end
def create
@investment.terms_of_service = "1"
@investment.author = managed_user
if @investment.save
notice= t('flash.actions.create.notice', resource_name: Budget::Investment.model_name.human, count: 1)
redirect_to management_budget_investment_path(@budget, @investment), notice: notice
else
render :new
end
end
def show
set_investment_votes(@investment)
end
def vote
@investment.register_selection(managed_user)
set_investment_votes(@investment)
end
def print
@investments = apply_filters_and_search(@investments).order(cached_votes_up: :desc).for_render.limit(15)
set_investment_votes(@investments)
end
private
def set_investment_votes(investments)
@investment_votes = managed_user ? managed_user.budget_investment_votes(investments) : {}
end
def investment_params
params.require(:budget_investment).permit(:title, :description, :external_url, :heading_id)
end
def only_verified_users
check_verified_user t("management.budget_investments.alert.unverified_user")
end
def apply_filters_and_search(investments)
investments = params[:unfeasible].present? ? investments.unfeasible : investments.not_unfeasible
if params[:heading_id].present?
investments = investments.by_heading(params[:heading_id])
@heading = Budget::Heading.find(params[:heading_id])
end
investments = investments.search(params[:search]) if params[:search].present?
investments
end
end

View File

@@ -1,16 +1,26 @@
class Management::BudgetsController < Management::BaseController
include FeatureFlags
include HasFilters
feature_flag :budgets
has_filters %w{open finished}, only: :index
before_action :only_verified_users, except: :print_investments
load_and_authorize_resource
def index
@budgets = @budgets.send(@current_filter).order(created_at: :desc).page(params[:page])
def create_investments
@budgets = Budget.accepting.order(created_at: :desc).page(params[:page])
end
def show
@budget = Budget.includes(groups: :headings).find(params[:id])
def support_investments
@budgets = Budget.selecting.order(created_at: :desc).page(params[:page])
end
def print_investments
@budgets = Budget.current.order(created_at: :desc).page(params[:page])
end
private
def only_verified_users
check_verified_user t("management.budget_investments.alert.unverified_user")
end
end

View File

@@ -1,11 +1,9 @@
module BudgetHeadingsHelper
def budget_heading_select_options(budget)
budget.headings.map {|heading| [heading.name, heading.id]}
budget.headings.order_by_group_name.map do |heading|
[heading.name_scoped_by_group, heading.id]
end
end
def budget_scoped_heading_select_options(budget)
budget.headings.includes(:group).order("group_id ASC, budget_headings.name ASC").map {|heading| [heading.group.name + ': ' + heading.name, heading.id]}
end
end
end

View File

@@ -1,36 +0,0 @@
module BudgetHelper
def format_price(budget, number)
number_to_currency(number,
precision: 0,
locale: I18n.default_locale,
unit: budget.currency_symbol)
end
def heading_name(heading)
heading.present? ? heading.name : t("budget.headings.none")
end
def namespaced_budget_investment_path(investment, options={})
@namespaced_budget_investment_path ||= namespace
options[:budget_id] ||= investment.budget.id
case @namespace_budget_investment_path
when "management"
management_budget_investment_path(investment, options)
else
budget_investment_path(investment, options)
end
end
def display_budget_countdown?(budget)
budget.balloting?
end
def css_for_ballot_heading(heading)
return '' unless current_ballot.present?
current_ballot.has_lines_in_heading?(heading) ? 'active' : ''
end
def current_ballot
Budget::Ballot.where(user: current_user, budget: @budget).first
end
end

View File

@@ -8,4 +8,38 @@ module BudgetsHelper
Budget::CURRENCY_SYMBOLS.map { |cs| [ cs, cs ] }
end
end
def heading_name(heading)
heading.present? ? heading.name : t("budget.headings.none")
end
def namespaced_budget_investment_path(investment, options={})
case namespace
when "management::budgets"
management_budget_investment_path(investment.budget, investment, options)
else
budget_investment_path(investment.budget, investment, options.merge(budget_id: investment.budget_id))
end
end
def namespaced_budget_investment_vote_path(investment, options={})
case namespace
when "management::budgets"
vote_management_budget_investment_path(investment.budget, investment, options)
else
vote_budget_investment_path(investment.budget, investment, options)
end
end
def display_budget_countdown?(budget)
budget.balloting?
end
def css_for_ballot_heading(heading)
return '' unless current_ballot.present?
current_ballot.has_lines_in_heading?(heading) ? 'active' : ''
end
def current_ballot
Budget::Ballot.where(user: current_user, budget: @budget).first
end
end

View File

@@ -14,7 +14,7 @@ module Abilities
can [:search, :read], Annotation
can [:read], Budget
can [:read], Budget::Group
can [:read], Budget::Investment
can [:read, :print], Budget::Investment
can :new, DirectMessage
end
end

View File

@@ -14,8 +14,13 @@ class Budget < ActiveRecord::Base
has_many :groups, dependent: :destroy
has_many :headings, through: :groups
scope :open, -> { where.not(phase: "finished") }
scope :on_hold, -> { where(phase: "on_hold") }
scope :accepting, -> { where(phase: "accepting") }
scope :selecting, -> { where(phase: "selecting") }
scope :balloting, -> { where(phase: "balloting") }
scope :finished, -> { where(phase: "finished") }
scope :current, -> { where.not(phase: "finished") }
scope :valuating, -> { where(valuating: true) }
def on_hold?
@@ -41,5 +46,20 @@ class Budget < ActiveRecord::Base
def heading_price(heading)
heading_ids.include?(heading.id) ? heading.price : -1
end
def translated_phase
I18n.t "budget.phase.#{phase}"
end
def formatted_amount(amount)
ActionController::Base.helpers.number_to_currency(amount,
precision: 0,
locale: I18n.default_locale,
unit: currency_symbol)
end
def formatted_heading_price(heading)
formatted_ammount(heading_price(heading))
end
end

View File

@@ -9,6 +9,8 @@ class Budget
validates :name, presence: true
validates :price, presence: true
scope :order_by_group_name, -> { includes(:group).order('budget_groups.name', 'budget_headings.name') }
def budget
group.budget
end
@@ -17,5 +19,9 @@ class Budget
group.budget = resource
end
def name_scoped_by_group
"#{group.name}: #{name}"
end
end
end

View File

@@ -55,6 +55,7 @@ class Budget
before_save :calculate_confidence_score
before_validation :set_responsible_name
before_validation :set_denormalized_ids
def self.filter_params(params)
params.select{|x,_| %w{heading_id group_id administrator_id tag_name valuator_id}.include? x.to_s }
@@ -155,7 +156,7 @@ class Budget
def permission_problem(user)
return :not_logged_in unless user
return :organization if user.organization?
return :not_verified unless user.can?(:vote, SpendingProposal)
return :not_verified unless user.can?(:vote, Budget::Investment)
return nil
end
@@ -188,5 +189,27 @@ class Budget
self.responsible_name = author.try(:document_number) if author.try(:document_number).present?
end
def should_show_aside?
(budget.selecting? && !unfeasible?) || (budget.balloting? && feasible?) || budget.on_hold?
end
def should_show_votes?
budget.selecting? || budget.on_hold?
end
def should_show_ballots?
budget.balloting?
end
def formatted_price
budget.formatted_amount(price)
end
private
def set_denormalized_ids
self.group_id ||= self.heading.group_id
self.budget_id ||= self.heading.group.budget_id
end
end
end

View File

@@ -23,7 +23,7 @@
</div>
<div class="small-12 column">
<%= f.select :heading_id, budget_scoped_heading_select_options(@budget), include_blank: t("admin.budget_investments.edit.select_heading") %>
<%= f.select :heading_id, budget_heading_select_options(@budget), include_blank: t("admin.budget_investments.edit.select_heading") %>
</div>
</div>
@@ -66,4 +66,4 @@
<% end %>
<hr>
<%# render 'valuation/budget_investments/written_by_valuators' %>
<%# render 'valuation/budget_investments/written_by_valuators' %>

View File

@@ -1,10 +1,25 @@
<%= form_for(Budget::Investment.new, url: url, as: :budget_investment, method: :get) do |f| %>
<div class="row">
<div class="small-12 medium-6 column">
<%= text_field_tag :search, "", placeholder: t("admin.shared.budget_investment_search.placeholder") %>
<%= text_field_tag :search, "" %>
</div>
<div class="small-12 medium-6 column">
<%= select_tag :heading_id,
options_for_select(budget_heading_select_options(@budget),
params[:heading_id]),
include_blank: true
%>
</div>
</div>
<div class="row">
<div class="small-12 medium-6 column">
<%= check_box_tag :unfeasible, "1", params[:unfeasible].present? %>
</div>
</div>
<div class="row">
<div class="form-inline small-12 medium-3 column end">
<%= f.submit t("admin.shared.budget_investment_search.button"), class: "button" %>
<%= f.submit t("shared.search"), class: "button" %>
</div>
</div>
<% end %>

View File

@@ -1,16 +0,0 @@
<div class="add in-favor">
<p class="investment-project-amount">
<%= format_price(@budget, investment.price) %>
</p>
<% if @budget.balloting? %>
<%= link_to budget_ballot_lines_url(investment_id: investment.id,
investments_ids: @ballot.investment_ids),
class: "button button-support small expanded",
title: t('budget.investments.investment.support_title'),
method: "post",
remote: true do %>
<%= t("budget.investments.investment.add") %>
<% end %>
<% end %>
</div>

View File

@@ -28,7 +28,7 @@
<h4 class="amount-spent text-right">
<%= t("budgets.ballots.show.amount_spent") %>
<span>
<%= format_price(@budget, @ballot.amount_spent(@ballot.heading_for_group(group).id)) %>
<%= @budget.formatted_amount(@ballot.amount_spent(@ballot.heading_for_group(group).id))) %>
</span>
</h4>
<% else %>
@@ -47,9 +47,9 @@
<h4>
<%= t("budgets.ballots.show.remaining",
amount_city: format_price(@budget, @ballot.amount_available(@ballot.heading_for_group(group)))).html_safe %>
amount_city: @budget.formatted_amount(@ballot.amount_available(@ballot.heading_for_group(group))))).html_safe %>
</h4>
</div>
<% end %>
</div>
</div>
</div>

View File

@@ -1,6 +1,6 @@
<li id="<%= dom_id(investment) %>">
<%= link_to investment.title, budget_investment_path(@budget, investment) %>
<span><%= format_price(@budget, investment.price) %></span>
<span><%= investment.formatted_price %></span>
<% if @budget.balloting? %>
<%= link_to budget_ballot_line_path(@budget, id: investment.id),

View File

@@ -1,6 +1,6 @@
<li id="<%= dom_id(investment) %>_sidebar">
<%= investment.title %>
<span><%= format_price(@budget, investment.price) %></span>
<span><%= investment.formatted_price %></span>
<% if @budget.balloting? %>
<%= link_to budget_ballot_line_url(id: investment.id,

View File

@@ -1,5 +1,5 @@
<span class="total-amount">
<%= format_price(@budget, @budget.heading_price(@heading)) %>
<%= @budget.formatted_heading_price(@heading) %>
</span>
<div class="progress" role="progressbar" tabindex="0"
@@ -18,10 +18,10 @@
<%= progress_bar_width(@budget.heading_price(@heading),
@ballot.amount_spent(@heading.id)) %>">
<p id="amount-spent" class="progress-meter-text spent-amount-text">
<%= format_price(@budget, @ballot.amount_spent(@heading.id)) %>
<%= @budget.format_amount(@ballot.amount_spent(@heading.id)) %>
<span id="amount-available" class="amount-available">
<%= t("spending_proposals.index.available") %>
<span><%= format_price(@budget, @ballot.amount_available(@heading)) %></span>
<%= t("budget.progress_bar.available") %>
<span><%= @budget.format_amount(@ballot.amount_available(@heading)) %></span>
</span>
</p>
</span>

View File

@@ -1,18 +0,0 @@
<div class="remove supported inline-block">
<span class="icon-check-circle bounceIn animated"
title="<%= t("budget.investments.investment.already_added") %>">
</span>
<p class="investment-project-amount">
<%= format_price(@budget, investment.price) %>
</p>
<% if @budget.balloting? %>
<%= link_to t('budgets.ballots.show.remove'),
budget_ballot_line_path(id: investment.id,
investments_ids: investment_ids),
class: "delete small expanded",
method: :delete,
remote: true %>
<% end %>
</div>

View File

@@ -1,4 +1,4 @@
<div class="row investment-projects-scope margin-bottom">
<div class="row budget-investments-scope margin-bottom">
<div id="select-district" class="small-12 medium-7 column select-district">
<%= link_to budget_path(@budget), class: "back" do %>
<span class="icon-angle-left"></span>
@@ -26,4 +26,4 @@
<div class="medium-5 column show-for-medium text-center margin-top">
<%= image_tag "map.jpg" %>
</div>
</div>
</div>

View File

@@ -20,7 +20,7 @@
<%= link_to budget.name, budget %>
</td>
<td>
<%= budget.phase %>
<%= budget.translated_phase %>
</td>
</tr>
<% end %>

View File

@@ -1,16 +1,46 @@
<% reason = investment.reason_for_not_being_ballotable_by(current_user, @ballot) %>
<% reason = investment.reason_for_not_being_ballotable_by(current_user, investment_ballot) %>
<div class="supports ballot">
<% if @ballot.has_investment?(investment) %>
<%= render 'budgets/ballot/remove',
investment: investment,
investment_ids: @investments %>
<% if investment_ballot.has_investment?(investment) %>
<div class="remove supported inline-block">
<span class="icon-check-circle bounceIn animated"
title="<%= t("budget.investments.investment.already_added") %>">
</span>
<p class="investment-project-amount">
<%= investment.formatted_price %>
</p>
<% if investment.should_show_ballots? %>
<%= link_to t('budgets.ballots.show.remove'),
budget_ballot_line_path(id: investment.id,
budget_id: investment.budget_id,
investments_ids: investment_ids),
class: "delete small expanded",
method: :delete,
remote: true %>
<% end %>
</div>
<% else %>
<%= render 'budgets/ballot/add',
investment: investment,
investment_ids: @investments %>
<div class="add in-favor">
<p class="investment-project-amount">
<%= investment.formatted_price %>
</p>
<% if investment.should_show_ballots? %>
<%= link_to t("budget.investments.investment.add"),
budget_ballot_lines_url(investment_id: investment.id,
budget_id: investment.budget_id,
investments_ids: investment_ids),
class: "button button-support small expanded",
title: t('budget.investments.investment.support_title'),
method: :post,
remote: true %>
<% end %>
</div>
<% end %>
<% if reason.present? && !@ballot.has_investment?(investment) %>
<% if reason.present? && !investment_ballot.has_investment?(investment) %>
<div class="no-supports-allowed" style='display:none'>
<p>
@@ -18,7 +48,9 @@
verify_account: link_to(t("votes.verify_account"), verification_path),
signin: link_to(t("votes.signin"), new_user_session_path),
signup: link_to(t("votes.signup"), new_user_registration_path),
my_heading: link_to(@ballot.try(:heading).try(:name), budget_investments_path(budget_id: @budget.id, heading_id: @ballot.try(:heading_id)))
my_heading: link_to(investment.heading.name,
budget_investments_path(budget_id: investment.budget_id,
heading_id: investment.heading_id))
).html_safe %>
</p>
</div>

View File

@@ -44,20 +44,28 @@
<% unless investment.unfeasible? %>
<% if @budget.selecting? || @budget.on_hold? %>
<% if investment.should_show_votes? %>
<div id="<%= dom_id(investment) %>_votes"
class="small-12 medium-3 column text-center">
<%= render 'votes',
{ investment: investment,
vote_url: vote_budget_investment_path(@budget, investment, value: 'yes') } %>
<%= render partial: '/budgets/investments/votes', locals: {
investment: investment,
investment_votes: investment_votes,
vote_url: namespaced_budget_investment_vote_path(investment, value: 'yes')
} %>
</div>
<% elsif @budget.balloting? %>
<% elsif investment.should_show_ballots? %>
<div id="<%= dom_id(investment) %>_ballot"
class="small-12 medium-3 column text-center">
<%= render 'ballot', investment: investment %>
<%= render partial: '/budgets/investments/ballot', locals: {
investment: investment,
investment_ids: investment_ids,
investment_ballot: investment_ballots[investment.budget]
} %>
</div>
<% end %>
<% end %>

View File

@@ -0,0 +1,89 @@
<section class="budget-investment-show" id="<%= dom_id(investment) %>">
<ul class="breadcrumbs">
<li><%= link_to investment.budget.name, budget_path(investment.budget) %></a></li>
<li><%= investment.group.name %></a></li>
<li><%= investment.heading.name %></a></li>
</ul>
<div id="<%= dom_id(investment) %>" class="row">
<div class="small-12 medium-9 column">
<%= link_to :back, class: "back" do %>
<span class="icon-angle-left"></span>
<%= t("shared.back") %>
<% end %>
<h1><%= investment.title %></h1>
<div class="budget-investment-info">
<%= render '/shared/author_info', resource: investment %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<%= l investment.created_at.to_date %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<%= heading_name(investment.heading) %>
</div>
<br>
<p id="investment_code">
<%= t("budget.investments.show.code") %>
<strong><%= investment.id %></strong>
</p>
<%= safe_html_with_links investment.description.html_safe %>
<% if investment.external_url.present? %>
<div class="document-link">
<%= text_with_links investment.external_url %>
</div>
<% end %>
<% if investment.unfeasible? && investment.unfeasibility_explanation.present? %>
<h2><%= t('budget.investments.show.unfeasibility_explanation') %></h2>
<p><%= investment.unfeasibility_explanation %></p>
<% end %>
<% if investment.feasible? && investment.price_explanation.present? %>
<h2><%= t('budget.investments.show.price_explanation') %></h2>
<p><%= investment.price_explanation %></p>
<% end %>
</div>
<% if investment.should_show_aside? %>
<aside class="small-12 medium-3 column">
<div class="sidebar-divider"></div>
<h3><%= t("votes.supports") %></h3>
<div class="text-center">
<% if investment.should_show_votes? %>
<div id="<%= dom_id(investment) %>_votes">
<%= render partial: '/budgets/investments/votes', locals: {
investment: investment,
investment_votes: investment_votes,
vote_url: vote_budget_investment_path(investment.budget, investment, value: 'yes')
} %>
</div>
<% elsif investment.should_show_ballots? %>
<div id="<%= dom_id(investment) %>_ballot">
<%= render 'ballot', investment: investment %>
</div>
<% end %>
</div>
<div class="sidebar-divider"></div>
<h3><%= t("budget.investments.show.share") %></h3>
<div class="social-share-full">
<%= social_share_button_tag("#{investment.title} #{setting['twitter_hashtag']}") %>
<% if browser.device.mobile? %>
<a href="whatsapp://send?text=<%= investment.title %> <%= budget_investment_url(budget_id: investment.budget_id, id: investment.id) %>" data-action="share/whatsapp/share">
<span class="icon-whatsapp whatsapp"></span>
</a>
<% end %>
</div>
</aside>
<% end %>
</div>
</section>

View File

@@ -13,7 +13,7 @@
<em>
<%= t("budget.investments.index.sidebar.voted_html",
count: @ballot.investments.by_heading(@heading.id).count,
amount_spent: format_price(@budget, @ballot.amount_spent(@heading))) %>
amount_spent: @budget.format_amount(@ballot.amount_spent(@heading))) %>
</em>
</p>
<% else %>

View File

@@ -1,6 +1,6 @@
<% reason = investment.reason_for_not_being_selectable_by(current_user) %>
<% voting_allowed = true unless reason.presence == :not_voting_allowed %>
<% user_voted_for = voted_for?(@budget_investment_votes, investment) %>
<% user_voted_for = voted_for?(investment_votes, investment) %>
<div class="supports">
@@ -8,12 +8,12 @@
<%= t("budget.investments.investment.supports", count: investment.total_votes) %>
</span>
<div class="in-favor">
<div class="in-favor js-in-favor">
<% if user_voted_for %>
<div class="supported">
<%= t("budget.investments.investment.already_supported") %>
</div>
<% elsif @budget.selecting? %>
<% elsif investment.should_show_votes? %>
<%= link_to vote_url,
class: "button button-support small expanded",
@@ -40,7 +40,7 @@
<% if user_voted_for && setting['twitter_handle'] %>
<div class="share-supported">
<%= social_share_button_tag("#{investment.title} #{setting['twitter_hashtag']}", url: budget_investment_url(budget_id: @budget.id, id: investment.id), via: setting['twitter_handle']) %>
<%= social_share_button_tag("#{investment.title} #{setting['twitter_hashtag']}", url: budget_investment_url(budget_id: investment.budget_id, id: investment.id), via: setting['twitter_handle']) %>
</div>
<% end %>
</div>

View File

@@ -1,87 +1,5 @@
<% provide :title do %><%= @investment.title %><% end %>
<% provide :title do %><%= investment.title %><% end %>
<section class="budget-investment-show">
<div id="<%= dom_id(@investment) %>" class="row">
<div class="small-12 medium-9 column">
<%= link_to :back, class: "back" do %>
<span class="icon-angle-left"></span>
<%= t("shared.back") %>
<% end %>
<%= render partial: '/budgets/investments/investment_show', locals: { investment: @investment, investment_votes: @investment_votes } %>
<h1><%= @investment.title %></h1>
<div class="budget-investment-info">
<%= render '/shared/author_info', resource: @investment %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<%= l @investment.created_at.to_date %>
<span class="bullet">&nbsp;&bull;&nbsp;</span>
<%= heading_name(@investment.heading) %>
</div>
<br>
<p id="investment_code">
<%= t("budget.investments.show.code") %>
<strong><%= @investment.id %></strong>
</p>
<%= safe_html_with_links @investment.description.html_safe %>
<% if @investment.external_url.present? %>
<div class="document-link">
<%= text_with_links @investment.external_url %>
</div>
<% end %>
<% if @investment.unfeasible? && @investment.unfeasibility_explanation.present? %>
<h2><%= t('budget.investments.show.unfeasibility_explanation') %></h2>
<p><%= @investment.unfeasibility_explanation %></p>
<% end %>
<% if @investment.feasible? && @investment.price_explanation.present? %>
<h2><%= t('budget.investments.show.price_explanation') %></h2>
<p><%= @investment.price_explanation %></p>
<% end %>
</div>
<% if (@budget.selecting? && !@investment.unfeasible?) ||
(@budget.balloting? && @investment.feasible? ||
(@budget.on_hold?)) %>
<aside class="small-12 medium-3 column">
<div class="sidebar-divider"></div>
<h3><%= t("votes.supports") %></h3>
<div class="text-center">
<% if @budget.selecting? || @budget.on_hold? %>
<div id="<%= dom_id(@investment) %>_votes">
<%= render 'votes',
{ investment: @investment,
vote_url: vote_budget_investment_path(@budget, @investment, value: 'yes') }
%>
</div>
<% else %>
<div id="<%= dom_id(@investment) %>_ballot">
<%= render 'ballot', investment: @investment %>
</div>
<% end %>
</div>
<div class="sidebar-divider"></div>
<h3><%= t("budget.investments.show.share") %></h3>
<div class="social-share-full">
<%= social_share_button_tag("#{@investment.title} #{setting['twitter_hashtag']}") %>
<% if browser.device.mobile? %>
<a href="whatsapp://send?text=<%= @investment.title %> <%= budget_investment_url(budget_id: budget.id, id: @investment.id) %>" data-action="share/whatsapp/share">
<span class="icon-whatsapp whatsapp"></span>
</a>
<% end %>
</div>
</aside>
<% end %>
</div>
</section>
<% unless namespace == 'management' %>
<%= render "budgets/investments/comments" %>
<% end %>
<%= render partial: '/comments/comment_tree', locals: { comment_tree: @comment_tree, comment_flags: @comment_flags } %>

View File

@@ -1 +1,4 @@
$("#<%= dom_id(@investment) %>_votes").html('<%= j render("budgets/investments/votes", investment: @investment, vote_url: vote_budget_investment_path(@budget, @investment, value: "yes")) %>');
$("#<%= dom_id(@investment) %>_votes").html('<%= j render("/budgets/investments/votes",
investment: @investment,
investment_votes: @budget_investment_votes,
vote_url: namespaced_budget_investment_vote_path(@investment, value: 'yes')) %>');

View File

@@ -6,8 +6,11 @@
<%= t('shared.back') %>
<% end %>
<h1><%= @budget.name %></h1>
<h1><%= @budget.name %>
<small><%= t("budgets.phases.#{@budget.phase}") %></small>
</h1>
<p><%= @budget.description %></p>
</div>
</div>
</div>
@@ -36,4 +39,4 @@
</tbody>
</table>
</div>
</div>
</div>

View File

@@ -1,4 +1,5 @@
<% cache [locale_and_user_status(comment), comment, commentable_cache_key(comment.commentable), comment.author, (@comment_flags[comment.id] if @comment_flags)] do %>
<% comment_flags ||= @comment_flags %>
<% cache [locale_and_user_status(comment), comment, commentable_cache_key(comment.commentable), comment.author, (comment_flags[comment.id] if comment_flags)] do %>
<div class="row">
<div id="<%= dom_id(comment) %>" class="comment small-12 column">

View File

@@ -0,0 +1,34 @@
<% commentable = comment_tree.commentable %>
<% current_order = comment_tree.order %>
<% cache [locale_and_user_status, current_order, commentable_cache_key(commentable), comment_tree.comments, comment_tree.comment_authors, commentable.comments_count, comment_flags] do %>
<section class="expanded comments">
<div class="row">
<div id="comments" class="small-12 column">
<h2>
<%= t("debates.show.comments_title") %>
<span class="js-comments-count">(<%= commentable.comments_count %>)</span>
</h2>
<%= render 'shared/wide_order_selector', i18n_namespace: "comments" %>
<% if user_signed_in? %>
<%= render 'comments/form', {commentable: commentable, parent_id: nil, toggeable: false} %>
<% else %>
<br>
<div data-alert class="callout primary">
<%= t("debates.show.login_to_comment",
signin: link_to(t("votes.signin"), new_user_session_path),
signup: link_to(t("votes.signup"), new_user_registration_path)).html_safe %>
</div>
<% end %>
<% comment_tree.root_comments.each do |comment| %>
<%= render 'comments/comment', {comment: comment, comment_flags: comment_flags} %>
<% end %>
<%= paginate comment_tree.root_comments %>
</div>
</div>
</section>
<% end %>

View File

@@ -16,64 +16,67 @@
<% end %>
</li>
<li <%= "class=active" if controller_name == "proposals" and action_name == "new" %>>
<li <%= "class=active" if controller_name == "proposals" && action_name == "new" %>>
<%= link_to new_management_proposal_path do %>
<span class="icon-proposals"></span>
<%= t("management.menu.create_proposal") %>
<% end %>
</li>
<li <%= "class=active" if controller_name == "proposals" and action_name == "index" %>>
<li <%= "class=active" if controller_name == "proposals" && action_name == "index" %>>
<%= link_to management_proposals_path do %>
<span class="icon-like"></span>
<%= t("management.menu.support_proposals") %>
<% end %>
</li>
<li <%= "class=active" if controller_name == "spending_proposals" and action_name == "new" %>>
<li <%= "class=active" if controller_name == "spending_proposals" && action_name == "new" %>>
<%= link_to new_management_spending_proposal_path do %>
<span class="icon-budget"></span>
<%= t("management.menu.create_spending_proposal") %>
<% end %>
</li>
<li <%= "class=active" if controller_name == "spending_proposals" and action_name == "index" %>>
<li <%= "class=active" if controller_name == "spending_proposals" && action_name == "index" %>>
<%= link_to management_spending_proposals_path do %>
<span class="icon-like"></span>
<%= t("management.menu.support_spending_proposals") %>
<% end %>
</li>
<li <%= "class=active" if controller_name == "budget_investments" and action_name == "new" %>>
<%= link_to new_management_budget_investment_path do %>
<li <%= "class=active" if (controller_name == "budget_investments" && action_name == "new") ||
(controller_name == "budget" && action_name == 'create_investments') %>>
<%= link_to create_investments_management_budgets_path do %>
<span class="icon-budget"></span>
<%= t("management.menu.create_budget_investment") %>
<% end %>
</li>
<li <%= "class=active" if controller_name == "budget_investments" and action_name == "index" %>>
<%= link_to management_budget_investments_path do %>
<li <%= "class=active" if (controller_name == "budget_investments" && action_name == "index") ||
(controller_name == "budget" && action_name == "support_investments")%>>
<%= link_to support_investments_management_budgets_path do %>
<span class="icon-like"></span>
<%= t("management.menu.support_budget_investments") %>
<% end %>
</li>
<li <%= "class=active" if controller_name == "proposals" and action_name == "print" %>>
<li <%= "class=active" if controller_name == "proposals" && action_name == "print" %>>
<%= link_to print_management_proposals_path do %>
<span class="icon-print"></span>
<%= t("management.menu.print_proposals") %>
<% end %>
</li>
<li <%= "class=active" if controller_name == "spending_proposals" and action_name == "print" %>>
<li <%= "class=active" if controller_name == "spending_proposals" && action_name == "print" %>>
<%= link_to print_management_spending_proposals_path do %>
<span class="icon-print"></span>
<%= t("management.menu.print_spending_proposals") %>
<% end %>
</li>
<li <%= "class=active" if controller_name == "budget_investments" and action_name == "print" %>>
<%= link_to print_management_budget_investments_path do %>
<li <%= "class=active" if (controller_name == "budget_investments" && action_name == "print") ||
(controller_name == "budgets" && action_name == "print_investments") %>>
<%= link_to print_investments_management_budgets_path do %>
<span class="icon-print"></span>
<%= t("management.menu.print_budget_investments") %>
<% end %>

View File

@@ -1 +0,0 @@
<%= render partial: 'budgets/investments/investment', locals: {investment: budget_investment} %>

View File

@@ -1,2 +0,0 @@
<%= render 'budgets/investments/votes',
{ investment: budget_investment, vote_url: vote_management_budget_investment_path(budget_investment.budget, budget_investment, value: 'yes') } %>

View File

@@ -1,25 +0,0 @@
<main>
<span class="not-print">
<%= render 'admin/shared/budget_investment_search', url: management_budget_investments_path %>
</span>
<div class="wrap row">
<div id="investment-projects" class="investment-projects-list small-12 medium-9 column">
<div class="small-12 search-results">
<%= content_tag(:h2, t("management.budget_investments.filters.unfeasible")) if params[:unfeasible].present? %>
<%= content_tag(:h2, t("management.budget_investments.filters.by_geozone", geozone: @geozone_name)) if @geozone_name.present? %>
<% if params[:search].present? %>
<h2>
<%= page_entries_info @budget_investments %>
<%= t("management.budget_investments.search_results", count: @budget_investments.size, search_term: params[:search]) %>
</h2>
<% end %>
</div>
<%= render @budget_investments %>
<%= paginate @budget_investments %>
</div>
</div>
</main>

View File

@@ -1,12 +0,0 @@
<div class="budget-investment-new">
<div class="clear float-right">
<%= render '/shared/print' %>
</div>
<div class="small-12 medium-9 column end">
<h1 class=""><%= t("management.budget_investments.create") %></h1>
<%= render "budgets/investments/form", form_url: management_budget_investments_url %>
</div>
</div>

View File

@@ -1,34 +0,0 @@
<main>
<div class="row">
<div id="investment-projects" class="investment-projects-list small-12 column">
<div class="not-print">
<%= form_tag print_management_budget_investments_path, method: :get, enforce_utf8: false do %>
<div class="small-12 medium-4 column float-left">
<%= select_tag :geozone,
options_for_select(geozone_select_options.unshift([t("geozones.none"), "all"]), params[:geozone]),
{ label: false,
class: "js-submit-on-change" } %>
</div>
<% end %>
<a id="print_link" href="javascript:window.print();" class="button warning float-right">
<%= t('management.budget_investments.print.print_button') %>
</a>
</div>
<div class="small-12 search-results">
<%= content_tag(:h2, t("management.budget_investments.filters.unfeasible"), class: "inline-block") if params[:unfeasible].present? %>
<%= content_tag(:h2, t("management.budget_investments.filters.by_geozone", geozone: @geozone_name), class: "inline-block") if @geozone_name.present? %>
<%= content_tag(:h2, t("management.budget_investments.search_results", count: @budget_investments.size, search_term: params[:search]), class: "inline-block") if params[:search].present? %>
</div>
<%= render @budget_investments %>
<div class="for-print-only">
<p><strong><%= t("management.print.budget_investments_info") %></strong><br>
<%= t("management.print.budget_investments_note") %></p>
</div>
</div>
</div>
</main>

View File

@@ -1,3 +0,0 @@
<%= render '/shared/print' %>
<%= render template: 'budgets/investments/show' %>

View File

@@ -1 +0,0 @@
<%= render template: 'budgets/investments/vote' %>

View File

@@ -0,0 +1,12 @@
<table>
<% @budgets.each do |budget| %>
<tr id="<%= dom_id(budget) %>">
<td><%= budget.name %></td>
<td><%= budget.translated_phase %></td>
<td align="right">
<%= link_to t("management.budgets.create_new_investment"),
new_management_budget_investment_path(budget) %>
</td>
</tr>
<% end %>
</table>

View File

@@ -0,0 +1,32 @@
<main>
<span class="not-print">
<%= render 'admin/shared/budget_investment_search', url: management_budget_investments_path(@budget) %>
</span>
<div class="wrap row">
<div id="budget-investments" class="budget-investments-list small-12 medium-9 column">
<div class="small-12 search-results">
<%= content_tag(:h2, t("management.budget_investments.filters.unfeasible")) if params[:unfeasible].present? %>
<%= content_tag(:h2, t("management.budget_investments.filters.heading", heading: @heading.name)) if @heading.present? %>
<% if params[:search].present? %>
<h2>
<%= page_entries_info @investments %>
<%= t("management.budget_investments.search_results", count: @investments.size, search_term: params[:search]) %>
</h2>
<% end %>
</div>
<% @investments.each do |investment| %>
<%= render partial: '/budgets/investments/investment', locals: {
investment: investment,
investment_ids: @investment_ids,
investment_votes: @investment_votes,
investment_ballots: @investment_ballots
} %>
<% end %>
<%= paginate @investments %>
</div>
</div>
</main>

View File

@@ -0,0 +1,56 @@
<div class="budget-investment-new">
<div class="clear float-right">
<%= render '/shared/print' %>
</div>
<div class="small-12 medium-9 column end">
<h1 class=""><%= t("management.budget_investments.create") %></h1>
<%= form_for(@investment, url: management_budget_investments_path(@budget), method: :post) do |f| %>
<%= render 'shared/errors', resource: @investment %>
<div class="row">
<div class="small-12 column">
<%= f.label :heading_id, t("budget.investments.form.heading") %>
<%= f.select :heading_id, budget_heading_select_options(@budget), {include_blank: t("budget.headings.none"), label: false} %>
</div>
<div class="small-12 column">
<%= f.label :title, t("budget.investments.form.title") %>
<%= f.text_field :title, maxlength: SpendingProposal.title_max_length, placeholder: t("budget.investments.form.title"), label: false %>
</div>
<%= f.invisible_captcha :subtitle %>
<div class="ckeditor small-12 column">
<%= f.label :description, t("budget.investments.form.description") %>
<%= f.cktext_area :description, maxlength: SpendingProposal.description_max_length, ckeditor: { language: I18n.locale }, label: false %>
</div>
<div class="small-12 column">
<%= f.label :external_url, t("budget.investments.form.external_url") %>
<%= f.text_field :external_url, placeholder: t("budget.investments.form.external_url"), label: false %>
</div>
<div class="small-12 column">
<%= f.label :terms_of_service do %>
<%= f.check_box :terms_of_service, title: t('form.accept_terms_title'), label: false %>
<span class="checkbox">
<%= t("form.accept_terms",
policy: link_to(t("form.policy"), "/privacy", target: "blank"),
conditions: link_to(t("form.conditions"), "/conditions", target: "blank")).html_safe %>
</span>
<% end %>
</div>
<div class="actions small-12 column">
<%= f.submit(class: "button", value: t("budget.investments.form.submit_buttons.#{action_name}")) %>
</div>
</div>
<% end %>
</div>
</div>

View File

@@ -0,0 +1,40 @@
<main>
<span class="not-print">
<%= render 'admin/shared/budget_investment_search', url: print_management_budget_investments_path(@budget) %>
</span>
<div class="wrap row">
<div id="budget-investments" class="budget-investments-list small-12 column">
<div class="not-print">
<a id="print_link" href="javascript:window.print();" class="button warning float-right">
<%= t('management.budget_investments.print.print_button') %>
</a>
</div>
<div class="small-12 search-results">
<% if params[:unfeasible].present? %>
<h2 class="inline-block"><%= t("management.budget_investments.filters.unfeasible") %></h2>
<% end %>
<% if @heading.present? %>
<h2 class="inline-block"><%= t("management.budget_investments.filters.heading", heading_name: @heading.name) %></h2>
<% end %>
<h2 class="inline-block"><%= t("management.budget_investments.search_results", count: @investments.count, search_term: params[:search]) %></h2>
</div>
<% @investments.each do |investment| %>
<%= render partial: '/budgets/investments/investment', locals: {
investment: investment,
investment_ids: @investment_ids,
investment_votes: @investment_votes,
investment_ballots: @investment_ballots
} %>
<% end %>
<div class="for-print-only">
<p><strong><%= t("management.print.budget_investments_info") %></strong><br>
<%= t("management.print.budget_investments_note") %></p>
</div>
</div>
</div>
</main>

View File

@@ -0,0 +1,8 @@
<% provide :title do %><%= @investment.title %><% end %>
<%= render '/shared/print' %>
<%= render partial: '/budgets/investments/investment_show', locals: {
investment: @investment,
investment_votes: @investment_votes
} %>

View File

@@ -0,0 +1,4 @@
$("#<%= dom_id(@investment) %>_votes").html('<%= j render("/budgets/investments/votes",
investment: @investment,
investment_votes: @investment_votes,
vote_url: namespaced_budget_investment_vote_path(@investment, value: 'yes')) %>');

View File

@@ -0,0 +1,12 @@
<table>
<% @budgets.each do |budget| %>
<tr id="<%= dom_id(budget) %>">
<td><%= budget.name %></td>
<td><%= budget.translated_phase %></td>
<td align="right">
<%= link_to t("management.budgets.print_investments"),
print_management_budget_investments_path(budget) %>
</td>
</tr>
<% end %>
</table>

View File

@@ -0,0 +1,12 @@
<table>
<% @budgets.each do |budget| %>
<tr id="<%= dom_id(budget) %>">
<td><%= budget.name %></td>
<td><%= budget.translated_phase %></td>
<td align="right">
<%= link_to t("management.budgets.support_investments"),
management_budget_investments_path(budget) %>
</td>
</tr>
<% end %>
</table>

View File

@@ -1,4 +1,4 @@
<table id="budget_investments_list" class="clear activity-investment-projects">
<table id="budget_investments_list" class="clear activity-budget-investments">
<% @budget_investments.each do |budget_investment| %>
<tr id="budget_investment_<%= budget_investment.id %>">
<td>

View File

@@ -102,4 +102,4 @@ en:
proposal_notification:
attributes:
minimum_interval:
invalid: "You have to wait a minium of %{interval} days between notifications"
invalid: "You have to wait a minium of %{interval} days between notifications"

View File

@@ -283,9 +283,6 @@ en:
proposal_search:
button: Search
placeholder: Search proposals by title, code, description or question
budget_investment_search:
button: Search
placeholder: Search investments by title or description
spending_proposal_search:
button: Search
placeholder: Search spending proposals by title or description

View File

@@ -33,6 +33,19 @@ en:
application:
close: Close
menu: Menu
budgets:
progress_bar:
available: Available
phases:
accepting: Accepting investment projects
on_hold: On Hold
selecting: Selecting investment projects
balloting: Voting investment projects
finished: Finished
budget_investments:
notice:
could_not_vote: Could not vote
voted: Vote stored successfully
comments:
comment:
admin: Administrator
@@ -428,6 +441,7 @@ en:
flag: Flag as inappropriate
print:
print_button: Print this info
search: Search
show: Show
suggest:
debate:

View File

@@ -33,6 +33,19 @@ es:
application:
close: Cerrar
menu: Menú
budgets:
progress_bar:
available: Disponible
phases:
accepting: Aceptación de proyectos
on_hold: En espera
selecting: Selección de proyectos
balloting: Votación de proyectos
finished: Terminado
budget_investments:
notice:
could_not_vote: No se pudo votar
voted: Voto emitido con éxito
comments:
comment:
admin: Administrador
@@ -428,6 +441,7 @@ es:
flag: Denunciar como inapropiado
print:
print_button: Imprimir esta información
search: Buscar
show: Mostrar
suggest:
debate:

View File

@@ -51,8 +51,8 @@ en:
print_spending_proposals: Print spending proposals
support_spending_proposals: Support spending proposals
create_budget_investment: Create budget investment
print_budget_investment: Print budget investment
support_budget_investment: Support budget investment
print_budget_investments: Print Budget Investments
support_budget_investments: Support Budget Investments
users: Users
edit_user_accounts: Edit user account
user_invites: User's invites
@@ -65,6 +65,8 @@ en:
proposals_info: Create yor proposal on http://url.consul
proposals_note: The proposals more supported will be voted. If are accepted by a majority, the city Council shall be carried out.
proposals_title: 'Proposals:'
spending_proposals_info: Participate at http://url.consul
spending_proposals_note: Participatory budget will be assigned to the most voted budget investment.
budget_investments_info: Participate at http://url.consul
budget_investments_note: Participatory budget will be assigned to the most voted budget investment.
print_info: Print this info
@@ -74,13 +76,17 @@ en:
create_proposal: Create proposal
print:
print_button: Print
budgets:
create_new_investment: Create New Investment
print_investments: Print Budget Investments
support_investments: Support Budget Investments
budget_investments:
alert:
unverified_user: User is not verified
create: Create budget investment
filters:
heading: Concepto
unfeasible: Unfeasible investment
by_geozone: "Investment with scope: %{geozone}"
print:
print_button: Print
search_results:

View File

@@ -50,6 +50,9 @@ es:
create_spending_proposal: Crear propuesta de inversión
print_spending_proposals: Imprimir propts. de inversión
support_spending_proposals: Apoyar propts. de inversión
create_budget_investment: Crear proyectos de inversión
print_budget_investments: Imprimir proyectos de inversión
support_budget_investments: Apoyar proyectos de inversión
users: Usuarios
edit_user_accounts: Editar cuenta de usuario
user_invites: Invitaciones para usuarios
@@ -64,6 +67,8 @@ es:
proposals_title: 'Propuestas:'
spending_proposals_info: Participa en http://url.consul
spending_proposals_note: Los presupuestos participativos se invertirán en las propuestas de inversión más apoyadas.
budget_investments_info: Participa en http://url.consul
budget_investments_note: Los presupuestos participativos se invertirán en las propuestas de inversión más apoyadas.
print_info: Imprimir esta información
proposals:
alert:
@@ -71,6 +76,22 @@ es:
create_proposal: Crear propuesta
print:
print_button: Imprimir
budgets:
create_new_investment: Crear nuevo proyecto
print_investments: Imprimir proyectos
support_investments: Apoyar proyectos
budget_investments:
alert:
unverified_user: Usuario no verificado
create: Crear nuevo proyecto
filters:
heading: Concepto
unfeasible: Proyectos no factibles
print:
print_button: Imprimir
search_results:
one: " contiene el término '%{search_term}'"
other: " contienen el término '%{search_term}'"
spending_proposals:
alert:
unverified_user: Este usuario no está verificado
@@ -106,4 +127,4 @@ es:
title: Invitaciones para usuarios
create:
success_html: Se han enviado <strong>%{count} invitaciones</strong>.
title: Invitaciones para usuarios
title: Invitaciones para usuarios

View File

@@ -286,9 +286,16 @@ Rails.application.routes.draw do
get :print, on: :collection
end
resources :budget_investments, only: [:index, :new, :create, :show] do
post :vote, on: :member
get :print, on: :collection
resources :budgets, only: :index do
collection do
get :create_investments
get :support_investments
get :print_investments
end
resources :investments, only: [:index, :new, :create, :show], controller: 'budgets/investments' do
post :vote, on: :member
get :print, on: :collection
end
end
end

View File

@@ -51,6 +51,9 @@ admin.create_administrator
moderator = create_user('mod@consul.dev', 'mod')
moderator.create_moderator
manager = create_user('manager@consul.dev', 'manager')
manager.create_manager
valuator = create_user('valuator@consul.dev', 'valuator')
valuator.create_valuator

View File

@@ -4,32 +4,32 @@ feature 'Budget Investments' do
background do
login_as_manager
@budget = create(:budget)
end
context "Select a budget" do
budget2 = create(:budget)
budget3 = create(:budget)
click_link "Create budget investment"
@budget = create(:budget, phase: 'selecting', name: "2016")
@group = create(:budget_group, budget: @budget, name: 'Whole city')
@heading = create(:budget_heading, group: @group, name: "Health")
end
context "Create" do
before { @budget.update(phase: 'accepting') }
scenario 'Creating budget investments on behalf of someone' do
scenario 'Creating budget investments on behalf of someone, selecting a budget' do
user = create(:user, :level_two)
login_managed_user(user)
click_link "Create budget investment"
within "#budget_#{@budget.id}" do
click_link "Create New Investment"
end
within(".account-info") do
expect(page).to have_content "Identified as"
expect(page).to have_content "#{user.username}"
expect(page).to have_content "#{user.email}"
expect(page).to have_content "#{user.document_number}"
expect(page).to have_content user.username
expect(page).to have_content user.email
expect(page).to have_content user.document_number
end
select "Whole city: Health", from: 'budget_investment_heading_id'
fill_in 'budget_investment_title', with: 'Build a park in my neighborhood'
fill_in 'budget_investment_description', with: 'There is no parks here...'
fill_in 'budget_investment_external_url', with: 'http://moarparks.com'
@@ -37,16 +37,16 @@ feature 'Budget Investments' do
click_button 'Create'
expect(page).to have_content 'budget investment created successfully.'
expect(page).to have_content 'Investment created successfully.'
expect(page).to have_content '2016'
expect(page).to have_content 'Whole city'
expect(page).to have_content 'Health'
expect(page).to have_content 'Build a park in my neighborhood'
expect(page).to have_content 'There is no parks here...'
expect(page).to have_content 'All city'
expect(page).to have_content 'http://moarparks.com'
expect(page).to have_content user.name
expect(page).to have_content I18n.l(Budget::Investment.last.created_at.to_date)
expect(current_path).to eq(management_budget_investment_path(Budget::Investment.last))
expect(page).to have_content I18n.l(@budget.created_at.to_date)
end
scenario "Should not allow unverified users to create budget investments" do
@@ -60,124 +60,138 @@ feature 'Budget Investments' do
end
context "Searching" do
scenario "by title" do
budget_investment1 = create(:budget_investment, title: "Show me what you got")
budget_investment2 = create(:budget_investment, title: "Get Schwifty")
budget_investment1 = create(:budget_investment, budget: @budget, title: "Show me what you got")
budget_investment2 = create(:budget_investment, budget: @budget, title: "Get Schwifty")
user = create(:user, :level_two)
login_managed_user(user)
click_link "Support budget investments"
click_link "Support Budget Investments"
expect(page).to have_content(@budget.name)
within "#budget_#{@budget.id}" do
click_link "Support Budget Investments"
end
fill_in "search", with: "what you got"
click_button "Search"
expect(current_path).to eq(management_budget_investments_path)
within("#investment-projects") do
expect(page).to have_css('.investment-project', count: 1)
within("#budget-investments") do
expect(page).to have_css('.budget-investment', count: 1)
expect(page).to have_content(budget_investment1.title)
expect(page).to_not have_content(budget_investment2.title)
expect(page).to have_css("a[href='#{management_budget_investment_path(budget_investment1)}']", text: budget_investment1.title)
expect(page).to have_css("a[href='#{management_budget_investment_path(budget_investment1)}']", text: budget_investment1.description)
expect(page).to have_css("a[href='#{management_budget_investment_path(@budget, budget_investment1)}']", text: budget_investment1.title)
expect(page).to have_css("a[href='#{management_budget_investment_path(@budget, budget_investment1)}']", text: budget_investment1.description)
end
end
scenario "by district" do
budget_investment1 = create(:budget_investment, title: "Hey ho", geozone_id: create(:geozone, name: "District 9").id)
budget_investment2 = create(:budget_investment, title: "Let's go", geozone_id: create(:geozone, name: "Area 52").id)
scenario "by heading" do
budget_investment1 = create(:budget_investment, budget: @budget, title: "Hey ho", heading: create(:budget_heading, name: "District 9"))
budget_investment2 = create(:budget_investment, budget: @budget, title: "Let's go", heading: create(:budget_heading, name: "Area 52"))
user = create(:user, :level_two)
login_managed_user(user)
click_link "Support budget investments"
click_link "Support Budget Investments"
expect(page).to have_content(@budget.name)
within "#budget_#{@budget.id}" do
click_link "Support Budget Investments"
end
fill_in "search", with: "Area 52"
click_button "Search"
expect(current_path).to eq(management_budget_investments_path)
within("#investment-projects") do
expect(page).to have_css('.investment-project', count: 1)
within("#budget-investments") do
expect(page).to have_css('.budget-investment', count: 1)
expect(page).to_not have_content(budget_investment1.title)
expect(page).to have_content(budget_investment2.title)
expect(page).to have_css("a[href='#{management_budget_investment_path(budget_investment2)}']", text: budget_investment2.title)
expect(page).to have_css("a[href='#{management_budget_investment_path(budget_investment2)}']", text: budget_investment2.description)
expect(page).to have_css("a[href='#{management_budget_investment_path(@budget, budget_investment2)}']", text: budget_investment2.title)
expect(page).to have_css("a[href='#{management_budget_investment_path(@budget, budget_investment2)}']", text: budget_investment2.description)
end
end
end
scenario "Listing" do
budget_investment1 = create(:budget_investment, title: "Show me what you got")
budget_investment2 = create(:budget_investment, title: "Get Schwifty")
budget_investment1 = create(:budget_investment, budget: @budget, title: "Show me what you got")
budget_investment2 = create(:budget_investment, budget: @budget, title: "Get Schwifty")
user = create(:user, :level_two)
login_managed_user(user)
click_link "Support budget investments"
expect(current_path).to eq(management_budget_investments_path)
click_link "Support Budget Investments"
expect(page).to have_content(@budget.name)
within "#budget_#{@budget.id}" do
click_link "Support Budget Investments"
end
within(".account-info") do
expect(page).to have_content "Identified as"
expect(page).to have_content "#{user.username}"
expect(page).to have_content "#{user.email}"
expect(page).to have_content "#{user.document_number}"
expect(page).to have_content user.username
expect(page).to have_content user.email
expect(page).to have_content user.document_number
end
within("#investment-projects") do
expect(page).to have_css('.investment-project', count: 2)
expect(page).to have_css("a[href='#{management_budget_investment_path(budget_investment1)}']", text: budget_investment1.title)
expect(page).to have_css("a[href='#{management_budget_investment_path(budget_investment1)}']", text: budget_investment1.description)
expect(page).to have_css("a[href='#{management_budget_investment_path(budget_investment2)}']", text: budget_investment2.title)
expect(page).to have_css("a[href='#{management_budget_investment_path(budget_investment2)}']", text: budget_investment2.description)
within("#budget-investments") do
expect(page).to have_css('.budget-investment', count: 2)
expect(page).to have_css("a[href='#{management_budget_investment_path(@budget, budget_investment1)}']", text: budget_investment1.title)
expect(page).to have_css("a[href='#{management_budget_investment_path(@budget, budget_investment1)}']", text: budget_investment1.description)
expect(page).to have_css("a[href='#{management_budget_investment_path(@budget, budget_investment2)}']", text: budget_investment2.title)
expect(page).to have_css("a[href='#{management_budget_investment_path(@budget, budget_investment2)}']", text: budget_investment2.description)
end
end
context "Voting" do
context "Supporting" do
scenario 'Voting budget investments on behalf of someone in index view', :js do
budget_investment = create(:budget_investment)
scenario 'Supporting budget investments on behalf of someone in index view', :js do
budget_investment = create(:budget_investment, budget: @budget)
user = create(:user, :level_two)
login_managed_user(user)
click_link "Support budget investments"
click_link "Support Budget Investments"
expect(page).to have_content(@budget.name)
within "#budget_#{@budget.id}" do
click_link "Support Budget Investments"
end
expect(page).to have_content(budget_investment.title)
within("#investment-projects") do
find('.in-favor a').click
within("#budget-investments") do
find('.js-in-favor a').click
expect(page).to have_content "1 support"
expect(page).to have_content "You have already supported this. Share it!"
end
expect(current_path).to eq(management_budget_investments_path)
end
scenario 'Voting budget investments on behalf of someone in show view', :js do
budget_investment = create(:budget_investment)
scenario 'Supporting budget investments on behalf of someone in show view', :js do
budget_investment = create(:budget_investment, budget: @budget)
user = create(:user, :level_two)
login_managed_user(user)
click_link "Support budget investments"
click_link "Support Budget Investments"
expect(page).to have_content(@budget.name)
within "#budget_#{@budget.id}" do
click_link "Support Budget Investments"
end
within("#investment-projects") do
within("#budget-investments") do
click_link budget_investment.title
end
find('.in-favor a').click
find('.js-in-favor a').click
expect(page).to have_content "1 support"
expect(page).to have_content "You have already supported this. Share it!"
expect(current_path).to eq(management_budget_investment_path(budget_investment))
end
scenario "Should not allow unverified users to vote proposals" do
budget_investment = create(:budget_investment)
budget_investment = create(:budget_investment, budget: @budget)
user = create(:user)
login_managed_user(user)
click_link "Support budget investments"
click_link "Support Budget Investments"
expect(page).to have_content "User is not verified"
end
@@ -186,41 +200,45 @@ feature 'Budget Investments' do
context "Printing" do
scenario 'Printing budget investments' do
16.times { create(:budget_investment, geozone_id: nil) }
16.times { create(:budget_investment, budget: @budget) }
click_link "Print budget investments"
click_link "Print Budget Investments"
expect(page).to have_content(@budget.name)
within "#budget_#{@budget.id}" do
click_link "Print Budget Investments"
end
expect(page).to have_css('.investment-project', count: 15)
expect(page).to have_css('.budget-investment', count: 15)
expect(page).to have_css("a[href='javascript:window.print();']", text: 'Print')
end
scenario "Filtering budget investments by geozone to be printed", :js do
district_9 = create(:geozone, name: "District Nine")
create(:budget_investment, title: 'Change district 9', geozone: district_9, cached_votes_up: 10)
create(:budget_investment, title: 'Destroy district 9', geozone: district_9, cached_votes_up: 100)
create(:budget_investment, title: 'Nuke district 9', geozone: district_9, cached_votes_up: 1)
create(:budget_investment, title: 'Add new districts to the city', geozone_id: nil)
scenario "Filtering budget investments by heading to be printed", :js do
district_9 = create(:budget_heading, group: @group, name: "District Nine")
create(:budget_investment, budget: @budget, title: 'Change district 9', heading: district_9, cached_votes_up: 10)
create(:budget_investment, budget: @budget, title: 'Destroy district 9', heading: district_9, cached_votes_up: 100)
create(:budget_investment, budget: @budget, title: 'Nuke district 9', heading: district_9, cached_votes_up: 1)
create(:budget_investment, budget: @budget, title: 'Add new districts to the city')
user = create(:user, :level_two)
login_managed_user(user)
click_link "Print budget investments"
expect(page).to have_content "Budget investments with scope: All city"
within '#investment-projects' do
expect(page).to have_content('Add new districts to the city')
expect(page).to_not have_content('Change district 9')
expect(page).to_not have_content('Destroy district 9')
expect(page).to_not have_content('Nuke district 9')
click_link "Print Budget Investments"
expect(page).to have_content(@budget.name)
within "#budget_#{@budget.id}" do
click_link "Print Budget Investments"
end
select 'District Nine', from: 'geozone'
within '#budget-investments' do
expect(page).to have_content('Add new districts to the city')
expect(page).to have_content('Change district 9')
expect(page).to have_content('Destroy district 9')
expect(page).to have_content('Nuke district 9')
end
expect(page).to have_content "Investment projects with scope: District Nine"
expect(current_url).to include("geozone=#{district_9.id}")
select 'Whole city: District Nine', from: 'heading_id'
click_button("Search")
within '#investment-projects' do
within '#budget-investments' do
expect(page).to_not have_content('Add new districts to the city')
expect('Destroy district 9').to appear_before('Change district 9')
expect('Change district 9').to appear_before('Nuke district 9')