Merge branch 'master' into content_blocks_for_headings

This commit is contained in:
Julian Nicolas Herrero
2018-12-11 16:40:25 +01:00
committed by GitHub
181 changed files with 1635 additions and 830 deletions

View File

@@ -12,6 +12,10 @@ class Budget
validates :price, presence: true
validates :slug, presence: true, format: /\A[a-z0-9\-_]+\z/
validates :population, numericality: { greater_than: 0 }, allow_nil: true
validates :latitude, length: { maximum: 22, minimum: 1 }, presence: true, \
format: /\A(-|\+)?([1-8]?\d(?:\.\d{1,})?|90(?:\.0{1,6})?)\z/
validates :longitude, length: { maximum: 22, minimum: 1}, presence: true, \
format: /\A(-|\+)?((?:1[0-7]|[1-9])?\d(?:\.\d{1,})?|180(?:\.0{1,})?)\z/
delegate :budget, :budget_id, to: :group, allow_nil: true

View File

@@ -24,6 +24,7 @@ class Budget
include Notifiable
include Filterable
include Flaggable
include Milestoneable
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
belongs_to :heading
@@ -40,8 +41,6 @@ class Budget
has_many :comments, -> {where(valuation: false)}, as: :commentable, class_name: 'Comment'
has_many :valuations, -> {where(valuation: true)}, as: :commentable, class_name: 'Comment'
has_many :milestones
validates :title, presence: true
validates :author, presence: true
validates :description, presence: true

View File

@@ -1,35 +0,0 @@
class Budget
class Investment
class Milestone < ActiveRecord::Base
include Imageable
include Documentable
documentable max_documents_allowed: 3,
max_file_size: 3.megabytes,
accepted_content_types: [ "application/pdf" ]
translates :title, :description, touch: true
include Globalizable
belongs_to :investment
belongs_to :status, class_name: 'Budget::Investment::Status'
validates :investment, presence: true
validates :publication_date, presence: true
validate :description_or_status_present?
scope :order_by_publication_date, -> { order(publication_date: :asc, created_at: :asc) }
scope :published, -> { where("publication_date <= ?", Date.current) }
scope :with_status, -> { where("status_id IS NOT NULL") }
def self.title_max_length
80
end
def description_or_status_present?
unless description.present? || status_id.present?
errors.add(:description)
end
end
end
end
end

View File

@@ -30,7 +30,7 @@ class Budget
end
def store_reclassified_votes(reason)
ballot_lines_for_investment.each do |line|
ballot_lines_for_investment.order(:id).each do |line|
attrs = { user: line.ballot.user,
investment: self,
reason: reason }

View File

@@ -0,0 +1,7 @@
module Milestoneable
extend ActiveSupport::Concern
included do
has_many :milestones, as: :milestoneable, dependent: :destroy
end
end

31
app/models/milestone.rb Normal file
View File

@@ -0,0 +1,31 @@
class Milestone < ActiveRecord::Base
include Imageable
include Documentable
documentable max_documents_allowed: 3,
max_file_size: 3.megabytes,
accepted_content_types: [ "application/pdf" ]
translates :title, :description, touch: true
include Globalizable
belongs_to :milestoneable, polymorphic: true
belongs_to :status
validates :milestoneable, presence: true
validates :publication_date, presence: true
validate :description_or_status_present?
scope :order_by_publication_date, -> { order(publication_date: :asc, created_at: :asc) }
scope :published, -> { where("publication_date <= ?", Date.current) }
scope :with_status, -> { where("status_id IS NOT NULL") }
def self.title_max_length
80
end
def description_or_status_present?
unless description.present? || status_id.present?
errors.add(:description)
end
end
end

View File

@@ -1,4 +1,4 @@
class Budget::Investment::Status < ActiveRecord::Base
class Milestone::Status < ActiveRecord::Base
acts_as_paranoid column: :hidden_at
has_many :milestones

View File

@@ -90,6 +90,10 @@ class Poll < ActiveRecord::Base
Poll::Voter.where(poll: self, user: user, origin: "web").exists?
end
def voted_by?(user)
Poll::Voter.where(poll: self, user: user).exists?
end
def date_range
unless starts_at.present? && ends_at.present? && starts_at <= ends_at
errors.add(:starts_at, I18n.t('errors.messages.invalid_date_range'))

View File

@@ -24,7 +24,7 @@ class Poll
end
def create_officer_assignments
booth.booth_assignments.each do |booth_assignment|
booth.booth_assignments.order(:id).each do |booth_assignment|
attrs = {
officer_id: officer_id,
date: date,