replace deprecated update_attributes with update

pull/36/head
viehlieb 2022-10-13 18:25:52 +02:00 committed by Patrick Gansterer
parent eb45a2bf21
commit 3ffdb424d5
28 changed files with 52 additions and 53 deletions

View File

@ -23,7 +23,7 @@ class Admin::BankAccountsController < Admin::BaseController
def update
@bank_account = BankAccount.find(params[:id])
if @bank_account.update_attributes(params[:bank_account])
if @bank_account.update(params[:bank_account])
redirect_to update_bank_accounts_admin_finances_url, :status => 303
else
render :action => 'new', :layout => false

View File

@ -23,7 +23,7 @@ class Admin::FinancialTransactionClassesController < Admin::BaseController
def update
@financial_transaction_class = FinancialTransactionClass.find(params[:id])
if @financial_transaction_class.update_attributes(params[:financial_transaction_class])
if @financial_transaction_class.update(params[:financial_transaction_class])
redirect_to update_transaction_types_admin_finances_url, status: 303
else
render action: 'new', layout: false

View File

@ -24,7 +24,7 @@ class Admin::FinancialTransactionTypesController < Admin::BaseController
def update
@financial_transaction_type = FinancialTransactionType.find(params[:id])
if @financial_transaction_type.update_attributes(params[:financial_transaction_type])
if @financial_transaction_type.update(params[:financial_transaction_type])
redirect_to update_transaction_types_admin_finances_url, status: 303
else
render action: 'new', layout: false

View File

@ -26,7 +26,7 @@ class Api::V1::User::GroupOrderArticlesController < Api::V1::BaseController
goa.update_quantities((create_params[:quantity] || 0).to_i, (create_params[:tolerance] || 0).to_i)
oa.update_results!
go.update_price!
go.update_attributes! updated_by: current_user
go.update!(updated_by: current_user)
end
render_goa_with_oa(goa)
end
@ -38,7 +38,7 @@ class Api::V1::User::GroupOrderArticlesController < Api::V1::BaseController
goa.update_quantities((update_params[:quantity] || goa.quantity).to_i, (update_params[:tolerance] || goa.tolerance).to_i)
goa.order_article.update_results!
goa.group_order.update_price!
goa.group_order.update_attributes! updated_by: current_user
goa.group_order.update!(updated_by: current_user)
end
render_goa_with_oa(goa)
end
@ -50,7 +50,7 @@ class Api::V1::User::GroupOrderArticlesController < Api::V1::BaseController
goa.destroy!
goa.order_article.update_results!
goa.group_order.update_price!
goa.group_order.update_attributes! updated_by: current_user
goa.group_order.update!(updated_by: current_user)
end
render_goa_with_oa(nil, goa.order_article)
end

View File

@ -64,7 +64,7 @@ class ArticlesController < ApplicationController
def update
@article = Article.find(params[:id])
if @article.update_attributes(params[:article])
if @article.update(params[:article])
render :layout => false
else
render :action => 'new', :layout => false
@ -93,7 +93,7 @@ class ArticlesController < ApplicationController
# Update other article attributes...
@articles = Article.find(params[:articles].keys)
@articles.each do |article|
unless article.update_attributes(params[:articles][article.id.to_s])
unless article.update(params[:articles][article.id.to_s])
invalid_articles = true unless invalid_articles # Remember that there are validation errors
end
end

View File

@ -33,7 +33,7 @@ class DeliveriesController < ApplicationController
def update
@delivery = Delivery.find(params[:id])
if @delivery.update_attributes(params[:delivery])
if @delivery.update(params[:delivery])
flash[:notice] = I18n.t('deliveries.update.notice')
redirect_to [@supplier, @delivery]
else

View File

