cleans up

This commit is contained in:
rgarcia
2017-05-17 20:32:05 +02:00
parent 47f97e342d
commit a63ca9649e
5 changed files with 51 additions and 28 deletions

View File

@@ -21,17 +21,20 @@ class Budget
budget.balloting? && heading_id_changed?
end
def log_heading_change
update_column(:previous_heading_id, heading_id_was)
end
def marked_as_unfeasible?
budget.balloting? && feasibility_changed? && unfeasible?
end
def log_heading_change
update_column(:previous_heading_id, heading_id_was)
end
def store_reclassified_votes(reason)
ballot_lines_for_investment.each do |line|
Budget::ReclassifiedVote.create!(user: line.ballot.user, investment: self, reason: reason)
attrs = { user: line.ballot.user,
investment: self,
reason: reason }
Budget::ReclassifiedVote.create!(attrs)
end
end

View File

@@ -63,12 +63,6 @@ ActiveRecord::Schema.define(version: 20170517123042) do
add_index "annotations", ["legislation_id"], name: "index_annotations_on_legislation_id", using: :btree
add_index "annotations", ["user_id"], name: "index_annotations_on_user_id", using: :btree
create_table "ar_internal_metadata", primary_key: "key", force: :cascade do |t|
t.string "value"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "banners", force: :cascade do |t|
t.string "title", limit: 80
t.string "description"

View File

@@ -670,25 +670,51 @@ feature 'Budget Investments' do
expect(page).to_not have_link("Vote")
end
scenario "Reclassification", :focus do
user = create(:user, :level_two)
investment = create(:budget_investment, :selected, heading: heading)
heading2 = create(:budget_heading, group: group)
feature "Reclassification" do
ballot = create(:budget_ballot, user: user, budget: budget)
ballot.investments << investment
scenario "Due to heading change" do
user = create(:user, :level_two)
investment = create(:budget_investment, :selected, heading: heading)
heading2 = create(:budget_heading, group: group)
login_as(user)
visit budget_ballot_path(budget)
ballot = create(:budget_ballot, user: user, budget: budget)
ballot.investments << investment
expect(page).to have_content("You have voted one investment")
login_as(user)
visit budget_ballot_path(budget)
investment.heading = heading2
investment.save
expect(page).to have_content("You have voted one investment")
visit budget_ballot_path(budget)
investment.heading = heading2
investment.save
visit budget_ballot_path(budget)
expect(page).to have_content("You have voted 0 investment")
end
scenario "Due to being unfeasible" do
user = create(:user, :level_two)
investment = create(:budget_investment, :selected, heading: heading)
heading2 = create(:budget_heading, group: group)
ballot = create(:budget_ballot, user: user, budget: budget)
ballot.investments << investment
login_as(user)
visit budget_ballot_path(budget)
expect(page).to have_content("You have voted one investment")
investment.feasibility = "unfeasible"
investment.unfeasibility_explanation = "too expensive"
investment.save
visit budget_ballot_path(budget)
expect(page).to have_content("You have voted 0 investment")
end
expect(page).to have_content("You have voted 0 investment")
end
end
end

View File

@@ -681,7 +681,7 @@ describe Budget::Investment do
end
describe "Reclassification", :focus do
describe "Reclassification" do
let(:budget) { create(:budget, phase: "balloting") }
let(:group) { create(:budget_group, budget: budget) }
@@ -737,7 +737,7 @@ describe Budget::Investment do
describe "store_reclassified_votes" do
it "stores the votes for a reclassified investment", :focus do
it "stores the votes for a reclassified investment" do
investment = create(:budget_investment, :selected, heading: heading1)
3.times do
@@ -780,7 +780,7 @@ describe Budget::Investment do
end
describe "check_for_reclassification", :focus do
describe "check_for_reclassification" do
it "stores reclassfied votes and removes actual votes if an investment has been reclassified" do
investment = create(:budget_investment, :selected, heading: heading1)

View File

@@ -2,7 +2,7 @@ require 'rails_helper'
describe Budget::ReclassifiedVote do
describe "Validations", :focus do
describe "Validations" do
let(:reclassified_vote) { build(:budget_reclassified_vote) }
it "should be valid" do