From 3ba961a2d756444112dfc6ab5cfa74c42cd831af Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Wed, 13 Mar 2019 22:57:47 +0100 Subject: [PATCH] Use double quotes in models --- app/models/abilities/valuator.rb | 2 +- app/models/activity.rb | 12 ++--- app/models/budget.rb | 6 +-- app/models/budget/investment.rb | 34 ++++++------- app/models/budget/investment/exporter.rb | 12 ++--- app/models/budget/phase.rb | 32 ++++++------ app/models/ckeditor/picture.rb | 6 +-- app/models/comment.rb | 2 +- app/models/concerns/filterable.rb | 4 +- app/models/concerns/graphqlable.rb | 6 +-- app/models/concerns/mappable.rb | 2 +- app/models/concerns/measurable.rb | 4 +- app/models/concerns/searchable.rb | 6 +-- app/models/custom/verification/residence.rb | 4 +- app/models/debate.rb | 26 +++++----- app/models/direct_message.rb | 8 +-- app/models/failed_census_call.rb | 2 +- app/models/flag.rb | 2 +- app/models/geozone.rb | 2 +- app/models/i18n_content.rb | 2 +- app/models/legislation.rb | 2 +- app/models/legislation/annotation.rb | 4 +- app/models/legislation/answer.rb | 4 +- app/models/legislation/draft_version.rb | 8 +-- app/models/legislation/process.rb | 18 +++---- app/models/legislation/proposal.rb | 22 ++++---- app/models/legislation/question.rb | 10 ++-- app/models/legislation/question_option.rb | 4 +- app/models/officing/residence.rb | 6 +-- app/models/organization.rb | 4 +- app/models/poll.rb | 12 ++--- app/models/poll/answer.rb | 2 +- app/models/poll/partial_result.rb | 2 +- app/models/poll/question.rb | 16 +++--- app/models/poll/question/answer.rb | 6 +-- app/models/poll/question/answer/video.rb | 2 +- app/models/poll/recount.rb | 8 +-- app/models/poll/shift.rb | 4 +- app/models/poll/stats.rb | 50 +++++++++---------- app/models/poll/voter.rb | 4 +- app/models/proposal.rb | 24 ++++----- app/models/proposal_notification.rb | 6 +-- app/models/related_content.rb | 6 +-- app/models/setting.rb | 6 +-- app/models/signature.rb | 6 +-- app/models/signature_sheet.rb | 4 +- app/models/site_customization.rb | 2 +- app/models/spending_proposal.rb | 14 +++--- app/models/tag_cloud.rb | 4 +- app/models/topic.rb | 2 +- app/models/user.rb | 16 +++--- app/models/valuator.rb | 4 +- app/models/valuator_group.rb | 4 +- app/models/verification/letter.rb | 4 +- app/models/verification/management/email.rb | 6 +-- .../verification/management/managed_user.rb | 4 +- app/models/verification/residence.rb | 8 +-- 57 files changed, 241 insertions(+), 241 deletions(-) diff --git a/app/models/abilities/valuator.rb b/app/models/abilities/valuator.rb index ade0a42b7..0e1213070 100644 --- a/app/models/abilities/valuator.rb +++ b/app/models/abilities/valuator.rb @@ -8,7 +8,7 @@ module Abilities can [:read, :update, :valuate], SpendingProposal can [:read, :update, :comment_valuation], Budget::Investment, id: valuator.assigned_investment_ids can [:valuate], Budget::Investment, { id: valuator.assigned_investment_ids, valuation_finished: false } - cannot [:update, :valuate, :comment_valuation], Budget::Investment, budget: { phase: 'finished' } + cannot [:update, :valuate, :comment_valuation], Budget::Investment, budget: { phase: "finished" } end end end diff --git a/app/models/activity.rb b/app/models/activity.rb index afe25bed3..b5f3e0281 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -6,12 +6,12 @@ class Activity < ActiveRecord::Base validates :action, inclusion: {in: VALID_ACTIONS} - scope :on_proposals, -> { where(actionable_type: 'Proposal') } - scope :on_debates, -> { where(actionable_type: 'Debate') } - scope :on_users, -> { where(actionable_type: 'User') } - scope :on_comments, -> { where(actionable_type: 'Comment') } - scope :on_budget_investments, -> { where(actionable_type: 'Budget::Investment') } - scope :on_system_emails, -> { where(actionable_type: 'ProposalNotification') } + scope :on_proposals, -> { where(actionable_type: "Proposal") } + scope :on_debates, -> { where(actionable_type: "Debate") } + scope :on_users, -> { where(actionable_type: "User") } + scope :on_comments, -> { where(actionable_type: "Comment") } + scope :on_budget_investments, -> { where(actionable_type: "Budget::Investment") } + scope :on_system_emails, -> { where(actionable_type: "ProposalNotification") } scope :for_render, -> { includes(user: [:moderator, :administrator]).includes(:actionable) } def self.log(user, action, actionable) diff --git a/app/models/budget.rb b/app/models/budget.rb index 53bd02e82..ecfacc5c0 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -147,11 +147,11 @@ class Budget < ActiveRecord::Base def investments_orders case phase - when 'accepting', 'reviewing' + when "accepting", "reviewing" %w{random} - when 'publishing_prices', 'balloting', 'reviewing_ballots' + when "publishing_prices", "balloting", "reviewing_ballots" %w{random price} - when 'finished' + when "finished" %w{random} else %w{random confidence_score} diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 97c187966..0021755dc 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -27,7 +27,7 @@ class Budget include Milestoneable include Randomizable - belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' + belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id" belongs_to :heading belongs_to :group belongs_to :budget @@ -39,8 +39,8 @@ class Budget has_many :valuator_group_assignments, dependent: :destroy has_many :valuator_groups, through: :valuator_group_assignments - has_many :comments, -> {where(valuation: false)}, as: :commentable, class_name: 'Comment' - has_many :valuations, -> {where(valuation: true)}, as: :commentable, class_name: 'Comment' + has_many :comments, -> {where(valuation: false)}, as: :commentable, class_name: "Comment" + has_many :valuations, -> {where(valuation: true)}, as: :commentable, class_name: "Comment" validates :title, presence: true validates :author, presence: true @@ -75,7 +75,7 @@ class Budget scope :unfeasible, -> { where(feasibility: "unfeasible") } scope :not_unfeasible, -> { where.not(feasibility: "unfeasible") } scope :undecided, -> { where(feasibility: "undecided") } - scope :with_supports, -> { where('cached_votes_up > 0') } + scope :with_supports, -> { where("cached_votes_up > 0") } scope :selected, -> { feasible.where(selected: true) } scope :compatible, -> { where(incompatible: false) } scope :incompatible, -> { where(incompatible: true) } @@ -133,10 +133,10 @@ class Budget def self.advanced_filters(params, results) ids = [] - ids += results.valuation_finished_feasible.pluck(:id) if params[:advanced_filters].include?('feasible') - ids += results.where(selected: true).pluck(:id) if params[:advanced_filters].include?('selected') - ids += results.undecided.pluck(:id) if params[:advanced_filters].include?('undecided') - ids += results.unfeasible.pluck(:id) if params[:advanced_filters].include?('unfeasible') + ids += results.valuation_finished_feasible.pluck(:id) if params[:advanced_filters].include?("feasible") + ids += results.where(selected: true).pluck(:id) if params[:advanced_filters].include?("selected") + ids += results.undecided.pluck(:id) if params[:advanced_filters].include?("undecided") + ids += results.unfeasible.pluck(:id) if params[:advanced_filters].include?("unfeasible") results.where("budget_investments.id IN (?)", ids) end @@ -173,11 +173,11 @@ class Budget end def searchable_values - { title => 'A', - author.username => 'B', - heading.try(:name) => 'B', - tag_list.join(' ') => 'B', - description => 'C' + { title => "A", + author.username => "B", + heading.try(:name) => "B", + tag_list.join(" ") => "B", + description => "C" } end @@ -186,7 +186,7 @@ class Budget end def self.by_heading(heading) - where(heading_id: heading == 'all' ? nil : heading.presence) + where(heading_id: heading == "all" ? nil : heading.presence) end def undecided? @@ -283,7 +283,7 @@ class Budget end def register_selection(user) - vote_by(voter: user, vote: 'yes') if selectable_by?(user) + vote_by(voter: user, vote: "yes") if selectable_by?(user) end def calculate_confidence_score @@ -342,11 +342,11 @@ class Budget end def assigned_valuators - self.valuators.collect(&:description_or_name).compact.join(', ').presence + self.valuators.collect(&:description_or_name).compact.join(", ").presence end def assigned_valuation_groups - self.valuator_groups.collect(&:name).compact.join(', ').presence + self.valuator_groups.collect(&:name).compact.join(", ").presence end def valuation_tag_list diff --git a/app/models/budget/investment/exporter.rb b/app/models/budget/investment/exporter.rb index c7e4ce461..ec5b6abf4 100644 --- a/app/models/budget/investment/exporter.rb +++ b/app/models/budget/investment/exporter.rb @@ -1,5 +1,5 @@ class Budget::Investment::Exporter - require 'csv' + require "csv" def initialize(investments) @investments = investments @@ -37,13 +37,13 @@ class Budget::Investment::Exporter investment.title, investment.total_votes.to_s, admin(investment), - investment.assigned_valuators || '-', - investment.assigned_valuation_groups || '-', + investment.assigned_valuators || "-", + investment.assigned_valuation_groups || "-", investment.heading.name, price(investment), - investment.valuation_finished? ? I18n.t('shared.yes') : I18n.t('shared.no'), - investment.selected? ? I18n.t('shared.yes') : I18n.t('shared.no'), - investment.visible_to_valuators? ? I18n.t('shared.yes') : I18n.t('shared.no'), + investment.valuation_finished? ? I18n.t("shared.yes") : I18n.t("shared.no"), + investment.selected? ? I18n.t("shared.yes") : I18n.t("shared.no"), + investment.visible_to_valuators? ? I18n.t("shared.yes") : I18n.t("shared.no"), investment.author.username ] end diff --git a/app/models/budget/phase.rb b/app/models/budget/phase.rb index de089413a..cd877e0cc 100644 --- a/app/models/budget/phase.rb +++ b/app/models/budget/phase.rb @@ -11,8 +11,8 @@ class Budget include Globalizable belongs_to :budget - belongs_to :next_phase, class_name: 'Budget::Phase', foreign_key: :next_phase_id - has_one :prev_phase, class_name: 'Budget::Phase', foreign_key: :next_phase_id + belongs_to :next_phase, class_name: "Budget::Phase", foreign_key: :next_phase_id + has_one :prev_phase, class_name: "Budget::Phase", foreign_key: :next_phase_id validates_translation :summary, length: { maximum: SUMMARY_MAX_LENGTH } validates_translation :description, length: { maximum: DESCRIPTION_MAX_LENGTH } @@ -26,17 +26,17 @@ class Budget after_save :touch_budget scope :enabled, -> { where(enabled: true) } - scope :published, -> { enabled.where.not(kind: 'drafting') } - scope :drafting, -> { find_by_kind('drafting') } - scope :informing, -> { find_by_kind('informing') } - scope :accepting, -> { find_by_kind('accepting')} - scope :reviewing, -> { find_by_kind('reviewing')} - scope :selecting, -> { find_by_kind('selecting')} - scope :valuating, -> { find_by_kind('valuating')} - scope :publishing_prices, -> { find_by_kind('publishing_prices')} - scope :balloting, -> { find_by_kind('balloting')} - scope :reviewing_ballots, -> { find_by_kind('reviewing_ballots')} - scope :finished, -> { find_by_kind('finished')} + scope :published, -> { enabled.where.not(kind: "drafting") } + scope :drafting, -> { find_by_kind("drafting") } + scope :informing, -> { find_by_kind("informing") } + scope :accepting, -> { find_by_kind("accepting")} + scope :reviewing, -> { find_by_kind("reviewing")} + scope :selecting, -> { find_by_kind("selecting")} + scope :valuating, -> { find_by_kind("valuating")} + scope :publishing_prices, -> { find_by_kind("publishing_prices")} + scope :balloting, -> { find_by_kind("balloting")} + scope :reviewing_ballots, -> { find_by_kind("reviewing_ballots")} + scope :finished, -> { find_by_kind("finished")} def next_enabled_phase next_phase&.enabled? ? next_phase : next_phase&.next_enabled_phase @@ -48,7 +48,7 @@ class Budget def invalid_dates_range? if starts_at.present? && ends_at.present? && starts_at >= ends_at - errors.add(:starts_at, I18n.t('budgets.phases.errors.dates_range_invalid')) + errors.add(:starts_at, I18n.t("budgets.phases.errors.dates_range_invalid")) end end @@ -72,7 +72,7 @@ class Budget prev_enabled_phase.assign_attributes(ends_at: starts_at) if prev_enabled_phase.invalid_dates_range? phase_name = I18n.t("budgets.phase.#{prev_enabled_phase.kind}") - error = I18n.t('budgets.phases.errors.prev_phase_dates_invalid', phase_name: phase_name) + error = I18n.t("budgets.phases.errors.prev_phase_dates_invalid", phase_name: phase_name) errors.add(:starts_at, error) end end @@ -83,7 +83,7 @@ class Budget next_enabled_phase.assign_attributes(starts_at: ends_at) if next_enabled_phase.invalid_dates_range? phase_name = I18n.t("budgets.phase.#{next_enabled_phase.kind}") - error = I18n.t('budgets.phases.errors.next_phase_dates_invalid', phase_name: phase_name) + error = I18n.t("budgets.phases.errors.next_phase_dates_invalid", phase_name: phase_name) errors.add(:ends_at, error) end end diff --git a/app/models/ckeditor/picture.rb b/app/models/ckeditor/picture.rb index 445c2bbd9..4a579b9d2 100644 --- a/app/models/ckeditor/picture.rb +++ b/app/models/ckeditor/picture.rb @@ -1,8 +1,8 @@ class Ckeditor::Picture < Ckeditor::Asset has_attached_file :data, - url: '/ckeditor_assets/pictures/:id/:style_:basename.:extension', - path: ':rails_root/public/ckeditor_assets/pictures/:id/:style_:basename.:extension', - styles: { content: '800>', thumb: '118x100#' } + url: "/ckeditor_assets/pictures/:id/:style_:basename.:extension", + path: ":rails_root/public/ckeditor_assets/pictures/:id/:style_:basename.:extension", + styles: { content: "800>", thumb: "118x100#" } validates_attachment_presence :data validates_attachment_size :data, less_than: 2.megabytes diff --git a/app/models/comment.rb b/app/models/comment.rb index d9329d3c0..f940a5b3c 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -117,7 +117,7 @@ class Comment < ActiveRecord::Base end def self.body_max_length - Setting['comments_body_max_length'].to_i + Setting["comments_body_max_length"].to_i end def calculate_confidence_score diff --git a/app/models/concerns/filterable.rb b/app/models/concerns/filterable.rb index 91c6b0a96..889067dd1 100644 --- a/app/models/concerns/filterable.rb +++ b/app/models/concerns/filterable.rb @@ -20,9 +20,9 @@ module Filterable def allowed_filter?(filter, value) return if value.blank? - ['official_level', 'date_range'].include?(filter) + ["official_level", "date_range"].include?(filter) end end -end \ No newline at end of file +end diff --git a/app/models/concerns/graphqlable.rb b/app/models/concerns/graphqlable.rb index c8b47cece..53e5a8e0d 100644 --- a/app/models/concerns/graphqlable.rb +++ b/app/models/concerns/graphqlable.rb @@ -4,7 +4,7 @@ module Graphqlable class_methods do def graphql_field_name - name.gsub('::', '_').underscore.to_sym + name.gsub("::", "_").underscore.to_sym end def graphql_field_description @@ -12,7 +12,7 @@ module Graphqlable end def graphql_pluralized_field_name - name.gsub('::', '_').underscore.pluralize.to_sym + name.gsub("::", "_").underscore.pluralize.to_sym end def graphql_pluralized_field_description @@ -20,7 +20,7 @@ module Graphqlable end def graphql_type_name - name.gsub('::', '_') + name.gsub("::", "_") end def graphql_type_description diff --git a/app/models/concerns/mappable.rb b/app/models/concerns/mappable.rb index 19af90432..fe2b847b9 100644 --- a/app/models/concerns/mappable.rb +++ b/app/models/concerns/mappable.rb @@ -13,7 +13,7 @@ module Mappable return true if skip_map? unless map_location.try(:available?) - skip_map_error = I18n.t('activerecord.errors.models.map_location.attributes.map.invalid') + skip_map_error = I18n.t("activerecord.errors.models.map_location.attributes.map.invalid") errors.add(:skip_map, skip_map_error) end end diff --git a/app/models/concerns/measurable.rb b/app/models/concerns/measurable.rb index 46625435d..9cf606e3f 100644 --- a/app/models/concerns/measurable.rb +++ b/app/models/concerns/measurable.rb @@ -4,11 +4,11 @@ module Measurable class_methods do def title_max_length - @@title_max_length ||= (columns.find { |c| c.name == 'title' }.limit rescue nil) || 80 + @@title_max_length ||= (columns.find { |c| c.name == "title" }.limit rescue nil) || 80 end def responsible_name_max_length - @@responsible_name_max_length ||= (columns.find { |c| c.name == 'responsible_name' }.limit rescue nil) || 60 + @@responsible_name_max_length ||= (columns.find { |c| c.name == "responsible_name" }.limit rescue nil) || 60 end def question_max_length diff --git a/app/models/concerns/searchable.rb b/app/models/concerns/searchable.rb index b749377f3..e6c8777d5 100644 --- a/app/models/concerns/searchable.rb +++ b/app/models/concerns/searchable.rb @@ -8,11 +8,11 @@ module Searchable pg_search_scope :pg_search, { against: :ignored, # not used since using a tsvector_column using: { - tsearch: { tsvector_column: 'tsv', dictionary: "spanish", prefix: true } + tsearch: { tsvector_column: "tsv", dictionary: "spanish", prefix: true } }, ignoring: :accents, - ranked_by: '(:tsearch)', - order_within_rank: (column_names.include?('cached_votes_up') ? "#{table_name}.cached_votes_up DESC" : nil) + ranked_by: "(:tsearch)", + order_within_rank: (column_names.include?("cached_votes_up") ? "#{table_name}.cached_votes_up DESC" : nil) } end diff --git a/app/models/custom/verification/residence.rb b/app/models/custom/verification/residence.rb index 1cbc6f7ab..4386b705c 100644 --- a/app/models/custom/verification/residence.rb +++ b/app/models/custom/verification/residence.rb @@ -1,5 +1,5 @@ -require_dependency Rails.root.join('app', 'models', 'verification', 'residence').to_s +require_dependency Rails.root.join("app", "models", "verification", "residence").to_s class Verification::Residence @@ -7,7 +7,7 @@ class Verification::Residence validate :residence_in_madrid def postal_code_in_madrid - errors.add(:postal_code, I18n.t('verification.residence.new.error_not_allowed_postal_code')) unless valid_postal_code? + errors.add(:postal_code, I18n.t("verification.residence.new.error_not_allowed_postal_code")) unless valid_postal_code? end def residence_in_madrid diff --git a/app/models/debate.rb b/app/models/debate.rb index 08743848b..e3b1aad68 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -1,4 +1,4 @@ -require 'numeric' +require "numeric" class Debate < ActiveRecord::Base include Rails.application.routes.url_helpers include Flaggable @@ -18,7 +18,7 @@ class Debate < ActiveRecord::Base acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases - belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' + belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id" belongs_to :geozone has_many :comments, as: :commentable @@ -60,11 +60,11 @@ class Debate < ActiveRecord::Base end def searchable_values - { title => 'A', - author.username => 'B', - tag_list.join(' ') => 'B', - geozone.try(:name) => 'B', - description => 'D' + { title => "A", + author.username => "B", + tag_list.join(" ") => "B", + geozone.try(:name) => "B", + description => "D" } end @@ -97,7 +97,7 @@ class Debate < ActiveRecord::Base end def editable? - total_votes <= Setting['max_votes_for_debate_edit'].to_i + total_votes <= Setting["max_votes_for_debate_edit"].to_i end def editable_by?(user) @@ -115,8 +115,8 @@ class Debate < ActiveRecord::Base return false unless user total_votes <= 100 || !user.unverified? || - Setting['max_ratio_anon_votes_on_debates'].to_i == 100 || - anonymous_votes_ratio < Setting['max_ratio_anon_votes_on_debates'].to_i || + Setting["max_ratio_anon_votes_on_debates"].to_i == 100 || + anonymous_votes_ratio < Setting["max_ratio_anon_votes_on_debates"].to_i || user.voted_for?(self) end @@ -139,11 +139,11 @@ class Debate < ActiveRecord::Base end def after_hide - tags.each{ |t| t.decrement_custom_counter_for('Debate') } + tags.each{ |t| t.decrement_custom_counter_for("Debate") } end def after_restore - tags.each{ |t| t.increment_custom_counter_for('Debate') } + tags.each{ |t| t.increment_custom_counter_for("Debate") } end def featured? @@ -152,7 +152,7 @@ class Debate < ActiveRecord::Base def self.debates_orders(user) orders = %w{hot_score confidence_score created_at relevance} - orders << "recommendations" if Setting['feature.user.recommendations_on_debates'] && user&.recommended_debates + orders << "recommendations" if Setting["feature.user.recommendations_on_debates"] && user&.recommended_debates return orders end end diff --git a/app/models/direct_message.rb b/app/models/direct_message.rb index 7c652c83e..b4907ae7a 100644 --- a/app/models/direct_message.rb +++ b/app/models/direct_message.rb @@ -1,6 +1,6 @@ class DirectMessage < ActiveRecord::Base - belongs_to :sender, class_name: 'User', foreign_key: 'sender_id' - belongs_to :receiver, class_name: 'User', foreign_key: 'receiver_id' + belongs_to :sender, class_name: "User", foreign_key: "sender_id" + belongs_to :receiver, class_name: "User", foreign_key: "receiver_id" validates :title, presence: true validates :body, presence: true @@ -8,7 +8,7 @@ class DirectMessage < ActiveRecord::Base validates :receiver, presence: true validate :max_per_day - scope :today, lambda { where('DATE(created_at) = DATE(?)', Time.current) } + scope :today, lambda { where("DATE(created_at) = DATE(?)", Time.current) } def max_per_day return if errors.any? @@ -16,7 +16,7 @@ class DirectMessage < ActiveRecord::Base return unless max if sender.direct_messages_sent.today.count >= max.to_i - errors.add(:title, I18n.t('activerecord.errors.models.direct_message.attributes.max_per_day.invalid')) + errors.add(:title, I18n.t("activerecord.errors.models.direct_message.attributes.max_per_day.invalid")) end end diff --git a/app/models/failed_census_call.rb b/app/models/failed_census_call.rb index b7d60e63a..c0add2070 100644 --- a/app/models/failed_census_call.rb +++ b/app/models/failed_census_call.rb @@ -1,4 +1,4 @@ class FailedCensusCall < ActiveRecord::Base belongs_to :user, counter_cache: true - belongs_to :poll_officer, class_name: 'Poll::Officer', counter_cache: true + belongs_to :poll_officer, class_name: "Poll::Officer", counter_cache: true end diff --git a/app/models/flag.rb b/app/models/flag.rb index 824175b07..a05d8a737 100644 --- a/app/models/flag.rb +++ b/app/models/flag.rb @@ -8,7 +8,7 @@ class Flag < ActiveRecord::Base flaggable_id: flaggable.id) end) - scope :for_comments, ->(comments) { where(flaggable_type: 'Comment', flaggable_id: comments) } + scope :for_comments, ->(comments) { where(flaggable_type: "Comment", flaggable_id: comments) } def self.flag(user, flaggable) return false if flagged?(user, flaggable) diff --git a/app/models/geozone.rb b/app/models/geozone.rb index a52ab5d15..7cdcbab27 100644 --- a/app/models/geozone.rb +++ b/app/models/geozone.rb @@ -15,7 +15,7 @@ class Geozone < ActiveRecord::Base end def self.city - where(name: 'city').first + where(name: "city").first end def safe_to_destroy? diff --git a/app/models/i18n_content.rb b/app/models/i18n_content.rb index d3b5f4858..81c4ebee7 100644 --- a/app/models/i18n_content.rb +++ b/app/models/i18n_content.rb @@ -42,7 +42,7 @@ class I18nContent < ActiveRecord::Base def self.flat_hash(input, path = nil, output = {}) return output.update({ path => input }) unless input.is_a? Hash - input.map { |key, value| flat_hash(value, [path, key].compact.join('.'), output) } + input.map { |key, value| flat_hash(value, [path, key].compact.join("."), output) } return output end diff --git a/app/models/legislation.rb b/app/models/legislation.rb index 5aa217fd0..b0b035cdd 100644 --- a/app/models/legislation.rb +++ b/app/models/legislation.rb @@ -1,5 +1,5 @@ module Legislation def self.table_name_prefix - 'legislation_' + "legislation_" end end diff --git a/app/models/legislation/annotation.rb b/app/models/legislation/annotation.rb index feab80902..5cb190cc2 100644 --- a/app/models/legislation/annotation.rb +++ b/app/models/legislation/annotation.rb @@ -5,8 +5,8 @@ class Legislation::Annotation < ActiveRecord::Base serialize :ranges, Array - belongs_to :draft_version, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_draft_version_id' - belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' + belongs_to :draft_version, class_name: "Legislation::DraftVersion", foreign_key: "legislation_draft_version_id" + belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id" has_many :comments, as: :commentable, dependent: :destroy validates :text, presence: true diff --git a/app/models/legislation/answer.rb b/app/models/legislation/answer.rb index 7ee6119b5..298fe9f6d 100644 --- a/app/models/legislation/answer.rb +++ b/app/models/legislation/answer.rb @@ -2,9 +2,9 @@ class Legislation::Answer < ActiveRecord::Base acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases - belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', + belongs_to :question, class_name: "Legislation::Question", foreign_key: "legislation_question_id", inverse_of: :answers, counter_cache: true - belongs_to :question_option, class_name: 'Legislation::QuestionOption', foreign_key: 'legislation_question_option_id', + belongs_to :question_option, class_name: "Legislation::QuestionOption", foreign_key: "legislation_question_option_id", inverse_of: :answers, counter_cache: true belongs_to :user, dependent: :destroy, inverse_of: :legislation_answers diff --git a/app/models/legislation/draft_version.rb b/app/models/legislation/draft_version.rb index fbcac76c3..99dafac76 100644 --- a/app/models/legislation/draft_version.rb +++ b/app/models/legislation/draft_version.rb @@ -11,14 +11,14 @@ class Legislation::DraftVersion < ActiveRecord::Base translates :toc_html, touch: true include Globalizable - belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id' - has_many :annotations, class_name: 'Legislation::Annotation', foreign_key: 'legislation_draft_version_id', dependent: :destroy + belongs_to :process, class_name: "Legislation::Process", foreign_key: "legislation_process_id" + has_many :annotations, class_name: "Legislation::Annotation", foreign_key: "legislation_draft_version_id", dependent: :destroy validates_translation :title, presence: true validates_translation :body, presence: true validates :status, presence: true, inclusion: { in: VALID_STATUSES } - scope :published, -> { where(status: 'published').order('id DESC') } + scope :published, -> { where(status: "published").order("id DESC") } before_save :render_html @@ -40,7 +40,7 @@ class Legislation::DraftVersion < ActiveRecord::Base end def display_title - status == 'draft' ? "#{title} *" : title + status == "draft" ? "#{title} *" : title end def total_comments diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index 462ad677c..46d879b63 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -24,16 +24,16 @@ class Legislation::Process < ActiveRecord::Base CSS_HEX_COLOR = /\A#?(?:[A-F0-9]{3}){1,2}\z/i - has_many :draft_versions, -> { order(:id) }, class_name: 'Legislation::DraftVersion', - foreign_key: 'legislation_process_id', + has_many :draft_versions, -> { order(:id) }, class_name: "Legislation::DraftVersion", + foreign_key: "legislation_process_id", dependent: :destroy - has_one :final_draft_version, -> { where final_version: true, status: 'published' }, - class_name: 'Legislation::DraftVersion', - foreign_key: 'legislation_process_id' - has_many :questions, -> { order(:id) }, class_name: 'Legislation::Question', - foreign_key: 'legislation_process_id', dependent: :destroy - has_many :proposals, -> { order(:id) }, class_name: 'Legislation::Proposal', - foreign_key: 'legislation_process_id', dependent: :destroy + has_one :final_draft_version, -> { where final_version: true, status: "published" }, + class_name: "Legislation::DraftVersion", + foreign_key: "legislation_process_id" + has_many :questions, -> { order(:id) }, class_name: "Legislation::Question", + foreign_key: "legislation_process_id", dependent: :destroy + has_many :proposals, -> { order(:id) }, class_name: "Legislation::Proposal", + foreign_key: "legislation_process_id", dependent: :destroy validates_translation :title, presence: true validates :start_date, presence: true diff --git a/app/models/legislation/proposal.rb b/app/models/legislation/proposal.rb index 2f97141b5..cbf25bccf 100644 --- a/app/models/legislation/proposal.rb +++ b/app/models/legislation/proposal.rb @@ -22,8 +22,8 @@ class Legislation::Proposal < ActiveRecord::Base acts_as_votable acts_as_paranoid column: :hidden_at - belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id' - belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' + belongs_to :process, class_name: "Legislation::Process", foreign_key: "legislation_process_id" + belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id" belongs_to :geozone has_many :comments, as: :commentable @@ -59,13 +59,13 @@ class Legislation::Proposal < ActiveRecord::Base end def searchable_values - { title => 'A', - question => 'B', - author.username => 'B', - tag_list.join(' ') => 'B', - geozone.try(:name) => 'B', - summary => 'C', - description => 'D'} + { title => "A", + question => "B", + author.username => "B", + tag_list.join(" ") => "B", + geozone.try(:name) => "B", + summary => "C", + description => "D"} end def self.search(terms) @@ -136,11 +136,11 @@ class Legislation::Proposal < ActiveRecord::Base end def after_hide - tags.each{ |t| t.decrement_custom_counter_for('LegislationProposal') } + tags.each{ |t| t.decrement_custom_counter_for("LegislationProposal") } end def after_restore - tags.each{ |t| t.increment_custom_counter_for('LegislationProposal') } + tags.each{ |t| t.increment_custom_counter_for("LegislationProposal") } end protected diff --git a/app/models/legislation/question.rb b/app/models/legislation/question.rb index f464920af..acee09088 100644 --- a/app/models/legislation/question.rb +++ b/app/models/legislation/question.rb @@ -6,12 +6,12 @@ class Legislation::Question < ActiveRecord::Base translates :title, touch: true include Globalizable - belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' - belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id' + belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id" + belongs_to :process, class_name: "Legislation::Process", foreign_key: "legislation_process_id" - has_many :question_options, -> { order(:id) }, class_name: 'Legislation::QuestionOption', foreign_key: 'legislation_question_id', + has_many :question_options, -> { order(:id) }, class_name: "Legislation::QuestionOption", foreign_key: "legislation_question_id", dependent: :destroy, inverse_of: :question - has_many :answers, class_name: 'Legislation::Answer', foreign_key: 'legislation_question_id', dependent: :destroy, inverse_of: :question + has_many :answers, class_name: "Legislation::Answer", foreign_key: "legislation_question_id", dependent: :destroy, inverse_of: :question has_many :comments, as: :commentable, dependent: :destroy accepts_nested_attributes_for :question_options, reject_if: proc { |attributes| attributes.all? { |k, v| v.blank? } }, allow_destroy: true @@ -19,7 +19,7 @@ class Legislation::Question < ActiveRecord::Base validates :process, presence: true validates_translation :title, presence: true - scope :sorted, -> { order('id ASC') } + scope :sorted, -> { order("id ASC") } def next_question_id @next_question_id ||= process.questions.where("id > ?", id).sorted.limit(1).pluck(:id).first diff --git a/app/models/legislation/question_option.rb b/app/models/legislation/question_option.rb index 35520b35b..f69c60894 100644 --- a/app/models/legislation/question_option.rb +++ b/app/models/legislation/question_option.rb @@ -5,8 +5,8 @@ class Legislation::QuestionOption < ActiveRecord::Base translates :value, touch: true include Globalizable - belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', inverse_of: :question_options - has_many :answers, class_name: 'Legislation::Answer', foreign_key: 'legislation_question_id', dependent: :destroy, inverse_of: :question + belongs_to :question, class_name: "Legislation::Question", foreign_key: "legislation_question_id", inverse_of: :question_options + has_many :answers, class_name: "Legislation::Answer", foreign_key: "legislation_question_id", dependent: :destroy, inverse_of: :question validates :question, presence: true validates_translation :value, presence: true diff --git a/app/models/officing/residence.rb b/app/models/officing/residence.rb index ba930b16c..1d20660d2 100644 --- a/app/models/officing/residence.rb +++ b/app/models/officing/residence.rb @@ -35,7 +35,7 @@ class Officing::Residence verified_at: Time.current, erased_at: Time.current, password: random_password, - terms_of_service: '1', + terms_of_service: "1", email: nil } self.user = User.create!(user_params) @@ -75,7 +75,7 @@ class Officing::Residence return unless @census_api_response.valid? unless allowed_age? - errors.add(:year_of_birth, I18n.t('verification.residence.new.error_not_allowed_age')) + errors.add(:year_of_birth, I18n.t("verification.residence.new.error_not_allowed_age")) end end @@ -119,7 +119,7 @@ class Officing::Residence end def random_password - (0...20).map { ('a'..'z').to_a[rand(26)] }.join + (0...20).map { ("a".."z").to_a[rand(26)] }.join end end diff --git a/app/models/organization.rb b/app/models/organization.rb index e5b568818..0c7aa92e9 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -43,11 +43,11 @@ class Organization < ActiveRecord::Base end def self.name_max_length - @@name_max_length ||= columns.find { |c| c.name == 'name' }.limit || 60 + @@name_max_length ||= columns.find { |c| c.name == "name" }.limit || 60 end def self.responsible_name_max_length - @@responsible_name_max_length ||= columns.find { |c| c.name == 'responsible_name' }.limit || 60 + @@responsible_name_max_length ||= columns.find { |c| c.name == "responsible_name" }.limit || 60 end private diff --git a/app/models/poll.rb b/app/models/poll.rb index 65d78446a..9276cf9fb 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -22,15 +22,15 @@ class Poll < ActiveRecord::Base has_many :comments, as: :commentable has_and_belongs_to_many :geozones - belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' + belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id" validates_translation :name, presence: true validate :date_range - scope :current, -> { where('starts_at <= ? and ? <= ends_at', Date.current.beginning_of_day, Date.current.beginning_of_day) } - scope :expired, -> { where('ends_at < ?', Date.current.beginning_of_day) } + scope :current, -> { where("starts_at <= ? and ? <= ends_at", Date.current.beginning_of_day, Date.current.beginning_of_day) } + scope :expired, -> { where("ends_at < ?", Date.current.beginning_of_day) } scope :recounting, -> { Poll.where(ends_at: (Date.current.beginning_of_day - RECOUNT_DURATION)..Date.current.beginning_of_day) } - scope :published, -> { where('published = ?', true) } + scope :published, -> { where("published = ?", true) } scope :by_geozone_id, ->(geozone_id) { where(geozones: {id: geozone_id}.joins(:geozones)) } scope :public_for_api, -> { all } @@ -62,7 +62,7 @@ class Poll < ActiveRecord::Base def self.answerable_by(user) return none if user.nil? || user.unverified? current.joins('LEFT JOIN "geozones_polls" ON "geozones_polls"."poll_id" = "polls"."id"') - .where('geozone_restricted = ? OR geozones_polls.geozone_id = ?', false, user.geozone_id) + .where("geozone_restricted = ? OR geozones_polls.geozone_id = ?", false, user.geozone_id) end def self.votable_by(user) @@ -103,7 +103,7 @@ class Poll < ActiveRecord::Base 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')) + errors.add(:starts_at, I18n.t("errors.messages.invalid_date_range")) end end diff --git a/app/models/poll/answer.rb b/app/models/poll/answer.rb index 851ce2fbc..8e92988ad 100644 --- a/app/models/poll/answer.rb +++ b/app/models/poll/answer.rb @@ -1,7 +1,7 @@ class Poll::Answer < ActiveRecord::Base belongs_to :question, -> { with_hidden } - belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' + belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id" delegate :poll, :poll_id, to: :question diff --git a/app/models/poll/partial_result.rb b/app/models/poll/partial_result.rb index 72a3372b3..b24ae9750 100644 --- a/app/models/poll/partial_result.rb +++ b/app/models/poll/partial_result.rb @@ -3,7 +3,7 @@ class Poll::PartialResult < ActiveRecord::Base VALID_ORIGINS = %w{web booth} belongs_to :question, -> { with_hidden } - belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' + belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id" belongs_to :booth_assignment belongs_to :officer_assignment diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb index 9ffd7ab93..3dc19dabb 100644 --- a/app/models/poll/question.rb +++ b/app/models/poll/question.rb @@ -9,11 +9,11 @@ class Poll::Question < ActiveRecord::Base include Globalizable belongs_to :poll - belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' + belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id" has_many :comments, as: :commentable - has_many :answers, class_name: 'Poll::Answer' - has_many :question_answers, -> { order 'given_order asc' }, class_name: 'Poll::Question::Answer' + has_many :answers, class_name: "Poll::Answer" + has_many :question_answers, -> { order "given_order asc" }, class_name: "Poll::Question::Answer" has_many :partial_results belongs_to :proposal @@ -23,7 +23,7 @@ class Poll::Question < ActiveRecord::Base scope :by_poll_id, ->(poll_id) { where(poll_id: poll_id) } - scope :sort_for_list, -> { order('poll_questions.proposal_id IS NULL', :created_at)} + scope :sort_for_list, -> { order("poll_questions.proposal_id IS NULL", :created_at)} scope :for_render, -> { includes(:author, :proposal) } def self.search(params) @@ -34,10 +34,10 @@ class Poll::Question < ActiveRecord::Base end def searchable_values - { title => 'A', - proposal.try(:title) => 'A', - author.username => 'C', - author_visible_name => 'C' } + { title => "A", + proposal.try(:title) => "A", + author.username => "C", + author_visible_name => "C" } end def copy_attributes_from_proposal(proposal) diff --git a/app/models/poll/question/answer.rb b/app/models/poll/question/answer.rb index db218a7de..2efa2b824 100644 --- a/app/models/poll/question/answer.rb +++ b/app/models/poll/question/answer.rb @@ -11,8 +11,8 @@ class Poll::Question::Answer < ActiveRecord::Base accepted_content_types: [ "application/pdf" ] accepts_nested_attributes_for :documents, allow_destroy: true - belongs_to :question, class_name: 'Poll::Question', foreign_key: 'question_id' - has_many :videos, class_name: 'Poll::Question::Answer::Video' + belongs_to :question, class_name: "Poll::Question", foreign_key: "question_id" + has_many :videos, class_name: "Poll::Question::Answer::Video" validates_translation :title, presence: true validates :given_order, presence: true, uniqueness: { scope: :question_id } @@ -34,7 +34,7 @@ class Poll::Question::Answer < ActiveRecord::Base end def self.last_position(question_id) - where(question_id: question_id).maximum('given_order') || 0 + where(question_id: question_id).maximum("given_order") || 0 end def total_votes diff --git a/app/models/poll/question/answer/video.rb b/app/models/poll/question/answer/video.rb index 3d214af96..4804f5188 100644 --- a/app/models/poll/question/answer/video.rb +++ b/app/models/poll/question/answer/video.rb @@ -1,5 +1,5 @@ class Poll::Question::Answer::Video < ActiveRecord::Base - belongs_to :answer, class_name: 'Poll::Question::Answer', foreign_key: 'answer_id' + belongs_to :answer, class_name: "Poll::Question::Answer", foreign_key: "answer_id" VIMEO_REGEX = /vimeo.*(staffpicks\/|channels\/|videos\/|video\/|\/)([^#\&\?]*).*/ YOUTUBE_REGEX = /youtu.*(be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/ diff --git a/app/models/poll/recount.rb b/app/models/poll/recount.rb index 74a6fe937..878b1ee55 100644 --- a/app/models/poll/recount.rb +++ b/app/models/poll/recount.rb @@ -2,16 +2,16 @@ class Poll::Recount < ActiveRecord::Base VALID_ORIGINS = %w{web booth letter}.freeze - belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' + belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id" belongs_to :booth_assignment belongs_to :officer_assignment validates :author, presence: true validates :origin, inclusion: {in: VALID_ORIGINS} - scope :web, -> { where(origin: 'web') } - scope :booth, -> { where(origin: 'booth') } - scope :letter, -> { where(origin: 'letter') } + scope :web, -> { where(origin: "web") } + scope :booth, -> { where(origin: "booth") } + scope :letter, -> { where(origin: "letter") } scope :by_author, ->(author_id) { where(author_id: author_id) } diff --git a/app/models/poll/shift.rb b/app/models/poll/shift.rb index 13b5c2009..dd5c1db32 100644 --- a/app/models/poll/shift.rb +++ b/app/models/poll/shift.rb @@ -10,8 +10,8 @@ class Poll enum task: { vote_collection: 0, recount_scrutiny: 1 } - scope :vote_collection, -> { where(task: 'vote_collection') } - scope :recount_scrutiny, -> { where(task: 'recount_scrutiny') } + scope :vote_collection, -> { where(task: "vote_collection") } + scope :recount_scrutiny, -> { where(task: "recount_scrutiny") } scope :current, -> { where(date: Date.current) } before_create :persist_data diff --git a/app/models/poll/stats.rb b/app/models/poll/stats.rb index f07795a73..7f12e2a56 100644 --- a/app/models/poll/stats.rb +++ b/app/models/poll/stats.rb @@ -18,121 +18,121 @@ class Poll private def total_participants - stats_cache('total_participants') { total_participants_web + total_participants_booth } + stats_cache("total_participants") { total_participants_web + total_participants_booth } end def total_participants_web - stats_cache('total_participants_web') { total_web_valid + total_web_white + total_web_null } + stats_cache("total_participants_web") { total_web_valid + total_web_white + total_web_null } end def total_participants_web_percentage - stats_cache('total_participants_web_percentage') do + stats_cache("total_participants_web_percentage") do total_participants.zero? ? 0 : total_participants_web * 100 / total_participants end end def total_participants_booth - stats_cache('total_participants_booth') { voters.where(origin: 'booth').count } + stats_cache("total_participants_booth") { voters.where(origin: "booth").count } end def total_participants_booth_percentage - stats_cache('total_participants_booth_percentage') do + stats_cache("total_participants_booth_percentage") do total_participants.zero? ? 0 : total_participants_booth * 100 / total_participants.to_f end end def total_web_valid - stats_cache('total_web_valid') { voters.where(origin: 'web').count } + stats_cache("total_web_valid") { voters.where(origin: "web").count } end def valid_percentage_web - stats_cache('valid_percentage_web') do + stats_cache("valid_percentage_web") do total_valid_votes.zero? ? 0 : total_web_valid * 100 / total_valid_votes.to_f end end def total_web_white - stats_cache('total_web_white') { 0 } + stats_cache("total_web_white") { 0 } end def white_percentage_web - stats_cache('white_percentage_web') { 0 } + stats_cache("white_percentage_web") { 0 } end def total_web_null - stats_cache('total_web_null') { 0 } + stats_cache("total_web_null") { 0 } end def null_percentage_web - stats_cache('null_percentage_web') { 0 } + stats_cache("null_percentage_web") { 0 } end def total_booth_valid - stats_cache('total_booth_valid') { recounts.sum(:total_amount) } + stats_cache("total_booth_valid") { recounts.sum(:total_amount) } end def valid_percentage_booth - stats_cache('valid_percentage_booth') do + stats_cache("valid_percentage_booth") do total_valid_votes.zero? ? 0 : total_booth_valid * 100 / total_valid_votes.to_f end end def total_booth_white - stats_cache('total_booth_white') { recounts.sum(:white_amount) } + stats_cache("total_booth_white") { recounts.sum(:white_amount) } end def white_percentage_booth - stats_cache('white_percentage_booth') do + stats_cache("white_percentage_booth") do total_white_votes.zero? ? 0 : total_booth_white * 100 / total_white_votes.to_f end end def total_booth_null - stats_cache('total_booth_null') { recounts.sum(:null_amount) } + stats_cache("total_booth_null") { recounts.sum(:null_amount) } end def null_percentage_booth - stats_cache('null_percentage_booth') do + stats_cache("null_percentage_booth") do total_null_votes.zero? ? 0 : total_booth_null * 100 / total_null_votes.to_f end end def total_valid_votes - stats_cache('total_valid_votes') { total_web_valid + total_booth_valid } + stats_cache("total_valid_votes") { total_web_valid + total_booth_valid } end def total_valid_percentage - stats_cache('total_valid_percentage') do + stats_cache("total_valid_percentage") do total_participants.zero? ? 0 : total_valid_votes * 100 / total_participants.to_f end end def total_white_votes - stats_cache('total_white_votes') { total_web_white + total_booth_white } + stats_cache("total_white_votes") { total_web_white + total_booth_white } end def total_white_percentage - stats_cache('total_white_percentage') do + stats_cache("total_white_percentage") do total_participants.zero? ? 0 : total_white_votes * 100 / total_participants.to_f end end def total_null_votes - stats_cache('total_null_votes') { total_web_null + total_booth_null } + stats_cache("total_null_votes") { total_web_null + total_booth_null } end def total_null_percentage - stats_cache('total_null_percentage') do + stats_cache("total_null_percentage") do total_participants.zero? ? 0 : total_null_votes * 100 / total_participants.to_f end end def voters - stats_cache('voters') { @poll.voters } + stats_cache("voters") { @poll.voters } end def recounts - stats_cache('recounts') { @poll.recounts } + stats_cache("recounts") { @poll.recounts } end def stats_cache(key, &block) diff --git a/app/models/poll/voter.rb b/app/models/poll/voter.rb index 778a5d88a..0826092d2 100644 --- a/app/models/poll/voter.rb +++ b/app/models/poll/voter.rb @@ -18,8 +18,8 @@ class Poll before_validation :set_demographic_info, :set_document_info - scope :web, -> { where(origin: 'web') } - scope :booth, -> { where(origin: 'booth') } + scope :web, -> { where(origin: "web") } + scope :booth, -> { where(origin: "booth") } def set_demographic_info return if user.blank? diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 3cf6811e4..cfaf197d1 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -29,7 +29,7 @@ class Proposal < ActiveRecord::Base RETIRE_OPTIONS = %w(duplicated started unfeasible done other) - belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' + belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id" belongs_to :geozone has_many :comments, as: :commentable, dependent: :destroy has_many :proposal_notifications, dependent: :destroy @@ -95,13 +95,13 @@ class Proposal < ActiveRecord::Base end def searchable_values - { title => 'A', - question => 'B', - author.username => 'B', - tag_list.join(' ') => 'B', - geozone.try(:name) => 'B', - summary => 'C', - description => 'D' + { title => "A", + question => "B", + author.username => "B", + tag_list.join(" ") => "B", + geozone.try(:name) => "B", + summary => "C", + description => "D" } end @@ -179,15 +179,15 @@ class Proposal < ActiveRecord::Base end def after_hide - tags.each{ |t| t.decrement_custom_counter_for('Proposal') } + tags.each{ |t| t.decrement_custom_counter_for("Proposal") } end def after_restore - tags.each{ |t| t.increment_custom_counter_for('Proposal') } + tags.each{ |t| t.increment_custom_counter_for("Proposal") } end def self.votes_needed_for_success - Setting['votes_for_proposal_success'].to_i + Setting["votes_for_proposal_success"].to_i end def successful? @@ -208,7 +208,7 @@ class Proposal < ActiveRecord::Base def self.proposals_orders(user) orders = %w{hot_score confidence_score created_at relevance archival_date} - orders << "recommendations" if Setting['feature.user.recommendations_on_proposals'] && user&.recommended_proposals + orders << "recommendations" if Setting["feature.user.recommendations_on_proposals"] && user&.recommended_proposals return orders end diff --git a/app/models/proposal_notification.rb b/app/models/proposal_notification.rb index 686fdc075..bdb9f7698 100644 --- a/app/models/proposal_notification.rb +++ b/app/models/proposal_notification.rb @@ -2,7 +2,7 @@ class ProposalNotification < ActiveRecord::Base include Graphqlable include Notifiable - belongs_to :author, class_name: 'User', foreign_key: 'author_id' + belongs_to :author, class_name: "User", foreign_key: "author_id" belongs_to :proposal validates :title, presence: true @@ -29,7 +29,7 @@ class ProposalNotification < ActiveRecord::Base interval = Setting[:proposal_notification_minimum_interval_in_days] minimum_interval = (Time.current - interval.to_i.days).to_datetime if proposal.notifications.last.created_at > minimum_interval - errors.add(:title, I18n.t('activerecord.errors.models.proposal_notification.attributes.minimum_interval.invalid', interval: interval)) + errors.add(:title, I18n.t("activerecord.errors.models.proposal_notification.attributes.minimum_interval.invalid", interval: interval)) end end @@ -38,7 +38,7 @@ class ProposalNotification < ActiveRecord::Base end def moderate_system_email(moderator) - Notification.where(notifiable_type: 'ProposalNotification', notifiable: self).destroy_all + Notification.where(notifiable_type: "ProposalNotification", notifiable: self).destroy_all Activity.log(moderator, :hide, self) end diff --git a/app/models/related_content.rb b/app/models/related_content.rb index 8a4cd949c..f9facb47a 100644 --- a/app/models/related_content.rb +++ b/app/models/related_content.rb @@ -1,14 +1,14 @@ class RelatedContent < ActiveRecord::Base - RELATED_CONTENT_SCORE_THRESHOLD = Setting['related_content_score_threshold'].to_f + RELATED_CONTENT_SCORE_THRESHOLD = Setting["related_content_score_threshold"].to_f RELATIONABLE_MODELS = %w{proposals debates budgets investments}.freeze acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases - belongs_to :author, class_name: 'User', foreign_key: 'author_id' + belongs_to :author, class_name: "User", foreign_key: "author_id" belongs_to :parent_relationable, polymorphic: true, touch: true belongs_to :child_relationable, polymorphic: true, touch: true - has_one :opposite_related_content, class_name: 'RelatedContent', foreign_key: :related_content_id + has_one :opposite_related_content, class_name: "RelatedContent", foreign_key: :related_content_id has_many :related_content_scores validates :parent_relationable_id, presence: true diff --git a/app/models/setting.rb b/app/models/setting.rb index c3d9768e6..00b87a4db 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -5,14 +5,14 @@ class Setting < ActiveRecord::Base def type if feature_flag? - 'feature' + "feature" else - 'common' + "common" end end def feature_flag? - key.start_with?('feature.') + key.start_with?("feature.") end def enabled? diff --git a/app/models/signature.rb b/app/models/signature.rb index b354a7a15..3f5729058 100644 --- a/app/models/signature.rb +++ b/app/models/signature.rb @@ -26,7 +26,7 @@ class Signature < ActiveRecord::Base def assign_vote_to_user set_user if signable.is_a? Budget::Investment - signable.vote_by(voter: user, vote: 'yes') if [nil, :no_selecting_allowed].include?(signable.reason_for_not_being_selectable_by(user)) + signable.vote_by(voter: user, vote: "yes") if [nil, :no_selecting_allowed].include?(signable.reason_for_not_being_selectable_by(user)) else signable.register_vote(user, "yes") end @@ -49,7 +49,7 @@ class Signature < ActiveRecord::Base verified_at: Time.current, erased_at: Time.current, password: random_password, - terms_of_service: '1', + terms_of_service: "1", email: nil, date_of_birth: @census_api_response.date_of_birth, gender: @census_api_response.gender, @@ -64,7 +64,7 @@ class Signature < ActiveRecord::Base end def random_password - (0...20).map { ('a'..'z').to_a[rand(26)] }.join + (0...20).map { ("a".."z").to_a[rand(26)] }.join end def in_census? diff --git a/app/models/signature_sheet.rb b/app/models/signature_sheet.rb index 3e46c1cd1..a8a10a150 100644 --- a/app/models/signature_sheet.rb +++ b/app/models/signature_sheet.rb @@ -1,6 +1,6 @@ class SignatureSheet < ActiveRecord::Base belongs_to :signable, polymorphic: true - belongs_to :author, class_name: 'User', foreign_key: 'author_id' + belongs_to :author, class_name: "User", foreign_key: "author_id" VALID_SIGNABLES = %w(Proposal Budget::Investment SpendingProposal) @@ -29,7 +29,7 @@ class SignatureSheet < ActiveRecord::Base end def parsed_document_numbers - document_numbers.split(/\r\n|\n|[,]/).collect {|d| d.gsub(/\s+/, '') } + document_numbers.split(/\r\n|\n|[,]/).collect {|d| d.gsub(/\s+/, "") } end def signable_found diff --git a/app/models/site_customization.rb b/app/models/site_customization.rb index e5d2f2137..5b9584f93 100644 --- a/app/models/site_customization.rb +++ b/app/models/site_customization.rb @@ -1,5 +1,5 @@ module SiteCustomization def self.table_name_prefix - 'site_customization_' + "site_customization_" end end diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index f6f367f62..3bd753476 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -6,7 +6,7 @@ class SpendingProposal < ActiveRecord::Base acts_as_votable - belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' + belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id" belongs_to :geozone belongs_to :administrator has_many :valuation_assignments, dependent: :destroy @@ -29,7 +29,7 @@ class SpendingProposal < ActiveRecord::Base scope :feasible, -> { where(feasible: true) } scope :unfeasible, -> { where(feasible: false) } scope :not_unfeasible, -> { where("feasible IS ? OR feasible = ?", nil, true) } - scope :with_supports, -> { where('cached_votes_up > 0') } + scope :with_supports, -> { where("cached_votes_up > 0") } scope :by_admin, ->(admin) { where(administrator_id: admin.presence) } scope :by_tag, ->(tag_name) { tagged_with(tag_name) } @@ -58,10 +58,10 @@ class SpendingProposal < ActiveRecord::Base end def searchable_values - { title => 'A', - author.username => 'B', - geozone.try(:name) => 'B', - description => 'C' + { title => "A", + author.username => "B", + geozone.try(:name) => "B", + description => "C" } end @@ -70,7 +70,7 @@ class SpendingProposal < ActiveRecord::Base end def self.by_geozone(geozone) - if geozone == 'all' + if geozone == "all" where(geozone_id: nil) else where(geozone_id: geozone.presence) diff --git a/app/models/tag_cloud.rb b/app/models/tag_cloud.rb index b0882af82..47b9a94fc 100644 --- a/app/models/tag_cloud.rb +++ b/app/models/tag_cloud.rb @@ -28,11 +28,11 @@ class TagCloud end def default_blacklist - [''] + [""] end def table_name resource_model.to_s.downcase.pluralize.gsub("::", "/") end -end \ No newline at end of file +end diff --git a/app/models/topic.rb b/app/models/topic.rb index 11c921dd4..e9e463aa5 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -4,7 +4,7 @@ class Topic < ActiveRecord::Base include Notifiable belongs_to :community - belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' + belongs_to :author, -> { with_hidden }, class_name: "User", foreign_key: "author_id" has_many :comments, as: :commentable diff --git a/app/models/user.rb b/app/models/user.rb index 0f58594ab..e02c93d99 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -23,14 +23,14 @@ class User < ActiveRecord::Base has_many :identities, dependent: :destroy has_many :debates, -> { with_hidden }, foreign_key: :author_id has_many :proposals, -> { with_hidden }, foreign_key: :author_id - has_many :budget_investments, -> { with_hidden }, foreign_key: :author_id, class_name: 'Budget::Investment' + has_many :budget_investments, -> { with_hidden }, foreign_key: :author_id, class_name: "Budget::Investment" has_many :comments, -> { with_hidden } has_many :spending_proposals, foreign_key: :author_id has_many :failed_census_calls has_many :notifications - has_many :direct_messages_sent, class_name: 'DirectMessage', foreign_key: :sender_id - has_many :direct_messages_received, class_name: 'DirectMessage', foreign_key: :receiver_id - has_many :legislation_answers, class_name: 'Legislation::Answer', dependent: :destroy, inverse_of: :user + has_many :direct_messages_sent, class_name: "DirectMessage", foreign_key: :sender_id + has_many :direct_messages_received, class_name: "DirectMessage", foreign_key: :receiver_id + has_many :legislation_answers, class_name: "Legislation::Answer", dependent: :destroy, inverse_of: :user has_many :follows belongs_to :geozone @@ -84,7 +84,7 @@ class User < ActiveRecord::Base email: oauth_email, oauth_email: oauth_email, password: Devise.friendly_token[0, 20], - terms_of_service: '1', + terms_of_service: "1", confirmed_at: oauth_email_confirmed ? DateTime.current : nil ) end @@ -177,7 +177,7 @@ class User < ActiveRecord::Base end def has_official_email? - domain = Setting['email_domain_for_officials'] + domain = Setting["email_domain_for_officials"] email.present? && ((email.end_with? "@#{domain}") || (email.end_with? ".#{domain}")) end @@ -251,11 +251,11 @@ class User < ActiveRecord::Base end def self.username_max_length - @@username_max_length ||= columns.find { |c| c.name == 'username' }.limit || 60 + @@username_max_length ||= columns.find { |c| c.name == "username" }.limit || 60 end def self.minimum_required_age - (Setting['min_age_to_participate'] || 16).to_i + (Setting["min_age_to_participate"] || 16).to_i end def show_welcome_screen? diff --git a/app/models/valuator.rb b/app/models/valuator.rb index 30b171823..2aedfc8f6 100644 --- a/app/models/valuator.rb +++ b/app/models/valuator.rb @@ -6,8 +6,8 @@ class Valuator < ActiveRecord::Base has_many :valuation_assignments, dependent: :destroy has_many :spending_proposals, through: :valuation_assignments - has_many :valuator_assignments, dependent: :destroy, class_name: 'Budget::ValuatorAssignment' - has_many :investments, through: :valuator_assignments, class_name: 'Budget::Investment' + has_many :valuator_assignments, dependent: :destroy, class_name: "Budget::ValuatorAssignment" + has_many :investments, through: :valuator_assignments, class_name: "Budget::Investment" validates :user_id, presence: true, uniqueness: true diff --git a/app/models/valuator_group.rb b/app/models/valuator_group.rb index 61a4e4458..26738b542 100644 --- a/app/models/valuator_group.rb +++ b/app/models/valuator_group.rb @@ -1,7 +1,7 @@ class ValuatorGroup < ActiveRecord::Base has_many :valuators - has_many :valuator_group_assignments, dependent: :destroy, class_name: 'Budget::ValuatorGroupAssignment' - has_many :investments, through: :valuator_group_assignments, class_name: 'Budget::Investment' + has_many :valuator_group_assignments, dependent: :destroy, class_name: "Budget::ValuatorGroupAssignment" + has_many :investments, through: :valuator_group_assignments, class_name: "Budget::Investment" validates :name, presence: true, uniqueness: true end diff --git a/app/models/verification/letter.rb b/app/models/verification/letter.rb index c746e73e4..e70da2b5f 100644 --- a/app/models/verification/letter.rb +++ b/app/models/verification/letter.rb @@ -22,14 +22,14 @@ class Verification::Letter def validate_existing_user unless user - errors.add(:email, I18n.t('devise.failure.invalid', authentication_keys: 'email')) + errors.add(:email, I18n.t("devise.failure.invalid", authentication_keys: "email")) end end def validate_correct_code return if errors.include?(:verification_code) if user.try(:letter_verification_code).to_i != verification_code.to_i - errors.add(:verification_code, I18n.t('verification.letter.errors.incorrect_code')) + errors.add(:verification_code, I18n.t("verification.letter.errors.incorrect_code")) end end diff --git a/app/models/verification/management/email.rb b/app/models/verification/management/email.rb index de13d1ab4..8cad381d2 100644 --- a/app/models/verification/management/email.rb +++ b/app/models/verification/management/email.rb @@ -40,9 +40,9 @@ class Verification::Management::Email def validate_user return if errors.count > 0 if !user? - errors.add(:email, I18n.t('errors.messages.user_not_found')) + errors.add(:email, I18n.t("errors.messages.user_not_found")) elsif user.level_three_verified? - errors.add(:email, I18n.t('management.email_verifications.already_verified')) + errors.add(:email, I18n.t("management.email_verifications.already_verified")) end end @@ -50,7 +50,7 @@ class Verification::Management::Email return if errors.count > 0 if document_number_mismatch? errors.add(:email, - I18n.t('management.email_verifications.document_mismatch', + I18n.t("management.email_verifications.document_mismatch", document_type: ApplicationController.helpers.humanize_document_type(user.document_type), document_number: user.document_number)) end diff --git a/app/models/verification/management/managed_user.rb b/app/models/verification/management/managed_user.rb index e61cc2937..7332b5f7e 100644 --- a/app/models/verification/management/managed_user.rb +++ b/app/models/verification/management/managed_user.rb @@ -2,9 +2,9 @@ class Verification::Management::ManagedUser include ActiveModel::Model def self.find(document_type, document_number) - User.where('document_number is not null'). + User.where("document_number is not null"). find_or_initialize_by(document_type: document_type, document_number: document_number) end -end \ No newline at end of file +end diff --git a/app/models/verification/residence.rb b/app/models/verification/residence.rb index 0b8f420ce..a8c20adfd 100644 --- a/app/models/verification/residence.rb +++ b/app/models/verification/residence.rb @@ -18,8 +18,8 @@ class Verification::Residence validate :document_number_uniqueness def initialize(attrs = {}) - self.date_of_birth = parse_date('date_of_birth', attrs) - attrs = remove_date('date_of_birth', attrs) + self.date_of_birth = parse_date("date_of_birth", attrs) + attrs = remove_date("date_of_birth", attrs) super clean_document_number end @@ -39,11 +39,11 @@ class Verification::Residence def allowed_age return if errors[:date_of_birth].any? || Age.in_years(date_of_birth) >= User.minimum_required_age - errors.add(:date_of_birth, I18n.t('verification.residence.new.error_not_allowed_age')) + errors.add(:date_of_birth, I18n.t("verification.residence.new.error_not_allowed_age")) end def document_number_uniqueness - errors.add(:document_number, I18n.t('errors.messages.taken')) if User.active.where(document_number: document_number).any? + errors.add(:document_number, I18n.t("errors.messages.taken")) if User.active.where(document_number: document_number).any? end def store_failed_attempt