diff --git a/.rubocop.yml b/.rubocop.yml index 499ba7224..f9bdb2d3b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -499,6 +499,9 @@ Style/RedundantParentheses: Style/RedundantReturn: Enabled: true +Style/RedundantSelf: + Enabled: true + Style/SafeNavigation: Enabled: true diff --git a/app/models/admin_notification.rb b/app/models/admin_notification.rb index 8ab699d5e..52c741c93 100644 --- a/app/models/admin_notification.rb +++ b/app/models/admin_notification.rb @@ -43,7 +43,7 @@ class AdminNotification < ApplicationRecord return unless link.present? unless link =~ /\A(http:\/\/|https:\/\/|\/)/ - self.link = "http://#{self.link}" + self.link = "http://#{link}" end end end diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index b92ac42da..d0b403f33 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -364,11 +364,11 @@ class Budget end def assigned_valuators - self.valuators.map(&:description_or_name).compact.join(", ").presence + valuators.map(&:description_or_name).compact.join(", ").presence end def assigned_valuation_groups - self.valuator_groups.map(&:name).compact.join(", ").presence + valuator_groups.map(&:name).compact.join(", ").presence end def self.with_milestone_status_id(status_id) diff --git a/app/models/budget/phase.rb b/app/models/budget/phase.rb index b6d4c64c5..0b27209f7 100644 --- a/app/models/budget/phase.rb +++ b/app/models/budget/phase.rb @@ -14,8 +14,8 @@ class Budget include Imageable belongs_to :budget, touch: true - belongs_to :next_phase, class_name: self.name, inverse_of: :prev_phase - has_one :prev_phase, class_name: self.name, foreign_key: :next_phase_id, inverse_of: :next_phase + belongs_to :next_phase, class_name: name, inverse_of: :prev_phase + has_one :prev_phase, class_name: name, foreign_key: :next_phase_id, inverse_of: :next_phase validates_translation :name, presence: true validates_translation :description, length: { maximum: DESCRIPTION_MAX_LENGTH } diff --git a/app/models/concerns/globalizable.rb b/app/models/concerns/globalizable.rb index 230aba1bd..98613b5a7 100644 --- a/app/models/concerns/globalizable.rb +++ b/app/models/concerns/globalizable.rb @@ -25,7 +25,7 @@ module Globalizable translated_attribute_names.any? { |attr| required_attribute?(attr) } end - if self.paranoid? && translation_class.attribute_names.include?("hidden_at") + if paranoid? && translation_class.attribute_names.include?("hidden_at") translation_class.send :acts_as_paranoid, column: :hidden_at end diff --git a/app/models/local_census_record.rb b/app/models/local_census_record.rb index fad2bfeb3..a812a4144 100644 --- a/app/models/local_census_record.rb +++ b/app/models/local_census_record.rb @@ -13,8 +13,8 @@ class LocalCensusRecord < ApplicationRecord private def sanitize - self.document_type = self.document_type&.strip - self.document_number = self.document_number&.strip - self.postal_code = self.postal_code&.strip + self.document_type = document_type&.strip + self.document_number = document_number&.strip + self.postal_code = postal_code&.strip end end diff --git a/app/models/proposal_notification.rb b/app/models/proposal_notification.rb index 829c863f8..ffed3ab9f 100644 --- a/app/models/proposal_notification.rb +++ b/app/models/proposal_notification.rb @@ -58,6 +58,6 @@ class ProposalNotification < ApplicationRecord private def set_author - self.update(author_id: self.proposal.author_id) if self.proposal + update(author_id: proposal.author_id) if proposal end end diff --git a/app/models/related_content.rb b/app/models/related_content.rb index 6e936f572..abd45fe51 100644 --- a/app/models/related_content.rb +++ b/app/models/related_content.rb @@ -8,7 +8,7 @@ class RelatedContent < ApplicationRecord belongs_to :author, class_name: "User" belongs_to :parent_relationable, polymorphic: true, optional: false, touch: true belongs_to :child_relationable, polymorphic: true, optional: false, touch: true - has_one :opposite_related_content, class_name: self.name, foreign_key: :related_content_id + has_one :opposite_related_content, class_name: name, foreign_key: :related_content_id has_many :related_content_scores, dependent: :destroy validates :parent_relationable_id, uniqueness: { scope: [:parent_relationable_type, :child_relationable_id, :child_relationable_type] } diff --git a/config/initializers/devise-security.rb b/config/initializers/devise-security.rb index 52bd5026e..ce6877365 100644 --- a/config/initializers/devise-security.rb +++ b/config/initializers/devise-security.rb @@ -42,11 +42,11 @@ module Devise module Models module PasswordExpirable def need_change_password? - self.administrator? && password_expired? + administrator? && password_expired? end def password_expired? - self.password_changed_at < self.expire_password_after.ago + password_changed_at < expire_password_after.ago end end @@ -60,11 +60,11 @@ module Devise end def current_equal_password_validation - if !self.new_record? && !self.encrypted_password_change.nil? && !self.erased? + if !new_record? && !encrypted_password_change.nil? && !erased? dummy = self.class.new - dummy.encrypted_password = self.encrypted_password_change.first - dummy.password_salt = self.password_salt_change.first if self.respond_to?(:password_salt_change) && !self.password_salt_change.nil? - self.errors.add(:password, :equal_to_current_password) if dummy.valid_password?(self.password) + dummy.encrypted_password = encrypted_password_change.first + dummy.password_salt = password_salt_change.first if respond_to?(:password_salt_change) && !password_salt_change.nil? + errors.add(:password, :equal_to_current_password) if dummy.valid_password?(password) end end end