can remove investment projects
This commit is contained in:
@@ -32,12 +32,12 @@ module Budgets
|
|||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
load_spending_proposal
|
@investment = @line.investment
|
||||||
load_spending_proposals
|
load_heading
|
||||||
load_geozone
|
|
||||||
|
|
||||||
@ballot_line.destroy
|
@line.destroy
|
||||||
@ballot.reset_geozone
|
load_investments
|
||||||
|
#@ballot.reset_geozone
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -72,9 +72,6 @@ module Budgets
|
|||||||
@heading = @investment.heading
|
@heading = @investment.heading
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_geozone
|
|
||||||
@geozone = @line.investment.geozone
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -99,7 +99,7 @@ module Budgets
|
|||||||
end
|
end
|
||||||
|
|
||||||
def load_heading
|
def load_heading
|
||||||
@heading = @budget.headings.find(params[:heading_id]) if params[:geozone_id].present?
|
@heading = @budget.headings.find(params[:heading_id]) if params[:heading_id].present?
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -13,15 +13,15 @@ class Budget
|
|||||||
#needed? validates :ballot_id, :budget_id, :group_id, :heading_id, :investment_id, presence: true
|
#needed? validates :ballot_id, :budget_id, :group_id, :heading_id, :investment_id, presence: true
|
||||||
|
|
||||||
def insufficient_funds
|
def insufficient_funds
|
||||||
errors.add(:money, "") if ballot.amount_available(investment.heading) < investment.price.to_i
|
errors.add(:money, "insufficient funds") if ballot.amount_available(investment.heading) < investment.price.to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
def different_geozone
|
def different_geozone
|
||||||
errors.add(:heading, "") if (ballot.heading.present? && investment.heading != ballot.heading)
|
errors.add(:heading, "different heading assigned") if (ballot.heading.present? && investment.heading != ballot.heading)
|
||||||
end
|
end
|
||||||
|
|
||||||
def unfeasible
|
def unfeasible
|
||||||
errors.add(:unfeasible, "") unless investment.feasible?
|
errors.add(:unfeasible, "unfeasible investment") unless investment.feasible?
|
||||||
end
|
end
|
||||||
|
|
||||||
def heading_proposal?
|
def heading_proposal?
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<% if @spending_proposals.present? %>
|
<% if @investments.present? %>
|
||||||
<% @spending_proposals.each do |spending_proposal| %>
|
<% @investments.each do |investment| %>
|
||||||
$("#<%= dom_id(spending_proposal) %>_ballot").html('<%= j render("spending_proposals/ballot", spending_proposal: spending_proposal) %>');
|
$("#<%= dom_id(investment) %>_ballot").html('<%= j render("budgets/investments/ballot", investment: investment) %>');
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
$("#progress_bar").html('<%= j render("spending_proposals/progress_bar", ballot: @ballot) %>');
|
$("#progress_bar").html('<%= j render("budgets/ballot/progress_bar", ballot: @ballot) %>');
|
||||||
$("#sidebar").html('<%= j render("spending_proposals/sidebar") %>');
|
$("#sidebar").html('<%= j render("spending_proposals/sidebar") %>');
|
||||||
$("#ballot").html('<%= j render("ballots/ballot") %>')
|
// $("#ballot").html('<%# j render("ballots/ballot") %>')
|
||||||
$("#<%= dom_id(@spending_proposal) %>_ballot").html('<%= j render("spending_proposals/ballot", spending_proposal: @spending_proposal) %>');
|
$("#<%= dom_id(@investment) %>_ballot").html('<%= j render("budgets/investments/ballot", investment: @investment) %>');
|
||||||
|
|
||||||
<%= render 'refresh_ballots' %>
|
<%= render 'refresh_ballots' %>
|
||||||
|
|||||||
@@ -27,7 +27,11 @@
|
|||||||
budget_ballot_path(@budget) %>
|
budget_ballot_path(@budget) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<% if @heading.present? && @ballot.heading.present? && @ballot.heading != @heading %>
|
<% if false
|
||||||
|
#@heading.present? &&
|
||||||
|
#@ballot.heading.present? &&
|
||||||
|
#@ballot.heading != @heading
|
||||||
|
%>
|
||||||
<br>
|
<br>
|
||||||
<p class="callout warning inline-block">
|
<p class="callout warning inline-block">
|
||||||
<%= t("budget.investments.header.different_heading_active") %>
|
<%= t("budget.investments.header.different_heading_active") %>
|
||||||
@@ -35,7 +39,7 @@
|
|||||||
</p>
|
</p>
|
||||||
<% else %>
|
<% else %>
|
||||||
<div id="progress_bar" class="no-margin-top">
|
<div id="progress_bar" class="no-margin-top">
|
||||||
<%= render 'progress_bar' %>
|
<%= render 'budgets/ballot/progress_bar' %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ feature 'Ballots' do
|
|||||||
|
|
||||||
let(:budget) { create(:budget, phase: "balloting") }
|
let(:budget) { create(:budget, phase: "balloting") }
|
||||||
let(:group) { create(:budget_group, budget: budget) }
|
let(:group) { create(:budget_group, budget: budget) }
|
||||||
let(:heading) { create(:budget_heading, group: group) }
|
let(:heading) { create(:budget_heading, group: group, name: "Heading 1", price: 1000000) }
|
||||||
|
|
||||||
context "Voting" do
|
context "Voting" do
|
||||||
let!(:user) { create(:user, :level_two) }
|
let!(:user) { create(:user, :level_two) }
|
||||||
@@ -16,11 +16,12 @@ feature 'Ballots' do
|
|||||||
|
|
||||||
context "City" do
|
context "City" do
|
||||||
|
|
||||||
scenario "Add a proposal", :js, :focus do
|
scenario "Add a proposal", :js do
|
||||||
investment1 = create(:budget_investment, :feasible, :finished, budget: budget, heading: heading, price: 10000)
|
investment1 = create(:budget_investment, :feasible, :finished, budget: budget, heading: heading, price: 10000)
|
||||||
investment2 = create(:budget_investment, :feasible, :finished, budget: budget, heading: heading, price: 20000)
|
investment2 = create(:budget_investment, :feasible, :finished, budget: budget, heading: heading, price: 20000)
|
||||||
|
|
||||||
click_link "No Heading"
|
visit budget_path(budget)
|
||||||
|
click_link "Heading 1"
|
||||||
|
|
||||||
within("#budget_investment_#{investment1.id}") do
|
within("#budget_investment_#{investment1.id}") do
|
||||||
find('.add a').trigger('click')
|
find('.add a').trigger('click')
|
||||||
@@ -48,35 +49,38 @@ feature 'Ballots' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "Remove a proposal", :js do
|
scenario "Remove a proposal", :js do
|
||||||
sp1 = create(:spending_proposal, :feasible, :finished, price: 10000)
|
investment1 = create(:budget_investment, :feasible, :finished, budget: budget, heading: heading, price: 10000)
|
||||||
ballot = create(:ballot, user: user, spending_proposals: [sp1])
|
ballot = create(:budget_ballot, user: user, budget: budget, investments: [investment1])
|
||||||
|
|
||||||
click_link "Vote city proposals"
|
visit budget_path(budget)
|
||||||
|
click_link "Heading 1"
|
||||||
|
|
||||||
|
expect(page).to have_content investment1.title
|
||||||
expect(page).to have_css("#amount-spent", text: "€10,000")
|
expect(page).to have_css("#amount-spent", text: "€10,000")
|
||||||
expect(page).to have_css("#amount-available", text: "€23,990,000")
|
expect(page).to have_css("#amount-available", text: "€990,000")
|
||||||
|
|
||||||
within("#sidebar") do
|
within("#sidebar") do
|
||||||
expect(page).to have_content sp1.title
|
expect(page).to have_content investment1.title
|
||||||
expect(page).to have_content "€10,000"
|
expect(page).to have_content "€10,000"
|
||||||
end
|
end
|
||||||
|
|
||||||
within("#spending_proposal_#{sp1.id}") do
|
within("#budget_investment_#{investment1.id}") do
|
||||||
find('.remove a').trigger('click')
|
find('.remove a').trigger('click')
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(page).to have_css("#amount-spent", text: "€0")
|
expect(page).to have_css("#amount-spent", text: "€0")
|
||||||
expect(page).to have_css("#amount-available", text: "€24,000,000")
|
expect(page).to have_css("#amount-available", text: "€1,000,000")
|
||||||
|
|
||||||
within("#sidebar") do
|
within("#sidebar") do
|
||||||
expect(page).to_not have_content sp1.title
|
expect(page).to_not have_content investment1.title
|
||||||
expect(page).to_not have_content "€10,000"
|
expect(page).to_not have_content "€10,000"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'District' do
|
#Not used anymore?
|
||||||
|
xcontext 'District' do
|
||||||
|
|
||||||
scenario "Add a proposal", :js do
|
scenario "Add a proposal", :js do
|
||||||
carabanchel = create(:geozone, name: "Carabanchel")
|
carabanchel = create(:geozone, name: "Carabanchel")
|
||||||
@@ -147,77 +151,92 @@ feature 'Ballots' do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "City and District" do
|
#Break up or simplify with helpers
|
||||||
|
context "Balloting in multiple headings" do
|
||||||
|
|
||||||
scenario "Independent progress bar for city and district proposals", :js do
|
scenario "Independent progress bar for headings", :js do
|
||||||
carabanchel = create(:geozone, name: "Carabanchel")
|
city = create(:budget_group, budget: budget)
|
||||||
|
districts = create(:budget_group, budget: budget)
|
||||||
|
|
||||||
sp1 = create(:spending_proposal, :feasible, :finished, geozone: nil, price: 10000)
|
city_heading = create(:budget_heading, group: city, name: "All city", price: 10000000)
|
||||||
sp2 = create(:spending_proposal, :feasible, :finished, geozone: carabanchel, price: 20000)
|
district_heading1 = create(:budget_heading, group: districts, name: "District 1", price: 1000000)
|
||||||
|
district_heading2 = create(:budget_heading, group: districts, name: "District 2", price: 2000000)
|
||||||
|
|
||||||
click_link "Vote city proposals"
|
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)
|
||||||
|
|
||||||
within("#spending_proposal_#{sp1.id}") do
|
visit budget_path(budget)
|
||||||
|
click_link "All city"
|
||||||
|
|
||||||
|
within("#budget_investment_#{investment1.id}") do
|
||||||
find('.add a').trigger('click')
|
find('.add a').trigger('click')
|
||||||
expect(page).to have_content "Remove"
|
expect(page).to have_content "Remove"
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(page).to have_css("#amount-spent", text: "€10,000")
|
expect(page).to have_css("#amount-spent", text: "€10,000")
|
||||||
expect(page).to have_css("#amount-available", text: "€23,990,000")
|
expect(page).to have_css("#amount-available", text: "€9,990,000")
|
||||||
|
|
||||||
within("#sidebar") do
|
within("#sidebar") do
|
||||||
expect(page).to have_content sp1.title
|
expect(page).to have_content investment1.title
|
||||||
expect(page).to have_content "€10,000"
|
expect(page).to have_content "€10,000"
|
||||||
end
|
end
|
||||||
|
|
||||||
visit spending_proposals_path(geozone: carabanchel)
|
visit budget_path(budget)
|
||||||
|
click_link "District 1"
|
||||||
|
|
||||||
expect(page).to have_css("#amount-spent", text: "€0")
|
expect(page).to have_css("#amount-spent", text: "€0")
|
||||||
expect(page).to have_css("#amount-spent", text: "€3,247,830")
|
expect(page).to have_css("#amount-spent", text: "€1,000,000")
|
||||||
|
|
||||||
within("#spending_proposal_#{sp2.id}") do
|
within("#budget_investment_#{investment2.id}") do
|
||||||
find('.add a').trigger('click')
|
find('.add a').trigger('click')
|
||||||
expect(page).to have_content "Remove"
|
expect(page).to have_content "Remove"
|
||||||
end
|
end
|
||||||
|
|
||||||
visit spending_proposals_path(geozone: carabanchel)
|
visit budget_path(budget)
|
||||||
|
click_link "District 1"
|
||||||
|
|
||||||
expect(page).to have_css("#amount-spent", text: "€20,000")
|
expect(page).to have_css("#amount-spent", text: "€20,000")
|
||||||
expect(page).to have_css("#amount-available", text: "€3,227,830")
|
expect(page).to have_css("#amount-available", text: "€980,000")
|
||||||
|
|
||||||
within("#sidebar") do
|
within("#sidebar") do
|
||||||
expect(page).to have_content sp2.title
|
expect(page).to have_content investment2.title
|
||||||
expect(page).to have_content "€20,000"
|
expect(page).to have_content "€20,000"
|
||||||
|
|
||||||
expect(page).to_not have_content sp1.title
|
expect(page).to_not have_content investment1.title
|
||||||
expect(page).to_not have_content "€10,000"
|
expect(page).to_not have_content "€10,000"
|
||||||
end
|
end
|
||||||
|
|
||||||
click_link "Participatory budgeting"
|
visit budget_path(budget)
|
||||||
click_link "Vote city proposals"
|
click_link "All city"
|
||||||
|
|
||||||
expect(page).to have_css("#amount-spent", text: "€10,000")
|
expect(page).to have_css("#amount-spent", text: "€10,000")
|
||||||
expect(page).to have_css("#amount-available", text: "€23,990,000")
|
expect(page).to have_css("#amount-available", text: "€9,990,000")
|
||||||
|
|
||||||
within("#sidebar") do
|
within("#sidebar") do
|
||||||
expect(page).to have_content sp1.title
|
expect(page).to have_content investment1.title
|
||||||
expect(page).to have_content "€10,000"
|
expect(page).to have_content "€10,000"
|
||||||
|
|
||||||
expect(page).to_not have_content sp2.title
|
expect(page).to_not have_content investment2.title
|
||||||
expect(page).to_not have_content "€20,000"
|
expect(page).to_not have_content "€20,000"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
visit budget_path(budget)
|
||||||
|
click_link "District 2"
|
||||||
|
|
||||||
|
expect(page).to have_css("#amount-spent", text: "€0")
|
||||||
|
expect(page).to have_css("#amount-spent", text: "€2,000,000")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Display progress bar after first district vote", :js do
|
scenario "Display progress bar after first vote", :js do
|
||||||
carabanchel = create(:geozone, name: "Carabanchel")
|
investment = create(:budget_investment, :feasible, :finished, heading: heading, price: 10000)
|
||||||
|
|
||||||
sp1 = create(:spending_proposal, :feasible, :finished, geozone: carabanchel, price: 10000)
|
visit budget_path(budget)
|
||||||
|
click_link "Heading 1"
|
||||||
|
|
||||||
click_link "Vote district proposals"
|
expect(page).to have_content investment.title
|
||||||
click_link carabanchel.name
|
within("#budget_investment_#{investment.id}") do
|
||||||
|
|
||||||
within("#spending_proposal_#{sp1.id}") do
|
|
||||||
find('.add a').trigger('click')
|
find('.add a').trigger('click')
|
||||||
expect(page).to have_content "Remove"
|
expect(page).to have_content "Remove"
|
||||||
end
|
end
|
||||||
@@ -228,70 +247,71 @@ feature 'Ballots' do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "Choosing my district" do
|
context "Groups" do
|
||||||
let!(:user) { create(:user, :level_two) }
|
let!(:user) { create(:user, :level_two) }
|
||||||
|
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) }
|
||||||
|
|
||||||
background do
|
background do
|
||||||
login_as(user)
|
login_as(user)
|
||||||
visit welcome_spending_proposals_path
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Select my district', :js do
|
scenario 'Select my heading', :js do
|
||||||
california = create(:geozone)
|
visit budget_path(budget)
|
||||||
new_york = create(:geozone)
|
click_link "Districts"
|
||||||
sp1 = create(:spending_proposal, :feasible, :finished, geozone: california)
|
click_link "California"
|
||||||
|
|
||||||
click_link "Vote district proposals"
|
within("#budget_investment_#{investment.id}") do
|
||||||
click_link california.name
|
|
||||||
|
|
||||||
within("#spending_proposal_#{sp1.id}") do
|
|
||||||
find('.add a').trigger('click')
|
find('.add a').trigger('click')
|
||||||
|
expect(page).to have_content "Remove"
|
||||||
end
|
end
|
||||||
|
|
||||||
visit select_district_path
|
visit budget_path(budget)
|
||||||
expect(page).to have_css("#geozone_#{california.id}.active")
|
click_link "Districts"
|
||||||
|
|
||||||
|
expect(page).to have_content "California"
|
||||||
|
expect(page).to have_css("#budget_heading_#{california_heading.id}.active")
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Change my district', :js do
|
scenario 'Change my heading', :js, :focus do
|
||||||
california = create(:geozone)
|
investment1 = create(:budget_investment, :feasible, :finished, heading: california_heading)
|
||||||
new_york = create(:geozone)
|
investment2 = create(:budget_investment, :feasible, :finished, heading: new_york_heading)
|
||||||
|
|
||||||
sp1 = create(:spending_proposal, :feasible, :finished, geozone: california)
|
create(:budget_ballot, user: user, budget: budget, investments: [investment1])
|
||||||
sp2 = create(:spending_proposal, :feasible, :finished, geozone: new_york)
|
|
||||||
|
|
||||||
create(:ballot, user: user, geozone: california, spending_proposals: [sp1])
|
visit budget_investments_path(budget, heading_id: california_heading.id)
|
||||||
|
|
||||||
visit spending_proposals_path(geozone: california)
|
within("#budget_investment_#{investment1.id}") do
|
||||||
|
|
||||||
within("#spending_proposal_#{sp1.id}") do
|
|
||||||
find('.remove a').trigger('click')
|
find('.remove a').trigger('click')
|
||||||
end
|
end
|
||||||
|
|
||||||
visit spending_proposals_path(geozone: new_york)
|
visit budget_investments_path(budget, heading_id: new_york_heading.id)
|
||||||
|
|
||||||
within("#spending_proposal_#{sp2.id}") do
|
within("#budget_investment_#{investment2.id}") do
|
||||||
find('.add a').trigger('click')
|
find('.add a').trigger('click')
|
||||||
end
|
end
|
||||||
|
|
||||||
visit select_district_path
|
visit budget_path(budget)
|
||||||
expect(page).to have_css("#geozone_#{new_york.id}.active")
|
click_link "Districts"
|
||||||
expect(page).to_not have_css("#geozone_#{california.id}.active")
|
expect(page).to have_css("#budget_heading_#{new_york_heading.id}.active")
|
||||||
|
expect(page).to_not have_css("#budget_heading_#{california_heading.id}.active")
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'View another district' do
|
|
||||||
california = create(:geozone)
|
|
||||||
new_york = create(:geozone)
|
|
||||||
|
|
||||||
sp1 = create(:spending_proposal, :feasible, :finished, geozone: california)
|
#From here on, not implemented yet
|
||||||
sp2 = create(:spending_proposal, :feasible, :finished, geozone: new_york)
|
|
||||||
|
|
||||||
create(:ballot, user: user, geozone: california, spending_proposals: [sp1])
|
scenario 'View another heading' do
|
||||||
|
investment = create(:budget_investment, :feasible, :finished, heading: california_heading)
|
||||||
|
|
||||||
visit spending_proposals_path(geozone: new_york)
|
create(:budget_ballot, user: user, budget: budget, investments: [investment])
|
||||||
|
|
||||||
|
visit budget_investments_path(budget, heading_id: new_york_heading.id)
|
||||||
|
|
||||||
expect(page).to_not have_css "#progressbar"
|
expect(page).to_not have_css "#progressbar"
|
||||||
expect(page).to have_content "You have active votes in another district:"
|
expect(page).to have_content "You have active votes in another district:"
|
||||||
expect(page).to have_link california.name, href: spending_proposals_path(geozone: california)
|
expect(page).to have_link california_heading.name, href: budget_investments_path(budget, heading: california_heading)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user