diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 124824030..d658e7ab2 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -6,6 +6,7 @@ class Budget include Searchable include Reclassification include Followable + include Communitable include Documentable documentable max_documents_allowed: 3, max_file_size: 3.megabytes, @@ -21,7 +22,6 @@ class Budget belongs_to :group belongs_to :budget belongs_to :administrator - belongs_to :community has_many :valuator_assignments, dependent: :destroy has_many :valuators, through: :valuator_assignments @@ -72,7 +72,6 @@ class Budget before_save :calculate_confidence_score after_save :recalculate_heading_winners if :incompatible_changed? - before_create :associate_community before_validation :set_responsible_name before_validation :set_denormalized_ids @@ -260,11 +259,6 @@ class Budget investments end - def associate_community - community = Community.create - self.community_id = community.id - end - private def set_denormalized_ids diff --git a/app/models/concerns/communitable.rb b/app/models/concerns/communitable.rb new file mode 100644 index 000000000..6f0a10f43 --- /dev/null +++ b/app/models/concerns/communitable.rb @@ -0,0 +1,14 @@ +module Communitable + extend ActiveSupport::Concern + + included do + belongs_to :community + before_create :associate_community + end + + def associate_community + community = Community.create + self.community_id = community.id + end + +end diff --git a/app/models/proposal.rb b/app/models/proposal.rb index ae4ed9682..4ee4f851e 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -9,6 +9,7 @@ class Proposal < ActiveRecord::Base include HasPublicAuthor include Graphqlable include Followable + include Communitable include Documentable documentable max_documents_allowed: 3, max_file_size: 3.megabytes, @@ -23,7 +24,6 @@ class Proposal < ActiveRecord::Base belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' belongs_to :geozone - belongs_to :community has_many :comments, as: :commentable has_many :proposal_notifications @@ -44,7 +44,6 @@ class Proposal < ActiveRecord::Base before_validation :set_responsible_name before_save :calculate_hot_score, :calculate_confidence_score - before_create :associate_community scope :for_render, -> { includes(:tags) } scope :sort_by_hot_score, -> { reorder(hot_score: :desc) } @@ -182,11 +181,6 @@ class Proposal < ActiveRecord::Base (voters + followers).uniq end - def associate_community - community = Community.create - self.community_id = community.id - end - protected def set_responsible_name