From ef38800baef42bc24415cb7c84c54481aaeda494 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Mon, 11 Sep 2017 13:16:08 +0200 Subject: [PATCH] Refactoring: Prefer .update! over .update, .update_attributes and .update_attribute - see http://www.davidverhasselt.com/set-attributes-in-activerecord/ . --- .../application_controller/renders_models.rb | 2 +- app/controllers/applications_controller.rb | 2 +- app/controllers/channels_email_controller.rb | 4 +-- app/controllers/network_controller.rb | 2 +- app/controllers/ticket_articles_controller.rb | 2 +- app/controllers/tickets_controller.rb | 2 +- app/controllers/users_controller.rb | 10 +++--- .../can_creates_and_updates.rb | 10 +++--- app/models/authorization.rb | 4 +-- app/models/avatar.rb | 2 +- app/models/calendar.rb | 2 +- app/models/channel/filter/identify_sender.rb | 4 +-- app/models/chat/agent.rb | 2 +- app/models/email_address.rb | 2 +- app/models/history.rb | 2 +- app/models/locale.rb | 4 +-- app/models/scheduler.rb | 6 ++-- app/models/text_module.rb | 2 +- app/models/translation.rb | 2 +- app/models/user.rb | 4 +-- lib/facebook.rb | 2 +- lib/import/integration_base.rb | 6 ++-- lib/import/ldap/user.rb | 2 +- lib/import/otrs/article.rb | 2 +- lib/import/otrs/customer.rb | 2 +- lib/import/otrs/customer_user.rb | 2 +- lib/import/otrs/priority.rb | 2 +- lib/import/otrs/queue.rb | 2 +- lib/import/otrs/state.rb | 2 +- lib/import/otrs/ticket.rb | 2 +- lib/import/otrs/user.rb | 2 +- lib/import/zendesk/ticket.rb | 2 +- lib/import/zendesk/ticket/comment.rb | 2 +- lib/telegram.rb | 4 +-- lib/tweet_base.rb | 4 +-- spec/lib/import/base_resource_spec.rb | 4 +-- spec/lib/import/ldap/user_spec.rb | 2 +- spec/lib/import/otrs/article_spec.rb | 2 +- spec/lib/import/otrs/customer_spec.rb | 2 +- spec/lib/import/otrs/customer_user_spec.rb | 4 +-- spec/lib/import/otrs/priority_spec.rb | 2 +- spec/lib/import/otrs/queue_spec.rb | 2 +- spec/lib/import/otrs/state_spec.rb | 2 +- spec/lib/import/otrs/ticket_spec.rb | 2 +- spec/lib/import/otrs/user_spec.rb | 4 +-- .../lib/import/zendesk/ticket/comment_spec.rb | 14 ++++---- spec/lib/import/zendesk/ticket_spec.rb | 2 +- spec/lib/ldap_spec.rb | 2 +- spec/models/concerns/has_groups_examples.rb | 2 +- spec/models/concerns/has_roles_examples.rb | 2 +- spec/models/import_job_spec.rb | 2 +- spec/models/scheduler_spec.rb | 6 ++-- spec/models/ticket_spec.rb | 4 +-- test/integration/clearbit_test.rb | 6 ++-- test/integration/email_deliver_test.rb | 6 ++-- test/integration/report_test.rb | 6 ++-- test/unit/activity_stream_test.rb | 14 ++++---- test/unit/auth_test.rb | 2 +- .../email_process_follow_up_possible_test.rb | 4 +-- test/unit/history_test.rb | 8 ++--- test/unit/online_notifiaction_test.rb | 26 +++++++-------- test/unit/session_basic_test.rb | 2 +- test/unit/ticket_sla_test.rb | 32 +++++++++---------- test/unit/ticket_trigger_test.rb | 4 +-- test/unit/user_test.rb | 8 ++--- 65 files changed, 143 insertions(+), 143 deletions(-) diff --git a/app/controllers/application_controller/renders_models.rb b/app/controllers/application_controller/renders_models.rb index d58932667..bedadcb79 100644 --- a/app/controllers/application_controller/renders_models.rb +++ b/app/controllers/application_controller/renders_models.rb @@ -41,7 +41,7 @@ module ApplicationController::RendersModels generic_object.with_lock do # set attributes - generic_object.update_attributes!(clean_params) + generic_object.update!(clean_params) # set relations generic_object.associations_from_param(params) diff --git a/app/controllers/applications_controller.rb b/app/controllers/applications_controller.rb index 69dcbf2f4..fd1744156 100644 --- a/app/controllers/applications_controller.rb +++ b/app/controllers/applications_controller.rb @@ -45,7 +45,7 @@ class ApplicationsController < ApplicationController def update application = Doorkeeper::Application.find(params[:id]) - application.update_attributes!(clean_params) + application.update!(clean_params) render json: application, status: :ok end diff --git a/app/controllers/channels_email_controller.rb b/app/controllers/channels_email_controller.rb index 7ee19b2e2..319d23f19 100644 --- a/app/controllers/channels_email_controller.rb +++ b/app/controllers/channels_email_controller.rb @@ -124,7 +124,7 @@ class ChannelsEmailController < ApplicationController # update account if channel_id channel = Channel.find(channel_id) - channel.update_attributes( + channel.update!( options: { inbound: params[:inbound], outbound: params[:outbound], @@ -163,7 +163,7 @@ class ChannelsEmailController < ApplicationController end if address - address.update_attributes( + address.update!( realname: params[:meta][:realname], email: email, active: true, diff --git a/app/controllers/network_controller.rb b/app/controllers/network_controller.rb index 5a7dd1a47..f257eb59f 100644 --- a/app/controllers/network_controller.rb +++ b/app/controllers/network_controller.rb @@ -63,7 +63,7 @@ class NetworksController < ApplicationController @network = Network.find(params[:id]) respond_to do |format| - if @network.update_attributes(params[:network]) + if @network.update!(params[:network]) format.html { redirect_to @network, notice: 'Network was successfully updated.' } format.json { render json: @network, status: :ok } else diff --git a/app/controllers/ticket_articles_controller.rb b/app/controllers/ticket_articles_controller.rb index 43cb987f1..baa28649b 100644 --- a/app/controllers/ticket_articles_controller.rb +++ b/app/controllers/ticket_articles_controller.rb @@ -111,7 +111,7 @@ class TicketArticlesController < ApplicationController clean_params = Ticket::Article.association_name_to_id_convert(params) clean_params = Ticket::Article.param_cleanup(clean_params, true) - article.update_attributes!(clean_params) + article.update!(clean_params) if params[:expand] result = article.attributes_with_association_names diff --git a/app/controllers/tickets_controller.rb b/app/controllers/tickets_controller.rb index 043878288..fd5c73ee3 100644 --- a/app/controllers/tickets_controller.rb +++ b/app/controllers/tickets_controller.rb @@ -192,7 +192,7 @@ class TicketsController < ApplicationController end ticket.with_lock do - ticket.update_attributes!(clean_params) + ticket.update!(clean_params) if params[:article] article_create(ticket, params[:article]) end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ff2a98185..92e289b6b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -253,7 +253,7 @@ class UsersController < ApplicationController user.with_lock do clean_params = User.association_name_to_id_convert(params) clean_params = User.param_cleanup(clean_params, true) - user.update_attributes(clean_params) + user.update!(clean_params) # only allow Admin's if current_user.permissions?('admin.user') && (params[:role_ids] || params[:roles]) @@ -765,7 +765,7 @@ curl http://localhost/api/v1/users/password_change -v -u #{login}:#{password} -H return end - user.update_attributes(password: params[:password_new]) + user.update!(password: params[:password_new]) NotificationFactory::Mailer.notification( template: 'password_change', @@ -980,7 +980,7 @@ curl http://localhost/api/v1/users/avatar -v -u #{login}:#{password} -H "Content # update user link user = User.find(current_user.id) - user.update_attributes(image: avatar.store_hash) + user.update!(image: avatar.store_hash) render json: { avatar: avatar }, status: :ok end @@ -996,7 +996,7 @@ curl http://localhost/api/v1/users/avatar -v -u #{login}:#{password} -H "Content # update user link user = User.find(current_user.id) - user.update_attributes(image: avatar.store_hash) + user.update!(image: avatar.store_hash) render json: {}, status: :ok end @@ -1013,7 +1013,7 @@ curl http://localhost/api/v1/users/avatar -v -u #{login}:#{password} -H "Content # update user link avatar = Avatar.get_default('User', current_user.id) user = User.find(current_user.id) - user.update_attributes(image: avatar.store_hash) + user.update!(image: avatar.store_hash) render json: {}, status: :ok end diff --git a/app/models/application_model/can_creates_and_updates.rb b/app/models/application_model/can_creates_and_updates.rb index 45fabaa1b..1f0bf2557 100644 --- a/app/models/application_model/can_creates_and_updates.rb +++ b/app/models/application_model/can_creates_and_updates.rb @@ -119,7 +119,7 @@ returns if data[:id] record = find_by(id: data[:id]) if record - record.update_attributes(data) + record.update!(data) return record end record = new(data) @@ -135,7 +135,7 @@ returns end records.each { |loop_record| if loop_record.name == data[:name] - loop_record.update_attributes(data) + loop_record.update!(data) return loop_record end } @@ -152,7 +152,7 @@ returns end records.each { |loop_record| if loop_record.login.casecmp(data[:login]).zero? - loop_record.update_attributes(data) + loop_record.update!(data) return loop_record end } @@ -169,7 +169,7 @@ returns end records.each { |loop_record| if loop_record.email.casecmp(data[:email]).zero? - loop_record.update_attributes(data) + loop_record.update!(data) return loop_record end } @@ -186,7 +186,7 @@ returns end records.each { |loop_record| if loop_record.locale.casecmp(data[:locale]).zero? - loop_record.update_attributes(data) + loop_record.update!(data) return loop_record end } diff --git a/app/models/authorization.rb b/app/models/authorization.rb index 771f4d2f5..6ae251654 100644 --- a/app/models/authorization.rb +++ b/app/models/authorization.rb @@ -14,14 +14,14 @@ class Authorization < ApplicationModel if auth # update auth tokens - auth.update_attributes( + auth.update!( token: hash['credentials']['token'], secret: hash['credentials']['secret'] ) # update username of auth entry if empty if !auth.username && hash['info']['nickname'] - auth.update_attributes( + auth.update!( username: hash['info']['nickname'], ) end diff --git a/app/models/avatar.rb b/app/models/avatar.rb index 6ea423f41..cb4159e09 100644 --- a/app/models/avatar.rb +++ b/app/models/avatar.rb @@ -211,7 +211,7 @@ add avatar by url # update existing if avatar_already_exists - avatar_already_exists.update_attributes(record) + avatar_already_exists.update!(record) avatar = avatar_already_exists # add new one and set it as default diff --git a/app/models/calendar.rb b/app/models/calendar.rb index 1ac32dc09..6324e278c 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -47,7 +47,7 @@ returns calendar object # find if auto generated calendar exists calendar = Calendar.find_by(default: true, updated_by_id: 1, created_by_id: 1) if calendar - calendar.update_attributes(calendar_details) + calendar.update!(calendar_details) return calendar end create(calendar_details) diff --git a/app/models/channel/filter/identify_sender.rb b/app/models/channel/filter/identify_sender.rb index e408ab10e..99a98bfae 100644 --- a/app/models/channel/filter/identify_sender.rb +++ b/app/models/channel/filter/identify_sender.rb @@ -141,7 +141,7 @@ module Channel::Filter::IdentifySender if user.firstname.blank? && user.lastname.blank? if data[:firstname].present? data[:firstname] = cleanup_name(data[:firstname]) - user.update_attributes( + user.update!( firstname: data[:firstname] ) end @@ -166,7 +166,7 @@ module Channel::Filter::IdentifySender data[:created_by_id] = 1 user = User.create(data) - user.update_attributes( + user.update!( updated_by_id: user.id, created_by_id: user.id, ) diff --git a/app/models/chat/agent.rb b/app/models/chat/agent.rb index fe3002bcb..99ea9be48 100644 --- a/app/models/chat/agent.rb +++ b/app/models/chat/agent.rb @@ -34,7 +34,7 @@ class Chat::Agent < ApplicationModel updated_by_id: params[:updated_by_id] ) if chat_agent - chat_agent.update_attributes(params) + chat_agent.update!(params) else Chat::Agent.create(params) end diff --git a/app/models/email_address.rb b/app/models/email_address.rb index 3c9985d30..59dee0acd 100644 --- a/app/models/email_address.rb +++ b/app/models/email_address.rb @@ -69,7 +69,7 @@ check and if channel not exists reset configured channels for email addresses # delete group.email_address_id reference if email address get's deleted def delete_group_reference Group.where(email_address_id: id).each { |group| - group.update_attributes!(email_address_id: nil) + group.update!(email_address_id: nil) } end diff --git a/app/models/history.rb b/app/models/history.rb index 80ef771c6..74a9bf6ef 100644 --- a/app/models/history.rb +++ b/app/models/history.rb @@ -73,7 +73,7 @@ add a new history entry for an object history_record = History.find_by(id: data[:id]) end if history_record - history_record.update_attributes(record) + history_record.update!(record) else record_new = History.create(record) if record[:id] diff --git a/app/models/locale.rb b/app/models/locale.rb index 969c51729..854fd75ce 100644 --- a/app/models/locale.rb +++ b/app/models/locale.rb @@ -117,9 +117,9 @@ all: data.each { |locale| exists = Locale.find_by(locale: locale['locale']) if exists - exists.update(locale.symbolize_keys!) + exists.update!(locale.symbolize_keys!) else - Locale.create(locale.symbolize_keys!) + Locale.create!(locale.symbolize_keys!) end } end diff --git a/app/models/scheduler.rb b/app/models/scheduler.rb index 22581ba9c..844fe5f84 100644 --- a/app/models/scheduler.rb +++ b/app/models/scheduler.rb @@ -169,7 +169,7 @@ class Scheduler < ApplicationModel end def self._start_job(job, try_count = 0, try_run_time = Time.zone.now) - job.update( + job.update!( last_run: Time.zone.now, pid: Thread.current.object_id, status: 'ok', @@ -205,7 +205,7 @@ class Scheduler < ApplicationModel error = "Failed to run #{job.method} after #{try_count} tries #{e.inspect}" logger.error error - job.update( + job.update!( error_message: error, status: 'error', active: false, @@ -285,7 +285,7 @@ class Scheduler < ApplicationModel # return [true] def self.restart_failed_jobs failed_jobs.each do |job| - job.update(active: true) + job.update!(active: true) end true diff --git a/app/models/text_module.rb b/app/models/text_module.rb index 7fcb7da83..b006d459b 100644 --- a/app/models/text_module.rb +++ b/app/models/text_module.rb @@ -38,7 +38,7 @@ load text modules from online exists = TextModule.find_by(foreign_id: text_module['foreign_id']) if exists next if !overwrite_existing_item - exists.update(text_module.symbolize_keys!) + exists.update!(text_module.symbolize_keys!) else text_module[:updated_by_id] = 1 text_module[:created_by_id] = 1 diff --git a/app/models/translation.rb b/app/models/translation.rb index 9f536b32d..3cea271b7 100644 --- a/app/models/translation.rb +++ b/app/models/translation.rb @@ -371,7 +371,7 @@ Get source file at https://i18n.zammad.com/api/v1/translations_empty_translation end } if update_needed - translation.update_attributes(translation_raw.symbolize_keys!) + translation.update!(translation_raw.symbolize_keys!) translation.save end else diff --git a/app/models/user.rb b/app/models/user.rb index d56a76fab..8cdbc49a3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -610,7 +610,7 @@ returns return if !user # reset password - user.update_attributes(password: password) + user.update!(password: password) # delete token Token.find_by(action: 'PasswordReset', name: token).destroy @@ -689,7 +689,7 @@ returns return if user && local_user.id != user.id # set verified - local_user.update_attributes(verified: true) + local_user.update!(verified: true) # delete token Token.find_by(action: 'Signup', name: token).destroy diff --git a/lib/facebook.rb b/lib/facebook.rb index 46f03291d..4be668974 100644 --- a/lib/facebook.rb +++ b/lib/facebook.rb @@ -147,7 +147,7 @@ result next if !new_value || new_value.empty? user_data[target] = new_value } - user.update_attributes(user_data) + user.update!(user_data) else user_data[:login] = item_user['id'] if item_user['first_name'] && item_user['last_name'] diff --git a/lib/import/integration_base.rb b/lib/import/integration_base.rb index ac995f9dd..45fad7193 100644 --- a/lib/import/integration_base.rb +++ b/lib/import/integration_base.rb @@ -135,9 +135,9 @@ module Import end def inform(message) - @import_job.update_attribute(:result, { - info: message - }) + @import_job.update!(result: { + info: message + }) end end end diff --git a/lib/import/ldap/user.rb b/lib/import/ldap/user.rb index 19eaba32f..e5c607a32 100644 --- a/lib/import/ldap/user.rb +++ b/lib/import/ldap/user.rb @@ -29,7 +29,7 @@ module Import # the active state this way to send notifications # to the client ::User.where(id: slice).each do |user| - user.update_attribute(:active, false) + user.update!(active: false) end end end diff --git a/lib/import/otrs/article.rb b/lib/import/otrs/article.rb index a50c7669c..bd8db5c03 100644 --- a/lib/import/otrs/article.rb +++ b/lib/import/otrs/article.rb @@ -53,7 +53,7 @@ module Import @local_article = ::Ticket::Article.find_by(id: article[:id]) return false if !@local_article log "update Ticket::Article.find_by(id: #{article[:id]})" - @local_article.update_attributes(article) + @local_article.update!(article) true end diff --git a/lib/import/otrs/customer.rb b/lib/import/otrs/customer.rb index 9a3d31e1a..ef4c4d8c6 100644 --- a/lib/import/otrs/customer.rb +++ b/lib/import/otrs/customer.rb @@ -44,7 +44,7 @@ module Import @local_customer = Organization.find_by(name: customer[:name]) return false if !@local_customer log "update Organization.find_by(name: #{customer[:name]})" - @local_customer.update_attributes(customer) + @local_customer.update!(customer) true end diff --git a/lib/import/otrs/customer_user.rb b/lib/import/otrs/customer_user.rb index 47b9b5e47..6e12bb4b6 100644 --- a/lib/import/otrs/customer_user.rb +++ b/lib/import/otrs/customer_user.rb @@ -52,7 +52,7 @@ module Import end log "update User.find_by(login: #{customer[:login]})" - @local_customer.update_attributes(customer) + @local_customer.update!(customer) true end diff --git a/lib/import/otrs/priority.rb b/lib/import/otrs/priority.rb index 8882a7ad9..784964003 100644 --- a/lib/import/otrs/priority.rb +++ b/lib/import/otrs/priority.rb @@ -33,7 +33,7 @@ module Import @local_priority = ::Ticket::Priority.find_by(id: priority[:id]) return false if !@local_priority log "update Ticket::Priority.find_by(id: #{priority[:id]})" - @local_priority.update_attributes(priority) + @local_priority.update!(priority) true end diff --git a/lib/import/otrs/queue.rb b/lib/import/otrs/queue.rb index a00e4531a..2ccfe99ce 100644 --- a/lib/import/otrs/queue.rb +++ b/lib/import/otrs/queue.rb @@ -33,7 +33,7 @@ module Import @local_queue = Group.find_by(id: queue[:id]) return false if !@local_queue log "update Group.find_by(id: #{queue[:id]})" - @local_queue.update_attributes(queue) + @local_queue.update!(queue) true end diff --git a/lib/import/otrs/state.rb b/lib/import/otrs/state.rb index 3841e441e..416654b3f 100644 --- a/lib/import/otrs/state.rb +++ b/lib/import/otrs/state.rb @@ -34,7 +34,7 @@ module Import @local_state = ::Ticket::State.find_by(id: state[:id]) return false if !@local_state log "update Ticket::State.find_by(id: #{state[:id]})" - @local_state.update_attributes(state) + @local_state.update!(state) true end diff --git a/lib/import/otrs/ticket.rb b/lib/import/otrs/ticket.rb index 4c40666ca..3c17fecef 100644 --- a/lib/import/otrs/ticket.rb +++ b/lib/import/otrs/ticket.rb @@ -50,7 +50,7 @@ module Import @local_ticket = ::Ticket.find_by(id: ticket[:id]) return false if !@local_ticket log "update Ticket.find_by(id: #{ticket[:id]})" - @local_ticket.update_attributes(ticket) + @local_ticket.update!(ticket) true end diff --git a/lib/import/otrs/user.rb b/lib/import/otrs/user.rb index 19291eb1c..e1d40fd43 100644 --- a/lib/import/otrs/user.rb +++ b/lib/import/otrs/user.rb @@ -43,7 +43,7 @@ module Import end log "update User.find_by(id: #{user[:id]})" - @local_user.update_attributes(user) + @local_user.update!(user) true end diff --git a/lib/import/zendesk/ticket.rb b/lib/import/zendesk/ticket.rb index 615e32ffe..7a18c0079 100644 --- a/lib/import/zendesk/ticket.rb +++ b/lib/import/zendesk/ticket.rb @@ -25,7 +25,7 @@ module Import def updated?(ticket) @local_ticket = ::Ticket.find_by(id: ticket[:id]) return false if !@local_ticket - @local_ticket.update_attributes(ticket) + @local_ticket.update!(ticket) true end diff --git a/lib/import/zendesk/ticket/comment.rb b/lib/import/zendesk/ticket/comment.rb index d6a2f3fff..996920d56 100644 --- a/lib/import/zendesk/ticket/comment.rb +++ b/lib/import/zendesk/ticket/comment.rb @@ -19,7 +19,7 @@ module Import def updated?(article) @local_article = ::Ticket::Article.find_by(message_id: article[:message_id]) return false if !@local_article - @local_article.update_attributes(article) + @local_article.update!(article) true end diff --git a/lib/telegram.rb b/lib/telegram.rb index ac4ac15fe..1ecddcb1f 100644 --- a/lib/telegram.rb +++ b/lib/telegram.rb @@ -243,7 +243,7 @@ returns } if auth user = User.find(auth.user_id) - user.update_attributes(user_data) + user.update!(user_data) else if message_user[:username] user_data[:note] = "Telegram @#{message_user[:username]}" @@ -261,7 +261,7 @@ returns provider: 'telegram' } if auth - auth.update_attributes(auth_data) + auth.update!(auth_data) else Authorization.create(auth_data) end diff --git a/lib/tweet_base.rb b/lib/tweet_base.rb index 00f8c693b..ccee60fb7 100644 --- a/lib/tweet_base.rb +++ b/lib/tweet_base.rb @@ -52,7 +52,7 @@ class TweetBase next if !new_value || new_value.empty? user_data[target] = new_value } - user.update_attributes(user_data) + user.update!(user_data) else user_data[:login] = tweet_user.screen_name user_data[:firstname] = tweet_user.name @@ -91,7 +91,7 @@ class TweetBase provider: 'twitter' } if auth - auth.update_attributes(auth_data) + auth.update!(auth_data) else Authorization.create!(auth_data) end diff --git a/spec/lib/import/base_resource_spec.rb b/spec/lib/import/base_resource_spec.rb index 8b5321321..6bbe77404 100644 --- a/spec/lib/import/base_resource_spec.rb +++ b/spec/lib/import/base_resource_spec.rb @@ -121,8 +121,8 @@ RSpec.describe Import::BaseResource do old_signature = create(:signature) old_users = create_list(:user, 2) - group.update_attribute(:signature_id, old_signature.id) - group.update_attribute(:user_ids, old_users.collect(&:id)) + group.update!(signature_id: old_signature.id) + group.update!(user_ids: old_users.collect(&:id)) # simulate next import run travel 20.minutes diff --git a/spec/lib/import/ldap/user_spec.rb b/spec/lib/import/ldap/user_spec.rb index 14e76c5bd..6fe2ea46c 100644 --- a/spec/lib/import/ldap/user_spec.rb +++ b/spec/lib/import/ldap/user_spec.rb @@ -245,7 +245,7 @@ RSpec.describe Import::Ldap::User do it "doesn't detect false changes" do # make sure that the nothing has changed - User.find_by(login: uid).update_attribute(:email, 'example@example.com') + User.find_by(login: uid).update!(email: 'example@example.com') expect_any_instance_of(User).not_to receive(:save!) instance = described_class.new(user_entry, ldap_config, user_roles, signup_role_ids) diff --git a/spec/lib/import/otrs/article_spec.rb b/spec/lib/import/otrs/article_spec.rb index 7ad1d137d..9b300f92b 100644 --- a/spec/lib/import/otrs/article_spec.rb +++ b/spec/lib/import/otrs/article_spec.rb @@ -11,7 +11,7 @@ RSpec.describe Import::OTRS::Article do def updates_with(zammad_structure) expect(import_object).to receive(:find_by).and_return(existing_object) - expect(existing_object).to receive(:update_attributes).with(zammad_structure) + expect(existing_object).to receive(:update!).with(zammad_structure) expect(import_object).not_to receive(:new) start_import_test end diff --git a/spec/lib/import/otrs/customer_spec.rb b/spec/lib/import/otrs/customer_spec.rb index ca16752f7..a39e66d03 100644 --- a/spec/lib/import/otrs/customer_spec.rb +++ b/spec/lib/import/otrs/customer_spec.rb @@ -10,7 +10,7 @@ RSpec.describe Import::OTRS::Customer do def updates_with(zammad_structure) expect(import_object).to receive(:find_by).and_return(existing_object) - expect(existing_object).to receive(:update_attributes).with(zammad_structure) + expect(existing_object).to receive(:update!).with(zammad_structure) expect(import_object).not_to receive(:new) start_import_test end diff --git a/spec/lib/import/otrs/customer_user_spec.rb b/spec/lib/import/otrs/customer_user_spec.rb index 086540800..c3a24c0a9 100644 --- a/spec/lib/import/otrs/customer_user_spec.rb +++ b/spec/lib/import/otrs/customer_user_spec.rb @@ -15,9 +15,9 @@ RSpec.describe Import::OTRS::CustomerUser do expect(import_object).to receive(:find_by).and_return(existing_object) # we delete the :role_ids from the zammad_structure to make sure that # a) role_ids call returns the initial role_ids - # b) and update_attributes gets called without them + # b) and update! gets called without them expect(existing_object).to receive(:role_ids).and_return(zammad_structure.delete(:role_ids)).at_least(:once) - expect(existing_object).to receive(:update_attributes).with(zammad_structure) + expect(existing_object).to receive(:update!).with(zammad_structure) expect(import_object).not_to receive(:new) start_import_test end diff --git a/spec/lib/import/otrs/priority_spec.rb b/spec/lib/import/otrs/priority_spec.rb index c7c5a3f6e..a17a75de4 100644 --- a/spec/lib/import/otrs/priority_spec.rb +++ b/spec/lib/import/otrs/priority_spec.rb @@ -11,7 +11,7 @@ RSpec.describe Import::OTRS::Priority do def updates_with(zammad_structure) expect(import_object).to receive(:find_by).and_return(existing_object) - expect(existing_object).to receive(:update_attributes).with(zammad_structure) + expect(existing_object).to receive(:update!).with(zammad_structure) expect(import_object).not_to receive(:new) start_import_test end diff --git a/spec/lib/import/otrs/queue_spec.rb b/spec/lib/import/otrs/queue_spec.rb index 4b0621ee9..7b25179d9 100644 --- a/spec/lib/import/otrs/queue_spec.rb +++ b/spec/lib/import/otrs/queue_spec.rb @@ -11,7 +11,7 @@ RSpec.describe Import::OTRS::Queue do def updates_with(zammad_structure) expect(import_object).to receive(:find_by).and_return(existing_object) - expect(existing_object).to receive(:update_attributes).with(zammad_structure) + expect(existing_object).to receive(:update!).with(zammad_structure) expect(import_object).not_to receive(:new) start_import_test end diff --git a/spec/lib/import/otrs/state_spec.rb b/spec/lib/import/otrs/state_spec.rb index 5e13ba04f..4347cfd99 100644 --- a/spec/lib/import/otrs/state_spec.rb +++ b/spec/lib/import/otrs/state_spec.rb @@ -12,7 +12,7 @@ RSpec.describe Import::OTRS::State do def updates_with(zammad_structure) expect(import_object).to receive(:find_by).and_return(existing_object) - expect(existing_object).to receive(:update_attributes).with(zammad_structure) + expect(existing_object).to receive(:update!).with(zammad_structure) expect(import_object).not_to receive(:new) start_import_test end diff --git a/spec/lib/import/otrs/ticket_spec.rb b/spec/lib/import/otrs/ticket_spec.rb index 389aaaef1..504f856ab 100644 --- a/spec/lib/import/otrs/ticket_spec.rb +++ b/spec/lib/import/otrs/ticket_spec.rb @@ -11,7 +11,7 @@ RSpec.describe Import::OTRS::Ticket do def updates_with(zammad_structure) expect(import_object).to receive(:find_by).and_return(existing_object) - expect(existing_object).to receive(:update_attributes).with(zammad_structure) + expect(existing_object).to receive(:update!).with(zammad_structure) expect(import_object).not_to receive(:new) start_import_test end diff --git a/spec/lib/import/otrs/user_spec.rb b/spec/lib/import/otrs/user_spec.rb index 3802b844f..fc7deb35c 100644 --- a/spec/lib/import/otrs/user_spec.rb +++ b/spec/lib/import/otrs/user_spec.rb @@ -14,9 +14,9 @@ RSpec.describe Import::OTRS::User do expect(import_object).to receive(:find_by).and_return(existing_object) # we delete the :role_ids from the zammad_structure to make sure that # a) role_ids call returns the initial role_ids - # b) and update_attributes gets called without them + # b) and update! gets called without them expect(existing_object).to receive(:role_ids).and_return(zammad_structure.delete(:role_ids)) - expect(existing_object).to receive(:update_attributes).with(zammad_structure) + expect(existing_object).to receive(:update!).with(zammad_structure) expect(import_object).not_to receive(:new) start_import_test end diff --git a/spec/lib/import/zendesk/ticket/comment_spec.rb b/spec/lib/import/zendesk/ticket/comment_spec.rb index 8b49efe8a..354f057d4 100644 --- a/spec/lib/import/zendesk/ticket/comment_spec.rb +++ b/spec/lib/import/zendesk/ticket/comment_spec.rb @@ -88,7 +88,7 @@ RSpec.describe Import::Zendesk::Ticket::Comment do expect(Import::Zendesk::Ticket::Comment::Sender).to receive(:local_id).with(local_user_id).and_return(update_structure[:sender_id]) local_article = double() - expect(local_article).to receive(:update_attributes).with(update_structure) + expect(local_article).to receive(:update!).with(update_structure) expect(::Ticket::Article).to receive(:find_by).with(message_id: comment.id).and_return(local_article) @@ -186,7 +186,7 @@ RSpec.describe Import::Zendesk::Ticket::Comment do expect(Import::Zendesk::Ticket::Comment::Sender).to receive(:local_id).with(local_user_id).and_return(update_structure[:sender_id]) local_article = double() - expect(local_article).to receive(:update_attributes).with(update_structure) + expect(local_article).to receive(:update!).with(update_structure) expect(::Ticket::Article).to receive(:find_by).with(message_id: comment.id).and_return(local_article) @@ -282,7 +282,7 @@ RSpec.describe Import::Zendesk::Ticket::Comment do expect(Import::Zendesk::Ticket::Comment::Sender).to receive(:local_id).with(local_user_id).and_return(update_structure[:sender_id]) local_article = double() - expect(local_article).to receive(:update_attributes).with(update_structure) + expect(local_article).to receive(:update!).with(update_structure) expect(::Ticket::Article).to receive(:find_by).with(message_id: comment.id).and_return(local_article) @@ -373,7 +373,7 @@ RSpec.describe Import::Zendesk::Ticket::Comment do expect(Import::Zendesk::Ticket::Comment::Sender).to receive(:local_id).with(local_user_id).and_return(update_structure[:sender_id]) local_article = double() - expect(local_article).to receive(:update_attributes).with(update_structure) + expect(local_article).to receive(:update!).with(update_structure) expect(::Ticket::Article).to receive(:find_by).with(message_id: comment.id).and_return(local_article) @@ -461,7 +461,7 @@ RSpec.describe Import::Zendesk::Ticket::Comment do expect(Import::Zendesk::Ticket::Comment::Sender).to receive(:local_id).with(local_user_id).and_return(update_structure[:sender_id]) local_article = double() - expect(local_article).to receive(:update_attributes).with(update_structure) + expect(local_article).to receive(:update!).with(update_structure) expect(::Ticket::Article).to receive(:find_by).with(message_id: comment.id).and_return(local_article) @@ -544,7 +544,7 @@ RSpec.describe Import::Zendesk::Ticket::Comment do expect(Import::Zendesk::Ticket::Comment::Sender).to receive(:local_id).with(local_user_id).and_return(update_structure[:sender_id]) local_article = double() - expect(local_article).to receive(:update_attributes).with(update_structure) + expect(local_article).to receive(:update!).with(update_structure) expect(::Ticket::Article).to receive(:find_by).with(message_id: comment.id).and_return(local_article) @@ -626,7 +626,7 @@ RSpec.describe Import::Zendesk::Ticket::Comment do expect(Import::Zendesk::Ticket::Comment::Sender).to receive(:local_id).with(local_user_id).and_return(update_structure[:sender_id]) local_article = double() - expect(local_article).to receive(:update_attributes).with(update_structure) + expect(local_article).to receive(:update!).with(update_structure) expect(::Ticket::Article).to receive(:find_by).with(message_id: comment.id).and_return(local_article) diff --git a/spec/lib/import/zendesk/ticket_spec.rb b/spec/lib/import/zendesk/ticket_spec.rb index 1a62722f7..3ffaec04b 100644 --- a/spec/lib/import/zendesk/ticket_spec.rb +++ b/spec/lib/import/zendesk/ticket_spec.rb @@ -122,7 +122,7 @@ RSpec.describe Import::Zendesk::Ticket do expect(Import::Zendesk::Ticket::CommentFactory).to receive(:import).with(ticket.comments, local_ticket, ticket) expect(::Ticket).to receive(:find_by).with(id: expected_structure[:id]).and_return(local_ticket) - expect(local_ticket).to receive(:update_attributes).with(expected_structure) + expect(local_ticket).to receive(:update!).with(expected_structure) created_instance = described_class.new(ticket) end diff --git a/spec/lib/ldap_spec.rb b/spec/lib/ldap_spec.rb index e3cd1dacf..bd43e70d3 100644 --- a/spec/lib/ldap_spec.rb +++ b/spec/lib/ldap_spec.rb @@ -279,7 +279,7 @@ RSpec.describe Ldap do expect(mocked_ldap).to receive(:search).with(include(expected)).and_yield(yield_entry).and_return(true) check_entry = nil - instancesearch(filter, additional) { |entry| check_entry = entry } + instance.search(filter, additional) { |entry| check_entry = entry } expect(check_entry).to eq(yield_entry) end diff --git a/spec/models/concerns/has_groups_examples.rb b/spec/models/concerns/has_groups_examples.rb index 4a91dec86..96b93af21 100644 --- a/spec/models/concerns/has_groups_examples.rb +++ b/spec/models/concerns/has_groups_examples.rb @@ -4,7 +4,7 @@ RSpec.shared_examples 'HasGroups' do context 'group' do let(:group_access_instance_inactive) { - group_access_instance.update_attribute(:active, false) + group_access_instance.update!(active: false) group_access_instance } let(:group_full) { create(:group) } diff --git a/spec/models/concerns/has_roles_examples.rb b/spec/models/concerns/has_roles_examples.rb index c591c317b..a17f2b73d 100644 --- a/spec/models/concerns/has_roles_examples.rb +++ b/spec/models/concerns/has_roles_examples.rb @@ -5,7 +5,7 @@ RSpec.shared_examples 'HasRoles' do context 'role' do let(:group_access_instance_inactive) { - group_access_instance.update_attribute(:active, false) + group_access_instance.update!(active: false) group_access_instance } let(:role) { create(:role) } diff --git a/spec/models/import_job_spec.rb b/spec/models/import_job_spec.rb index adb6d1a88..2a5670cc1 100644 --- a/spec/models/import_job_spec.rb +++ b/spec/models/import_job_spec.rb @@ -221,7 +221,7 @@ RSpec.describe ImportJob do instance = create(:import_job) delayed_job = double() - instance.update_attribute(:finished_at, Time.zone.now) + instance.update!(finished_at: Time.zone.now) expect(instance.reschedule?(delayed_job)).to be false end diff --git a/spec/models/scheduler_spec.rb b/spec/models/scheduler_spec.rb index 67412c29d..78c820cec 100644 --- a/spec/models/scheduler_spec.rb +++ b/spec/models/scheduler_spec.rb @@ -117,7 +117,7 @@ RSpec.describe Scheduler do # lock job (simluates interrupted scheduler task) locked_job = Delayed::Job.last - locked_job.update_attribute(:locked_at, Time.zone.now) + locked_job.update!(locked_at: Time.zone.now) expect do simulate_threads_call @@ -134,7 +134,7 @@ RSpec.describe Scheduler do # lock job (simluates interrupted scheduler task) locked_job = Delayed::Job.last - locked_job.update_attribute(:locked_at, Time.zone.now) + locked_job.update!(locked_at: Time.zone.now) expect do simulate_threads_call @@ -151,7 +151,7 @@ RSpec.describe Scheduler do # lock job (simluates interrupted scheduler task) locked_job = Delayed::Job.last - locked_job.update_attribute(:locked_at, Time.zone.now) + locked_job.update!(locked_at: Time.zone.now) expect do simulate_threads_call diff --git a/spec/models/ticket_spec.rb b/spec/models/ticket_spec.rb index f90bf2029..0dee7dee3 100644 --- a/spec/models/ticket_spec.rb +++ b/spec/models/ticket_spec.rb @@ -213,14 +213,14 @@ RSpec.describe Ticket do pending_time: Time.zone.now + 2.days) expect(ticket.pending_time).not_to be nil - ticket.update_attribute(:state, Ticket::State.lookup(name: 'open')) + ticket.update!(state: Ticket::State.lookup(name: 'open')) expect(ticket.pending_time).to be nil end it 'lets handle ActiveRecord nil as new value' do ticket = create(:ticket) expect do - ticket.update_attribute(:state, nil) + ticket.update!(state: nil) end.to raise_error(ActiveRecord::StatementInvalid) end diff --git a/test/integration/clearbit_test.rb b/test/integration/clearbit_test.rb index 82ef6bad5..a8d867070 100644 --- a/test/integration/clearbit_test.rb +++ b/test/integration/clearbit_test.rb @@ -93,7 +93,7 @@ class ClearbitTest < ActiveSupport::TestCase assert_equal('OTRS is an Open Source helpdesk software and an IT Service Management software free of licence costs. Improve your Customer Service Management with OTRS.', organization2_lookup.note) # update with own values (do not overwrite) - customer2.update_attributes( + customer2.update!( firstname: 'Martini', note: 'changed by my self', ) @@ -122,7 +122,7 @@ class ClearbitTest < ActiveSupport::TestCase assert_equal('Norsk-Data-Straße 1, 61352 Bad Homburg vor der Höhe, Germany', customer2_lookup.address) # update with own values (do not overwrite) - customer2.update_attributes( + customer2.update!( firstname: '', note: 'changed by my self', ) @@ -139,7 +139,7 @@ class ClearbitTest < ActiveSupport::TestCase assert_equal('Norsk-Data-Straße 1, 61352 Bad Homburg vor der Höhe, Germany', customer2_lookup.address) # update with changed values at clearbit site (do overwrite) - customer2.update_attributes( + customer2.update!( email: 'me2@example.com', ) diff --git a/test/integration/email_deliver_test.rb b/test/integration/email_deliver_test.rb index 7fa409897..bb5f48251 100644 --- a/test/integration/email_deliver_test.rb +++ b/test/integration/email_deliver_test.rb @@ -91,7 +91,7 @@ class EmailDeliverTest < ActiveSupport::TestCase assert_nil(article1_lookup.preferences['delivery_status_message']) # send with invalid smtp settings - channel.update_attributes( + channel.update!( options: { inbound: { adapter: 'imap', @@ -125,7 +125,7 @@ class EmailDeliverTest < ActiveSupport::TestCase assert(article1_lookup.preferences['delivery_status_message']) # send with correct smtp settings - channel.update_attributes( + channel.update!( options: { inbound: { adapter: 'imap', @@ -162,7 +162,7 @@ class EmailDeliverTest < ActiveSupport::TestCase Delayed::Job.destroy_all # send with invalid smtp settings - channel.update_attributes( + channel.update!( options: { inbound: { adapter: 'imap', diff --git a/test/integration/report_test.rb b/test/integration/report_test.rb index 90b52a714..af1164ae8 100644 --- a/test/integration/report_test.rb +++ b/test/integration/report_test.rb @@ -66,7 +66,7 @@ class ReportTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - @ticket1.update_attributes( + @ticket1.update!( group: Group.lookup(name: 'Users'), updated_at: '2015-10-28 14:30:00 UTC', ) @@ -97,7 +97,7 @@ class ReportTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - @ticket2.update_attributes( + @ticket2.update!( group_id: group2.id, updated_at: '2015-10-28 14:30:00 UTC', ) @@ -184,7 +184,7 @@ class ReportTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - @ticket5.update_attributes( + @ticket5.update!( state: Ticket::State.lookup(name: 'open'), updated_at: '2015-10-28 14:30:00 UTC', ) diff --git a/test/unit/activity_stream_test.rb b/test/unit/activity_stream_test.rb index 8da295f33..01110299e 100644 --- a/test/unit/activity_stream_test.rb +++ b/test/unit/activity_stream_test.rb @@ -47,7 +47,7 @@ class ActivityStreamTest < ActiveSupport::TestCase ) travel 100.seconds - ticket.update_attributes( + ticket.update!( title: 'Unit Test 1 (äöüß) - update!', state_id: Ticket::State.lookup(name: 'open').id, priority_id: Ticket::Priority.lookup(name: '1 low').id, @@ -55,7 +55,7 @@ class ActivityStreamTest < ActiveSupport::TestCase updated_at = ticket.updated_at travel 1.second - ticket.update_attributes( + ticket.update!( title: 'Unit Test 2 (äöüß) - update!', priority_id: Ticket::Priority.lookup(name: '2 normal').id, ) @@ -99,11 +99,11 @@ class ActivityStreamTest < ActiveSupport::TestCase travel 100.seconds assert_equal(organization.class, Organization) - organization.update_attributes(name: 'some name (äöüß)') + organization.update!(name: 'some name (äöüß)') updated_at = organization.updated_at travel 10.seconds - organization.update_attributes(name: 'some name 2 (äöüß)') + organization.update!(name: 'some name 2 (äöüß)') # check activity_stream stream = @admin_user.activity_stream(3) @@ -138,7 +138,7 @@ class ActivityStreamTest < ActiveSupport::TestCase created_by_id: @current_user.id, ) assert_equal(user.class, User) - user.update_attributes( + user.update!( firstname: 'Bob U', lastname: 'Smith U', ) @@ -172,14 +172,14 @@ class ActivityStreamTest < ActiveSupport::TestCase travel 100.seconds assert_equal(user.class, User) - user.update_attributes( + user.update!( firstname: 'Bob U', lastname: 'Smith U', ) updated_at = user.updated_at travel 10.seconds - user.update_attributes( + user.update!( firstname: 'Bob', lastname: 'Smith', ) diff --git a/test/unit/auth_test.rb b/test/unit/auth_test.rb index f0b2b6a85..ffcd46e8d 100644 --- a/test/unit/auth_test.rb +++ b/test/unit/auth_test.rb @@ -5,7 +5,7 @@ class AuthTest < ActiveSupport::TestCase test 'auth' do user = User.find_by(email: 'nicole.braun@zammad.org') - user.update_attributes( + user.update!( login: 'nicole.braun', firstname: 'Nicole', lastname: 'Braun', diff --git a/test/unit/email_process_follow_up_possible_test.rb b/test/unit/email_process_follow_up_possible_test.rb index cf8def07d..32529ceaf 100644 --- a/test/unit/email_process_follow_up_possible_test.rb +++ b/test/unit/email_process_follow_up_possible_test.rb @@ -36,7 +36,7 @@ Subject: #{ticket.subject_build('some new subject')} Some Text" - users_group.update_attribute('follow_up_possible', 'new_ticket') + users_group.update!('follow_up_possible' => 'new_ticket') travel 1.second ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, follow_up_raw) @@ -60,7 +60,7 @@ Some Text" assert_equal('some new subject2', ticket_p.title) assert_equal('some new subject2', article_p.subject) - users_group.update_attribute('follow_up_possible', 'yes') + users_group.update!('follow_up_possible' => 'yes') travel 1.second ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, follow_up_raw) diff --git a/test/unit/history_test.rb b/test/unit/history_test.rb index 989b92152..b3ab587d1 100644 --- a/test/unit/history_test.rb +++ b/test/unit/history_test.rb @@ -164,10 +164,10 @@ class HistoryTest < ActiveSupport::TestCase # update ticket if test[:ticket_update][:ticket] - ticket.update_attributes(test[:ticket_update][:ticket]) + ticket.update!(test[:ticket_update][:ticket]) end if test[:ticket_update][:article] - article.update_attributes(test[:ticket_update][:article]) + article.update!(test[:ticket_update][:article]) end end @@ -260,7 +260,7 @@ class HistoryTest < ActiveSupport::TestCase # update user if test[:user_update][:user] test[:user_update][:user][:active] = false - user.update_attributes(test[:user_update][:user]) + user.update!(test[:user_update][:user]) end end @@ -323,7 +323,7 @@ class HistoryTest < ActiveSupport::TestCase # update organization if test[:organization_update][:organization] - organization.update_attributes(test[:organization_update][:organization]) + organization.update!(test[:organization_update][:organization]) end end diff --git a/test/unit/online_notifiaction_test.rb b/test/unit/online_notifiaction_test.rb index f30c37588..8c2710266 100644 --- a/test/unit/online_notifiaction_test.rb +++ b/test/unit/online_notifiaction_test.rb @@ -78,7 +78,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket1.id, 'create', @agent_user1, false)) assert(OnlineNotification.exists?(@agent_user2, 'Ticket', ticket1.id, 'create', @agent_user1, true)) - ticket1.update_attributes( + ticket1.update!( title: 'Unit Test 1 (äöüß) - update!', state_id: Ticket::State.lookup(name: 'open').id, priority_id: Ticket::Priority.lookup(name: '1 low').id, @@ -133,7 +133,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket2.id, 'create', @customer_user, false)) assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket2.id, 'create', @customer_user, true)) - ticket2.update_attributes( + ticket2.update!( title: 'Unit Test 1 (äöüß) - update!', state_id: Ticket::State.lookup(name: 'open').id, priority_id: Ticket::Priority.lookup(name: '1 low').id, @@ -187,7 +187,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase assert(OnlineNotification.exists?(@agent_user2, 'Ticket', ticket3.id, 'create', @agent_user1, false)) assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket3.id, 'create', @agent_user1, true)) - ticket3.update_attributes( + ticket3.update!( title: 'Unit Test 2 (äöüß) - update!', state_id: Ticket::State.lookup(name: 'closed').id, priority_id: Ticket::Priority.lookup(name: '1 low').id, @@ -267,7 +267,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket4.id, 'create', @customer_user, false)) assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket4.id, 'create', @customer_user, true)) - ticket4.update_attributes( + ticket4.update!( title: 'Unit Test 3 (äöüß) - update!', state_id: Ticket::State.lookup(name: 'open').id, priority_id: Ticket::Priority.lookup(name: '1 low').id, @@ -321,7 +321,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase assert(OnlineNotification.exists?(@agent_user2, 'Ticket', ticket5.id, 'create', @agent_user1, false)) assert(!OnlineNotification.exists?(@agent_user2, 'Ticket', ticket5.id, 'create', @agent_user1, true)) - ticket5.update_attributes( + ticket5.update!( title: 'Unit Test 4 (äöüß) - update!', state_id: Ticket::State.lookup(name: 'open').id, priority_id: Ticket::Priority.lookup(name: '1 low').id, @@ -398,7 +398,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase assert_equal(ticket1.online_notification_seen_state(@agent_user2), false) # pending reminder, just let new owner to unseed - ticket1.update_attributes( + ticket1.update!( owner_id: @agent_user1.id, state: Ticket::State.lookup(name: 'pending reminder'), updated_by_id: @agent_user2.id, @@ -409,7 +409,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase assert_equal(ticket1.online_notification_seen_state(@agent_user2.id), true) # pending reminder, just let new owner to unseed - ticket1.update_attributes( + ticket1.update!( owner_id: 1, state: Ticket::State.lookup(name: 'pending reminder'), updated_by_id: @agent_user2.id, @@ -420,7 +420,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase assert_equal(ticket1.online_notification_seen_state(@agent_user2.id), false) # pending reminder, self done, all to unseed - ticket1.update_attributes( + ticket1.update!( owner_id: @agent_user1.id, state: Ticket::State.lookup(name: 'pending reminder'), updated_by_id: @agent_user1.id, @@ -431,7 +431,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase assert_equal(ticket1.online_notification_seen_state(@agent_user2.id), true) # pending close, all to unseen - ticket1.update_attributes( + ticket1.update!( owner_id: @agent_user1.id, state: Ticket::State.lookup(name: 'pending close'), updated_by_id: @agent_user2.id, @@ -442,7 +442,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase assert_equal(ticket1.online_notification_seen_state(@agent_user2.id), true) # to open, all to seen - ticket1.update_attributes( + ticket1.update!( owner_id: @agent_user1.id, state: Ticket::State.lookup(name: 'open'), updated_by_id: @agent_user2.id, @@ -453,7 +453,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase assert_equal(ticket1.online_notification_seen_state(@agent_user2.id), false) # to closed, all only others to seen - ticket1.update_attributes( + ticket1.update!( owner_id: @agent_user1.id, state: Ticket::State.lookup(name: 'closed'), updated_by_id: @agent_user2.id, @@ -464,7 +464,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase assert_equal(ticket1.online_notification_seen_state(@agent_user2.id), true) # to closed by owner self, all to seen - ticket1.update_attributes( + ticket1.update!( owner_id: @agent_user1.id, state: Ticket::State.lookup(name: 'closed'), updated_by_id: @agent_user1.id, @@ -475,7 +475,7 @@ class OnlineNotificationTest < ActiveSupport::TestCase assert_equal(ticket1.online_notification_seen_state(@agent_user2.id), true) # to closed by owner self, all to seen - ticket1.update_attributes( + ticket1.update!( owner_id: @agent_user1.id, state: Ticket::State.lookup(name: 'merged'), updated_by_id: @agent_user2.id, diff --git a/test/unit/session_basic_test.rb b/test/unit/session_basic_test.rb index bcf9405c9..b3a029774 100644 --- a/test/unit/session_basic_test.rb +++ b/test/unit/session_basic_test.rb @@ -243,7 +243,7 @@ class SessionBasicTest < ActiveSupport::TestCase result1 = as_client1.push assert(!result1, 'check as agent1 - recall 2') - agent1.update_attribute(:email, 'activity-stream-agent11@example.com') + agent1.update!(email: 'activity-stream-agent11@example.com') ticket = Ticket.create!( title: '12323', group_id: 1, diff --git a/test/unit/ticket_sla_test.rb b/test/unit/ticket_sla_test.rb index 2b6e0d814..3f0c45454 100644 --- a/test/unit/ticket_sla_test.rb +++ b/test/unit/ticket_sla_test.rb @@ -168,7 +168,7 @@ class TicketSlaTest < ActiveSupport::TestCase assert_nil(ticket.close_diff_in_min, 'ticket.close_diff_in_min verify 2') # set first response in time - ticket.update_attributes( + ticket.update!( first_response_at: '2013-03-21 10:00:00 UTC', ) @@ -187,7 +187,7 @@ class TicketSlaTest < ActiveSupport::TestCase assert_nil(ticket.close_diff_in_min, 'ticket.close_diff_in_min verify 3') # set first reponse over time - ticket.update_attributes( + ticket.update!( first_response_at: '2013-03-21 14:00:00 UTC', ) @@ -206,7 +206,7 @@ class TicketSlaTest < ActiveSupport::TestCase assert_nil(ticket.close_diff_in_min, 'ticket.close_diff_in_min verify 4') # set update time in time - ticket.update_attributes( + ticket.update!( last_contact_agent_at: '2013-03-21 11:00:00 UTC', ) assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.escalation_at verify 5') @@ -225,7 +225,7 @@ class TicketSlaTest < ActiveSupport::TestCase assert_nil(ticket.close_diff_in_min, 'ticket.close_diff_in_min verify 5') # set update time over time - ticket.update_attributes( + ticket.update!( last_contact_agent_at: '2013-03-21 12:00:00 UTC', ) assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.escalation_at verify 6') @@ -244,7 +244,7 @@ class TicketSlaTest < ActiveSupport::TestCase assert_nil(ticket.close_diff_in_min, 'ticket.close_diff_in_min verify 6') # set update time over time - ticket.update_attributes( + ticket.update!( last_contact_customer_at: '2013-03-21 12:05:00 UTC', ) assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.escalation_at verify 6') @@ -263,7 +263,7 @@ class TicketSlaTest < ActiveSupport::TestCase assert_nil(ticket.close_diff_in_min, 'ticket.close_diff_in_min verify 6') # set update time over time - ticket.update_attributes( + ticket.update!( last_contact_agent_at: '2013-03-21 12:10:00 UTC', ) assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 12:30:00 UTC', 'ticket.escalation_at verify 6') @@ -282,7 +282,7 @@ class TicketSlaTest < ActiveSupport::TestCase assert_nil(ticket.close_diff_in_min, 'ticket.close_diff_in_min verify 6') # set close time in time - ticket.update_attributes( + ticket.update!( close_at: '2013-03-21 11:30:00 UTC', ) assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 14:10:00 UTC', 'ticket.escalation_at verify 7') @@ -301,7 +301,7 @@ class TicketSlaTest < ActiveSupport::TestCase assert_equal(ticket.close_diff_in_min, 60, 'ticket.close_diff_in_min verify 7') # set close time over time - ticket.update_attributes( + ticket.update!( close_at: '2013-03-21 13:00:00 UTC', ) assert_equal(ticket.escalation_at.gmtime.to_s, '2013-03-21 14:10:00 UTC', 'ticket.escalation_at verify 8') @@ -320,7 +320,7 @@ class TicketSlaTest < ActiveSupport::TestCase assert_equal(ticket.close_diff_in_min, -30, 'ticket.close_diff_in_min verify 8') # set close time over time - ticket.update_attributes( + ticket.update!( state: Ticket::State.lookup(name: 'closed') ) assert_nil(ticket.escalation_at, 'ticket.escalation_at verify 9') @@ -1097,12 +1097,12 @@ class TicketSlaTest < ActiveSupport::TestCase ) # set update time - ticket.update_attributes( + ticket.update!( last_contact_agent_at: '2013-06-04 10:15:00 UTC', ) # set first response time - ticket.update_attributes( + ticket.update!( first_response_at: '2013-06-04 10:45:00 UTC', ) @@ -1121,7 +1121,7 @@ class TicketSlaTest < ActiveSupport::TestCase updated_at: '2013-06-04 12:00:00 UTC' ) - ticket.update_attributes( + ticket.update!( close_at: '2013-06-04 12:00:00 UTC', ) @@ -1218,7 +1218,7 @@ class TicketSlaTest < ActiveSupport::TestCase created_at: '2013-06-04 12:00:00 UTC', updated_at: '2013-06-04 12:00:00 UTC', ) - ticket.update_attributes( + ticket.update!( close_at: '2013-06-04 12:00:00 UTC', ) ticket.escalation_calculation(true) @@ -1346,7 +1346,7 @@ class TicketSlaTest < ActiveSupport::TestCase created_at: '2013-06-04 12:00:00 UTC', updated_at: '2013-06-04 12:00:00 UTC', ) - ticket.update_attributes( + ticket.update!( close_at: '2013-06-04 12:00:00 UTC', ) @@ -1489,7 +1489,7 @@ class TicketSlaTest < ActiveSupport::TestCase created_at: '2013-06-04 12:00:00 UTC', updated_at: '2013-06-04 12:00:00 UTC', ) - ticket.update_attributes( + ticket.update!( close_at: '2013-06-04 12:00:00 UTC', ) @@ -2074,7 +2074,7 @@ class TicketSlaTest < ActiveSupport::TestCase assert_nil(ticket.close_escalation_at, 'ticket.close_escalation_at verify 1') # set sla's for timezone "Europe/Berlin" wintertime (+1), so UTC times are 3:00-18:00 - calendar.update_attributes( + calendar.update!( business_hours: { mon: { active: true, diff --git a/test/unit/ticket_trigger_test.rb b/test/unit/ticket_trigger_test.rb index 724650e60..2310efbd8 100644 --- a/test/unit/ticket_trigger_test.rb +++ b/test/unit/ticket_trigger_test.rb @@ -1497,7 +1497,7 @@ class TicketTriggerTest < ActiveSupport::TestCase assert_equal(1, ticket1.articles.count, 'ticket1.articles verify') assert_equal([], ticket1.tag_list) - ticket1.update_attribute(:customer, User.lookup(email: 'nicole.braun@zammad.org') ) + ticket1.update!(customer: User.lookup(email: 'nicole.braun@zammad.org') ) UserInfo.current_user_id = agent.id Ticket::Article.create( @@ -1608,7 +1608,7 @@ class TicketTriggerTest < ActiveSupport::TestCase assert_equal(1, ticket1.articles.count, 'ticket1.articles verify') assert_equal([], ticket1.tag_list) - ticket1.update_attribute(:customer, customer ) + ticket1.update!(customer: customer ) UserInfo.current_user_id = agent.id Ticket::Article.create( diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 89447737c..1dcdae943 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -271,7 +271,7 @@ class UserTest < ActiveSupport::TestCase assert_equal(test[:create_verify][:image_md5], file_md5, "create avatar md5 check in (#{test[:name]})") end if test[:update] - user.update_attributes( test[:update] ) + user.update!( test[:update] ) test[:update_verify].each { |key, value| next if key == :image_md5 @@ -848,18 +848,18 @@ class UserTest < ActiveSupport::TestCase admin_count_inital = User.with_permissions('admin').count assert_equal(3, admin_count_inital) - admin1.update_attribute(:roles, Role.where(name: %w(Agent))) + admin1.update!(roles: Role.where(name: %w(Agent))) admin_count_inital = User.with_permissions('admin').count assert_equal(2, admin_count_inital) - admin2.update_attribute(:roles, Role.where(name: %w(Agent))) + admin2.update!(roles: Role.where(name: %w(Agent))) admin_count_inital = User.with_permissions('admin').count assert_equal(1, admin_count_inital) assert_raises(Exceptions::UnprocessableEntity) { - admin3.update_attribute(:roles, Role.where(name: %w(Agent))) + admin3.update!(roles: Role.where(name: %w(Agent))) } admin_count_inital = User.with_permissions('admin').count