diff options
author | Benjamin Neff <benjamin@coding4coffee.ch> | 2022-07-16 19:17:06 +0300 |
---|---|---|
committer | Benjamin Neff <benjamin@coding4coffee.ch> | 2022-07-20 22:26:58 +0300 |
commit | b5a46cf7bbd5e9a857e26443a40b5b1a6b696cb1 (patch) | |
tree | 3ecc4170d8d4e6d1b490561ee883b858d4c25894 | |
parent | 2d38a24a8688b3db5e8cba90e81a0eccd8086474 (diff) |
Fix deprecation warnings for rails 6.0
20 files changed, 47 insertions, 44 deletions
diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index f03036e10..f7d4a49a4 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 99a0297a0..f129ecb05 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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) diff --git a/app/models/invitation_code.rb b/app/models/invitation_code.rb index 428096756..1f941c818 100644 --- a/app/models/invitation_code.rb +++ b/app/models/invitation_code.rb @@ -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) diff --git a/app/models/user.rb b/app/models/user.rb index 788fe6aba..131fbcf68 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/models/user/connecting.rb b/app/models/user/connecting.rb index 232dba405..62a3a4a02 100644 --- a/app/models/user/connecting.rb +++ b/app/models/user/connecting.rb @@ -58,7 +58,7 @@ class User if destroy contact.destroy else - contact.update_attributes(direction => false) + contact.update(direction => false) end end end diff --git a/config/logging.rb b/config/logging.rb index 06d57f041..38faf0f5c 100644 --- a/config/logging.rb +++ b/config/logging.rb @@ -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 diff --git a/db/migrate/20170813160104_cleanup_aspects_and_add_unique_index.rb b/db/migrate/20170813160104_cleanup_aspects_and_add_unique_index.rb index 1d8c7325a..7741d5b08 100644 --- a/db/migrate/20170813160104_cleanup_aspects_and_add_unique_index.rb +++ b/db/migrate/20170813160104_cleanup_aspects_and_add_unique_index.rb @@ -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 diff --git a/features/support/integration_sessions_controller.rb b/features/support/integration_sessions_controller.rb index 1d6bccbe8..357d1cc86 100644 --- a/features/support/integration_sessions_controller.rb +++ b/features/support/integration_sessions_controller.rb @@ -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 diff --git a/lib/account_deleter.rb b/lib/account_deleter.rb index 302669bc4..d7f976c1a 100644 --- a/lib/account_deleter.rb +++ b/lib/account_deleter.rb @@ -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 diff --git a/lib/diaspora/federation/receive.rb b/lib/diaspora/federation/receive.rb index dd136ac42..adc3a9c82 100644 --- a/lib/diaspora/federation/receive.rb +++ b/lib/diaspora/federation/receive.rb @@ -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, diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index a243cfaf8..9e35896d6 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -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} diff --git a/spec/controllers/contacts_controller_spec.rb b/spec/controllers/contacts_controller_spec.rb index 10cdc3ab5..2e32ec52e 100644 --- a/spec/controllers/contacts_controller_spec.rb +++ b/spec/controllers/contacts_controller_spec.rb @@ -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 diff --git a/spec/controllers/invitations_controller_spec.rb b/spec/controllers/invitations_controller_spec.rb index 7919b6a8b..87232f401 100644 --- a/spec/controllers/invitations_controller_spec.rb +++ b/spec/controllers/invitations_controller_spec.rb @@ -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 diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index 7bb94bcaa..8c43191a5 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -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 diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index ac3e79727..9c4e29adf 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -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 diff --git a/spec/helpers/notifications_helper_spec.rb b/spec/helpers/notifications_helper_spec.rb index dea069ef6..bfffc8f1a 100644 --- a/spec/helpers/notifications_helper_spec.rb +++ b/spec/helpers/notifications_helper_spec.rb @@ -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 diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index 4cdc3c319..872530e9b 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -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 diff --git a/spec/models/user/querying_spec.rb b/spec/models/user/querying_spec.rb index 53843a7bc..27ad42d44 100644 --- a/spec/models/user/querying_spec.rb +++ b/spec/models/user/querying_spec.rb @@ -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 diff --git a/spec/views/status_messages/_status_message.mobile.haml_spec.rb b/spec/views/status_messages/_status_message.mobile.haml_spec.rb index 5487d6a55..e5ad542f7 100644 --- a/spec/views/status_messages/_status_message.mobile.haml_spec.rb +++ b/spec/views/status_messages/_status_message.mobile.haml_spec.rb @@ -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 diff --git a/spec/workers/check_birthday_spec.rb b/spec/workers/check_birthday_spec.rb index 594be68f0..1f026ab61 100644 --- a/spec/workers/check_birthday_spec.rb +++ b/spec/workers/check_birthday_spec.rb @@ -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, []) |