diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 535d674fc..5ce274570 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -475,11 +475,6 @@ Style/RedundantParentheses: - 'spec/features/proposals_spec.rb' - 'spec/models/debate_spec.rb' -# Offense count: 49 -# Cop supports --auto-correct. -Style/RedundantSelf: - Enabled: false - # Offense count: 3 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes. diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 9d779299d..2dd0d4031 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -3,7 +3,7 @@ module Abilities include CanCan::Ability def initialize(user) - self.merge Abilities::Moderation.new(user) + merge Abilities::Moderation.new(user) can :restore, Comment cannot :restore, Comment, hidden_at: nil diff --git a/app/models/abilities/common.rb b/app/models/abilities/common.rb index 71e839d3d..2b32abd07 100644 --- a/app/models/abilities/common.rb +++ b/app/models/abilities/common.rb @@ -3,7 +3,7 @@ module Abilities include CanCan::Ability def initialize(user) - self.merge Abilities::Everyone.new(user) + merge Abilities::Everyone.new(user) can [:read, :update], User, id: user.id diff --git a/app/models/abilities/moderation.rb b/app/models/abilities/moderation.rb index 2fa26a607..e9a1da2ac 100644 --- a/app/models/abilities/moderation.rb +++ b/app/models/abilities/moderation.rb @@ -3,7 +3,7 @@ module Abilities include CanCan::Ability def initialize(user) - self.merge Abilities::Common.new(user) + merge Abilities::Common.new(user) can :read, Organization can(:verify, Organization){ |o| !o.verified? } diff --git a/app/models/abilities/moderator.rb b/app/models/abilities/moderator.rb index ba8c659ba..479223b21 100644 --- a/app/models/abilities/moderator.rb +++ b/app/models/abilities/moderator.rb @@ -3,7 +3,7 @@ module Abilities include CanCan::Ability def initialize(user) - self.merge Abilities::Moderation.new(user) + merge Abilities::Moderation.new(user) can :comment_as_moderator, [Debate, Comment, Proposal, Budget::Investment, Poll::Question, Legislation::Question, Legislation::Annotation] end diff --git a/app/models/ability.rb b/app/models/ability.rb index 98ff4e55c..4580db880 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -7,17 +7,17 @@ class Ability alias_action :hide_in_moderation_screen, to: :hide if user # logged-in users - self.merge Abilities::Valuator.new(user) if user.valuator? + merge Abilities::Valuator.new(user) if user.valuator? if user.administrator? - self.merge Abilities::Administrator.new(user) + merge Abilities::Administrator.new(user) elsif user.moderator? - self.merge Abilities::Moderator.new(user) + merge Abilities::Moderator.new(user) else - self.merge Abilities::Common.new(user) + merge Abilities::Common.new(user) end else - self.merge Abilities::Everyone.new(user) + merge Abilities::Everyone.new(user) end end diff --git a/app/models/budget.rb b/app/models/budget.rb index bc7231f29..6ad8ffe61 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -28,7 +28,7 @@ class Budget < ActiveRecord::Base scope :current, -> { where.not(phase: "finished") } def description - self.send("description_#{self.phase}").try(:html_safe) + send("description_#{phase}").try(:html_safe) end def self.description_max_length @@ -134,8 +134,8 @@ class Budget < ActiveRecord::Base def sanitize_descriptions s = WYSIWYGSanitizer.new PHASES.each do |phase| - sanitized = s.sanitize(self.send("description_#{phase}")) - self.send("description_#{phase}=", sanitized) + sanitized = s.sanitize(send("description_#{phase}")) + send("description_#{phase}=", sanitized) end end end diff --git a/app/models/budget/ballot.rb b/app/models/budget/ballot.rb index 83e799d6f..c35222f3a 100644 --- a/app/models/budget/ballot.rb +++ b/app/models/budget/ballot.rb @@ -33,7 +33,7 @@ class Budget end def has_lines_in_group?(group) - self.groups.include?(group) + groups.include?(group) end def wrong_budget?(heading) @@ -54,7 +54,7 @@ class Budget end def has_lines_with_heading? - self.heading_id.present? + heading_id.present? end def has_lines_in_heading?(heading) @@ -62,12 +62,12 @@ class Budget end def has_investment?(investment) - self.investment_ids.include?(investment.id) + investment_ids.include?(investment.id) end def heading_for_group(group) return nil unless has_lines_in_group?(group) - self.investments.where(group: group).first.heading + investments.where(group: group).first.heading end end diff --git a/app/models/budget/ballot/line.rb b/app/models/budget/ballot/line.rb index e4e1d598b..2b70953f1 100644 --- a/app/models/budget/ballot/line.rb +++ b/app/models/budget/ballot/line.rb @@ -22,7 +22,7 @@ class Budget end def check_valid_heading - errors.add(:heading, "This heading's budget is invalid, or a heading on the same group was already selected") unless ballot.valid_heading?(self.heading) + errors.add(:heading, "This heading's budget is invalid, or a heading on the same group was already selected") unless ballot.valid_heading?(heading) end def check_selected @@ -32,9 +32,9 @@ class Budget private def set_denormalized_ids - self.heading_id ||= self.investment.try(:heading_id) - self.group_id ||= self.investment.try(:group_id) - self.budget_id ||= self.investment.try(:budget_id) + self.heading_id ||= investment.try(:heading_id) + self.group_id ||= investment.try(:group_id) + self.budget_id ||= investment.try(:budget_id) end end end diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 845d695bb..5fcf2e882 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -94,7 +94,7 @@ class Budget end def self.search(terms) - self.pg_search(terms) + pg_search(terms) end def self.by_heading(heading) @@ -191,7 +191,7 @@ class Budget end def enough_money?(ballot) - available_money = ballot.amount_available(self.heading) + available_money = ballot.amount_available(heading) price.to_i <= available_money end @@ -256,8 +256,8 @@ class Budget private def set_denormalized_ids - self.group_id = self.heading.try(:group_id) if self.heading_id_changed? - self.budget_id ||= self.heading.try(:group).try(:budget_id) + self.group_id = heading.try(:group_id) if heading_id_changed? + self.budget_id ||= heading.try(:group).try(:budget_id) end end diff --git a/app/models/budget/reclassification.rb b/app/models/budget/reclassification.rb index 3ce3ab146..b77dc374a 100644 --- a/app/models/budget/reclassification.rb +++ b/app/models/budget/reclassification.rb @@ -43,7 +43,7 @@ class Budget end def ballot_lines_for_investment - Budget::Ballot::Line.by_investment(self.id) + Budget::Ballot::Line.by_investment(id) end end diff --git a/app/models/comment.rb b/app/models/comment.rb index 5c7f4dd4e..44bb1f6f3 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -100,7 +100,7 @@ class Comment < ActiveRecord::Base end def call_after_commented - self.commentable.try(:after_commented) + commentable.try(:after_commented) end def self.body_max_length diff --git a/app/models/concerns/filterable.rb b/app/models/concerns/filterable.rb index c5402d9b2..91c6b0a96 100644 --- a/app/models/concerns/filterable.rb +++ b/app/models/concerns/filterable.rb @@ -9,7 +9,7 @@ module Filterable class_methods do def filter(params) - resources = self.all + resources = all params.each do |filter, value| if allowed_filter?(filter, value) resources = resources.send("by_#{filter}", value) diff --git a/app/models/concerns/graphqlable.rb b/app/models/concerns/graphqlable.rb index 5b88dfc59..228810579 100644 --- a/app/models/concerns/graphqlable.rb +++ b/app/models/concerns/graphqlable.rb @@ -4,33 +4,33 @@ module Graphqlable class_methods do def graphql_field_name - self.name.gsub('::', '_').underscore.to_sym + name.gsub('::', '_').underscore.to_sym end def graphql_field_description - "Find one #{self.model_name.human} by ID" + "Find one #{model_name.human} by ID" end def graphql_pluralized_field_name - self.name.gsub('::', '_').underscore.pluralize.to_sym + name.gsub('::', '_').underscore.pluralize.to_sym end def graphql_pluralized_field_description - "Find all #{self.model_name.human.pluralize}" + "Find all #{model_name.human.pluralize}" end def graphql_type_name - self.name.gsub('::', '_') + name.gsub('::', '_') end def graphql_type_description - (self.model_name.human).to_s + (model_name.human).to_s end end def public_created_at - self.created_at.change(min: 0) + created_at.change(min: 0) end end diff --git a/app/models/concerns/has_public_author.rb b/app/models/concerns/has_public_author.rb index a1af255c5..5132c33c9 100644 --- a/app/models/concerns/has_public_author.rb +++ b/app/models/concerns/has_public_author.rb @@ -1,5 +1,5 @@ module HasPublicAuthor def public_author - self.author.public_activity? ? self.author : nil + author.public_activity? ? author : nil end end diff --git a/app/models/concerns/measurable.rb b/app/models/concerns/measurable.rb index 5ac2f2a14..46625435d 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 ||= (self.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 ||= (self.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/sanitizable.rb b/app/models/concerns/sanitizable.rb index a4520ba2f..055859c8b 100644 --- a/app/models/concerns/sanitizable.rb +++ b/app/models/concerns/sanitizable.rb @@ -17,7 +17,7 @@ module Sanitizable end def sanitize_tag_list - self.tag_list = TagSanitizer.new.sanitize_tag_list(self.tag_list) if self.class.taggable? + self.tag_list = TagSanitizer.new.sanitize_tag_list(tag_list) if self.class.taggable? end end diff --git a/app/models/concerns/search_cache.rb b/app/models/concerns/search_cache.rb index 9b9e62024..e3e211647 100644 --- a/app/models/concerns/search_cache.rb +++ b/app/models/concerns/search_cache.rb @@ -7,7 +7,7 @@ module SearchCache def calculate_tsvector ActiveRecord::Base.connection.execute(" - UPDATE #{self.class.table_name} SET tsv = (#{searchable_values_sql}) WHERE id = #{self.id}") + UPDATE #{self.class.table_name} SET tsv = (#{searchable_values_sql}) WHERE id = #{id}") end private diff --git a/app/models/concerns/searchable.rb b/app/models/concerns/searchable.rb index 6694df114..b749377f3 100644 --- a/app/models/concerns/searchable.rb +++ b/app/models/concerns/searchable.rb @@ -12,7 +12,7 @@ module Searchable }, ignoring: :accents, ranked_by: '(:tsearch)', - order_within_rank: (self.column_names.include?('cached_votes_up') ? "#{self.table_name}.cached_votes_up DESC" : nil) + order_within_rank: (column_names.include?('cached_votes_up') ? "#{table_name}.cached_votes_up DESC" : nil) } end diff --git a/app/models/debate.rb b/app/models/debate.rb index 95940b3c3..9d74597b8 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -55,7 +55,7 @@ class Debate < ActiveRecord::Base end def self.search(terms) - self.pg_search(terms) + pg_search(terms) end def to_param @@ -124,15 +124,15 @@ class Debate < ActiveRecord::Base end def after_hide - self.tags.each{ |t| t.decrement_custom_counter_for('Debate') } + tags.each{ |t| t.decrement_custom_counter_for('Debate') } end def after_restore - self.tags.each{ |t| t.increment_custom_counter_for('Debate') } + tags.each{ |t| t.increment_custom_counter_for('Debate') } end def featured? - self.featured_at.present? + featured_at.present? end end diff --git a/app/models/legislation/annotation.rb b/app/models/legislation/annotation.rb index f2d419200..feab80902 100644 --- a/app/models/legislation/annotation.rb +++ b/app/models/legislation/annotation.rb @@ -45,7 +45,7 @@ class Legislation::Annotation < ActiveRecord::Base end def create_first_comment - comments.create(body: self.text, user: self.author) + comments.create(body: text, user: author) end def title diff --git a/app/models/notification.rb b/app/models/notification.rb index d08baecf2..84fc72f1c 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -12,7 +12,7 @@ class Notification < ActiveRecord::Base end def mark_as_read - self.destroy + destroy end def self.add(user_id, notifiable) diff --git a/app/models/officing/residence.rb b/app/models/officing/residence.rb index b0fc56078..6386ce0fd 100644 --- a/app/models/officing/residence.rb +++ b/app/models/officing/residence.rb @@ -23,12 +23,12 @@ class Officing::Residence if user_exists? self.user = find_user_by_document - self.user.update(verified_at: Time.current) + user.update(verified_at: Time.current) else user_params = { document_number: document_number, document_type: document_type, - geozone: self.geozone, + geozone: geozone, date_of_birth: date_of_birth.to_datetime, gender: gender, residence_verified_at: Time.current, @@ -115,7 +115,7 @@ class Officing::Residence end def clean_document_number - self.document_number = self.document_number.gsub(/[^a-z0-9]+/i, "").upcase if self.document_number.present? + self.document_number = document_number.gsub(/[^a-z0-9]+/i, "").upcase if document_number.present? end def random_password diff --git a/app/models/organization.rb b/app/models/organization.rb index f3f8956d5..37b46df55 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -39,11 +39,11 @@ class Organization < ActiveRecord::Base end def self.name_max_length - @@name_max_length ||= self.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 ||= self.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/final_recount.rb b/app/models/poll/final_recount.rb index 6ebf5eede..3647c85ca 100644 --- a/app/models/poll/final_recount.rb +++ b/app/models/poll/final_recount.rb @@ -10,9 +10,9 @@ class Poll before_save :update_logs def update_logs - if self.count_changed? && self.count_was.present? - self.count_log += ":#{self.count_was.to_s}" - self.officer_assignment_id_log += ":#{self.officer_assignment_id_was.to_s}" + if count_changed? && count_was.present? + self.count_log += ":#{count_was.to_s}" + self.officer_assignment_id_log += ":#{officer_assignment_id_was.to_s}" end end end diff --git a/app/models/poll/null_result.rb b/app/models/poll/null_result.rb index bdd708504..d10fe3cb0 100644 --- a/app/models/poll/null_result.rb +++ b/app/models/poll/null_result.rb @@ -14,10 +14,10 @@ class Poll::NullResult < ActiveRecord::Base before_save :update_logs def update_logs - if self.amount_changed? && self.amount_was.present? - self.amount_log += ":#{self.amount_was.to_s}" - self.officer_assignment_id_log += ":#{self.officer_assignment_id_was.to_s}" - self.author_id_log += ":#{self.author_id_was.to_s}" + if amount_changed? && amount_was.present? + self.amount_log += ":#{amount_was.to_s}" + self.officer_assignment_id_log += ":#{officer_assignment_id_was.to_s}" + self.author_id_log += ":#{author_id_was.to_s}" end end end diff --git a/app/models/poll/partial_result.rb b/app/models/poll/partial_result.rb index dbc0d6bae..12b16aa3a 100644 --- a/app/models/poll/partial_result.rb +++ b/app/models/poll/partial_result.rb @@ -19,10 +19,10 @@ class Poll::PartialResult < ActiveRecord::Base before_save :update_logs def update_logs - if self.amount_changed? && self.amount_was.present? - self.amount_log += ":#{self.amount_was.to_s}" - self.officer_assignment_id_log += ":#{self.officer_assignment_id_was.to_s}" - self.author_id_log += ":#{self.author_id_was.to_s}" + if amount_changed? && amount_was.present? + self.amount_log += ":#{amount_was.to_s}" + self.officer_assignment_id_log += ":#{officer_assignment_id_was.to_s}" + self.author_id_log += ":#{author_id_was.to_s}" end end end diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb index a1d949d42..b67650a8d 100644 --- a/app/models/poll/question.rb +++ b/app/models/poll/question.rb @@ -25,7 +25,7 @@ class Poll::Question < ActiveRecord::Base scope :for_render, -> { includes(:author, :proposal) } def self.search(params) - results = self.all + results = all results = results.by_poll_id(params[:poll_id]) if params[:poll_id].present? results = results.pg_search(params[:search]) if params[:search].present? results diff --git a/app/models/poll/recount.rb b/app/models/poll/recount.rb index b4e28583e..57ced61fb 100644 --- a/app/models/poll/recount.rb +++ b/app/models/poll/recount.rb @@ -11,9 +11,9 @@ class Poll before_save :update_logs def update_logs - if self.count_changed? && self.count_was.present? - self.count_log += ":#{self.count_was.to_s}" - self.officer_assignment_id_log += ":#{self.officer_assignment_id_was.to_s}" + if count_changed? && count_was.present? + self.count_log += ":#{count_was.to_s}" + self.officer_assignment_id_log += ":#{officer_assignment_id_was.to_s}" end end end diff --git a/app/models/poll/white_result.rb b/app/models/poll/white_result.rb index 3f41795b3..a4a4e5a4d 100644 --- a/app/models/poll/white_result.rb +++ b/app/models/poll/white_result.rb @@ -14,10 +14,10 @@ class Poll::WhiteResult < ActiveRecord::Base before_save :update_logs def update_logs - if self.amount_changed? && self.amount_was.present? - self.amount_log += ":#{self.amount_was.to_s}" - self.officer_assignment_id_log += ":#{self.officer_assignment_id_was.to_s}" - self.author_id_log += ":#{self.author_id_was.to_s}" + if amount_changed? && amount_was.present? + self.amount_log += ":#{amount_was.to_s}" + self.officer_assignment_id_log += ":#{officer_assignment_id_was.to_s}" + self.author_id_log += ":#{author_id_was.to_s}" end end end diff --git a/app/models/proposal.rb b/app/models/proposal.rb index 8c7e2065a..9e02c197e 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -71,12 +71,12 @@ class Proposal < ActiveRecord::Base end def self.search(terms) - by_code = self.search_by_code(terms.strip) - by_code.present? ? by_code : self.pg_search(terms) + by_code = search_by_code(terms.strip) + by_code.present? ? by_code : pg_search(terms) end def self.search_by_code(terms) - matched_code = self.match_code(terms) + matched_code = match_code(terms) results = where(id: matched_code[1]) if matched_code return results if (results.present? && results.first.code == terms) end @@ -147,11 +147,11 @@ class Proposal < ActiveRecord::Base end def after_hide - self.tags.each{ |t| t.decrement_custom_counter_for('Proposal') } + tags.each{ |t| t.decrement_custom_counter_for('Proposal') } end def after_restore - self.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 @@ -163,7 +163,7 @@ class Proposal < ActiveRecord::Base end def archived? - self.created_at <= Setting["months_to_archive_proposals"].to_i.months.ago + created_at <= Setting["months_to_archive_proposals"].to_i.months.ago end def notifications diff --git a/app/models/signature.rb b/app/models/signature.rb index 543965aed..88b875894 100644 --- a/app/models/signature.rb +++ b/app/models/signature.rb @@ -59,8 +59,8 @@ class Signature < ActiveRecord::Base end def clean_document_number - return if self.document_number.blank? - self.document_number = self.document_number.gsub(/[^a-z0-9]+/i, "").upcase + return if document_number.blank? + self.document_number = document_number.gsub(/[^a-z0-9]+/i, "").upcase end def random_password diff --git a/app/models/signature_sheet.rb b/app/models/signature_sheet.rb index 3b2f8333d..3e46c1cd1 100644 --- a/app/models/signature_sheet.rb +++ b/app/models/signature_sheet.rb @@ -22,7 +22,7 @@ class SignatureSheet < ActiveRecord::Base def verify_signatures parsed_document_numbers.each do |document_number| - signature = self.signatures.where(document_number: document_number).first_or_create + signature = signatures.where(document_number: document_number).first_or_create signature.verify end update(processed: true) diff --git a/app/models/spending_proposal.rb b/app/models/spending_proposal.rb index 8026a3b9f..f6f367f62 100644 --- a/app/models/spending_proposal.rb +++ b/app/models/spending_proposal.rb @@ -66,7 +66,7 @@ class SpendingProposal < ActiveRecord::Base end def self.search(terms) - self.pg_search(terms) + pg_search(terms) end def self.by_geozone(geozone) diff --git a/app/models/user.rb b/app/models/user.rb index 9df08c014..b41057157 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -169,7 +169,7 @@ class User < ActiveRecord::Base comments_ids = Comment.where(user_id: id).pluck(:id) proposal_ids = Proposal.where(author_id: id).pluck(:id) - self.hide + hide Debate.hide_all debates_ids Comment.hide_all comments_ids @@ -177,7 +177,7 @@ class User < ActiveRecord::Base end def erase(erase_reason = nil) - self.update( + update( erased_at: Time.current, erase_reason: erase_reason, username: nil, @@ -191,7 +191,7 @@ class User < ActiveRecord::Base confirmed_phone: nil, unconfirmed_phone: nil ) - self.identities.destroy_all + identities.destroy_all end def erased? @@ -201,17 +201,17 @@ class User < ActiveRecord::Base def take_votes_if_erased_document(document_number, document_type) erased_user = User.erased.where(document_number: document_number).where(document_type: document_type).first if erased_user.present? - self.take_votes_from(erased_user) + take_votes_from(erased_user) erased_user.update(document_number: nil, document_type: nil) end end def take_votes_from(other_user) return if other_user.blank? - Poll::Voter.where(user_id: other_user.id).update_all(user_id: self.id) - Budget::Ballot.where(user_id: other_user.id).update_all(user_id: self.id) - Vote.where("voter_id = ? AND voter_type = ?", other_user.id, "User").update_all(voter_id: self.id) - self.update(former_users_data_log: "#{self.former_users_data_log} | id: #{other_user.id} - #{Time.current.strftime('%Y-%m-%d %H:%M:%S')}") + Poll::Voter.where(user_id: other_user.id).update_all(user_id: id) + Budget::Ballot.where(user_id: other_user.id).update_all(user_id: id) + Vote.where("voter_id = ? AND voter_type = ?", other_user.id, "User").update_all(voter_id: id) + update(former_users_data_log: "#{former_users_data_log} | id: #{other_user.id} - #{Time.current.strftime('%Y-%m-%d %H:%M:%S')}") end def locked? @@ -223,7 +223,7 @@ class User < ActiveRecord::Base end def self.username_max_length - @@username_max_length ||= self.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 @@ -257,10 +257,10 @@ class User < ActiveRecord::Base def send_oauth_confirmation_instructions if oauth_email != email - self.update(confirmed_at: nil) - self.send_confirmation_instructions + update(confirmed_at: nil) + send_confirmation_instructions end - self.update(oauth_email: nil) if oauth_email.present? + update(oauth_email: nil) if oauth_email.present? end def name_and_email @@ -274,11 +274,11 @@ class User < ActiveRecord::Base def save_requiring_finish_signup begin self.registering_with_oauth = true - self.save(validate: false) + save(validate: false) # Devise puts unique constraints for the email the db, so we must detect & handle that rescue ActiveRecord::RecordNotUnique self.email = nil - self.save(validate: false) + save(validate: false) end true end @@ -311,7 +311,7 @@ class User < ActiveRecord::Base private def clean_document_number - self.document_number = self.document_number.gsub(/[^a-z0-9]+/i, "").upcase if self.document_number.present? + self.document_number = document_number.gsub(/[^a-z0-9]+/i, "").upcase if document_number.present? end def validate_username_length diff --git a/app/models/verification/email.rb b/app/models/verification/email.rb index 7e177bd10..95faecad3 100644 --- a/app/models/verification/email.rb +++ b/app/models/verification/email.rb @@ -27,7 +27,7 @@ class Verification::Email end def self.find(user, token) - self.valid_token?(user, token) + valid_token?(user, token) end def self.valid_token?(user, token) diff --git a/app/models/verification/residence.rb b/app/models/verification/residence.rb index 7fa7f74b4..c14bba85d 100644 --- a/app/models/verification/residence.rb +++ b/app/models/verification/residence.rb @@ -31,7 +31,7 @@ class Verification::Residence user.update(document_number: document_number, document_type: document_type, - geozone: self.geozone, + geozone: geozone, date_of_birth: date_of_birth.to_datetime, gender: gender, residence_verified_at: Time.current) @@ -39,7 +39,7 @@ class Verification::Residence def allowed_age return if errors[:date_of_birth].any? - errors.add(:date_of_birth, I18n.t('verification.residence.new.error_not_allowed_age')) unless Age.in_years(self.date_of_birth) >= User.minimum_required_age + errors.add(:date_of_birth, I18n.t('verification.residence.new.error_not_allowed_age')) unless Age.in_years(date_of_birth) >= User.minimum_required_age end def document_number_uniqueness @@ -81,7 +81,7 @@ class Verification::Residence end def clean_document_number - self.document_number = self.document_number.gsub(/[^a-z0-9]+/i, "").upcase if self.document_number.present? + self.document_number = document_number.gsub(/[^a-z0-9]+/i, "").upcase if document_number.present? end end diff --git a/app/models/verification/sms.rb b/app/models/verification/sms.rb index 7c1a1bfa6..830204009 100644 --- a/app/models/verification/sms.rb +++ b/app/models/verification/sms.rb @@ -12,7 +12,7 @@ class Verification::Sms end def save - return false unless self.valid? + return false unless valid? update_user_phone_information send_sms Lock.increase_tries(user) diff --git a/lib/acts_as_paranoid_aliases.rb b/lib/acts_as_paranoid_aliases.rb index 17587fca8..c95acee0d 100644 --- a/lib/acts_as_paranoid_aliases.rb +++ b/lib/acts_as_paranoid_aliases.rb @@ -2,7 +2,7 @@ module ActsAsParanoidAliases def self.included(base) base.extend(ClassMethods) - self.class_eval do + class_eval do def hide return false if hidden? diff --git a/lib/numeric.rb b/lib/numeric.rb index c741715dd..9ed1aabae 100644 --- a/lib/numeric.rb +++ b/lib/numeric.rb @@ -1,5 +1,5 @@ class Numeric def percent_of(n) - (self.to_f / n * 100).to_i + (to_f / n * 100).to_i end end \ No newline at end of file