Fix deprecation warnings for rails 6.1

This commit is contained in:
Benjamin Neff 2022-07-17 03:00:23 +02:00
parent fe84d3e101
commit 3bb9b9a18d
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
9 changed files with 23 additions and 27 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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!

View file

@ -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"

View file

@ -15,8 +15,8 @@ module Diaspora
# tag's name is limited to 255 charchters according to ActsAsTaggableOn gem, so we check the length of the name for each tag
def tag_name_max_length
self.tag_list.each do |tag|
errors[:tags] << I18n.t('tags.name_too_long', :count => 255, :current_length => tag.length) if tag.length > 255
tag_list.each do |tag|
errors.add(:tags, I18n.t("tags.name_too_long", count: 255, current_length: tag.length)) if tag.length > 255
end
end
protected :tag_name_max_length

View file

@ -10,8 +10,9 @@ describe "status_messages/_status_message.mobile.haml" do
)
post = FactoryGirl.create(:status_message, public: true, open_graph_cache: open_graph_cache)
render template: "status_messages/_status_message.mobile.haml", locals: {post: post, photos: post.photos}
render template: "status_messages/_status_message", locals: {post: post, photos: post.photos}
expect(rendered).to_not include("<script>")
expect(rendered).to include("&lt;script&gt;alert(0);&lt;/script&gt;")
end
end