diff --git a/app/controllers/admin/bank_accounts_controller.rb b/app/controllers/admin/bank_accounts_controller.rb index a54ea798..e23b03b2 100644 --- a/app/controllers/admin/bank_accounts_controller.rb +++ b/app/controllers/admin/bank_accounts_controller.rb @@ -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 diff --git a/app/controllers/admin/financial_transaction_classes_controller.rb b/app/controllers/admin/financial_transaction_classes_controller.rb index 10359acd..e5d27efd 100644 --- a/app/controllers/admin/financial_transaction_classes_controller.rb +++ b/app/controllers/admin/financial_transaction_classes_controller.rb @@ -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 diff --git a/app/controllers/admin/financial_transaction_types_controller.rb b/app/controllers/admin/financial_transaction_types_controller.rb index 401f31e7..2710bd6e 100644 --- a/app/controllers/admin/financial_transaction_types_controller.rb +++ b/app/controllers/admin/financial_transaction_types_controller.rb @@ -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 diff --git a/app/controllers/api/v1/user/group_order_articles_controller.rb b/app/controllers/api/v1/user/group_order_articles_controller.rb index eeeb122c..ce258898 100644 --- a/app/controllers/api/v1/user/group_order_articles_controller.rb +++ b/app/controllers/api/v1/user/group_order_articles_controller.rb @@ -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 diff --git a/app/controllers/articles_controller.rb b/app/controllers/articles_controller.rb index 5e8c402d..4161e66a 100644 --- a/app/controllers/articles_controller.rb +++ b/app/controllers/articles_controller.rb @@ -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 diff --git a/app/controllers/deliveries_controller.rb b/app/controllers/deliveries_controller.rb index 21ae0c71..0ecacc9c 100644 --- a/app/controllers/deliveries_controller.rb +++ b/app/controllers/deliveries_controller.rb @@ -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 diff --git a/app/controllers/finance/balancing_controller.rb b/app/controllers/finance/balancing_controller.rb index 09c109f8..4f23ac4f 100644 --- a/app/controllers/finance/balancing_controller.rb +++ b/app/controllers/finance/balancing_controller.rb @@ -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) diff --git a/app/controllers/finance/invoices_controller.rb b/app/controllers/finance/invoices_controller.rb index 33949017..d981277b 100644 --- a/app/controllers/finance/invoices_controller.rb +++ b/app/controllers/finance/invoices_controller.rb @@ -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 diff --git a/app/controllers/foodcoop/workgroups_controller.rb b/app/controllers/foodcoop/workgroups_controller.rb index 794c21a0..e0f571be 100644 --- a/app/controllers/foodcoop/workgroups_controller.rb +++ b/app/controllers/foodcoop/workgroups_controller.rb @@ -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' diff --git a/app/controllers/group_order_articles_controller.rb b/app/controllers/group_order_articles_controller.rb index d34db7a1..5aa50a87 100644 --- a/app/controllers/group_order_articles_controller.rb +++ b/app/controllers/group_order_articles_controller.rb @@ -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) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 6f677b6b..86f9e2eb 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -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 diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 72b10deb..cfa7cef6 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -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 diff --git a/app/controllers/stockit_controller.rb b/app/controllers/stockit_controller.rb index c44e3380..6dd1511e 100644 --- a/app/controllers/stockit_controller.rb +++ b/app/controllers/stockit_controller.rb @@ -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 diff --git a/app/controllers/suppliers_controller.rb b/app/controllers/suppliers_controller.rb index 058c4fbc..e5188f8b 100644 --- a/app/controllers/suppliers_controller.rb +++ b/app/controllers/suppliers_controller.rb @@ -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 diff --git a/app/models/bank_transaction.rb b/app/models/bank_transaction.rb index ff2dc9ef..5d9d6c04 100644 --- a/app/models/bank_transaction.rb +++ b/app/models/bank_transaction.rb @@ -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 diff --git a/app/models/order.rb b/app/models/order.rb index 15e209d1..e83307f3 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -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) diff --git a/app/models/order_article.rb b/app/models/order_article.rb index 38f353ab..cda24ae2 100644 --- a/app/models/order_article.rb +++ b/app/models/order_article.rb @@ -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 diff --git a/db/migrate/021_remove_table_article_prices.rb b/db/migrate/021_remove_table_article_prices.rb index dc664347..7f172065 100644 --- a/db/migrate/021_remove_table_article_prices.rb +++ b/db/migrate/021_remove_table_article_prices.rb @@ -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" diff --git a/db/migrate/20090120184410_road_to_version_three.rb b/db/migrate/20090120184410_road_to_version_three.rb index 4b8aa9ab..4bacff24 100644 --- a/db/migrate/20090120184410_road_to_version_three.rb +++ b/db/migrate/20090120184410_road_to_version_three.rb @@ -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 diff --git a/db/migrate/20130622095040_move_weekly_tasks.rb b/db/migrate/20130622095040_move_weekly_tasks.rb index b780f3e9..3865a498 100644 --- a/db/migrate/20130622095040_move_weekly_tasks.rb +++ b/db/migrate/20130622095040_move_weekly_tasks.rb @@ -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 diff --git a/plugins/links/app/controllers/admin/links_controller.rb b/plugins/links/app/controllers/admin/links_controller.rb index e7b60aa5..2b6a7a35 100644 --- a/plugins/links/app/controllers/admin/links_controller.rb +++ b/plugins/links/app/controllers/admin/links_controller.rb @@ -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 diff --git a/plugins/polls/app/controllers/polls_controller.rb b/plugins/polls/app/controllers/polls_controller.rb index aac4ef0e..b0c1a9eb 100644 --- a/plugins/polls/app/controllers/polls_controller.rb +++ b/plugins/polls/app/controllers/polls_controller.rb @@ -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' diff --git a/plugins/printer/app/models/printer_job.rb b/plugins/printer/app/models/printer_job.rb index 2a0e1ec6..b8baadb8 100644 --- a/plugins/printer/app/models/printer_job.rb +++ b/plugins/printer/app/models/printer_job.rb @@ -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 diff --git a/spec/api/v1/order_articles_spec.rb b/spec/api/v1/order_articles_spec.rb index 85249401..e65867db 100644 --- a/spec/api/v1/order_articles_spec.rb +++ b/spec/api/v1/order_articles_spec.rb @@ -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 diff --git a/spec/integration/balancing_spec.rb b/spec/integration/balancing_spec.rb index 77fe0ec7..556d102d 100644 --- a/spec/integration/balancing_spec.rb +++ b/spec/integration/balancing_spec.rb @@ -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 diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index abf96ddf..77c3aea0 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -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 diff --git a/spec/models/order_article_spec.rb b/spec/models/order_article_spec.rb index 32b280dc..829678a9 100644 --- a/spec/models/order_article_spec.rb +++ b/spec/models/order_article_spec.rb @@ -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]) diff --git a/spec/models/ordergroup_spec.rb b/spec/models/ordergroup_spec.rb index 0c142a33..a7f0c94a 100644 --- a/spec/models/ordergroup_spec.rb +++ b/spec/models/ordergroup_spec.rb @@ -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