@ -51,7 +51,7 @@ class Finance::BalancingController < Finance::BaseController
def update_note
@order = Order.find(params[:id])
if @order.update_attributes(params[:order])
if @order.update(params[:order])
render :layout => false
else
render :action => :edit_note, :layout => false
@ -65,7 +65,7 @@ class Finance::BalancingController < Finance::BaseController
def update_transport
@order = Order.find(params[:id])
@order.update_attributes! params[:order]
@order.update!(params[:order])
redirect_to new_finance_order_path(order_id: @order.id)
rescue => error
redirect_to new_finance_order_path(order_id: @order.id), alert: t('errors.general_msg', msg: error.message)

View File

@ -63,7 +63,7 @@ class Finance::InvoicesController < ApplicationController
end
def update
if @invoice.update_attributes(params[:invoice])
if @invoice.update(params[:invoice])
redirect_to [:finance, @invoice], notice: I18n.t('finance.update.notice')
else
fill_deliveries_and_orders_collection @invoice.id, @invoice.supplier_id

View File

@ -12,7 +12,7 @@ class Foodcoop::WorkgroupsController < ApplicationController
def update
@workgroup = Workgroup.find(params[:id])
if @workgroup.update_attributes(params[:workgroup])
if @workgroup.update(params[:workgroup])
redirect_to foodcoop_workgroups_url, :notice => I18n.t('workgroups.update.notice')
else
render :action => 'edit'

View File

@ -19,7 +19,7 @@ class GroupOrderArticlesController < ApplicationController
goa = GroupOrderArticle.where(group_order_id: @group_order_article.group_order_id,
order_article_id: @order_article.id).first
if goa && goa.update_attributes(params[:group_order_article])
if goa && goa.update(params[:group_order_article])
@group_order_article = goa
update_summaries(@group_order_article)
@ -38,7 +38,7 @@ class GroupOrderArticlesController < ApplicationController
if params[:delta]
@group_order_article.update_attribute :result, [@group_order_article.result + params[:delta].to_f, 0].max
else
@group_order_article.update_attributes(params[:group_order_article])
@group_order_article.update(params[:group_order_article])
end
update_summaries(@group_order_article)

View File

@ -23,8 +23,8 @@ class HomeController < ApplicationController
end
def update_profile
if @current_user.update_attributes(user_params)
@current_user.ordergroup.update_attributes(ordergroup_params) if ordergroup_params
if @current_user.update(user_params)
@current_user.ordergroup.update(ordergroup_params) if ordergroup_params
session[:locale] = @current_user.locale
redirect_to my_profile_url, notice: I18n.t('home.changes_saved')
else

View File

@ -94,7 +94,7 @@ class OrdersController < ApplicationController
# Update an existing order.
def update
@order = Order.find params[:id]
if @order.update_attributes params[:order].merge(updated_by: current_user)
if @order.update(params[:order].merge(updated_by: current_user))
flash[:notice] = I18n.t('orders.update.notice')
redirect_to :action => 'show', :id => @order
else

View File

@ -54,7 +54,7 @@ class StockitController < ApplicationController
def update
@stock_article = StockArticle.find(params[:id])
@stock_article.update_attributes!(params[:stock_article])
@stock_article.update!(params[:stock_article])
render :layout => false
rescue ActiveRecord::RecordInvalid
render :action => 'edit', :layout => false

View File

@ -41,7 +41,7 @@ class SuppliersController < ApplicationController
def update
@supplier = Supplier.find(params[:id])
if @supplier.update_attributes(supplier_params)
if @supplier.update(supplier_params)
flash[:notice] = I18n.t('suppliers.update.notice')
redirect_to @supplier
else

View File

@ -45,7 +45,7 @@ class BankTransaction < ApplicationRecord
transaction do
link = FinancialLink.new
invoices.each { |i| i.update_attributes! financial_link: link, paid_on: date }
invoices.each { |i| i.update!(financial_link: link, paid_on: date) }
update_attribute :financial_link, link
end

View File

