<%= t("votes.budget_investments.#{reason}",
verify_account: link_to(t("votes.verify_account"), verification_path),
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 86755181e..8548bdfca 100755
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -599,6 +599,12 @@ en:
organization: Organisations are not permitted to vote
unfeasible: Unfeasible investment projects can not be supported
not_voting_allowed: Voting phase is closed
+ budget_investments:
+ not_logged_in: You must %{signin} or %{signup} to continue.
+ not_verified: Only verified users can vote on proposals; %{verify_account}.
+ organization: Organisations are not permitted to vote
+ unfeasible: Unfeasible investment projects can not be supported
+ not_voting_allowed: Selecting phase is closed
welcome:
debates:
description: For meeting, discussing and sharing the things that matter to us in our city.
diff --git a/spec/features/budgets/votes_spec.rb b/spec/features/budgets/votes_spec.rb
index a83ad205a..dbcd36411 100644
--- a/spec/features/budgets/votes_spec.rb
+++ b/spec/features/budgets/votes_spec.rb
@@ -94,16 +94,16 @@ feature 'Votes' do
visit budget_investments_path(budget, heading_id: heading.id)
within("#budget_investment_#{investment.id}") do
- find("div.supports").hover
- expect_message_selecting_not_allowed
+ find("div.js-supports").hover
+ expect(page).to have_content 'No Selecting Allowed'
end
visit budget_investment_path(budget, investment)
within("#budget_investment_#{investment.id}") do
- find("div.supports").hover
- expect_message_selecting_not_allowed
+ find("div.js-supports").hover
+ expect(page).to have_content 'No Selecting Allowed'
end
end
end
-end
\ No newline at end of file
+end
From 8839b26dd02b49cf50e3519320903a77e30b74f7 Mon Sep 17 00:00:00 2001
From: kikito
Date: Mon, 19 Dec 2016 19:11:22 +0100
Subject: [PATCH 25/73] Fixes almost all investments_spec
---
.../investments/_investment_show.html.erb | 2 +-
spec/features/budgets/investments_spec.rb | 167 +++++++++---------
2 files changed, 88 insertions(+), 81 deletions(-)
diff --git a/app/views/budgets/investments/_investment_show.html.erb b/app/views/budgets/investments/_investment_show.html.erb
index 96fc74681..b3cc81ba6 100644
--- a/app/views/budgets/investments/_investment_show.html.erb
+++ b/app/views/budgets/investments/_investment_show.html.erb
@@ -6,7 +6,7 @@
<%= investment.heading.name %>
-
+
<%= link_to :back, class: "back" do %>
diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb
index daa31f2a6..76ddd8d32 100644
--- a/spec/features/budgets/investments_spec.rb
+++ b/spec/features/budgets/investments_spec.rb
@@ -135,72 +135,75 @@ feature 'Budget Investments' do
end
- xscenario 'Create with invisible_captcha honeypot field' do
- login_as(author)
- visit new_budget_investment_path(budget_id: budget.id)
+ context 'Phase I - Accepting' do
+ before(:each) { budget.update(phase: 'accepting') }
- fill_in 'investment_title', with: 'I am a bot'
- fill_in 'investment_subtitle', with: 'This is the honeypot'
- fill_in 'investment_description', with: 'This is the description'
- select 'All city', from: 'investment_heading_id'
- check 'investment_terms_of_service'
+ scenario 'Create with invisible_captcha honeypot field' do
+ login_as(author)
+ visit new_budget_investment_path(budget_id: budget.id)
- click_button 'Create'
+ select 'Health: More hospitals', from: 'budget_investment_heading_id'
+ fill_in 'budget_investment_title', with: 'I am a bot'
+ fill_in 'budget_investment_subtitle', with: 'This is the honeypot'
+ fill_in 'budget_investment_description', with: 'This is the description'
+ check 'budget_investment_terms_of_service'
- expect(page.status_code).to eq(200)
- expect(page.html).to be_empty
- expect(current_path).to eq(budget_investments_path(budget_id: budget.id))
- end
+ click_button 'Create'
- xscenario 'Create spending proposal too fast' do
- allow(InvisibleCaptcha).to receive(:timestamp_threshold).and_return(Float::INFINITY)
-
- login_as(author)
-
- visit new_budget_investments_path(budget_id: budget.id)
- fill_in 'investment_title', with: 'I am a bot'
- fill_in 'investment_description', with: 'This is the description'
- select 'All city', from: 'investment_heading_id'
- check 'investment_terms_of_service'
-
- click_button 'Create'
-
- expect(page).to have_content 'Sorry, that was too quick! Please resubmit'
- expect(current_path).to eq(new_budget_investment_path(budget_id: budget.id))
- end
-
- xscenario 'Create notice' do
- budget.update(phase: "accepting")
- login_as(author)
-
- visit new_budget_investment_path(budget_id: budget.id)
- save_and_open_page
- fill_in 'budget_investment_title', with: 'Build a skyscraper'
- fill_in 'budget_investment_description', with: 'I want to live in a high tower over the clouds'
- fill_in 'budget_investment_external_url', with: 'http://http://skyscraperpage.com/'
- select 'All city', from: 'investment_heading_id'
- check 'investment_terms_of_service'
-
- click_button 'Create'
-
- expect(page).to have_content 'Investment created successfully'
- expect(page).to have_content 'You can access it from My activity'
-
- within "#notice" do
- click_link 'My activity'
+ expect(page.status_code).to eq(200)
+ expect(page.html).to be_empty
+ expect(current_path).to eq(budget_investments_path(budget_id: budget.id))
end
- expect(current_url).to eq(user_url(author, filter: :budget_investments))
- expect(page).to have_content "1 Investment"
- expect(page).to have_content "Build a skyscraper"
- end
+ scenario 'Create spending proposal too fast' do
+ allow(InvisibleCaptcha).to receive(:timestamp_threshold).and_return(Float::INFINITY)
- xscenario 'Errors on create' do
- login_as(author)
+ login_as(author)
+ visit new_budget_investment_path(budget_id: budget.id)
- visit new_budget_investment_path(budget_id: budget.id)
- click_button 'Create'
- expect(page).to have_content error_message
+ select 'Health: More hospitals', from: 'budget_investment_heading_id'
+ fill_in 'budget_investment_title', with: 'I am a bot'
+ fill_in 'budget_investment_description', with: 'This is the description'
+ check 'budget_investment_terms_of_service'
+
+ click_button 'Create'
+
+ expect(page).to have_content 'Sorry, that was too quick! Please resubmit'
+ expect(current_path).to eq(new_budget_investment_path(budget_id: budget.id))
+ end
+
+ scenario 'Create notice' do
+ login_as(author)
+
+ visit new_budget_investment_path(budget_id: budget.id)
+
+ select 'Health: More hospitals', from: 'budget_investment_heading_id'
+ fill_in 'budget_investment_title', with: 'Build a skyscraper'
+ fill_in 'budget_investment_description', with: 'I want to live in a high tower over the clouds'
+ fill_in 'budget_investment_external_url', with: 'http://http://skyscraperpage.com/'
+ check 'budget_investment_terms_of_service'
+
+ click_button 'Create'
+
+ expect(page).to have_content 'Investment created successfully'
+ expect(page).to have_content 'You can access it from My activity'
+
+ within "#notice" do
+ click_link 'My activity'
+ end
+
+ expect(current_url).to eq(user_url(author, filter: :budget_investments))
+ expect(page).to have_content "1 Investment"
+ expect(page).to have_content "Build a skyscraper"
+ end
+
+ scenario 'Errors on create' do
+ login_as(author)
+
+ visit new_budget_investment_path(budget_id: budget.id)
+ click_button 'Create'
+ expect(page).to have_content error_message
+ end
end
scenario "Show" do
@@ -259,7 +262,7 @@ feature 'Budget Investments' do
context "Destroy" do
- xscenario "Admin cannot destroy spending proposals" do
+ scenario "Admin cannot destroy spending proposals" do
admin = create(:administrator)
user = create(:user, :level_two)
investment = create(:budget_investment, heading: heading, author: user)
@@ -267,7 +270,7 @@ feature 'Budget Investments' do
login_as(admin.user)
visit user_path(user)
- within("#investment_#{investment.id}") do
+ within("#budget_investment_#{investment.id}") do
expect(page).to_not have_link "Delete"
end
end
@@ -280,7 +283,7 @@ feature 'Budget Investments' do
budget.update(phase: "balloting")
end
- xscenario "Index" do
+ scenario "Index" do
user = create(:user, :level_two)
sp1 = create(:budget_investment, :feasible, :finished, heading: heading, price: 10000)
sp2 = create(:budget_investment, :feasible, :finished, heading: heading, price: 20000)
@@ -290,7 +293,7 @@ feature 'Budget Investments' do
first(:link, "Participatory budgeting").click
click_link budget.name
- click_link "No Heading"
+ click_link "Health"
within("#budget_investment_#{sp1.id}") do
expect(page).to have_content sp1.title
@@ -303,7 +306,6 @@ feature 'Budget Investments' do
end
end
- xscenario 'Order by cost (only in phase3)' do
scenario 'Order by cost (only in phase3)' do
create(:budget_investment, :feasible, :finished, heading: heading, title: 'Build a nice house', price: 1000).update_column(:confidence_score, 10)
create(:budget_investment, :feasible, :finished, heading: heading, title: 'Build an ugly house', price: 1000).update_column(:confidence_score, 5)
@@ -335,36 +337,41 @@ feature 'Budget Investments' do
expect(page).to have_content "€10,000"
end
- xscenario "Confirm", :js do
+ scenario "Confirm", :js do
+ budget.update(phase: 'balloting')
user = create(:user, :level_two)
- carabanchel = create(:geozone, name: "Carabanchel")
- new_york = create(:geozone, name: "New York")
+ global_group = create(:budget_group, budget: budget, name: 'Global Group')
+ global_heading = create(:budget_heading, group: global_group, name: 'Global Heading')
- carabanchel_heading = create(:budget_heading, heading: heading, geozone: carabanchel, name: carabanchel.name)
- new_york_heading = create(:budget_heading, heading: heading, geozone: new_york, name: new_york.name)
+ carabanchel = create(:geozone, name: "Carabanchel")
+ new_york = create(:geozone, name: "New York")
+ carabanchel_heading = create(:budget_heading, group: group, geozone: carabanchel, name: carabanchel.name)
+ new_york_heading = create(:budget_heading, group: group, geozone: new_york, name: new_york.name)
- sp1 = create(:budget_investment, :feasible, :finished, price: 1, heading: nil)
- sp2 = create(:budget_investment, :feasible, :finished, price: 10, heading: nil)
- sp3 = create(:budget_investment, :feasible, :finished, price: 100, heading: nil)
- sp4 = create(:budget_investment, :feasible, :finished, price: 1000, budget: budget, group: group, heading: carabanchel_heading)
- sp5 = create(:budget_investment, :feasible, :finished, price: 10000, budget: budget, group: group, heading: carabanchel_heading)
- sp6 = create(:budget_investment, :feasible, :finished, price: 100000, budget: budget, group: group, heading: new_york_heading)
+
+ sp1 = create(:budget_investment, :feasible, :finished, price: 1, heading: global_heading)
+ sp2 = create(:budget_investment, :feasible, :finished, price: 10, heading: global_heading)
+ sp3 = create(:budget_investment, :feasible, :finished, price: 100, heading: global_heading)
+ sp4 = create(:budget_investment, :feasible, :finished, price: 1000, heading: carabanchel_heading)
+ sp5 = create(:budget_investment, :feasible, :finished, price: 10000, heading: carabanchel_heading)
+ sp6 = create(:budget_investment, :feasible, :finished, price: 100000, heading: new_york_heading)
login_as(user)
- visit root_path
+ visit budget_path(budget)
- first(:link, "Participatory budgeting").click
- click_link budget.name
- click_link "No Heading"
+ click_link "Global Group"
+ # No need to click_link "Global Heading" because groups with a single heading redirect to the
+ # list of investments directly
add_to_ballot(sp1)
add_to_ballot(sp2)
- first(:link, "Participatory budgeting").click
+ visit budgets_path
click_link budget.name
- click_link carabanchel.name
+ click_link "Health"
+ click_link "Carabanchel"
add_to_ballot(sp4)
add_to_ballot(sp5)
From a73626d712e0a6605715e3b4089301d22125ca40 Mon Sep 17 00:00:00 2001
From: kikito
Date: Mon, 19 Dec 2016 19:11:45 +0100
Subject: [PATCH 26/73] Refactors and simplifies ballot/lines_controller.rb
---
.../budgets/ballot/lines_controller.rb | 18 ++++--------------
1 file changed, 4 insertions(+), 14 deletions(-)
diff --git a/app/controllers/budgets/ballot/lines_controller.rb b/app/controllers/budgets/ballot/lines_controller.rb
index c64efbd84..f759dc311 100644
--- a/app/controllers/budgets/ballot/lines_controller.rb
+++ b/app/controllers/budgets/ballot/lines_controller.rb
@@ -9,25 +9,15 @@ module Budgets
before_action :load_investments
load_and_authorize_resource :budget
- load_and_authorize_resource :ballot, class: "Budget::Ballot"
+ load_and_authorize_resource :ballot, class: "Budget::Ballot", through: :budget
load_and_authorize_resource :line, through: :ballot, find_by: :investment_id, class: "Budget::Ballot::Line"
def create
load_investment
load_heading
- if @ballot.add_investment(@investment)
- #@ballot.set_geozone(@geozone)
- #@current_user.update(representative_id: nil)
- if request.get?
- redirect_to @investment, notice: t('budget_investments.notice.voted')
- end
- else
- if request.get?
- redirect_to @investment, notice: t('budget_investments.notice.could_not_vote')
- else
- render :new
- end
+ unless @ballot.add_investment(@investment)
+ head :bad_request
end
end
@@ -47,7 +37,7 @@ module Budgets
end
def line_params
- params.permit(:investment_id)
+ params.permit(:investment_id, :budget_id)
end
def load_budget
From 688f52bb6299c442871b92550d9e0cea2ae4ecd2 Mon Sep 17 00:00:00 2001
From: kikito
Date: Thu, 22 Dec 2016 20:23:48 +0100
Subject: [PATCH 27/73] Renames supports to allow_participation
---
app/assets/javascripts/allow_participation.js.coffee | 12 ++++++++++++
app/assets/javascripts/application.js | 4 ++--
app/assets/javascripts/supports.js.coffee | 12 ------------
app/views/budgets/investments/_ballot.html.erb | 4 ++--
app/views/budgets/investments/_votes.html.erb | 4 ++--
5 files changed, 18 insertions(+), 18 deletions(-)
create mode 100644 app/assets/javascripts/allow_participation.js.coffee
delete mode 100644 app/assets/javascripts/supports.js.coffee
diff --git a/app/assets/javascripts/allow_participation.js.coffee b/app/assets/javascripts/allow_participation.js.coffee
new file mode 100644
index 000000000..116e374ca
--- /dev/null
+++ b/app/assets/javascripts/allow_participation.js.coffee
@@ -0,0 +1,12 @@
+App.AllowParticipation =
+
+ initialize: ->
+ $(document).on {
+ 'mouseenter focus': ->
+ $(this).find(".js-participation-not-allowed").show();
+ $(this).find(".js-participation-allowed").hide();
+ mouseleave: ->
+ $(this).find(".js-participation-not-allowed").hide();
+ $(this).find(".js-participation-allowed").show();
+ }, ".js-participation"
+ false
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js
index 7a6b87095..2445c5f3d 100644
--- a/app/assets/javascripts/application.js
+++ b/app/assets/javascripts/application.js
@@ -36,7 +36,7 @@
//= require tags
//= require users
//= require votes
-//= require supports
+//= require allow_participation
//= require annotatable
//= require advanced_search
//= require registration_form
@@ -54,7 +54,7 @@ var initialize_modules = function() {
App.Comments.initialize();
App.Users.initialize();
App.Votes.initialize();
- App.Supports.initialize();
+ App.AllowParticipation.initialize();
App.Tags.initialize();
App.Dropdown.initialize();
App.LocationChanger.initialize();
diff --git a/app/assets/javascripts/supports.js.coffee b/app/assets/javascripts/supports.js.coffee
deleted file mode 100644
index 78f7b258c..000000000
--- a/app/assets/javascripts/supports.js.coffee
+++ /dev/null
@@ -1,12 +0,0 @@
-App.Supports =
-
- initialize: ->
- $(document).on {
- 'mouseenter focus': ->
- $(this).find(".js-supports-not-allowed").show();
- $(this).find(".js-supports-allowed").hide();
- mouseleave: ->
- $(this).find(".js-supports-not-allowed").hide();
- $(this).find(".js-supports-allowed").show();
- }, ".js-supports"
- false
diff --git a/app/views/budgets/investments/_ballot.html.erb b/app/views/budgets/investments/_ballot.html.erb
index bbac474af..6b6d3a668 100644
--- a/app/views/budgets/investments/_ballot.html.erb
+++ b/app/views/budgets/investments/_ballot.html.erb
@@ -1,5 +1,5 @@
<% reason = investment.reason_for_not_being_ballotable_by(current_user, ballot) %>
-
+
<% if ballot.has_investment?(investment) %>
@@ -42,7 +42,7 @@
<% if reason.present? && !ballot.has_investment?(investment) %>
-
+
<%= t("votes.budget_investments.#{reason}",
verify_account: link_to(t("votes.verify_account"), verification_path),
diff --git a/app/views/budgets/investments/_votes.html.erb b/app/views/budgets/investments/_votes.html.erb
index 7a8a7826b..77a95a221 100644
--- a/app/views/budgets/investments/_votes.html.erb
+++ b/app/views/budgets/investments/_votes.html.erb
@@ -2,7 +2,7 @@
<% voting_allowed = true unless reason.presence == :not_voting_allowed %>
<% user_voted_for = voted_for?(investment_votes, investment) %>
-
+
<%= t("budget.investments.investment.supports", count: investment.total_votes) %>
@@ -27,7 +27,7 @@
<% if reason.present? && !user_voted_for %>
-
+
<%= t("votes.budget_investments.#{reason}",
verify_account: link_to(t("votes.verify_account"), verification_path),
From 430507ec1e80b21accda880ba1efe354098881f7 Mon Sep 17 00:00:00 2001
From: kikito
Date: Thu, 22 Dec 2016 20:24:59 +0100
Subject: [PATCH 28/73] Adds budget_lines.selected
---
app/models/budget/ballot/line.rb | 6 +++---
app/models/budget/investment.rb | 10 ++++++++--
db/dev_seeds.rb | 7 ++++++-
...20161221172447_add_selected_to_budget_investment.rb | 5 +++++
db/schema.rb | 3 ++-
spec/factories.rb | 4 ++++
6 files changed, 28 insertions(+), 7 deletions(-)
create mode 100644 db/migrate/20161221172447_add_selected_to_budget_investment.rb
diff --git a/app/models/budget/ballot/line.rb b/app/models/budget/ballot/line.rb
index 85434ad2d..730398edc 100644
--- a/app/models/budget/ballot/line.rb
+++ b/app/models/budget/ballot/line.rb
@@ -11,7 +11,7 @@ class Budget
validate :insufficient_funds
#needed? validate :different_geozone, :if => :district_proposal?
- validate :unfeasible
+ validate :unselected
before_validation :set_denormalized_ids
@@ -23,8 +23,8 @@ class Budget
errors.add(:heading, "different heading assigned") if (ballot.heading.present? && investment.heading != ballot.heading)
end
- def unfeasible
- errors.add(:unfeasible, "unfeasible investment") unless investment.feasible?
+ def unselected
+ errors.add(:unselected, "unselected investment") unless investment.selected?
end
def heading_proposal?
diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb
index 23586ec3a..240509609 100644
--- a/app/models/budget/investment.rb
+++ b/app/models/budget/investment.rb
@@ -44,6 +44,7 @@ class Budget
scope :not_unfeasible, -> { where.not(feasibility: "unfeasible") }
scope :undecided, -> { where(feasibility: "undecided") }
scope :with_supports, -> { where('cached_votes_up > 0') }
+ scope :selected, -> { where(selected: true) }
scope :by_group, -> (group_id) { where(group_id: group_id) }
scope :by_heading, -> (heading_id) { where(heading_id: heading_id) }
@@ -205,8 +206,13 @@ class Budget
budget.formatted_amount(price)
end
- def self.apply_filters_and_search(params)
- investments = params[:unfeasible].present? ? unfeasible : not_unfeasible
+ def self.apply_filters_and_search(budget, params)
+ investments = all
+ if budget.balloting?
+ investments = investments.selected
+ else
+ investments = params[:unfeasible].present? ? investments.unfeasible : investments.not_unfeasible
+ end
investments = investments.by_heading(params[:heading_id]) if params[:heading_id].present?
investments = investments.search(params[:search]) if params[:search].present?
investments
diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb
index 9563e4e83..2d8ccb55a 100644
--- a/db/dev_seeds.rb
+++ b/db/dev_seeds.rb
@@ -362,7 +362,7 @@ tags = Faker::Lorem.words(10)
external_url: Faker::Internet.url,
description: "#{Faker::Lorem.paragraphs.join('
')}
",
created_at: rand((Time.now - 1.week) .. Time.now),
- feasibility: %w{undecided feasible unfeasible}.sample,
+ feasibility: %w{undecided unfeasible feasible feasible feasible feasible}.sample,
unfeasibility_explanation: "#{Faker::Lorem.paragraphs.join('
')}
",
valuation_finished: [false, true].sample,
tag_list: tags.sample(3).join(','),
@@ -371,6 +371,11 @@ tags = Faker::Lorem.words(10)
puts " #{investment.title}"
end
+puts "Selecting Investments"
+Budget.balloting.reorder("RANDOM()").limit(3).each do |budget|
+ budget.investments.feasible.reorder("RANDOM()").limit(10).update_all(selected: true)
+end
+
puts "Creating Valuation Assignments"
(1..17).to_a.sample.times do
diff --git a/db/migrate/20161221172447_add_selected_to_budget_investment.rb b/db/migrate/20161221172447_add_selected_to_budget_investment.rb
new file mode 100644
index 000000000..de983aee4
--- /dev/null
+++ b/db/migrate/20161221172447_add_selected_to_budget_investment.rb
@@ -0,0 +1,5 @@
+class AddSelectedToBudgetInvestment < ActiveRecord::Migration
+ def change
+ add_column :budget_investments, :selected, :bool, default: false, index: true
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 3668e1ebf..f891b40ff 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20161102133838) do
+ActiveRecord::Schema.define(version: 20161221172447) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -141,6 +141,7 @@ ActiveRecord::Schema.define(version: 20161102133838) do
t.string "responsible_name"
t.integer "budget_id"
t.integer "group_id"
+ t.boolean "selected", default: false
end
add_index "budget_investments", ["administrator_id"], name: "index_budget_investments_on_administrator_id", using: :btree
diff --git a/spec/factories.rb b/spec/factories.rb
index 5126a8643..4a1dc8e9f 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -248,6 +248,10 @@ FactoryGirl.define do
unfeasibility_explanation "set to unfeasible on creation"
end
+ trait :selected do
+ selected true
+ end
+
trait :finished do
valuation_finished true
end
From 15fade56609e8d69bb4f11d1f47fec43806b6033 Mon Sep 17 00:00:00 2001
From: kikito
Date: Thu, 22 Dec 2016 20:25:17 +0100
Subject: [PATCH 29/73] loads ballot in budget_investments_controller
---
app/controllers/admin/budget_investments_controller.rb | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/app/controllers/admin/budget_investments_controller.rb b/app/controllers/admin/budget_investments_controller.rb
index 399ec0ec8..8369c6cf0 100644
--- a/app/controllers/admin/budget_investments_controller.rb
+++ b/app/controllers/admin/budget_investments_controller.rb
@@ -4,6 +4,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
before_action :load_budget
before_action :load_investment, only: [:show, :edit, :update]
+ before_action :load_ballot, only: [:show, :index]
has_filters %w{valuation_open without_admin managed valuating valuation_finished all}, only: :index
@@ -57,4 +58,10 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
def load_tags
@tags = ActsAsTaggableOn::Tag.budget_investment_tags
end
-end
\ No newline at end of file
+
+ def load_ballot
+ if @budget.balloting?
+ @ballot = Budget::Ballot.where(user: current_user, budget: @budget).first_or_create
+ end
+ end
+end
From 260b9aa1e485b8b733c5c9791b67c3097509b2a2 Mon Sep 17 00:00:00 2001
From: kikito
Date: Thu, 22 Dec 2016 20:25:41 +0100
Subject: [PATCH 30/73] loads @investment_ids in ballot lines controller
---
app/controllers/budgets/ballot/lines_controller.rb | 1 +
1 file changed, 1 insertion(+)
diff --git a/app/controllers/budgets/ballot/lines_controller.rb b/app/controllers/budgets/ballot/lines_controller.rb
index f759dc311..0f8209e5a 100644
--- a/app/controllers/budgets/ballot/lines_controller.rb
+++ b/app/controllers/budgets/ballot/lines_controller.rb
@@ -54,6 +54,7 @@ module Budgets
def load_investments
if params[:investments_ids].present?
+ @investment_ids = params[:investment_ids]
@investments = Budget::Investment.where(id: params[:investments_ids])
end
end
From 54bd5aeeb1e645b6fe4bfc6d1a08fc858e06f0f2 Mon Sep 17 00:00:00 2001
From: kikito
Date: Thu, 22 Dec 2016 20:26:21 +0100
Subject: [PATCH 31/73] adds @budget param to apply_filters_and_search
---
app/controllers/budgets/investments_controller.rb | 2 +-
app/controllers/management/budgets/investments_controller.rb | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb
index 6ad781da6..c17a356cb 100644
--- a/app/controllers/budgets/investments_controller.rb
+++ b/app/controllers/budgets/investments_controller.rb
@@ -24,7 +24,7 @@ module Budgets
respond_to :html, :js
def index
- @investments = @investments.apply_filters_and_search(params).send("sort_by_#{@current_order}").page(params[:page]).per(10).for_render
+ @investments = @investments.apply_filters_and_search(@budget, params).send("sort_by_#{@current_order}").page(params[:page]).per(10).for_render
@investment_ids = @investments.pluck(:id)
load_investment_votes(@investments)
end
diff --git a/app/controllers/management/budgets/investments_controller.rb b/app/controllers/management/budgets/investments_controller.rb
index d7d0789e4..7d9faff34 100644
--- a/app/controllers/management/budgets/investments_controller.rb
+++ b/app/controllers/management/budgets/investments_controller.rb
@@ -7,7 +7,7 @@ class Management::Budgets::InvestmentsController < Management::BaseController
before_action :load_heading, only: [:index, :show, :print]
def index
- @investments = @investments.apply_filters_and_search(params).page(params[:page])
+ @investments = @investments.apply_filters_and_search(@budget, params).page(params[:page])
load_investment_votes(@investments)
end
@@ -36,7 +36,7 @@ class Management::Budgets::InvestmentsController < Management::BaseController
end
def print
- @investments = @investments.apply_filters_and_search(params).order(cached_votes_up: :desc).for_render.limit(15)
+ @investments = @investments.apply_filters_and_search(@budget, params).order(cached_votes_up: :desc).for_render.limit(15)
load_investment_votes(@investments)
end
From 7acedb30f64f473cbabf6490b7ec23935838549c Mon Sep 17 00:00:00 2001
From: kikito
Date: Thu, 22 Dec 2016 20:26:39 +0100
Subject: [PATCH 32/73] fixes parenthesis
---
app/views/budgets/ballot/_ballot.html.erb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/views/budgets/ballot/_ballot.html.erb b/app/views/budgets/ballot/_ballot.html.erb
index 7ed6851ae..749e2121a 100644
--- a/app/views/budgets/ballot/_ballot.html.erb
+++ b/app/views/budgets/ballot/_ballot.html.erb
@@ -47,7 +47,7 @@
<%= t("budgets.ballots.show.remaining",
- amount_city: @ballot.formatted_amount_available(@ballot.heading_for_group(group)).html_safe %>
+ amount_city: @ballot.formatted_amount_available(@ballot.heading_for_group(group))).html_safe %>
<% end %>
From eb648b7269ca0b7db13ae87121b31d017fec5649 Mon Sep 17 00:00:00 2001
From: kikito
Date: Thu, 22 Dec 2016 20:27:01 +0100
Subject: [PATCH 33/73] Adds missing parameters to partials
---
.../budgets/ballot/lines/_refresh_ballots.js.erb | 7 +++++--
app/views/budgets/ballot/lines/create.js.erb | 14 ++++++++++----
app/views/budgets/ballot/lines/destroy.js.erb | 10 ++++++++--
app/views/budgets/investments/index.html.erb | 2 +-
4 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/app/views/budgets/ballot/lines/_refresh_ballots.js.erb b/app/views/budgets/ballot/lines/_refresh_ballots.js.erb
index 69b5aae0b..f81560d96 100644
--- a/app/views/budgets/ballot/lines/_refresh_ballots.js.erb
+++ b/app/views/budgets/ballot/lines/_refresh_ballots.js.erb
@@ -1,5 +1,8 @@
<% if @investments.present? %>
<% @investments.each do |investment| %>
- $("#<%= dom_id(investment) %>_ballot").html('<%= j render("budgets/investments/ballot", investment: investment) %>');
+ $("#<%= dom_id(investment) %>_ballot").html('<%= j render("/budgets/investments/ballot",
+ investment: investment,
+ investment_ids: investment_ids,
+ ballot: ballot) %>');
<% end %>
-<% end %>
\ No newline at end of file
+<% end %>
diff --git a/app/views/budgets/ballot/lines/create.js.erb b/app/views/budgets/ballot/lines/create.js.erb
index 5680fb063..b1c9f76be 100644
--- a/app/views/budgets/ballot/lines/create.js.erb
+++ b/app/views/budgets/ballot/lines/create.js.erb
@@ -1,5 +1,11 @@
-$("#progress_bar").html('<%= j render("budgets/ballot/progress_bar", ballot: @ballot) %>');
-$("#sidebar").html('<%= j render("budgets/investments/sidebar") %>');
-$("#<%= dom_id(@investment) %>_ballot").html('<%= j render("budgets/investments/ballot", investment: @investment) %>');
+$("#progress_bar").html('<%= j render("/budgets/ballot/progress_bar", ballot: @ballot) %>');
+$("#sidebar").html('<%= j render("/budgets/investments/sidebar") %>');
+$("#<%= dom_id(@investment) %>_ballot").html('<%= j render("/budgets/investments/ballot",
+ investment: @investment,
+ investment_ids: @investment_ids,
+ ballot: @ballot) %>');
-<%= render 'refresh_ballots' %>
+<%= render 'refresh_ballots',
+ investment: @investment,
+ investment_ids: @investment_ids,
+ ballot: @ballot %>
diff --git a/app/views/budgets/ballot/lines/destroy.js.erb b/app/views/budgets/ballot/lines/destroy.js.erb
index aaa5ea302..82c303047 100644
--- a/app/views/budgets/ballot/lines/destroy.js.erb
+++ b/app/views/budgets/ballot/lines/destroy.js.erb
@@ -1,6 +1,12 @@
$("#progress_bar").html('<%= j render("budgets/ballot/progress_bar", ballot: @ballot) %>');
$("#sidebar").html('<%= j render("budgets/investments/sidebar") %>');
$("#ballot").html('<%= j render("budgets/ballot/ballot") %>')
-$("#<%= dom_id(@investment) %>_ballot").html('<%= j render("budgets/investments/ballot", investment: @investment) %>');
-<%= render 'refresh_ballots' %>
+$("#<%= dom_id(@investment) %>_ballot").html('<%= j render("/budgets/investments/ballot",
+ investment: @investment,
+ investment_ids: @investment_ids,
+ ballot: @ballot) %>');
+<%= render 'refresh_ballots',
+ investment: @investment,
+ investment_ids: @investment_ids,
+ ballot: @ballot %>
diff --git a/app/views/budgets/investments/index.html.erb b/app/views/budgets/investments/index.html.erb
index 967bbb2e3..b52d09fd7 100644
--- a/app/views/budgets/investments/index.html.erb
+++ b/app/views/budgets/investments/index.html.erb
@@ -8,7 +8,7 @@
<% unless params[:search].present? %>
- <%= render 'header' %>
+ <%= render '/budgets/investments/header' %>
<% end %>
From cd72b7e5374b764df9e0aea8416049a9bccf92b7 Mon Sep 17 00:00:00 2001
From: kikito
Date: Thu, 22 Dec 2016 20:27:16 +0100
Subject: [PATCH 34/73] Renames i18n param
---
config/locales/budgets.en.yml | 4 ++--
config/locales/budgets.es.yml | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/config/locales/budgets.en.yml b/config/locales/budgets.en.yml
index 0c8eb34e1..04af83ddc 100644
--- a/config/locales/budgets.en.yml
+++ b/config/locales/budgets.en.yml
@@ -4,7 +4,7 @@ en:
show:
title: Your ballot
amount_spent: Amount spent
- remaining: "You still have %{amount_city} to invest."
+ remaining: "You still have %{amount} to invest."
remove: Remove vote
voted_html:
one: "You have voted one proposal."
@@ -110,4 +110,4 @@ en:
group: Group
heading: Heading
price: Price
- no_heading: No Heading
\ No newline at end of file
+ no_heading: No Heading
diff --git a/config/locales/budgets.es.yml b/config/locales/budgets.es.yml
index 163dd25ac..cd02e1cd3 100644
--- a/config/locales/budgets.es.yml
+++ b/config/locales/budgets.es.yml
@@ -4,7 +4,7 @@ es:
show:
title: Mis votos
amount_spent: Coste total
- remaining: "Te quedan %{amount_city} para invertir"
+ remaining: "Te quedan %{amount} para invertir"
remove: Quitar voto
voted_html:
one: "Has votado una propuesta."
@@ -110,4 +110,4 @@ es:
group: Grupo
heading: Partida
price: Cantidad
- no_heading: Sin línea
\ No newline at end of file
+ no_heading: Sin línea
From 44758c9278a862474c671568db23f1d18e5b2ff6 Mon Sep 17 00:00:00 2001
From: kikito
Date: Thu, 22 Dec 2016 20:27:29 +0100
Subject: [PATCH 35/73] Fixes spec
---
spec/features/budgets/votes_spec.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/spec/features/budgets/votes_spec.rb b/spec/features/budgets/votes_spec.rb
index dbcd36411..3c92bf658 100644
--- a/spec/features/budgets/votes_spec.rb
+++ b/spec/features/budgets/votes_spec.rb
@@ -94,14 +94,14 @@ feature 'Votes' do
visit budget_investments_path(budget, heading_id: heading.id)
within("#budget_investment_#{investment.id}") do
- find("div.js-supports").hover
+ find("div.js-participation").hover
expect(page).to have_content 'No Selecting Allowed'
end
visit budget_investment_path(budget, investment)
within("#budget_investment_#{investment.id}") do
- find("div.js-supports").hover
+ find("div.js-participation").hover
expect(page).to have_content 'No Selecting Allowed'
end
end
From bb1258f2b2376a180181602ffc65ee29a6716f47 Mon Sep 17 00:00:00 2001
From: kikito
Date: Thu, 22 Dec 2016 20:27:46 +0100
Subject: [PATCH 36/73] Fixes view
---
.../budgets/investments/_header.html.erb | 24 ++++++++-----------
1 file changed, 10 insertions(+), 14 deletions(-)
diff --git a/app/views/budgets/investments/_header.html.erb b/app/views/budgets/investments/_header.html.erb
index 468d1b3c6..610d55186 100644
--- a/app/views/budgets/investments/_header.html.erb
+++ b/app/views/budgets/investments/_header.html.erb
@@ -1,4 +1,4 @@
-<% if @filter_heading_name.present? %>
+<% if @heading.present? %>
@@ -27,20 +27,16 @@
budget_ballot_path(@budget) %>
<% end %>
- <% if false
- #@heading.present? &&
- #@ballot.heading.present? &&
- #@ballot.heading != @heading
- %>
-
-
- <%= t("budget.investments.header.different_heading_active") %>
- <%= link_to @ballot.heading.name, budget_investments_path(budget_id: budget.id, heading_id: @ballot.heading_id) %>
-
+ <% if @ballot.valid_heading?(@heading) %>
+
+ <%= render 'budgets/ballot/progress_bar' %>
+
<% else %>
-
- <%= render 'budgets/ballot/progress_bar' %>
-
+
+
+ <%= t("budget.investments.header.different_heading_active") %>
+ <%= link_to @ballot.heading.name, budget_investments_path(budget_id: budget.id, heading_id: @ballot.heading_id) %>
+
<% end %>
From b5c25cb6ce93c3d9ce21873a1164a99b23e7051c Mon Sep 17 00:00:00 2001
From: kikito
Date: Thu, 22 Dec 2016 20:28:07 +0100
Subject: [PATCH 37/73] Starts working on the budget/ballot_spec
---
spec/features/budgets/ballots_spec.rb | 109 +++++++++++++-------------
1 file changed, 55 insertions(+), 54 deletions(-)
diff --git a/spec/features/budgets/ballots_spec.rb b/spec/features/budgets/ballots_spec.rb
index 6e6977e24..a021c41ac 100644
--- a/spec/features/budgets/ballots_spec.rb
+++ b/spec/features/budgets/ballots_spec.rb
@@ -41,7 +41,7 @@ feature 'Ballots' do
expect(page).to have_link "Investments Type1"
expect(page).to have_link "Investments Type2"
- click_link "Go back"
+ visit budget_path(budget)
click_link "Districts"
expect(page).to have_link "District 1"
@@ -58,11 +58,11 @@ feature 'Ballots' do
district_heading1 = create(:budget_heading, group: districts, name: "District 1")
district_heading2 = create(:budget_heading, group: districts, name: "District 2")
- city_investment1 = create(:budget_investment, :feasible, :finished, heading: city_heading1)
- city_investment2 = create(:budget_investment, :feasible, :finished, heading: city_heading1)
- district1_investment1 = create(:budget_investment, :feasible, :finished, heading: district_heading1)
- district1_investment2 = create(:budget_investment, :feasible, :finished, heading: district_heading1)
- district2_investment1 = create(:budget_investment, :feasible, :finished, heading: district_heading2)
+ city_investment1 = create(:budget_investment, :selected, heading: city_heading1)
+ city_investment2 = create(:budget_investment, :selected, heading: city_heading1)
+ district1_investment1 = create(:budget_investment, :selected, heading: district_heading1)
+ district1_investment2 = create(:budget_investment, :selected, heading: district_heading1)
+ district2_investment1 = create(:budget_investment, :selected, heading: district_heading2)
visit budget_path(budget)
click_link "City"
@@ -72,8 +72,7 @@ feature 'Ballots' do
expect(page).to have_content city_investment1.title
expect(page).to have_content city_investment2.title
- click_link "Go back"
- click_link "Go back"
+ visit budget_path(budget)
click_link "Districts"
click_link "District 1"
@@ -82,7 +81,8 @@ feature 'Ballots' do
expect(page).to have_content district1_investment1.title
expect(page).to have_content district1_investment2.title
- click_link "Go back"
+ visit budget_path(budget)
+ click_link "Districts"
click_link "District 2"
expect(page).to have_css(".budget-investment", count: 1)
@@ -97,7 +97,7 @@ feature 'Ballots' do
district_heading1 = create(:budget_heading, group: districts, name: "District 1")
district_heading2 = create(:budget_heading, group: districts, name: "District 2")
- city_investment = create(:budget_investment, :feasible, :finished, heading: city_heading)
+ city_investment = create(:budget_investment, :selected, heading: city_heading)
visit budget_path(budget)
click_link "City"
@@ -110,8 +110,8 @@ feature 'Ballots' do
context "Adding and Removing Investments" do
scenario "Add a proposal", :js do
- investment1 = create(:budget_investment, :feasible, :finished, budget: budget, heading: heading, group: group, price: 10000)
- investment2 = create(:budget_investment, :feasible, :finished, budget: budget, heading: heading, group: group, price: 20000)
+ investment1 = create(:budget_investment, :selected, budget: budget, heading: heading, group: group, price: 10000)
+ investment2 = create(:budget_investment, :selected, budget: budget, heading: heading, group: group, price: 20000)
visit budget_path(budget)
click_link "Group 1"
@@ -141,23 +141,24 @@ feature 'Ballots' do
end
end
- scenario "Remove a proposal", :js do
- investment1 = create(:budget_investment, :feasible, :finished, budget: budget, heading: heading, group: group, price: 10000)
- ballot = create(:budget_ballot, user: user, budget: budget, investments: [investment1])
+ scenario "Removing a proposal", :js do
+ investment = create(:budget_investment, :selected, budget: budget, heading: heading, group: group, price: 10000)
+ ballot = create(:budget_ballot, user: user, budget: budget)
+ ballot.add_investment(investment)
visit budget_path(budget)
- click_link "Group 1"
+ click_link group.name
- expect(page).to have_content investment1.title
+ expect(page).to have_content investment.title
expect(page).to have_css("#amount-spent", text: "€10,000")
expect(page).to have_css("#amount-available", text: "€990,000")
within("#sidebar") do
- expect(page).to have_content investment1.title
+ expect(page).to have_content investment.title
expect(page).to have_content "€10,000"
end
- within("#budget_investment_#{investment1.id}") do
+ within("#budget_investment_#{investment.id}") do
find('.remove a').trigger('click')
end
@@ -165,7 +166,7 @@ feature 'Ballots' do
expect(page).to have_css("#amount-available", text: "€1,000,000")
within("#sidebar") do
- expect(page).to_not have_content investment1.title
+ expect(page).to_not have_content investment.title
expect(page).to_not have_content "€10,000"
end
end
@@ -183,9 +184,9 @@ feature 'Ballots' do
district_heading1 = create(:budget_heading, group: districts, name: "District 1", price: 1000000)
district_heading2 = create(:budget_heading, group: districts, name: "District 2", price: 2000000)
- investment1 = create(:budget_investment, :feasible, :finished, heading: city_heading, price: 10000)
- investment2 = create(:budget_investment, :feasible, :finished, heading: district_heading1, price: 20000)
- investment3 = create(:budget_investment, :feasible, :finished, heading: district_heading2, price: 30000)
+ investment1 = create(:budget_investment, :selected, heading: city_heading, price: 10000)
+ investment2 = create(:budget_investment, :selected, heading: district_heading1, price: 20000)
+ investment3 = create(:budget_investment, :selected, heading: district_heading2, price: 30000)
visit budget_path(budget)
click_link "City"
@@ -254,7 +255,7 @@ feature 'Ballots' do
end
scenario "Display progress bar after first vote", :js do
- investment = create(:budget_investment, :feasible, :finished, heading: heading, price: 10000)
+ investment = create(:budget_investment, :selected, heading: heading, price: 10000)
visit budget_investments_path(budget, heading_id: heading.id)
@@ -275,7 +276,7 @@ feature 'Ballots' do
let!(:districts_group) { create(:budget_group, budget: budget, name: "Districts") }
let!(:california_heading) { create(:budget_heading, group: districts_group, name: "California") }
let!(:new_york_heading) { create(:budget_heading, group: districts_group, name: "New York") }
- let!(:investment) { create(:budget_investment, :feasible, :finished, heading: california_heading) }
+ let!(:investment) { create(:budget_investment, :selected, heading: california_heading) }
background do
login_as(user)
@@ -299,8 +300,8 @@ feature 'Ballots' do
end
scenario 'Change my heading', :js do
- investment1 = create(:budget_investment, :feasible, :finished, heading: california_heading)
- investment2 = create(:budget_investment, :feasible, :finished, heading: new_york_heading)
+ investment1 = create(:budget_investment, :selected, heading: california_heading)
+ investment2 = create(:budget_investment, :selected, heading: new_york_heading)
create(:budget_ballot, user: user, budget: budget, investments: [investment1])
@@ -323,7 +324,7 @@ feature 'Ballots' do
end
scenario 'View another heading' do
- investment = create(:budget_investment, :feasible, :finished, heading: california_heading)
+ investment = create(:budget_investment, :selected, heading: california_heading)
create(:budget_ballot, user: user, budget: budget, investments: [investment])
@@ -350,12 +351,12 @@ feature 'Ballots' do
ballot = create(:budget_ballot, user: user, budget: budget)
- investment1 = create(:budget_investment, :feasible, price: 10, heading: heading1, group: group1)
- investment2 = create(:budget_investment, :feasible, price: 10, heading: heading1, group: group1)
+ investment1 = create(:budget_investment, :selected, price: 10, heading: heading1, group: group1)
+ investment2 = create(:budget_investment, :selected, price: 10, heading: heading1, group: group1)
- investment3 = create(:budget_investment, :feasible, price: 5, heading: heading2, group: group2)
- investment4 = create(:budget_investment, :feasible, price: 5, heading: heading2, group: group2)
- investment5 = create(:budget_investment, :feasible, price: 5, heading: heading2, group: group2)
+ investment3 = create(:budget_investment, :selected, price: 5, heading: heading2, group: group2)
+ investment4 = create(:budget_investment, :selected, price: 5, heading: heading2, group: group2)
+ investment5 = create(:budget_investment, :selected, price: 5, heading: heading2, group: group2)
create(:budget_ballot_line, ballot: ballot, investment: investment1, group: group1)
create(:budget_ballot_line, ballot: ballot, investment: investment2, group: group1)
@@ -387,7 +388,7 @@ feature 'Ballots' do
scenario 'Removing spending proposals from ballot', :js do
user = create(:user, :level_two)
ballot = create(:budget_ballot, user: user, budget: budget)
- investment = create(:budget_investment, :feasible, :finished, price: 10, heading: heading, group: group)
+ investment = create(:budget_investment, :selected, price: 10, heading: heading, group: group)
create(:budget_ballot_line, ballot: ballot, investment: investment, heading: heading, group: group)
login_as(user)
@@ -405,8 +406,8 @@ feature 'Ballots' do
scenario 'Removing spending proposals from ballot (sidebar)', :js do
user = create(:user, :level_two)
- investment1 = create(:budget_investment, :feasible, :finished, price: 10000, heading: heading)
- investment2 = create(:budget_investment, :feasible, :finished, price: 20000, heading: heading)
+ investment1 = create(:budget_investment, :selected, price: 10000, heading: heading)
+ investment2 = create(:budget_investment, :selected, price: 20000, heading: heading)
ballot = create(:budget_ballot, budget: budget, user: user, investments: [investment1, investment2])
@@ -443,7 +444,7 @@ feature 'Ballots' do
context 'Permissions' do
scenario 'User not logged in', :js do
- investment = create(:budget_investment, :feasible, :finished, heading: heading)
+ investment = create(:budget_investment, :selected, heading: heading)
visit budget_investments_path(budget, heading_id: heading.id)
@@ -455,7 +456,7 @@ feature 'Ballots' do
scenario 'User not verified', :js do
user = create(:user)
- investment = create(:budget_investment, :feasible, :finished, heading: heading)
+ investment = create(:budget_investment, :selected, heading: heading)
login_as(user)
visit budget_investments_path(budget, heading_id: heading.id)
@@ -468,7 +469,7 @@ feature 'Ballots' do
scenario 'User is organization', :js do
org = create(:organization)
- investment = create(:budget_investment, :feasible, :finished, heading: heading)
+ investment = create(:budget_investment, :selected, heading: heading)
login_as(org.user)
visit budget_investments_path(budget, heading_id: heading.id)
@@ -479,9 +480,9 @@ feature 'Ballots' do
end
end
- scenario 'Unfeasible investments' do
+ scenario 'Unselected investments' do
user = create(:user, :level_two)
- investment = create(:budget_investment, :finished, :unfeasible, heading: heading)
+ investment = create(:budget_investment, heading: heading)
login_as(user)
visit budget_investments_path(budget, heading_id: heading.id, unfeasible: 1)
@@ -493,7 +494,7 @@ feature 'Ballots' do
scenario 'Investments with feasibility undecided are not shown' do
user = create(:user, :level_two)
- investment = create(:budget_investment, :finished, feasibility: "undecided", heading: heading)
+ investment = create(:budget_investment, feasibility: "undecided", heading: heading)
login_as(user)
visit budget_investments_path(budget, heading_id: heading.id)
@@ -509,8 +510,8 @@ feature 'Ballots' do
california = create(:geozone)
new_york = create(:geozone)
- sp1 = create(:spending_proposal, :feasible, :finished, geozone: california)
- sp2 = create(:spending_proposal, :feasible, :finished, geozone: new_york)
+ sp1 = create(:spending_proposal, :selected, geozone: california)
+ sp2 = create(:spending_proposal, :selected, geozone: new_york)
create(:ballot, user: user, geozone: california, spending_proposals: [sp1])
@@ -527,7 +528,7 @@ feature 'Ballots' do
user = create(:user, :level_two)
california = create(:geozone)
- sp1 = create(:spending_proposal, :feasible, :finished, price: 25000000)
+ sp1 = create(:spending_proposal, :selected, price: 25000000)
login_as(user)
visit spending_proposals_path(geozone: 'all')
@@ -542,8 +543,8 @@ feature 'Ballots' do
user = create(:user, :level_two)
california = create(:geozone)
- sp1 = create(:spending_proposal, :feasible, :finished, price: 20000000)
- sp2 = create(:spending_proposal, :feasible, :finished, price: 5000000)
+ sp1 = create(:spending_proposal, :selected, price: 20000000)
+ sp2 = create(:spending_proposal, :selected, price: 5000000)
login_as(user)
visit spending_proposals_path(geozone: 'all')
@@ -563,8 +564,8 @@ feature 'Ballots' do
scenario 'Displays error message for all proposals (on destroy)', :js do
user = create(:user, :level_two)
- sp1 = create(:spending_proposal, :feasible, :finished, price: 24000000)
- sp2 = create(:spending_proposal, :feasible, :finished, price: 5000000)
+ sp1 = create(:spending_proposal, :selected, price: 24000000)
+ sp2 = create(:spending_proposal, :selected, price: 5000000)
create(:ballot, user: user, spending_proposals: [sp1])
@@ -591,8 +592,8 @@ feature 'Ballots' do
scenario 'Displays error message for all proposals (on destroy from sidebar)', :js do
user = create(:user, :level_two)
- sp1 = create(:spending_proposal, :feasible, :finished, price: 24000000)
- sp2 = create(:spending_proposal, :feasible, :finished, price: 5000000)
+ sp1 = create(:spending_proposal, :selected, price: 24000000)
+ sp2 = create(:spending_proposal, :selected, price: 5000000)
create(:ballot, user: user, spending_proposals: [sp1])
@@ -622,8 +623,8 @@ feature 'Ballots' do
user = create(:user, :level_two)
california = create(:geozone)
- sp1 = create(:spending_proposal, :feasible, :finished, price: 20000000)
- sp2 = create(:spending_proposal, :feasible, :finished, price: 5000000)
+ sp1 = create(:spending_proposal, :selected, price: 20000000)
+ sp2 = create(:spending_proposal, :selected, price: 5000000)
login_as(user)
visit spending_proposals_path(geozone: 'all')
@@ -644,7 +645,7 @@ end
feature "Ballots in the wrong phase" do
background { login_as(create(:user, :level_two)) }
- let(:sp) { create(:spending_proposal, :feasible, :finished, price: 10000) }
+ let(:sp) { create(:spending_proposal, :selected, price: 10000) }
scenario "When not on phase 3" do
Setting['feature.spending_proposal_features.phase3'] = nil
From f125941bbfdb4e768851adc652cac3124a17537e Mon Sep 17 00:00:00 2001
From: kikito
Date: Fri, 23 Dec 2016 15:22:19 +0100
Subject: [PATCH 38/73] Tweaks unselected error in ballot/line
---
app/models/budget/ballot/line.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/models/budget/ballot/line.rb b/app/models/budget/ballot/line.rb
index 730398edc..83e388ee1 100644
--- a/app/models/budget/ballot/line.rb
+++ b/app/models/budget/ballot/line.rb
@@ -24,7 +24,7 @@ class Budget
end
def unselected
- errors.add(:unselected, "unselected investment") unless investment.selected?
+ errors.add(:investment, "unselected investment") unless investment.selected?
end
def heading_proposal?
From 21f396faaaccf4d4e87373ceaebd48ea85bcdbc7 Mon Sep 17 00:00:00 2001
From: kikito
Date: Fri, 23 Dec 2016 15:23:31 +0100
Subject: [PATCH 39/73] Fixes budget model specs using :selected & automatic
line denormalization
---
spec/models/budget/ballot/line_spec.rb | 17 ++++++---------
spec/models/budget/ballot_spec.rb | 30 ++++++++++++--------------
spec/models/budget/investment_spec.rb | 16 +++++++-------
3 files changed, 28 insertions(+), 35 deletions(-)
diff --git a/spec/models/budget/ballot/line_spec.rb b/spec/models/budget/ballot/line_spec.rb
index 885998eb1..7ce4dcbf7 100644
--- a/spec/models/budget/ballot/line_spec.rb
+++ b/spec/models/budget/ballot/line_spec.rb
@@ -6,7 +6,7 @@ describe "Budget::Ballot::Line" do
let(:budget){ create(:budget) }
let(:group){ create(:budget_group, budget: budget) }
let(:heading){ create(:budget_heading, group: group, price: 10000000) }
- let(:investment){ create(:budget_investment, :feasible, price: 5000000, heading: heading) }
+ let(:investment){ create(:budget_investment, :selected, price: 5000000, heading: heading) }
let(:ballot) { create(:budget_ballot, budget: budget) }
let(:ballot_line) { build(:budget_ballot_line, ballot: ballot, investment: investment) }
@@ -29,19 +29,14 @@ describe "Budget::Ballot::Line" do
end
end
- describe 'Feasibility' do
- it "should not be valid if investment is unfeasible" do
- investment.update(feasibility: "unfeasible")
+ describe 'Selectibility' do
+ it "should not be valid if investment is unselected" do
+ investment.update(selected: false)
expect(ballot_line).to_not be_valid
end
- it "should not be valid if investment feasibility is undecided" do
- investment.update(feasibility: "undecided", price: 20000)
- expect(ballot_line).to_not be_valid
- end
-
- it "should be valid if investment is feasible" do
- investment.update(feasibility: "feasible", price: 20000)
+ it "should be valid if investment is selected" do
+ investment.update(selected: true, price: 20000)
expect(ballot_line).to be_valid
end
end
diff --git a/spec/models/budget/ballot_spec.rb b/spec/models/budget/ballot_spec.rb
index 97fa966fc..e99a2276d 100644
--- a/spec/models/budget/ballot_spec.rb
+++ b/spec/models/budget/ballot_spec.rb
@@ -9,15 +9,15 @@ describe Budget::Ballot do
group2 = create(:budget_group, budget: budget)
heading1 = create(:budget_heading, group: group1, price: 100000)
heading2 = create(:budget_heading, group: group2, price: 200000)
- inv1 = create(:budget_investment, :feasible, price: 10000, heading: heading1)
- inv2 = create(:budget_investment, :feasible, price: 20000, heading: heading2)
+ inv1 = create(:budget_investment, :selected, price: 10000, heading: heading1)
+ inv2 = create(:budget_investment, :selected, price: 20000, heading: heading2)
ballot = create(:budget_ballot, budget: budget)
- ballot.add_investment inv1
+ ballot.investments << inv1
expect(ballot.total_amount_spent).to eq 10000
- ballot.add_investment inv2
+ ballot.investments << inv2
expect(ballot.total_amount_spent).to eq 30000
end
@@ -25,17 +25,16 @@ describe Budget::Ballot do
it "returns the amount spent on all investments assigned to a specific heading" do
heading = create(:budget_heading)
budget = heading.group.budget
- inv1 = create(:budget_investment, :feasible, price: 10000, heading: heading)
- inv2 = create(:budget_investment, :feasible, price: 20000, heading: create(:budget_heading, group: heading.group))
- inv3 = create(:budget_investment, :feasible, price: 40000, heading: heading)
+ inv1 = create(:budget_investment, :selected, price: 10000, heading: heading)
+ inv2 = create(:budget_investment, :selected, price: 20000, heading: create(:budget_heading, group: heading.group))
+ inv3 = create(:budget_investment, :selected, price: 40000, heading: heading)
ballot = create(:budget_ballot, budget: budget)
- ballot.add_investment inv1
- ballot.add_investment inv2
+ ballot.investments << inv1 << inv2
expect(ballot.amount_spent(heading)).to eq 10000
- ballot.add_investment inv3
+ ballot.investments << inv3
expect(ballot.amount_spent(heading)).to eq 50000
end
@@ -47,18 +46,17 @@ describe Budget::Ballot do
group = create(:budget_group, budget: budget)
heading1 = create(:budget_heading, group: group, price: 1000)
heading2 = create(:budget_heading, group: group, price: 300)
- inv1 = create(:budget_investment, :feasible, price: 100, heading: heading1)
- inv2 = create(:budget_investment, :feasible, price: 200, heading: heading2)
- inv3 = create(:budget_investment, :feasible, price: 400, heading: heading1)
+ inv1 = create(:budget_investment, :selected, price: 100, heading: heading1)
+ inv2 = create(:budget_investment, :selected, price: 200, heading: heading2)
+ inv3 = create(:budget_investment, :selected, price: 400, heading: heading1)
ballot = create(:budget_ballot, budget: budget)
- ballot.add_investment inv1
- ballot.add_investment inv2
+ ballot.investments << inv1 << inv2
expect(ballot.amount_available(heading1)).to eq 900
expect(ballot.amount_available(heading2)).to eq 100
- ballot.add_investment inv3
+ ballot.investments << inv3
expect(ballot.amount_available(heading1)).to eq 500
end
diff --git a/spec/models/budget/investment_spec.rb b/spec/models/budget/investment_spec.rb
index 6b98025ad..a56cfe46e 100644
--- a/spec/models/budget/investment_spec.rb
+++ b/spec/models/budget/investment_spec.rb
@@ -338,23 +338,23 @@ describe Budget::Investment do
california = create(:budget_heading, group: group)
new_york = create(:budget_heading, group: group)
- inv1 = create(:budget_investment, :feasible, budget: budget, group: group, heading: california)
- inv2 = create(:budget_investment, :feasible, budget: budget, group: group, heading: new_york)
- b = create(:budget_ballot, user: user, budget: budget)
- b.add_investment inv1
+ inv1 = create(:budget_investment, :selected, budget: budget, group: group, heading: california)
+ inv2 = create(:budget_investment, :selected, budget: budget, group: group, heading: new_york)
+ ballot = create(:budget_ballot, user: user, budget: budget)
+ ballot.investments << inv1
- expect(inv2.reason_for_not_being_ballotable_by(user, b)).to eq(:different_heading_assigned)
+ expect(inv2.reason_for_not_being_ballotable_by(user, ballot)).to eq(:different_heading_assigned)
end
it "rejects proposals with price higher than current available money" do
budget.phase = "balloting"
districts = create(:budget_group, budget: budget)
carabanchel = create(:budget_heading, group: districts, price: 35)
- inv1 = create(:budget_investment, :feasible, budget: budget, group: districts, heading: carabanchel, price: 30)
- inv2 = create(:budget_investment, :feasible, budget: budget, group: districts, heading: carabanchel, price: 10)
+ inv1 = create(:budget_investment, :selected, budget: budget, group: districts, heading: carabanchel, price: 30)
+ inv2 = create(:budget_investment, :selected, budget: budget, group: districts, heading: carabanchel, price: 10)
ballot = create(:budget_ballot, user: user, budget: budget)
- ballot.add_investment inv1
+ ballot.investments << inv1
expect(inv2.reason_for_not_being_ballotable_by(user, ballot)).to eq(:not_enough_money)
end
From a589d8a76ddedca984bdf19c45a85e6669ae697b Mon Sep 17 00:00:00 2001
From: kikito
Date: Fri, 23 Dec 2016 15:37:32 +0100
Subject: [PATCH 40/73] Simplifies ballot.add_investment using automatic
denormalization
---
app/models/budget/ballot.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/models/budget/ballot.rb b/app/models/budget/ballot.rb
index 79aa56ce7..8f466936c 100644
--- a/app/models/budget/ballot.rb
+++ b/app/models/budget/ballot.rb
@@ -9,7 +9,7 @@ class Budget
has_many :headings, -> { uniq }, through: :groups
def add_investment(investment)
- lines.create!(budget: budget, investment: investment, heading: investment.heading, group_id: investment.heading.group_id)
+ lines.create!(investment: investment)
end
def total_amount_spent
From 615217e36e79c630299bcb0770fb77b113da4dab Mon Sep 17 00:00:00 2001
From: kikito
Date: Fri, 23 Dec 2016 15:37:55 +0100
Subject: [PATCH 41/73] Fixes errors in header view
---
app/views/budgets/investments/_header.html.erb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/app/views/budgets/investments/_header.html.erb b/app/views/budgets/investments/_header.html.erb
index 610d55186..3dfc0fab6 100644
--- a/app/views/budgets/investments/_header.html.erb
+++ b/app/views/budgets/investments/_header.html.erb
@@ -34,8 +34,8 @@
<% else %>
- <%= t("budget.investments.header.different_heading_active") %>
- <%= link_to @ballot.heading.name, budget_investments_path(budget_id: budget.id, heading_id: @ballot.heading_id) %>
+ <%= t("budget.investments.header.different_heading_assigned") %>
+ <%= link_to @heading.name, budget_investments_path(budget_id: @budget.id, heading_id: @heading.id) %>
<% end %>
From 0578fb5479dcbc6f18c17d80fb9cdf7a1cca2f43 Mon Sep 17 00:00:00 2001
From: kikito
Date: Fri, 23 Dec 2016 15:38:21 +0100
Subject: [PATCH 42/73] Fixes errors when adding investments to ballots in
specs
---
spec/features/budgets/ballots_spec.rb | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/spec/features/budgets/ballots_spec.rb b/spec/features/budgets/ballots_spec.rb
index a021c41ac..7913dad7c 100644
--- a/spec/features/budgets/ballots_spec.rb
+++ b/spec/features/budgets/ballots_spec.rb
@@ -144,7 +144,7 @@ feature 'Ballots' do
scenario "Removing a proposal", :js do
investment = create(:budget_investment, :selected, budget: budget, heading: heading, group: group, price: 10000)
ballot = create(:budget_ballot, user: user, budget: budget)
- ballot.add_investment(investment)
+ ballot.investments << investment
visit budget_path(budget)
click_link group.name
@@ -216,10 +216,6 @@ feature 'Ballots' do
expect(page).to have_content "Remove"
end
- visit budget_path(budget)
- click_link "Districts"
- click_link "District 1"
-
expect(page).to have_css("#amount-spent", text: "€20,000")
expect(page).to have_css("#amount-available", text: "€980,000")
@@ -249,8 +245,7 @@ feature 'Ballots' do
click_link "Districts"
click_link "District 2"
- expect(page).to have_css("#amount-spent", text: "€0")
- expect(page).to have_css("#amount-spent", text: "€2,000,000")
+ expect(page).to have_content("You have active votes in another heading")
end
end
@@ -303,7 +298,8 @@ feature 'Ballots' do
investment1 = create(:budget_investment, :selected, heading: california_heading)
investment2 = create(:budget_investment, :selected, heading: new_york_heading)
- create(:budget_ballot, user: user, budget: budget, investments: [investment1])
+ ballot = create(:budget_ballot, user: user, budget: budget)
+ ballot.investments << investment1
visit budget_investments_path(budget, heading_id: california_heading.id)
@@ -326,7 +322,8 @@ feature 'Ballots' do
scenario 'View another heading' do
investment = create(:budget_investment, :selected, heading: california_heading)
- create(:budget_ballot, user: user, budget: budget, investments: [investment])
+ ballot = create(:budget_ballot, user: user, budget: budget)
+ ballot.investments << investment
visit budget_investments_path(budget, heading_id: new_york_heading.id)
@@ -409,7 +406,8 @@ feature 'Ballots' do
investment1 = create(:budget_investment, :selected, price: 10000, heading: heading)
investment2 = create(:budget_investment, :selected, price: 20000, heading: heading)
- ballot = create(:budget_ballot, budget: budget, user: user, investments: [investment1, investment2])
+ ballot = create(:budget_ballot, budget: budget, user: user)
+ ballot.investments << investment1 << investment2
login_as(user)
visit budget_investments_path(budget, heading_id: heading.id)
From 9e0007ba359f91c48f232c3e0d13ef36993dd382 Mon Sep 17 00:00:00 2001
From: kikito
Date: Fri, 23 Dec 2016 15:38:31 +0100
Subject: [PATCH 43/73] renames i18n entry
---
config/locales/budgets.en.yml | 2 +-
config/locales/budgets.es.yml | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/config/locales/budgets.en.yml b/config/locales/budgets.en.yml
index 04af83ddc..3ff3ff007 100644
--- a/config/locales/budgets.en.yml
+++ b/config/locales/budgets.en.yml
@@ -105,7 +105,7 @@ en:
vote: Vote
header:
check_ballot: Check my ballot
- different_heading_active: You have active votes in another district.
+ different_heading_assigned: You have active votes in another heading.
show:
group: Group
heading: Heading
diff --git a/config/locales/budgets.es.yml b/config/locales/budgets.es.yml
index cd02e1cd3..d5466dc5d 100644
--- a/config/locales/budgets.es.yml
+++ b/config/locales/budgets.es.yml
@@ -105,7 +105,7 @@ es:
vote: Votar
header:
check_ballot: Revisar mis votos
- different_heading_active: Ya apoyaste propuestas de otro distrito.
+ different_heading_assigned: Ya apoyaste propuestas de otro distrito.
show:
group: Grupo
heading: Partida
From 4589ba5f0bdb828ecf4ab522335c998b1b10371f Mon Sep 17 00:00:00 2001
From: kikito
Date: Fri, 23 Dec 2016 18:34:42 +0100
Subject: [PATCH 44/73] Fixes incorrect implementation of add_to_ballot common
action
---
spec/support/common_actions.rb | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb
index e6529c557..8eaf5782f 100644
--- a/spec/support/common_actions.rb
+++ b/spec/support/common_actions.rb
@@ -278,7 +278,9 @@ module CommonActions
def add_to_ballot(budget_investment)
within("#budget_investment_#{budget_investment.id}") do
- click_link "Spend money on this"#find('.add a').trigger('click')
+ find('.add a').trigger('click')
+ expect(page).to have_content "Remove"
end
end
+
end
From 56b19b257d14068132c265750c6824974cca8bd3 Mon Sep 17 00:00:00 2001
From: kikito
Date: Fri, 23 Dec 2016 18:35:25 +0100
Subject: [PATCH 45/73] Uses add_to_ballot in a bunch of specs
---
spec/features/budgets/ballots_spec.rb | 42 ++++++---------------------
1 file changed, 9 insertions(+), 33 deletions(-)
diff --git a/spec/features/budgets/ballots_spec.rb b/spec/features/budgets/ballots_spec.rb
index 7913dad7c..155d02da8 100644
--- a/spec/features/budgets/ballots_spec.rb
+++ b/spec/features/budgets/ballots_spec.rb
@@ -116,9 +116,7 @@ feature 'Ballots' do
visit budget_path(budget)
click_link "Group 1"
- within("#budget_investment_#{investment1.id}") do
- find('.add a').trigger('click')
- end
+ add_to_ballot(investment1)
expect(page).to have_css("#amount-spent", text: "€10,000")
expect(page).to have_css("#amount-available", text: "€990,000")
@@ -128,9 +126,7 @@ feature 'Ballots' do
expect(page).to have_content "€10,000"
end
- within("#budget_investment_#{investment2.id}") do
- find('.add a').trigger('click')
- end
+ add_to_ballot(investment2)
expect(page).to have_css("#amount-spent", text: "€30,000")
expect(page).to have_css("#amount-available", text: "€970,000")
@@ -191,10 +187,7 @@ feature 'Ballots' do
visit budget_path(budget)
click_link "City"
- within("#budget_investment_#{investment1.id}") do
- find('.add a').trigger('click')
- expect(page).to have_content "Remove"
- end
+ add_to_ballot(investment1)
expect(page).to have_css("#amount-spent", text: "€10,000")
expect(page).to have_css("#amount-available", text: "€9,990,000")
@@ -211,10 +204,7 @@ feature 'Ballots' do
expect(page).to have_css("#amount-spent", text: "€0")
expect(page).to have_css("#amount-spent", text: "€1,000,000")
- within("#budget_investment_#{investment2.id}") do
- find('.add a').trigger('click')
- expect(page).to have_content "Remove"
- end
+ add_to_ballot(investment2)
expect(page).to have_css("#amount-spent", text: "€20,000")
expect(page).to have_css("#amount-available", text: "€980,000")
@@ -255,10 +245,7 @@ feature 'Ballots' do
visit budget_investments_path(budget, heading_id: heading.id)
expect(page).to have_content investment.title
- within("#budget_investment_#{investment.id}") do
- find('.add a').trigger('click')
- expect(page).to have_content "Remove"
- end
+ add_to_ballot(investment)
within("#progress_bar") do
expect(page).to have_css("#amount-spent", text: "€10,000")
@@ -282,10 +269,7 @@ feature 'Ballots' do
click_link "Districts"
click_link "California"
- within("#budget_investment_#{investment.id}") do
- find('.add a').trigger('click')
- expect(page).to have_content "Remove"
- end
+ add_to_ballot(investment)
visit budget_path(budget)
click_link "Districts"
@@ -309,9 +293,7 @@ feature 'Ballots' do
visit budget_investments_path(budget, heading_id: new_york_heading.id)
- within("#budget_investment_#{investment2.id}") do
- find('.add a').trigger('click')
- end
+ add_to_ballot(investment2)
visit budget_path(budget)
click_link "Districts"
@@ -547,10 +529,7 @@ feature 'Ballots' do
login_as(user)
visit spending_proposals_path(geozone: 'all')
- within("#spending_proposal_#{sp1.id}") do
- find('.add a').trigger('click')
- expect(page).to have_content "Remove vote"
- end
+ add_to_ballot(sp1)
within("#spending_proposal_#{sp2.id}") do
find("div.ballot").hover
@@ -627,10 +606,7 @@ feature 'Ballots' do
login_as(user)
visit spending_proposals_path(geozone: 'all')
- within("#spending_proposal_#{sp1.id}") do
- find('.add a').trigger('click')
- expect(page).to have_content "Remove vote"
- end
+ add_to_ballot(sp1)
within("#spending_proposal_#{sp2.id}") do
find("div.ballot").trigger(:mouseover)
From 0cb07758723bf3f6561b3039cdd12d6a7202fbf6 Mon Sep 17 00:00:00 2001
From: kikito
Date: Fri, 23 Dec 2016 18:36:19 +0100
Subject: [PATCH 46/73] Uses selected instead of valuation_finished in
investment_spec
---
spec/features/budgets/investments_spec.rb | 26 +++++++++++------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb
index 76ddd8d32..3dd2c03e4 100644
--- a/spec/features/budgets/investments_spec.rb
+++ b/spec/features/budgets/investments_spec.rb
@@ -285,8 +285,8 @@ feature 'Budget Investments' do
scenario "Index" do
user = create(:user, :level_two)
- sp1 = create(:budget_investment, :feasible, :finished, heading: heading, price: 10000)
- sp2 = create(:budget_investment, :feasible, :finished, heading: heading, price: 20000)
+ sp1 = create(:budget_investment, :selected, heading: heading, price: 10000)
+ sp2 = create(:budget_investment, :selected, heading: heading, price: 20000)
login_as(user)
visit root_path
@@ -306,10 +306,10 @@ feature 'Budget Investments' do
end
end
- scenario 'Order by cost (only in phase3)' do
- create(:budget_investment, :feasible, :finished, heading: heading, title: 'Build a nice house', price: 1000).update_column(:confidence_score, 10)
- create(:budget_investment, :feasible, :finished, heading: heading, title: 'Build an ugly house', price: 1000).update_column(:confidence_score, 5)
- create(:budget_investment, :feasible, :finished, heading: heading, title: 'Build a skyscraper', price: 20000)
+ scenario 'Order by cost (only when balloting)' do
+ create(:budget_investment, :selected, heading: heading, title: 'Build a nice house', price: 1000).update_column(:confidence_score, 10)
+ create(:budget_investment, :selected, heading: heading, title: 'Build an ugly house', price: 1000).update_column(:confidence_score, 5)
+ create(:budget_investment, :selected, heading: heading, title: 'Build a skyscraper', price: 20000)
visit budget_investments_path(budget, heading_id: heading.id)
@@ -327,7 +327,7 @@ feature 'Budget Investments' do
scenario "Show" do
user = create(:user, :level_two)
- sp1 = create(:budget_investment, :feasible, :finished, heading: heading, price: 10000)
+ sp1 = create(:budget_investment, :selected, heading: heading, price: 10000)
login_as(user)
visit budget_investments_path(budget, heading_id: heading.id)
@@ -350,12 +350,12 @@ feature 'Budget Investments' do
new_york_heading = create(:budget_heading, group: group, geozone: new_york, name: new_york.name)
- sp1 = create(:budget_investment, :feasible, :finished, price: 1, heading: global_heading)
- sp2 = create(:budget_investment, :feasible, :finished, price: 10, heading: global_heading)
- sp3 = create(:budget_investment, :feasible, :finished, price: 100, heading: global_heading)
- sp4 = create(:budget_investment, :feasible, :finished, price: 1000, heading: carabanchel_heading)
- sp5 = create(:budget_investment, :feasible, :finished, price: 10000, heading: carabanchel_heading)
- sp6 = create(:budget_investment, :feasible, :finished, price: 100000, heading: new_york_heading)
+ sp1 = create(:budget_investment, :selected, price: 1, heading: global_heading)
+ sp2 = create(:budget_investment, :selected, price: 10, heading: global_heading)
+ sp3 = create(:budget_investment, :selected, price: 100, heading: global_heading)
+ sp4 = create(:budget_investment, :selected, price: 1000, heading: carabanchel_heading)
+ sp5 = create(:budget_investment, :selected, price: 10000, heading: carabanchel_heading)
+ sp6 = create(:budget_investment, :selected, price: 100000, heading: new_york_heading)
login_as(user)
visit budget_path(budget)
From de1ade0eb89f702b94d6661b6665b092fedc3fa5 Mon Sep 17 00:00:00 2001
From: kikito
Date: Fri, 23 Dec 2016 18:36:42 +0100
Subject: [PATCH 47/73] Fixes erroneous link in view
---
app/views/budgets/investments/_header.html.erb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/views/budgets/investments/_header.html.erb b/app/views/budgets/investments/_header.html.erb
index 3dfc0fab6..1bd8cc4a0 100644
--- a/app/views/budgets/investments/_header.html.erb
+++ b/app/views/budgets/investments/_header.html.erb
@@ -11,7 +11,7 @@
<% if can? :show, @ballot %>
<%= link_to t("budget.investments.header.check_ballot"),
- budget_ballot_path(@budget, @ballot),
+ budget_ballot_path(@budget),
class: "button float-right" %>
<% end %>
From bbb8ac830c2e6f9b44f869f1f2883307cf7f6ac0 Mon Sep 17 00:00:00 2001
From: kikito
Date: Fri, 23 Dec 2016 18:37:02 +0100
Subject: [PATCH 48/73] Fixes erroneous i18n param in view
---
app/views/budgets/ballot/_ballot.html.erb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/views/budgets/ballot/_ballot.html.erb b/app/views/budgets/ballot/_ballot.html.erb
index 749e2121a..11be78ff2 100644
--- a/app/views/budgets/ballot/_ballot.html.erb
+++ b/app/views/budgets/ballot/_ballot.html.erb
@@ -47,7 +47,7 @@
<%= t("budgets.ballots.show.remaining",
- amount_city: @ballot.formatted_amount_available(@ballot.heading_for_group(group))).html_safe %>
+ amount: @ballot.formatted_amount_available(@ballot.heading_for_group(group))).html_safe %>
<% end %>
From 767c5378839006fc798e1affa724cf9e69e190a2 Mon Sep 17 00:00:00 2001
From: kikito
Date: Fri, 23 Dec 2016 18:37:14 +0100
Subject: [PATCH 49/73] Fixes 1 spec in investments_spec
---
spec/features/budgets/investments_spec.rb | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb
index 3dd2c03e4..2db767bd7 100644
--- a/spec/features/budgets/investments_spec.rb
+++ b/spec/features/budgets/investments_spec.rb
@@ -361,26 +361,25 @@ feature 'Budget Investments' do
visit budget_path(budget)
click_link "Global Group"
- # No need to click_link "Global Heading" because groups with a single heading redirect to the
- # list of investments directly
+ # No need to click_link "Global Heading" because the link of a group with a single heading
+ # points to the list of investments directly
add_to_ballot(sp1)
add_to_ballot(sp2)
- visit budgets_path
+ visit budget_path(budget)
- click_link budget.name
click_link "Health"
click_link "Carabanchel"
add_to_ballot(sp4)
add_to_ballot(sp5)
- click_link "Check my ballot"
+ visit budget_ballot_path(budget)
expect(page).to have_content "You can change your vote at any time until the close of this phase"
- within("#city_wide") do
+ within("#budget_group_#{global_group.id}") do
expect(page).to have_content sp1.title
expect(page).to have_content sp1.price
@@ -391,15 +390,15 @@ feature 'Budget Investments' do
expect(page).to_not have_content sp3.price
end
- within("#district_wide") do
+ within("#budget_group_#{group.id}") do
expect(page).to have_content sp4.title
- expect(page).to have_content "$1,000"
+ expect(page).to have_content "€1,000"
expect(page).to have_content sp5.title
- expect(page).to have_content "$10,000"
+ expect(page).to have_content "€10,000"
expect(page).to_not have_content sp6.title
- expect(page).to_not have_content "$100,000"
+ expect(page).to_not have_content "€100,000"
end
end
From 03ef20bfdeb89d194dea0364fd5a07412cec5a96 Mon Sep 17 00:00:00 2001
From: kikito
Date: Sat, 24 Dec 2016 14:42:46 +0100
Subject: [PATCH 50/73] Merges orders_helper functionality inside has_orders
concern
Both these objects where using/setting a variable called valid_orders.
As a results, some specs where becoming flacky
(features/budgets/investments_spec.rb, balloting phase). By putting
them together, there is no `valid_orders` variable any more (everything
is @valid_orders) and the flackyness is gone.
---
app/controllers/concerns/has_orders.rb | 4 ++--
app/helpers/orders_helper.rb | 7 -------
app/views/shared/_order_links.html.erb | 2 +-
app/views/shared/_order_selector.html.erb | 2 +-
spec/controllers/concerns/has_orders_spec.rb | 13 +++++++++----
spec/helpers/orders_helper_spec.rb | 18 ------------------
6 files changed, 13 insertions(+), 33 deletions(-)
delete mode 100644 app/helpers/orders_helper.rb
delete mode 100644 spec/helpers/orders_helper_spec.rb
diff --git a/app/controllers/concerns/has_orders.rb b/app/controllers/concerns/has_orders.rb
index b17781da2..7adadc1d3 100644
--- a/app/controllers/concerns/has_orders.rb
+++ b/app/controllers/concerns/has_orders.rb
@@ -4,8 +4,8 @@ module HasOrders
class_methods do
def has_orders(valid_orders, *args)
before_action(*args) do |c|
- valid_orders = valid_orders.call(c) if valid_orders.respond_to?(:call)
- @valid_orders = valid_orders
+ @valid_orders = valid_orders.respond_to?(:call) ? valid_orders.call(c) : valid_orders
+ @valid_orders.delete('relevance') unless params[:search].present?
@current_order = @valid_orders.include?(params[:order]) ? params[:order] : @valid_orders.first
end
end
diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb
deleted file mode 100644
index 08d5588ca..000000000
--- a/app/helpers/orders_helper.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-module OrdersHelper
-
- def valid_orders
- @valid_orders.reject { |order| order =='relevance' && params[:search].blank? }
- end
-
-end
\ No newline at end of file
diff --git a/app/views/shared/_order_links.html.erb b/app/views/shared/_order_links.html.erb
index 1032939d9..622f253ec 100644
--- a/app/views/shared/_order_links.html.erb
+++ b/app/views/shared/_order_links.html.erb
@@ -1,5 +1,5 @@