Fix deprecation warnings for rails 6.0

This commit is contained in:
Benjamin Neff 2022-07-16 18:17:06 +02:00
parent 2d38a24a86
commit b5a46cf7bb
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
20 changed files with 47 additions and 44 deletions

View file

@ -15,8 +15,7 @@ class PeopleController < ApplicationController
respond_to :json, :only => [:index, :show]
rescue_from ActiveRecord::RecordNotFound do
render :file => Rails.root.join('public', '404').to_s,
:format => :html, :layout => false, :status => 404
render file: Rails.root.join("public/404.html").to_s, format: :html, layout: false, status: :not_found
end
rescue_from Diaspora::AccountClosed do

View file

@ -34,7 +34,7 @@ class UsersController < ApplicationController
def update_privacy_settings
privacy_params = params.fetch(:user).permit(:strip_exif)
if current_user.update_attributes(strip_exif: privacy_params[:strip_exif])
if current_user.update(strip_exif: privacy_params[:strip_exif])
flash[:notice] = t("users.update.settings_updated")
else
flash[:error] = t("users.update.settings_not_updated")
@ -199,7 +199,7 @@ class UsersController < ApplicationController
end
def change_language(user_data)
if @user.update_attributes(user_data)
if @user.update(user_data)
I18n.locale = @user.language
flash.now[:notice] = t("users.update.language_changed")
else
@ -229,7 +229,7 @@ class UsersController < ApplicationController
end
def change_settings(user_data, successful="users.update.settings_updated", error="users.update.settings_not_updated")
if @user.update_attributes(user_data)
if @user.update(user_data)
flash.now[:notice] = t(successful)
else
flash.now[:error] = t(error)

View file

@ -16,17 +16,18 @@ class InvitationCode < ApplicationRecord
end
def add_invites!
self.update_attributes(:count => self.count+100)
update(count: count + 100)
end
def use!
self.update_attributes(:count => self.count-1)
update(count: count - 1)
end
def generate_token
begin
loop do
self.token = SecureRandom.hex(6)
end while InvitationCode.exists?(:token => self[:token])
break unless InvitationCode.default_scoped.exists?(token: token)
end
end
def self.default_inviter_or(user)

View file

@ -250,7 +250,7 @@ class User < ApplicationRecord
def update_post(post, post_hash={})
if self.owns? post
post.update_attributes(post_hash)
post.update(post_hash)
self.dispatch_post(post)
end
end
@ -375,7 +375,7 @@ class User < ApplicationRecord
########### Profile ######################
def update_profile(params)
if photo = params.delete(:photo)
photo.update_attributes(:pending => false) if photo.pending
photo.update(pending: false) if photo.pending
params[:image_url] = photo.url(:thumb_large)
params[:image_url_medium] = photo.url(:thumb_medium)
params[:image_url_small] = photo.url(:thumb_small)
@ -383,7 +383,7 @@ class User < ApplicationRecord
params.stringify_keys!
params.slice!(*(Profile.column_names+['tag_string', 'date']))
if self.profile.update_attributes(params)
if profile.update(params)
deliver_profile_update
true
else

View file

@ -58,7 +58,7 @@ class User
if destroy
contact.destroy
else
contact.update_attributes(direction => false)
contact.update(direction => false)
end
end
end

View file

@ -112,4 +112,4 @@ end
# the logging gem is no-op. See: https://github.com/TwP/logging/issues/11
Logging::Logger.send :alias_method, :local_level, :level
Logging::Logger.send :alias_method, :local_level=, :level=
Logging::Logger.send :include, LoggerSilence
Logging::Logger.include ActiveSupport::LoggerSilence

View file

@ -17,7 +17,7 @@ class CleanupAspectsAndAddUniqueIndex < ActiveRecord::Migration[5.1]
Aspect.where(user_id: 0).delete_all
Aspect.joins("INNER JOIN aspects as a2 ON aspects.user_id = a2.user_id AND aspects.name = a2.name")
.where("aspects.id > a2.id").each do |aspect|
aspect.update_attributes(name: "#{aspect.name}_#{UUID.generate(:compact)}")
aspect.update(name: "#{aspect.name}_#{UUID.generate(:compact)}")
end
end
end

View file

@ -1,10 +1,13 @@
# frozen_string_literal: true
class IntegrationSessionsController < ActionController::Base
prepend_view_path(Rails.root.join("features/support"))
def new
@user_id = params[:user_id]
render file: 'features/support/integration_sessions_form', layout: false
render template: "integration_sessions_form", layout: false
end
def create
sign_in_and_redirect User.find(params[:user_id])
end