@ -235,7 +235,7 @@ class Order < ApplicationRecord
unless finished?
Order.transaction do
# set new order state (needed by notify_order_finished)
update_attributes!(:state => 'finished', :ends => Time.now, :updated_by => user)
update!(state: 'finished', ends: Time.now, updated_by: user)
# Update order_articles. Save the current article_price to keep price consistency
# Also save results for each group_order_result
@ -281,7 +281,7 @@ class Order < ApplicationRecord
end
end
self.update_attributes! :state => 'closed', :updated_by => user, :foodcoop_result => profit
self.update!(state: 'closed', updated_by: user, foodcoop_result: profit)
end
end
@ -290,7 +290,7 @@ class Order < ApplicationRecord
raise I18n.t('orders.model.error_closed') if closed?
comments.create(user: user, text: I18n.t('orders.model.close_direct_message')) unless FoodsoftConfig[:charge_members_manually]
update_attributes! state: 'closed', updated_by: user
update!(state: 'closed', updated_by: user)
end
def send_to_supplier!(user)

View File

@ -159,10 +159,10 @@ class OrderArticle < ApplicationRecord
def update_article_and_price!(order_article_attributes, article_attributes, price_attributes = nil)
OrderArticle.transaction do
# Updates self
self.update_attributes!(order_article_attributes)
self.update!(order_article_attributes)
# Updates article
article.update_attributes!(article_attributes)
article.update!(article_attributes)
# Updates article_price belonging to current order article
if price_attributes.present?
@ -170,7 +170,7 @@ class OrderArticle < ApplicationRecord
if article_price.changed?
# Updates also price attributes of article if update_global_price is selected
if update_global_price
article.update_attributes!(price_attributes)
article.update!(price_attributes)
self.article_price = article.article_prices.first and save # Assign new created article price to order article
else
# Creates a new article_price if neccessary

View File

@ -16,14 +16,14 @@ class RemoveTableArticlePrices < ActiveRecord::Migration[4.2]
puts "now copy values of article_prices into new articles-columns..."
Article.find(:all).each do |article|
price = article.current_price
article.update_attributes!(:clear_price => price.clear_price,
:gross_price => price.gross_price,
:tax => price.tax,
:refund => price.refund,
:unit_quantity => price.unit_quantity,
:order_number => price.order_number,
:updated_at => price.updated_on,
:created_at => price.updated_on)
article.update!(clear_price: price.clear_price,
gross_price: price.gross_price,
tax: price.tax,
refund: price.refund,
unit_quantity: price.unit_quantity,
order_number: price.order_number,
updated_at: price.updated_on,
created_at: price.updated_on)
end
puts "delete article_prices, current_price attribute"

View File

@ -47,8 +47,7 @@ class RoadToVersionThree < ActiveRecord::Migration[4.2]
Ordergroup.all.each do |ordergroup|
contact = ordergroup.users.first
if contact
ordergroup.update_attributes :contact_person => contact.name,
:contact_phone => contact.phone, :contact_address => contact.address
ordergroup.update(contact_person: contact.name, contact_phone: contact.phone, contact_address: contact.address)
end
end
remove_column :users, :address

View File

@ -27,7 +27,7 @@ class MoveWeeklyTasks < ActiveRecord::Migration[4.2]
task_required_users: task.required_users,
task_duration: task.duration
}
workgroup.update_attributes workgroup_attributes
workgroup.update(workgroup_attributes)
task_group.tasks.update_all weekly: true
end
end

View File

@ -25,7 +25,7 @@ class Admin::LinksController < Admin::BaseController
def update
@link = Link.find(params[:id])
if @link.update_attributes!(link_params)
if @link.update!(link_params)
index
render action: :update_links
else

View File

@ -37,7 +37,7 @@ class PollsController < ApplicationController
if user_has_no_right
redirect_to polls_path, alert: t('.no_right')
elsif @poll.update_attributes(poll_params)
elsif @poll.update(poll_params)
redirect_to @poll, notice: t('.notice')
else
render action: 'edit'

View File

@ -26,6 +26,6 @@ class PrinterJob < ActiveRecord::Base
def finish!(user = nil)
return unless finished_at.nil?
update_attributes finished_at: Time.now, finished_by: user
update(finished_at: Time.now, finished_by: user)
end
end

