diff --git a/app/controllers/budgets/ballot/lines_controller.rb b/app/controllers/budgets/ballot/lines_controller.rb index 5483f40a3..c64efbd84 100644 --- a/app/controllers/budgets/ballot/lines_controller.rb +++ b/app/controllers/budgets/ballot/lines_controller.rb @@ -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 \ No newline at end of file +end diff --git a/app/controllers/management/budget_investments_controller.rb b/app/controllers/management/budget_investments_controller.rb deleted file mode 100644 index 64dd30492..000000000 --- a/app/controllers/management/budget_investments_controller.rb +++ /dev/null @@ -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 diff --git a/app/controllers/management/budgets/investments_controller.rb b/app/controllers/management/budgets/investments_controller.rb new file mode 100644 index 000000000..e8c10ab50 --- /dev/null +++ b/app/controllers/management/budgets/investments_controller.rb @@ -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 diff --git a/app/controllers/management/budgets_controller.rb b/app/controllers/management/budgets_controller.rb index d4d5b8592..c5cfdee76 100644 --- a/app/controllers/management/budgets_controller.rb +++ b/app/controllers/management/budgets_controller.rb @@ -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 diff --git a/app/helpers/budget_headings_helper.rb b/app/helpers/budget_headings_helper.rb index b9944be9b..3fa1eac89 100644 --- a/app/helpers/budget_headings_helper.rb +++ b/app/helpers/budget_headings_helper.rb @@ -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 \ No newline at end of file +end diff --git a/app/helpers/budget_helper.rb b/app/helpers/budget_helper.rb deleted file mode 100644 index af239f074..000000000 --- a/app/helpers/budget_helper.rb +++ /dev/null @@ -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 diff --git a/app/helpers/budgets_helper.rb b/app/helpers/budgets_helper.rb index d281ef182..6c1471c90 100644 --- a/app/helpers/budgets_helper.rb +++ b/app/helpers/budgets_helper.rb @@ -8,4 +8,38 @@ module BudgetsHelper Budget::CURRENCY_SYMBOLS.map { |cs| [ cs, cs ] } end -end \ No newline at end of file + 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 diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index cf8af477b..98080aa4c 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -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 diff --git a/app/models/budget.rb b/app/models/budget.rb index e716c0181..28b37a896 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -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 diff --git a/app/models/budget/heading.rb b/app/models/budget/heading.rb index c658c5d28..52da63c4f 100644 --- a/app/models/budget/heading.rb +++ b/app/models/budget/heading.rb @@ -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 diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 619602b2a..aa86888fc 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -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 diff --git a/app/views/admin/budget_investments/edit.html.erb b/app/views/admin/budget_investments/edit.html.erb index db57c423b..e98483772 100644 --- a/app/views/admin/budget_investments/edit.html.erb +++ b/app/views/admin/budget_investments/edit.html.erb @@ -23,7 +23,7 @@
- <%= format_price(@budget, investment.price) %> -
- - <% 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 %> -- <%= format_price(@budget, @ballot.amount_spent(@heading.id)) %> + <%= @budget.format_amount(@ballot.amount_spent(@heading.id)) %> - <%= t("spending_proposals.index.available") %> - <%= format_price(@budget, @ballot.amount_available(@heading)) %> + <%= t("budget.progress_bar.available") %> + <%= @budget.format_amount(@ballot.amount_available(@heading)) %>
diff --git a/app/views/budgets/ballot/_remove.html.erb b/app/views/budgets/ballot/_remove.html.erb deleted file mode 100644 index e789b0ae6..000000000 --- a/app/views/budgets/ballot/_remove.html.erb +++ /dev/null @@ -1,18 +0,0 @@ -- <%= format_price(@budget, investment.price) %> -
- - <% 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 %> -+ <%= investment.formatted_price %> +
+ <% 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 %> ++ <%= investment.formatted_price %> +
+ <% 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 %> ++ <%= t("budget.investments.show.code") %> + <%= investment.id %> +
+ + <%= safe_html_with_links investment.description.html_safe %> + + <% if investment.external_url.present? %> +<%= investment.unfeasibility_explanation %>
+ <% end %> + + <% if investment.feasible? && investment.price_explanation.present? %> +<%= investment.price_explanation %>
+ <% end %> +- <%= t("budget.investments.show.code") %> - <%= @investment.id %> -
- - <%= safe_html_with_links @investment.description.html_safe %> - - <% if @investment.external_url.present? %> -<%= @investment.unfeasibility_explanation %>
- <% end %> - - <% if @investment.feasible? && @investment.price_explanation.present? %> -<%= @investment.price_explanation %>
- <% end %> -<%= @budget.description %>
+<%= t("management.print.budget_investments_info") %>
- <%= t("management.print.budget_investments_note") %>
| <%= budget.name %> | +<%= budget.translated_phase %> | ++ <%= link_to t("management.budgets.create_new_investment"), + new_management_budget_investment_path(budget) %> + | +
<%= t("management.print.budget_investments_info") %>
+ <%= t("management.print.budget_investments_note") %>
| <%= budget.name %> | +<%= budget.translated_phase %> | ++ <%= link_to t("management.budgets.print_investments"), + print_management_budget_investments_path(budget) %> + | +
| <%= budget.name %> | +<%= budget.translated_phase %> | ++ <%= link_to t("management.budgets.support_investments"), + management_budget_investments_path(budget) %> + | +
| diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index 8961ee584..b5549210f 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -102,4 +102,4 @@ en: proposal_notification: attributes: minimum_interval: - invalid: "You have to wait a minium of %{interval} days between notifications" \ No newline at end of file + invalid: "You have to wait a minium of %{interval} days between notifications" diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 8511dbfc4..c9bd21c18 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 5379484be..6972ef4ed 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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: diff --git a/config/locales/es.yml b/config/locales/es.yml index a1edcfc77..4bafd0c70 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -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: diff --git a/config/locales/management.en.yml b/config/locales/management.en.yml index 8daa53235..636e42349 100644 --- a/config/locales/management.en.yml +++ b/config/locales/management.en.yml @@ -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: diff --git a/config/locales/management.es.yml b/config/locales/management.es.yml index fe3d08697..f4ada5c9e 100644 --- a/config/locales/management.es.yml +++ b/config/locales/management.es.yml @@ -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 %{count} invitaciones. - title: Invitaciones para usuarios \ No newline at end of file + title: Invitaciones para usuarios diff --git a/config/routes.rb b/config/routes.rb index 90decfb7e..77f7d167e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 6ca056a33..9563e4e83 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -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 diff --git a/spec/features/management/budget_investments_spec.rb b/spec/features/management/budget_investments_spec.rb index 75cc7b4eb..9f5d11c79 100644 --- a/spec/features/management/budget_investments_spec.rb +++ b/spec/features/management/budget_investments_spec.rb @@ -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') |
+ <%= t("debates.show.comments_title") %> + (<%= commentable.comments_count %>) +
+ + <%= render 'shared/wide_order_selector', i18n_namespace: "comments" %> + + <% if user_signed_in? %> + <%= render 'comments/form', {commentable: commentable, parent_id: nil, toggeable: false} %> + <% else %> ++ +