Adds budget_lines.selected
This commit is contained in:
@@ -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?
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -362,7 +362,7 @@ tags = Faker::Lorem.words(10)
|
||||
external_url: Faker::Internet.url,
|
||||
description: "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>",
|
||||
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: "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>",
|
||||
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
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddSelectedToBudgetInvestment < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :budget_investments, :selected, :bool, default: false, index: true
|
||||
end
|
||||
end
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user