View File

@ -14,10 +14,10 @@ describe Api::V1::OrderArticlesController, type: :controller do
let(:order_articles) { order.order_articles }
before do
order_articles[0].update_attributes! quantity: 0, tolerance: 0, units_to_order: 0
order_articles[1].update_attributes! quantity: 1, tolerance: 0, units_to_order: 0
order_articles[2].update_attributes! quantity: 0, tolerance: 1, units_to_order: 0
order_articles[3].update_attributes! quantity: 0, tolerance: 0, units_to_order: 1
order_articles[0].update!(quantity: 0, tolerance: 0, units_to_order: 0)
order_articles[1].update!(quantity: 1, tolerance: 0, units_to_order: 0)
order_articles[2].update!(quantity: 0, tolerance: 1, units_to_order: 0)
order_articles[3].update!(quantity: 0, tolerance: 0, units_to_order: 1)
end
it "(unset)" do

View File

@ -97,7 +97,7 @@ feature 'settling an order', js: true do
end
it 'deletes a GroupOrderArticle with no ordered amounts' do
goa1.update_attributes({ :quantity => 0, :tolerance => 0 })
goa1.update(quantity: 0, tolerance: 0)
click_link article.name
expect(page).to have_selector("#group_order_article_#{goa1.id}")
within("#group_order_article_#{goa1.id}") do

View File

@ -78,7 +78,7 @@ describe Article do
# TODO move article sync from supplier to article
article # need to reference for it to exist when syncing
updated_article = supplier.sync_all[0].select { |s| s[0].id == article.id }.first[0]
article.update_attributes updated_article.attributes.reject { |k, v| k == 'id' or k == 'type' }
article.update(updated_article.attributes.reject { |k, v| k == 'id' or k == 'type' })
expect(article.name).to eq(shared_article.name)
# now synchronising shouldn't change anything anymore
expect(article.shared_article_changed?).to be_falsey
@ -101,14 +101,14 @@ describe Article do
article.save!
# TODO get sync functionality in article
updated_article = supplier.sync_all[0].select { |s| s[0].id == article.id }.first[0]
article.update_attributes! updated_article.attributes.reject { |k, v| k == 'id' or k == 'type' }
article.update!(updated_article.attributes.reject { |k, v| k == 'id' or k == 'type' })
expect(article.unit).to eq '200g'
expect(article.unit_quantity).to eq 5
expect(article.price).to be_within(0.005).of(shared_article.price / 5)
end
it 'does not synchronise when it has no order number' do
article.update_attributes :order_number => nil
article.update(order_number: nil)
expect(supplier.sync_all).to eq [[], [], []]
end
end

View File

@ -151,7 +151,7 @@ describe OrderArticle do
# actual test
it(success ? 'succeeds' : 'fails') do
order.update_attributes(boxfill: boxfill_from)
order.update(boxfill: boxfill_from)
r = proc {
goa.update_quantities(*q.values[0])

View File

@ -127,13 +127,13 @@ describe Ordergroup do
expect(og.account_balance).to eq 444
ftc1.reload
ftc1.update_attributes!(ignore_for_account_balance: true)
ftc1.update!(ignore_for_account_balance: true)
og.reload
expect(og.account_balance).to eq 440
ftt2.reload
ftt2.update_attributes!(financial_transaction_class: ftc1)
ftt2.update!(financial_transaction_class: ftc1)
og.reload
expect(og.account_balance).to eq 400
@ -146,7 +146,7 @@ describe Ordergroup do
expect(result["sum_of_class_#{ftc2.id}"]).to eq 440
ftt2.reload
ftt2.update_attributes!(financial_transaction_class: ftc1)
ftt2.update!(financial_transaction_class: ftc1)
result = Ordergroup.include_transaction_class_sum.where(id: og).first
expect(result["sum_of_class_#{ftc1.id}"]).to eq 44