diff --git a/app/controllers/users/sessions_controller.rb b/app/controllers/users/sessions_controller.rb index 046d0a6f2..6a077ee54 100644 --- a/app/controllers/users/sessions_controller.rb +++ b/app/controllers/users/sessions_controller.rb @@ -15,7 +15,7 @@ class Users::SessionsController < Devise::SessionsController end def verifying_via_email? - return false unless resource.present? + return false if resource.blank? stored_path = session[stored_location_key_for(resource)] || "" stored_path[0..5] == "/email" end diff --git a/app/controllers/valuation/budget_investments_controller.rb b/app/controllers/valuation/budget_investments_controller.rb index ae747464e..c01f87c38 100644 --- a/app/controllers/valuation/budget_investments_controller.rb +++ b/app/controllers/valuation/budget_investments_controller.rb @@ -59,7 +59,7 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController end def params_for_current_valuator - Budget::Investment.filter_params(params).merge({valuator_id: current_user.valuator.id, budget_id: @budget.id}) + Budget::Investment.filter_params(params).merge(valuator_id: current_user.valuator.id, budget_id: @budget.id) end def valuation_params diff --git a/app/helpers/budgets_helper.rb b/app/helpers/budgets_helper.rb index 3a07f0393..fefda85ab 100644 --- a/app/helpers/budgets_helper.rb +++ b/app/helpers/budgets_helper.rb @@ -8,7 +8,7 @@ module BudgetsHelper Budget::CURRENCY_SYMBOLS.map { |cs| [ cs, cs ] } end - def namespaced_budget_investment_path(investment, options={}) + def namespaced_budget_investment_path(investment, options = {}) case namespace when "management/budgets" management_budget_investment_path(investment.budget, investment, options) @@ -17,7 +17,7 @@ module BudgetsHelper end end - def namespaced_budget_investment_vote_path(investment, options={}) + def namespaced_budget_investment_vote_path(investment, options = {}) case namespace when "management/budgets" vote_management_budget_investment_path(investment.budget, investment, options) @@ -31,7 +31,7 @@ module BudgetsHelper end def css_for_ballot_heading(heading) - return '' unless current_ballot.present? + return '' if current_ballot.blank? current_ballot.has_lines_in_heading?(heading) ? 'active' : '' end diff --git a/app/helpers/layouts_helper.rb b/app/helpers/layouts_helper.rb index c92f57898..40c8b0b98 100644 --- a/app/helpers/layouts_helper.rb +++ b/app/helpers/layouts_helper.rb @@ -3,7 +3,7 @@ module LayoutsHelper def layout_menu_link_to(text, path, is_active, options) if is_active content_tag(:span, t('shared.you_are_in'), class: 'sr-only') + ' ' + - link_to(text, path, options.merge(class: "active")) + link_to(text, path, options.merge(class: "active")) else link_to(text, path, options) end diff --git a/app/helpers/officing_helper.rb b/app/helpers/officing_helper.rb index 2cfebf832..f5bdb26ea 100644 --- a/app/helpers/officing_helper.rb +++ b/app/helpers/officing_helper.rb @@ -11,9 +11,9 @@ module OfficingHelper def booths_for_officer_select_options(officer_assignments) options = [] officer_assignments.each do |oa| - options << ["#{oa.booth_assignment.booth.name}", oa.id] + options << [oa.booth_assignment.booth.name.to_s, oa.id] end - options.sort! {|x,y| x[0]<=>y[0]} + options.sort! {|x, y| x[0]<=>y[0]} options_for_select(options, params[:oa]) end diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index 5425a6b52..169599a7c 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -1,9 +1,9 @@ module PollsHelper - def poll_select_options(include_all=nil) - options = @polls.collect {|poll| + def poll_select_options(include_all = nil) + options = @polls.collect do |poll| [poll.name, current_path_with_query_params(poll_id: poll.id)] - } + end options << all_polls if include_all options_for_select(options, request.fullpath) end diff --git a/app/models/budget/ballot/line.rb b/app/models/budget/ballot/line.rb index 175e9886d..e4e1d598b 100644 --- a/app/models/budget/ballot/line.rb +++ b/app/models/budget/ballot/line.rb @@ -13,7 +13,7 @@ class Budget validate :check_sufficient_funds validate :check_valid_heading - scope :by_investment, -> (investment_id) { where(investment_id: investment_id) } + scope :by_investment, ->(investment_id) { where(investment_id: investment_id) } before_validation :set_denormalized_ids diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 7aabf7093..01ab15de3 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -52,11 +52,11 @@ class Budget scope :unselected, -> { not_unfeasible.where(selected: false) } scope :last_week, -> { where("created_at >= ?", 7.days.ago)} - scope :by_group, -> (group_id) { where(group_id: group_id) } - scope :by_heading, -> (heading_id) { where(heading_id: heading_id) } - scope :by_admin, -> (admin_id) { where(administrator_id: admin_id) } - scope :by_tag, -> (tag_name) { tagged_with(tag_name) } - scope :by_valuator, -> (valuator_id) { where("budget_valuator_assignments.valuator_id = ?", valuator_id).joins(:valuator_assignments) } + scope :by_group, ->(group_id) { where(group_id: group_id) } + scope :by_heading, ->(heading_id) { where(heading_id: heading_id) } + scope :by_admin, ->(admin_id) { where(administrator_id: admin_id) } + scope :by_tag, ->(tag_name) { tagged_with(tag_name) } + scope :by_valuator, ->(valuator_id) { where("budget_valuator_assignments.valuator_id = ?", valuator_id).joins(:valuator_assignments) } scope :for_render, -> { includes(:heading) } @@ -65,7 +65,7 @@ class Budget before_validation :set_denormalized_ids def self.filter_params(params) - params.select{|x,_| %w{heading_id group_id administrator_id tag_name valuator_id}.include? x.to_s } + params.select{|x, _| %w{heading_id group_id administrator_id tag_name valuator_id}.include? x.to_s } end def self.scoped_filter(params, current_filter) @@ -152,7 +152,7 @@ class Budget return :not_logged_in unless user return :organization if user.organization? return :not_verified unless user.can?(:vote, Budget::Investment) - return nil + nil end def permission_problem?(user) @@ -177,8 +177,8 @@ class Budget end def heading_voted_by_user?(user) - user.votes.for_budget_investments(budget.investments.where(group: group)). - votables.map(&:heading_id).first + user.votes.for_budget_investments(budget.investments.where(group: group)) + .votables.map(&:heading_id).first end def ballotable_by?(user) @@ -204,8 +204,8 @@ class Budget def should_show_aside? (budget.selecting? && !unfeasible?) || - (budget.balloting? && feasible?) || - (budget.valuating? && !unfeasible?) + (budget.balloting? && feasible?) || + (budget.valuating? && !unfeasible?) end def should_show_votes? @@ -222,21 +222,21 @@ class Budget def should_show_price? feasible? && - selected? && - (budget.reviewing_ballots? || budget.finished?) + selected? && + (budget.reviewing_ballots? || budget.finished?) end def should_show_price_info? feasible? && - price_explanation.present? && - (budget.balloting? || budget.reviewing_ballots? || budget.finished?) + price_explanation.present? && + (budget.balloting? || budget.reviewing_ballots? || budget.finished?) end def formatted_price budget.formatted_amount(price) end - def self.apply_filters_and_search(budget, params, current_filter=nil) + def self.apply_filters_and_search(_budget, params, current_filter = nil) investments = all investments = investments.send(current_filter) if current_filter.present? investments = investments.by_heading(params[:heading_id]) if params[:heading_id].present? diff --git a/app/models/budget/reclassification.rb b/app/models/budget/reclassification.rb index f8d1db7fd..3ce3ab146 100644 --- a/app/models/budget/reclassification.rb +++ b/app/models/budget/reclassification.rb @@ -7,14 +7,14 @@ class Budget end def check_for_reclassification - if heading_changed? - log_heading_change - store_reclassified_votes("heading_changed") - remove_reclassified_votes - elsif marked_as_unfeasible? - store_reclassified_votes("unfeasible") - remove_reclassified_votes - end + if heading_changed? + log_heading_change + store_reclassified_votes("heading_changed") + remove_reclassified_votes + elsif marked_as_unfeasible? + store_reclassified_votes("unfeasible") + remove_reclassified_votes + end end def heading_changed? diff --git a/app/models/officing/residence.rb b/app/models/officing/residence.rb index 6343fc5f7..539b557a5 100644 --- a/app/models/officing/residence.rb +++ b/app/models/officing/residence.rb @@ -108,7 +108,7 @@ class Officing::Residence def residency_valid? @census_api_response.valid? && - @census_api_response.date_of_birth.year.to_s == year_of_birth.to_s + @census_api_response.date_of_birth.year.to_s == year_of_birth.to_s end def census_year_of_birth @@ -116,7 +116,7 @@ class Officing::Residence end def clean_document_number - self.document_number = self.document_number.gsub(/[^a-z0-9]+/i, "").upcase unless self.document_number.blank? + self.document_number = self.document_number.gsub(/[^a-z0-9]+/i, "").upcase if self.document_number.present? end def random_password diff --git a/app/models/poll/answer.rb b/app/models/poll/answer.rb index 52fb11469..a1ff30f0a 100644 --- a/app/models/poll/answer.rb +++ b/app/models/poll/answer.rb @@ -10,8 +10,8 @@ class Poll::Answer < ActiveRecord::Base validates :answer, presence: true validates :answer, inclusion: {in: ->(a) { a.question.valid_answers }} - scope :by_author, -> (author_id) { where(author_id: author_id) } - scope :by_question, -> (question_id) { where(question_id: question_id) } + scope :by_author, ->(author_id) { where(author_id: author_id) } + scope :by_question, ->(question_id) { where(question_id: question_id) } def record_voter_participation Poll::Voter.create!(user: author, poll: poll) diff --git a/app/models/poll/null_result.rb b/app/models/poll/null_result.rb index 222432c7f..d1724037b 100644 --- a/app/models/poll/null_result.rb +++ b/app/models/poll/null_result.rb @@ -1,6 +1,6 @@ class Poll::NullResult < ActiveRecord::Base - VALID_ORIGINS = %w{ web booth } + VALID_ORIGINS = %w{web booth} belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' belongs_to :booth_assignment @@ -9,7 +9,7 @@ class Poll::NullResult < ActiveRecord::Base validates :author, presence: true validates :origin, inclusion: {in: VALID_ORIGINS} - scope :by_author, -> (author_id) { where(author_id: author_id) } + scope :by_author, ->(author_id) { where(author_id: author_id) } before_save :update_logs @@ -20,4 +20,4 @@ class Poll::NullResult < ActiveRecord::Base self.author_id_log += ":#{self.author_id_was.to_s}" end end -end \ No newline at end of file +end diff --git a/app/models/poll/partial_result.rb b/app/models/poll/partial_result.rb index e42589a03..dbc0d6bae 100644 --- a/app/models/poll/partial_result.rb +++ b/app/models/poll/partial_result.rb @@ -1,6 +1,6 @@ class Poll::PartialResult < ActiveRecord::Base - VALID_ORIGINS = %w{ web booth } + VALID_ORIGINS = %w{web booth} belongs_to :question, -> { with_hidden } belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' @@ -13,8 +13,8 @@ class Poll::PartialResult < ActiveRecord::Base validates :answer, inclusion: {in: ->(a) { a.question.valid_answers }} validates :origin, inclusion: {in: VALID_ORIGINS} - scope :by_author, -> (author_id) { where(author_id: author_id) } - scope :by_question, -> (question_id) { where(question_id: question_id) } + scope :by_author, ->(author_id) { where(author_id: author_id) } + scope :by_question, ->(question_id) { where(question_id: question_id) } before_save :update_logs @@ -25,4 +25,4 @@ class Poll::PartialResult < ActiveRecord::Base self.author_id_log += ":#{self.author_id_was.to_s}" end end -end \ No newline at end of file +end diff --git a/app/models/poll/voter.rb b/app/models/poll/voter.rb index b05839501..6da6b98b2 100644 --- a/app/models/poll/voter.rb +++ b/app/models/poll/voter.rb @@ -14,7 +14,7 @@ class Poll before_validation :set_demographic_info, :set_document_info def set_demographic_info - return unless user.present? + return if user.blank? self.gender = user.gender self.age = user.age @@ -22,7 +22,7 @@ class Poll end def set_document_info - return unless user.present? + return if user.blank? self.document_type = user.document_type self.document_number = user.document_number @@ -51,7 +51,7 @@ class Poll nil else now = Time.current.to_date - now.year - dob.year - ((now.month > dob.month || (now.month == dob.month && now.day >= dob.day)) ? 0 : 1) + now.year - dob.year - (now.month > dob.month || (now.month == dob.month && now.day >= dob.day) ? 0 : 1) end end diff --git a/app/models/poll/white_result.rb b/app/models/poll/white_result.rb index 5b0aa4966..6ca613d05 100644 --- a/app/models/poll/white_result.rb +++ b/app/models/poll/white_result.rb @@ -1,6 +1,6 @@ class Poll::WhiteResult < ActiveRecord::Base - VALID_ORIGINS = %w{ web booth } + VALID_ORIGINS = %w{web booth} belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' belongs_to :booth_assignment @@ -9,7 +9,7 @@ class Poll::WhiteResult < ActiveRecord::Base validates :author, presence: true validates :origin, inclusion: {in: VALID_ORIGINS} - scope :by_author, -> (author_id) { where(author_id: author_id) } + scope :by_author, ->(author_id) { where(author_id: author_id) } before_save :update_logs @@ -20,4 +20,4 @@ class Poll::WhiteResult < ActiveRecord::Base self.author_id_log += ":#{self.author_id_was.to_s}" end end -end \ No newline at end of file +end diff --git a/app/models/signature_sheet.rb b/app/models/signature_sheet.rb index 1434143ac..3b2f8333d 100644 --- a/app/models/signature_sheet.rb +++ b/app/models/signature_sheet.rb @@ -2,7 +2,7 @@ class SignatureSheet < ActiveRecord::Base belongs_to :signable, polymorphic: true belongs_to :author, class_name: 'User', foreign_key: 'author_id' - VALID_SIGNABLES = %w( Proposal Budget::Investment SpendingProposal ) + VALID_SIGNABLES = %w(Proposal Budget::Investment SpendingProposal) has_many :signatures @@ -35,4 +35,4 @@ class SignatureSheet < ActiveRecord::Base def signable_found errors.add(:signable_id, :not_found) if errors.messages[:signable].present? end -end \ No newline at end of file +end diff --git a/app/models/site_customization/image.rb b/app/models/site_customization/image.rb index 2230a96ce..0886a3d03 100644 --- a/app/models/site_customization/image.rb +++ b/app/models/site_customization/image.rb @@ -9,7 +9,7 @@ class SiteCustomization::Image < ActiveRecord::Base has_attached_file :image validates :name, presence: true, uniqueness: true, inclusion: { in: VALID_IMAGES.keys } - validates_attachment_content_type :image, :content_type => ["image/png"] + validates_attachment_content_type :image, content_type: ["image/png"] validate :check_image def self.all_images diff --git a/app/models/user.rb b/app/models/user.rb index e55bd00e5..7d696297e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -154,7 +154,7 @@ class User < ActiveRecord::Base def has_official_email? domain = Setting['email_domain_for_officials'] - !email.blank? && ( (email.end_with? "@#{domain}") || (email.end_with? ".#{domain}") ) + email.present? && ( (email.end_with? "@#{domain}") || (email.end_with? ".#{domain}") ) end def display_official_position_badge? @@ -289,7 +289,7 @@ class User < ActiveRecord::Base private def clean_document_number - self.document_number = self.document_number.gsub(/[^a-z0-9]+/i, "").upcase unless self.document_number.blank? + self.document_number = self.document_number.gsub(/[^a-z0-9]+/i, "").upcase if self.document_number.present? end def validate_username_length diff --git a/app/models/verification/residence.rb b/app/models/verification/residence.rb index ea000677f..bafff129b 100644 --- a/app/models/verification/residence.rb +++ b/app/models/verification/residence.rb @@ -81,7 +81,7 @@ class Verification::Residence end def clean_document_number - self.document_number = self.document_number.gsub(/[^a-z0-9]+/i, "").upcase unless self.document_number.blank? + self.document_number = self.document_number.gsub(/[^a-z0-9]+/i, "").upcase if self.document_number.present? end end diff --git a/lib/age.rb b/lib/age.rb index f0ca9abe0..cf619133d 100644 --- a/lib/age.rb +++ b/lib/age.rb @@ -1,7 +1,7 @@ module Age def self.in_years(dob, now = Time.current.to_date) - return nil unless dob.present? + return nil if dob.blank? # reference: http://stackoverflow.com/questions/819263/get-persons-age-in-ruby#comment21200772_819263 - now.year - dob.year - ((now.month > dob.month || (now.month == dob.month && now.day >= dob.day)) ? 0 : 1) + now.year - dob.year - (now.month > dob.month || (now.month == dob.month && now.day >= dob.day) ? 0 : 1) end end diff --git a/lib/document_parser.rb b/lib/document_parser.rb index c6cd53c92..c60b180dc 100644 --- a/lib/document_parser.rb +++ b/lib/document_parser.rb @@ -26,18 +26,18 @@ module DocumentParser else letter = nil end - return document_number, letter + [document_number, letter] end # if the number has less digits than it should, pad with zeros to the left and add each variant to the list # For example, if the initial document_number is 1234, and digits=8, the result is # ['1234', '01234', '001234', '0001234'] - def get_number_variants_with_leading_zeroes_from(document_number, digits=8) + def get_number_variants_with_leading_zeroes_from(document_number, digits = 8) document_number = document_number.to_s.last(digits) # Keep only the last x digits document_number = document_number.gsub(/^0+/, '') # Removes leading zeros variants = [] - variants << document_number unless document_number.blank? + variants << document_number if document_number.present? while document_number.size < digits document_number = "0#{document_number}" variants << document_number @@ -50,7 +50,7 @@ module DocumentParser # ['1234a', '1234A', '01234a', '01234A'] def get_letter_variants(number_variants, letter) variants = [] - if letter.present? then + if letter.present? number_variants.each do |number| variants << number + letter.downcase << number + letter.upcase end