View file

@ -97,6 +97,6 @@ class AccountDeleter
end
def mark_account_deletion_complete
AccountDeletion.find_by(person: person)&.update_attributes(completed_at: Time.now.utc)
AccountDeletion.find_by(person: person)&.update(completed_at: Time.now.utc)
end
end

View file

@ -116,7 +116,7 @@ module Diaspora
if persisted_photo
persisted_photo.tap do |photo|
photo.update_attributes(
photo.update(
text: entity.text,
public: entity.public,
created_at: entity.created_at,
@ -145,7 +145,7 @@ module Diaspora
def self.profile(entity)
author_of(entity).profile.tap do |profile|
profile.update_attributes(
profile.update(
first_name: entity.first_name,
last_name: entity.last_name,
image_url: entity.image_url,

View file

@ -98,8 +98,8 @@ describe AspectsController, :type => :controller do
describe "update_order" do
it "updates the aspect order" do
@alices_aspect_1.update_attributes(order_id: 10)
@alices_aspect_2.update_attributes(order_id: 20)
@alices_aspect_1.update(order_id: 10)
@alices_aspect_2.update(order_id: 20)
ordered_aspect_ids = [@alices_aspect_2.id, @alices_aspect_1.id]
put :update_order, params: {ordered_aspect_ids: ordered_aspect_ids}

View file

@ -76,7 +76,7 @@ describe ContactsController, :type => :controller do
it "returns only contacts which are receiving (the user is sharing with them)" do
contact = bob.contacts.first
contact.update_attributes(receiving: false)
contact.update(receiving: false)
get :index, params: {params: {page: "1"}}, format: :json
contact_ids = JSON.parse(response.body).map {|c| c["id"] }
@ -88,7 +88,7 @@ describe ContactsController, :type => :controller do
context "set: all" do
before do
contact = bob.contacts.first
contact.update_attributes(receiving: false)
contact.update(receiving: false)
end
it "returns all contacts (sharing and receiving)" do

View file

@ -117,7 +117,7 @@ describe InvitationsController, type: :controller do
end
it "displays an error when no invitations are left" do
alice.invitation_code.update_attributes(count: 0)
alice.invitation_code.update(count: 0)
post :create, params: invite_params
@ -127,7 +127,7 @@ describe InvitationsController, type: :controller do
it "does not display an error when registration is open" do
AppConfig.settings.invitations.open = false
alice.invitation_code.update_attributes(count: 0)
alice.invitation_code.update(count: 0)
post :create, params: invite_params

View file

@ -49,7 +49,7 @@ describe RegistrationsController, type: :controller do
it "does redirect if there are no invites available with this code" do
code = InvitationCode.create(user: bob)
code.update_attributes(count: 0)
code.update(count: 0)
get :new, params: {invite: {token: code.token}}
expect(response).to redirect_to registrations_closed_path
@ -67,7 +67,7 @@ describe RegistrationsController, type: :controller do
AppConfig.settings.enable_registrations = true
code = InvitationCode.create(user: bob)
code.update_attributes(count: 0)
code.update(count: 0)
get :new, params: {invite: {token: code.token}}
expect(response).not_to be_redirect

View file

@ -138,22 +138,22 @@ describe UsersController, :type => :controller do
before do
allow(@controller).to receive(:current_user).and_return(@user)
allow(@user).to receive(:update_with_password)
allow(@user).to receive(:update_attributes)
allow(@user).to receive(:update)
end
it "uses devise's update with password" do
put :update, params: params
expect(@user).to have_received(:update_with_password).with(hash_including(password_params))
expect(@user).not_to have_received(:update_attributes).with(hash_including(password_params))
expect(@user).not_to have_received(:update).with(hash_including(password_params))
end
it "does not update the password without the change_password param" do
put :update, params: params.except(:change_password).deep_merge(user: {language: "de"})
expect(@user).not_to have_received(:update_with_password).with(hash_including(password_params))
expect(@user).not_to have_received(:update_attributes).with(hash_including(password_params))
expect(@user).to have_received(:update_attributes).with(hash_including(language: "de"))
expect(@user).not_to have_received(:update).with(hash_including(password_params))
expect(@user).to have_received(:update).with(hash_including(language: "de"))
end
end
@ -163,13 +163,13 @@ describe UsersController, :type => :controller do
before do
allow(@controller).to receive(:current_user).and_return(@user)
allow(@user).to receive(:update_attributes)
allow(@user).to receive(:update)
end
it "does not accept the params" do
put :update, params: params
expect(@user).not_to have_received(:update_attributes)
expect(@user).not_to have_received(:update)
.with(hash_including(:otp_required_for_login, :otp_secret))
end
end

View file

@ -128,13 +128,13 @@ describe NotificationsHelper, type: :helper do
let(:notification) { Notifications::ContactsBirthday.create(recipient: alice, target: bob.person) }
it "contains the date" do
bob.profile.update_attributes(birthday: Time.zone.today)
bob.profile.update(birthday: Time.zone.today)
link = object_link(notification, notification_people_link(notification))
expect(link).to include(I18n.l(Time.zone.today, format: I18n.t("date.formats.fullmonth_day")))
end
it "doesn't break, when the person removes the birthday date" do
bob.profile.update_attributes(birthday: nil)
bob.profile.update(birthday: nil)
link = object_link(notification, notification_people_link(notification))
expect(link).to include(I18n.l(Time.zone.today, format: I18n.t("date.formats.fullmonth_day")))
end

View file

@ -516,7 +516,7 @@ describe Notifier, type: :mailer do
end
it "has the inviter id if the name is nil" do
bob.person.profile.update_attributes(first_name: "", last_name: "")
bob.person.profile.update(first_name: "", last_name: "")
mail = Notifier.invite(alice.email, bob, "1234", "en")
expect(email.body.encoded).to_not include("#{bob.name} (#{bob.diaspora_handle})")
expect(mail.body.encoded).to include(bob.person.diaspora_handle)
@ -573,7 +573,7 @@ describe Notifier, type: :mailer do
end
it "FROM: header should be 'pod_name (username)' when there is no first and last name" do
bob.person.profile.update_attributes(first_name: "", last_name: "")
bob.person.profile.update(first_name: "", last_name: "")
mail = Notifier.send_notification("started_sharing", alice.id, bob.person.id)
expect(mail["From"].to_s).to eq("\"#{pod_name} (#{bob.person.username})\" <#{AppConfig.mail.sender_address}>")
end

View file

@ -74,7 +74,7 @@ describe User::Querying, :type => :model do
end
it "does not pull back hidden posts" do
@status.share_visibilities.where(user_id: alice.id).first.update_attributes(hidden: true)
@status.share_visibilities.where(user_id: alice.id).first.update(hidden: true)
expect(alice.visible_shareable_ids(Post).include?(@status.id)).to be false
end
end

View file

@ -10,7 +10,7 @@ describe "status_messages/_status_message.mobile.haml" do
)
post = FactoryGirl.create(:status_message, public: true, open_graph_cache: open_graph_cache)
render file: "status_messages/_status_message.mobile.haml", locals: {post: post, photos: post.photos}
render template: "status_messages/_status_message.mobile.haml", locals: {post: post, photos: post.photos}
expect(rendered).to_not include("<script>")
end

View file

@ -7,7 +7,7 @@ describe Workers::CheckBirthday do
before do
Timecop.freeze(Time.zone.local(1999, 9, 9))
birthday_profile.update_attributes(birthday: "1990-09-09")
birthday_profile.update(birthday: "1990-09-09")
allow(Notifications::ContactsBirthday).to receive(:notify)
end
@ -22,13 +22,13 @@ describe Workers::CheckBirthday do
end
it "does nothing if the birthday does not exist" do
birthday_profile.update_attributes(birthday: nil)
birthday_profile.update(birthday: nil)
Workers::CheckBirthday.new.perform
expect(Notifications::ContactsBirthday).not_to have_received(:notify)
end
it "does nothing if the person's birthday is not today" do
birthday_profile.update_attributes(birthday: "1988-04-15")
birthday_profile.update(birthday: "1988-04-15")
Workers::CheckBirthday.new.perform
expect(Notifications::ContactsBirthday).not_to have_received(:notify)
end
@ -41,14 +41,14 @@ describe Workers::CheckBirthday do
end
it "does not call notify method if a contact user is not :receiving from the birthday person" do
contact2.update_attributes(receiving: false)
contact2.update(receiving: false)
Workers::CheckBirthday.new.perform
expect(Notifications::ContactsBirthday).to have_received(:notify).with(contact1, [])
expect(Notifications::ContactsBirthday).not_to have_received(:notify).with(contact2, [])
end
it "does not call notify method if a birthday person is not :sharing with the contact user" do
contact2.update_attributes(sharing: false)
contact2.update(sharing: false)
Workers::CheckBirthday.new.perform
expect(Notifications::ContactsBirthday).to have_received(:notify).with(contact1, [])
expect(Notifications::ContactsBirthday).not_to have_received(:notify).with(contact2, [])