Merge pull request #1049 from consul/spending_proposal_responsible
Spending proposal responsible
This commit is contained in:
@@ -36,6 +36,8 @@ class SpendingProposal < ActiveRecord::Base
|
||||
|
||||
scope :for_render, -> { includes(:geozone) }
|
||||
|
||||
before_validation :set_responsible_name
|
||||
|
||||
def description
|
||||
super.try :html_safe
|
||||
end
|
||||
@@ -120,4 +122,8 @@ class SpendingProposal < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def set_responsible_name
|
||||
self.responsible_name = author.try(:document_number)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddResponsibleNameToSpendingProposals < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :spending_proposals, :responsible_name, :string, limit: 60
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160329160106) do
|
||||
ActiveRecord::Schema.define(version: 20160406163649) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -314,6 +314,7 @@ ActiveRecord::Schema.define(version: 20160329160106) do
|
||||
t.datetime "unfeasible_email_sent_at"
|
||||
t.integer "cached_votes_up", default: 0
|
||||
t.tsvector "tsv"
|
||||
t.string "responsible_name", limit: 60
|
||||
end
|
||||
|
||||
add_index "spending_proposals", ["author_id"], name: "index_spending_proposals_on_author_id", using: :btree
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
namespace :spending_proposals do
|
||||
desc "Sends an email to the authors of unfeasible spending proposals"
|
||||
task send_unfeasible_emails: :environment do
|
||||
SpendingProposal.find_each do |spending_propsal|
|
||||
if spending_propsal.unfeasible_email_pending?
|
||||
spending_propsal.send_unfeasible_email
|
||||
puts "email sent for proposal #{spending_propsal.title}"
|
||||
SpendingProposal.find_each do |spending_proposal|
|
||||
if spending_proposal.unfeasible_email_pending?
|
||||
spending_proposal.send_unfeasible_email
|
||||
puts "email sent for proposal #{spending_proposal.title}"
|
||||
else
|
||||
puts "this proposal is feasible: #{spending_propsal.title}"
|
||||
puts "this proposal is feasible: #{spending_proposal.title}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
desc "Updates all spending proposals to recalculate their tsv column"
|
||||
desc "Updates all spending proposals to recalculate their tsv and responsible_name columns"
|
||||
task touch: :environment do
|
||||
SpendingProposal.find_in_batches do |spending_propsal|
|
||||
spending_propsal.each(&:save)
|
||||
SpendingProposal.find_in_batches do |spending_proposal|
|
||||
spending_proposal.each(&:save)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -261,4 +261,12 @@ describe SpendingProposal do
|
||||
end
|
||||
end
|
||||
|
||||
describe "responsible_name" do
|
||||
it "gets updated with the document_number" do
|
||||
u = create(:user, document_number: "123456")
|
||||
sp = create(:spending_proposal, author: u)
|
||||
expect(sp.responsible_name).to eq("123456")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user