diff options
author | Benjamin Neff <benjamin@coding4coffee.ch> | 2022-07-17 04:00:23 +0300 |
---|---|---|
committer | Benjamin Neff <benjamin@coding4coffee.ch> | 2022-07-20 22:27:41 +0300 |
commit | 3bb9b9a18d6ead883d4dfc05cecff810ca322fd4 (patch) | |
tree | 72d7d5346239f9c21b79429a28eb477f24a2e3ea /app | |
parent | fe84d3e1017132790b4b4206562857eccafe4a10 (diff) |
Fix deprecation warnings for rails 6.1
Diffstat (limited to 'app')
-rw-r--r-- | app/models/block.rb | 6 | ||||
-rw-r--r-- | app/models/message.rb | 8 | ||||
-rw-r--r-- | app/models/report.rb | 12 | ||||
-rw-r--r-- | app/models/reshare.rb | 5 | ||||
-rw-r--r-- | app/models/status_message.rb | 2 | ||||
-rw-r--r-- | app/models/user.rb | 8 | ||||
-rw-r--r-- | app/views/users/_edit.haml | 2 |
7 files changed, 19 insertions, 24 deletions
diff --git a/app/models/block.rb b/app/models/block.rb index 48254071a..1d835dc46 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -11,9 +11,9 @@ class Block < ApplicationRecord validate :not_blocking_yourself def not_blocking_yourself - if self.user.person.id == self.person_id - errors[:person_id] << "stop blocking yourself!" - end + return unless user.person.id == person_id + + errors.add(:person_id, "stop blocking yourself!") end # @return [Array<Person>] The recipient of the block diff --git a/app/models/message.rb b/app/models/message.rb index e0c738d00..1dd4d9f72 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -37,10 +37,8 @@ class Message < ApplicationRecord private def participant_of_parent_conversation - if conversation && !conversation.participants.include?(author) - errors[:base] << "Author is not participating in the conversation" - else - true - end + return unless conversation&.participants&.exclude?(author) + + errors.add(:base, "Author is not participating in the conversation") end end diff --git a/app/models/report.rb b/app/models/report.rb index ab169e7f1..1da8c4b24 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -22,15 +22,15 @@ class Report < ApplicationRecord end def entry_does_not_exist - if Report.where(item_id: item_id, item_type: item_type).exists?(user_id: user_id) - errors[:base] << 'You cannot report the same post twice.' - end + return unless Report.where(item_id: item_id, item_type: item_type).exists?(user_id: user_id) + + errors.add(:base, "You cannot report the same post twice.") end def post_or_comment_does_exist - if Post.find_by_id(item_id).nil? && Comment.find_by_id(item_id).nil? - errors[:base] << 'Post or comment was already deleted or doesn\'t exists.' - end + return unless Post.find_by(id: item_id).nil? && Comment.find_by(id: item_id).nil? + + errors.add(:base, "Post or comment was already deleted or doesn't exists.") end def destroy_reported_item diff --git a/app/models/reshare.rb b/app/models/reshare.rb index ecbd64971..d3e5115d7 100644 --- a/app/models/reshare.rb +++ b/app/models/reshare.rb @@ -86,9 +86,6 @@ class Reshare < Post private def root_must_be_public - if self.root && !self.root.public - errors[:base] << "Only posts which are public may be reshared." - return false - end + errors.add(:base, "Only posts which are public may be reshared.") if root && !root.public end end diff --git a/app/models/status_message.rb b/app/models/status_message.rb index 4f8e192d7..418b53ed8 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -130,7 +130,7 @@ class StatusMessage < Post private def presence_of_content - errors[:base] << "Cannot create a StatusMessage without content" if text_and_photos_blank? + errors.add(:base, "Cannot create a StatusMessage without content") if text_and_photos_blank? end end diff --git a/app/models/user.rb b/app/models/user.rb index 131fbcf68..4cfd9eb4b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -535,10 +535,10 @@ class User < ApplicationRecord end def no_person_with_same_username - diaspora_id = "#{self.username}#{User.diaspora_id_host}" - if self.username_changed? && Person.exists?(:diaspora_handle => diaspora_id) - errors[:base] << 'That username has already been taken' - end + diaspora_id = "#{username}#{User.diaspora_id_host}" + return unless username_changed? && Person.exists?(diaspora_handle: diaspora_id) + + errors.add(:base, "That username has already been taken") end def close_account! diff --git a/app/views/users/_edit.haml b/app/views/users/_edit.haml index adeb9bddf..e20bcff44 100644 --- a/app/views/users/_edit.haml +++ b/app/views/users/_edit.haml @@ -34,7 +34,7 @@ .col-md-12 %h3= t(".change_password") = form_for @user, url: edit_user_path, html: {method: :put, class: "form-horizontal"} do |f| - - if (@user.errors.keys & %i(password password_confirmation current_password)).present? + - if (@user.errors.attribute_names & %i[password password_confirmation current_password]).present? = f.error_messages .form-group = f.label :current_password, t(".current_password"), class: "col-sm-6 control-label" |