From f848a89a006119c6fdf00eab9e625fada752f071 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Mon, 22 Jun 2020 13:15:36 +0100 Subject: [PATCH] Rename update_attributes to update #rails4 --- .../admin/bulk_line_items_controller.rb | 2 +- .../admin/enterprises_controller.rb | 8 ++--- .../admin/subscriptions_controller.rb | 2 +- app/controllers/api/customers_controller.rb | 2 +- .../api/enterprise_attachment_controller.rb | 2 +- app/controllers/api/enterprises_controller.rb | 6 ++-- .../api/product_images_controller.rb | 2 +- app/controllers/api/products_controller.rb | 2 +- app/controllers/api/shipments_controller.rb | 4 +-- app/controllers/api/taxons_controller.rb | 2 +- app/controllers/api/variants_controller.rb | 2 +- app/controllers/checkout_controller.rb | 2 +- .../orders/customer_details_controller.rb | 2 +- .../spree/admin/orders_controller.rb | 2 +- .../spree/admin/payment_methods_controller.rb | 2 +- .../spree/admin/resource_controller.rb | 2 +- .../spree/admin/taxons_controller.rb | 2 +- .../spree/admin/users_controller.rb | 2 +- .../spree/credit_cards_controller.rb | 2 +- app/controllers/spree/orders_controller.rb | 2 +- app/controllers/spree/users_controller.rb | 2 +- app/helpers/i18n_helper.rb | 4 +-- app/jobs/subscription_placement_job.rb | 2 +- app/models/spree/adjustment_decorator.rb | 2 +- app/models/spree/line_item_decorator.rb | 2 +- app/models/spree/product_set.rb | 2 +- app/services/line_item_syncer.rb | 2 +- app/services/order_factory.rb | 2 +- app/services/order_syncer.rb | 4 +-- app/services/user_default_address_setter.rb | 4 +-- .../order_cycle_form_applicator.rb | 2 +- lib/stripe/profile_storer.rb | 2 +- .../admin/proxy_orders_controller_spec.rb | 12 +++---- .../admin/subscriptions_controller_spec.rb | 18 +++++----- .../controllers/api/orders_controller_spec.rb | 2 +- .../controllers/line_items_controller_spec.rb | 2 +- .../admin/payment_methods_controller_spec.rb | 2 +- .../spree/orders_controller_spec.rb | 4 +-- spec/features/admin/subscriptions_spec.rb | 6 ++-- spec/features/admin/variant_overrides_spec.rb | 4 +-- spec/features/admin/variants_spec.rb | 4 +-- spec/features/consumer/account_spec.rb | 2 +- spec/features/consumer/registration_spec.rb | 2 +- spec/features/consumer/shopping/cart_spec.rb | 18 +++++----- .../features/consumer/shopping/orders_spec.rb | 6 ++-- .../consumer/shopping/shopping_spec.rb | 16 ++++----- spec/jobs/subscription_confirm_job_spec.rb | 14 ++++---- spec/jobs/subscription_placement_job_spec.rb | 14 ++++---- spec/models/customer_spec.rb | 2 +- spec/models/enterprise_caching_spec.rb | 4 +-- spec/models/exchange_spec.rb | 4 +-- spec/models/order_cycle_spec.rb | 6 ++-- spec/models/proxy_order_spec.rb | 10 +++--- spec/models/spree/adjustment_spec.rb | 2 +- spec/models/spree/credit_card_spec.rb | 6 ++-- spec/models/spree/line_item_spec.rb | 36 +++++++++---------- spec/models/spree/order_spec.rb | 10 +++--- spec/models/spree/product_spec.rb | 10 +++--- spec/models/spree/user_spec.rb | 4 +-- spec/models/spree/variant_spec.rb | 22 ++++++------ spec/requests/checkout/stripe_connect_spec.rb | 2 +- spec/services/order_syncer_spec.rb | 10 +++--- 62 files changed, 168 insertions(+), 168 deletions(-) diff --git a/app/controllers/admin/bulk_line_items_controller.rb b/app/controllers/admin/bulk_line_items_controller.rb index 5437be7c45..99e3b68998 100644 --- a/app/controllers/admin/bulk_line_items_controller.rb +++ b/app/controllers/admin/bulk_line_items_controller.rb @@ -28,7 +28,7 @@ module Admin # See https://github.com/rails/rails/blob/3-2-stable/activerecord/lib/active_record/locking/pessimistic.rb#L69 # and https://www.postgresql.org/docs/current/static/sql-select.html#SQL-FOR-UPDATE-SHARE order.with_lock do - if @line_item.update_attributes(line_item_params) + if @line_item.update(line_item_params) order.update_distribution_charge! render nothing: true, status: :no_content # No Content, does not trigger ng resource auto-update else diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 479896f0b1..333926a728 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -47,7 +47,7 @@ module Admin tag_rules_attributes = params[object_name].delete :tag_rules_attributes update_tag_rules(tag_rules_attributes) if tag_rules_attributes.present? update_enterprise_notifications - if @object.update_attributes(enterprise_params) + if @object.update(enterprise_params) invoke_callbacks(:update, :after) flash[:success] = flash_message_for(@object, :successfully_updated) respond_with(@object) do |format| @@ -71,7 +71,7 @@ module Admin attributes = { sells: params[:sells], visible: true } - if @enterprise.update_attributes(attributes) + if @enterprise.update(attributes) flash[:success] = I18n.t(:enterprise_register_success_notice, enterprise: @enterprise.name) redirect_to admin_dashboard_path else @@ -214,7 +214,7 @@ module Admin rule = @object.tag_rules.find_by(id: attrs.delete(:id)) || attrs[:type].constantize.new(enterprise: @object) create_calculator_for(rule, attrs) if rule.type == "TagRule::DiscountOrder" && rule.calculator.nil? - rule.update_attributes(attrs) + rule.update(attrs) end end end @@ -227,7 +227,7 @@ module Admin def create_calculator_for(rule, attrs) if attrs[:calculator_type].present? && attrs[:calculator_attributes].present? - rule.update_attributes(calculator_type: attrs[:calculator_type]) + rule.update(calculator_type: attrs[:calculator_type]) attrs[:calculator_attributes].merge!( id: rule.calculator.id ) end end diff --git a/app/controllers/admin/subscriptions_controller.rb b/app/controllers/admin/subscriptions_controller.rb index f7dd07e236..c2c45bcef3 100644 --- a/app/controllers/admin/subscriptions_controller.rb +++ b/app/controllers/admin/subscriptions_controller.rb @@ -52,7 +52,7 @@ module Admin @subscription.proxy_orders.placed_and_open.each(&:cancel) end - @subscription.update_attributes(paused_at: Time.zone.now) + @subscription.update(paused_at: Time.zone.now) render_as_json @subscription end diff --git a/app/controllers/api/customers_controller.rb b/app/controllers/api/customers_controller.rb index 99c5834578..172d4580b8 100644 --- a/app/controllers/api/customers_controller.rb +++ b/app/controllers/api/customers_controller.rb @@ -11,7 +11,7 @@ module Api @customer = Customer.find(params[:id]) authorize! :update, @customer - if @customer.update_attributes(params[:customer]) + if @customer.update(params[:customer]) render json: @customer, serializer: CustomerSerializer, status: :ok else invalid_resource!(@customer) diff --git a/app/controllers/api/enterprise_attachment_controller.rb b/app/controllers/api/enterprise_attachment_controller.rb index a1f16ba41d..d9b619ab8e 100644 --- a/app/controllers/api/enterprise_attachment_controller.rb +++ b/app/controllers/api/enterprise_attachment_controller.rb @@ -14,7 +14,7 @@ module Api def destroy return respond_with_conflict(error: destroy_attachment_does_not_exist_error_message) unless @enterprise.public_send("#{attachment_name}?") - @enterprise.update_attributes!(attachment_name => nil) + @enterprise.update!(attachment_name => nil) render json: @enterprise, serializer: Admin::EnterpriseSerializer, spree_current_user: spree_current_user end diff --git a/app/controllers/api/enterprises_controller.rb b/app/controllers/api/enterprises_controller.rb index c7c96e843d..5b8d2f2bc4 100644 --- a/app/controllers/api/enterprises_controller.rb +++ b/app/controllers/api/enterprises_controller.rb @@ -25,7 +25,7 @@ module Api @enterprise = Enterprise.find_by(permalink: params[:id]) || Enterprise.find(params[:id]) authorize! :update, @enterprise - if @enterprise.update_attributes(params[:enterprise]) + if @enterprise.update(params[:enterprise]) render text: @enterprise.id, status: :ok else invalid_resource!(@enterprise) @@ -36,9 +36,9 @@ module Api @enterprise = Enterprise.find_by(permalink: params[:id]) || Enterprise.find(params[:id]) authorize! :update, @enterprise - if params[:logo] && @enterprise.update_attributes( logo: params[:logo] ) + if params[:logo] && @enterprise.update( logo: params[:logo] ) render text: @enterprise.logo.url(:medium), status: :ok - elsif params[:promo] && @enterprise.update_attributes( promo_image: params[:promo] ) + elsif params[:promo] && @enterprise.update( promo_image: params[:promo] ) render text: @enterprise.promo_image.url(:medium), status: :ok else invalid_resource!(@enterprise) diff --git a/app/controllers/api/product_images_controller.rb b/app/controllers/api/product_images_controller.rb index e7551aeea7..e688a03e6e 100644 --- a/app/controllers/api/product_images_controller.rb +++ b/app/controllers/api/product_images_controller.rb @@ -11,7 +11,7 @@ module Api render json: @image, serializer: ImageSerializer, status: :created else @image = @product.images.first - @image.update_attributes(attachment: params[:file]) + @image.update(attachment: params[:file]) render json: @image, serializer: ImageSerializer, status: :ok end end diff --git a/app/controllers/api/products_controller.rb b/app/controllers/api/products_controller.rb index 49246bc624..bc99830dcd 100644 --- a/app/controllers/api/products_controller.rb +++ b/app/controllers/api/products_controller.rb @@ -32,7 +32,7 @@ module Api def update authorize! :update, Spree::Product @product = find_product(params[:id]) - if @product.update_attributes(params[:product]) + if @product.update(params[:product]) render json: @product, serializer: Api::Admin::ProductSerializer, status: :ok else invalid_resource!(@product) diff --git a/app/controllers/api/shipments_controller.rb b/app/controllers/api/shipments_controller.rb index a3d973945f..99f03bef7a 100644 --- a/app/controllers/api/shipments_controller.rb +++ b/app/controllers/api/shipments_controller.rb @@ -30,7 +30,7 @@ module Api @shipment.adjustment.open end - @shipment.update_attributes(params[:shipment]) + @shipment.update(params[:shipment]) if unlock == 'yes' @shipment.adjustment.close @@ -88,7 +88,7 @@ module Api def find_and_update_shipment @shipment = @order.shipments.find_by!(number: params[:id]) - @shipment.update_attributes(params[:shipment]) + @shipment.update(params[:shipment]) @shipment.reload end diff --git a/app/controllers/api/taxons_controller.rb b/app/controllers/api/taxons_controller.rb index 68d9a6fdd8..cd0734054a 100644 --- a/app/controllers/api/taxons_controller.rb +++ b/app/controllers/api/taxons_controller.rb @@ -44,7 +44,7 @@ module Api def update authorize! :update, Spree::Taxon - if taxon.update_attributes(params[:taxon]) + if taxon.update(params[:taxon]) render json: taxon, serializer: Api::TaxonSerializer, status: :ok else invalid_resource!(taxon) diff --git a/app/controllers/api/variants_controller.rb b/app/controllers/api/variants_controller.rb index 2074c61b0d..af1f41d7b0 100644 --- a/app/controllers/api/variants_controller.rb +++ b/app/controllers/api/variants_controller.rb @@ -28,7 +28,7 @@ module Api def update authorize! :update, Spree::Variant @variant = scope.find(params[:id]) - if @variant.update_attributes(params[:variant]) + if @variant.update(params[:variant]) render json: @variant, serializer: Api::VariantSerializer, status: :ok else invalid_resource!(@product) diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index 6ef86318ca..8616f4f6ad 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -45,7 +45,7 @@ class CheckoutController < Spree::StoreController def update params_adapter = Checkout::FormDataAdapter.new(permitted_params, @order, spree_current_user) - return update_failed unless @order.update_attributes(params_adapter.params[:order]) + return update_failed unless @order.update(params_adapter.params[:order]) fire_event('spree.checkout.update') diff --git a/app/controllers/spree/admin/orders/customer_details_controller.rb b/app/controllers/spree/admin/orders/customer_details_controller.rb index d9d8a7355a..82c0c2347e 100644 --- a/app/controllers/spree/admin/orders/customer_details_controller.rb +++ b/app/controllers/spree/admin/orders/customer_details_controller.rb @@ -18,7 +18,7 @@ module Spree end def update - if @order.update_attributes(order_params) + if @order.update(order_params) if params[:guest_checkout] == "false" @order.associate_user!(Spree.user_class.find_by(email: @order.email)) end diff --git a/app/controllers/spree/admin/orders_controller.rb b/app/controllers/spree/admin/orders_controller.rb index a92f255242..22715108e9 100644 --- a/app/controllers/spree/admin/orders_controller.rb +++ b/app/controllers/spree/admin/orders_controller.rb @@ -44,7 +44,7 @@ module Spree end def update - unless @order.update_attributes(order_params) && @order.line_items.present? + unless @order.update(order_params) && @order.line_items.present? if @order.line_items.empty? @order.errors.add(:line_items, Spree.t('errors.messages.blank')) end diff --git a/app/controllers/spree/admin/payment_methods_controller.rb b/app/controllers/spree/admin/payment_methods_controller.rb index bb8265c1ff..8825e4ea69 100644 --- a/app/controllers/spree/admin/payment_methods_controller.rb +++ b/app/controllers/spree/admin/payment_methods_controller.rb @@ -40,7 +40,7 @@ module Spree @payment_method = PaymentMethod.find(params[:id]) end - if @payment_method.update_attributes(params_for_update) + if @payment_method.update(params_for_update) invoke_callbacks(:update, :after) flash[:success] = Spree.t(:successfully_updated, resource: Spree.t(:payment_method)) redirect_to edit_admin_payment_method_path(@payment_method) diff --git a/app/controllers/spree/admin/resource_controller.rb b/app/controllers/spree/admin/resource_controller.rb index b34f3729d4..fce4dc1e4c 100644 --- a/app/controllers/spree/admin/resource_controller.rb +++ b/app/controllers/spree/admin/resource_controller.rb @@ -28,7 +28,7 @@ module Spree def update invoke_callbacks(:update, :before) - if @object.update_attributes(permitted_resource_params) + if @object.update(permitted_resource_params) invoke_callbacks(:update, :after) flash[:success] = flash_message_for(@object, :successfully_updated) respond_with(@object) do |format| diff --git a/app/controllers/spree/admin/taxons_controller.rb b/app/controllers/spree/admin/taxons_controller.rb index fab6eaeb12..0b171567d2 100644 --- a/app/controllers/spree/admin/taxons_controller.rb +++ b/app/controllers/spree/admin/taxons_controller.rb @@ -81,7 +81,7 @@ module Spree @update_children = true end - if @taxon.update_attributes(taxon_params) + if @taxon.update(taxon_params) flash[:success] = flash_message_for(@taxon, :successfully_updated) end diff --git a/app/controllers/spree/admin/users_controller.rb b/app/controllers/spree/admin/users_controller.rb index dcdcbeb62e..e6ffeaa6cd 100644 --- a/app/controllers/spree/admin/users_controller.rb +++ b/app/controllers/spree/admin/users_controller.rb @@ -41,7 +41,7 @@ module Spree roles = params[:user].delete("spree_role_ids") end - if @user.update_attributes(user_params) + if @user.update(user_params) if roles @user.spree_roles = roles.reject(&:blank?).collect{ |r| Spree::Role.find(r) } end diff --git a/app/controllers/spree/credit_cards_controller.rb b/app/controllers/spree/credit_cards_controller.rb index 29be3b78d6..fe23cd5d6e 100644 --- a/app/controllers/spree/credit_cards_controller.rb +++ b/app/controllers/spree/credit_cards_controller.rb @@ -26,7 +26,7 @@ module Spree authorize! :update, @credit_card - if @credit_card.update_attributes(credit_card_params) + if @credit_card.update(credit_card_params) render json: @credit_card, serializer: ::Api::CreditCardSerializer, status: :ok else update_failed diff --git a/app/controllers/spree/orders_controller.rb b/app/controllers/spree/orders_controller.rb index a1c8409941..d77c4c0719 100644 --- a/app/controllers/spree/orders_controller.rb +++ b/app/controllers/spree/orders_controller.rb @@ -74,7 +74,7 @@ module Spree redirect_to(main_app.root_path) && return end - if @order.update_attributes(order_params) + if @order.update(order_params) discard_empty_line_items with_open_adjustments { update_totals_and_taxes } diff --git a/app/controllers/spree/users_controller.rb b/app/controllers/spree/users_controller.rb index c0bd3739b5..f524f8d465 100644 --- a/app/controllers/spree/users_controller.rb +++ b/app/controllers/spree/users_controller.rb @@ -39,7 +39,7 @@ module Spree end def update - if @user.update_attributes(user_params) + if @user.update(user_params) if params[:user][:password].present? # this logic needed b/c devise wants to log us out after password changes Spree::User.reset_password_by_token(params[:user]) diff --git a/app/helpers/i18n_helper.rb b/app/helpers/i18n_helper.rb index 3293d42d98..b316b3e3ce 100644 --- a/app/helpers/i18n_helper.rb +++ b/app/helpers/i18n_helper.rb @@ -2,13 +2,13 @@ module I18nHelper def set_locale # Save a given locale if params[:locale] && available_locale?(params[:locale]) - spree_current_user.update_attributes!(locale: params[:locale]) if spree_current_user + spree_current_user.update!(locale: params[:locale]) if spree_current_user cookies[:locale] = params[:locale] end # After logging in, check if the user chose a locale before if spree_current_user && spree_current_user.locale.nil? && cookies[:locale] - spree_current_user.update_attributes!(locale: params[:locale]) + spree_current_user.update!(locale: params[:locale]) end I18n.locale = spree_current_user.andand.locale || cookies[:locale] || I18n.default_locale diff --git a/app/jobs/subscription_placement_job.rb b/app/jobs/subscription_placement_job.rb index adfbe5cba1..8b5df2b159 100644 --- a/app/jobs/subscription_placement_job.rb +++ b/app/jobs/subscription_placement_job.rb @@ -54,7 +54,7 @@ class SubscriptionPlacementJob end unavailable_stock_lines_for(order).each do |line_item| changes[line_item.id] = changes[line_item.id] || line_item.quantity - line_item.update_attributes(quantity: 0) + line_item.update(quantity: 0) end changes end diff --git a/app/models/spree/adjustment_decorator.rb b/app/models/spree/adjustment_decorator.rb index dbbaa6ae95..8afe7bfb03 100644 --- a/app/models/spree/adjustment_decorator.rb +++ b/app/models/spree/adjustment_decorator.rb @@ -32,7 +32,7 @@ module Spree end def set_absolute_included_tax!(tax) - update_attributes! included_tax: tax.round(2) + update! included_tax: tax.round(2) end def display_included_tax diff --git a/app/models/spree/line_item_decorator.rb b/app/models/spree/line_item_decorator.rb index 5d22c0fbc4..c58b072892 100644 --- a/app/models/spree/line_item_decorator.rb +++ b/app/models/spree/line_item_decorator.rb @@ -87,7 +87,7 @@ Spree::LineItem.class_eval do scoper.scope(variant) return if variant.on_demand - update_attributes!(quantity: variant.on_hand) if quantity > variant.on_hand + update!(quantity: variant.on_hand) if quantity > variant.on_hand end def has_tax? diff --git a/app/models/spree/product_set.rb b/app/models/spree/product_set.rb index 5de24ddc52..408021c8e4 100644 --- a/app/models/spree/product_set.rb +++ b/app/models/spree/product_set.rb @@ -99,7 +99,7 @@ class Spree::ProductSet < ModelSet def create_or_update_variant(product, variant_attributes) variant = find_model(product.variants_including_master, variant_attributes[:id]) if variant.present? - variant.update_attributes(variant_attributes.except(:id)) + variant.update(variant_attributes.except(:id)) else create_variant(product, variant_attributes) end diff --git a/app/services/line_item_syncer.rb b/app/services/line_item_syncer.rb index e190db0be5..c8eb0da6dc 100644 --- a/app/services/line_item_syncer.rb +++ b/app/services/line_item_syncer.rb @@ -64,7 +64,7 @@ class LineItemSyncer def update_quantity(line_item, sli) if line_item.quantity == sli.quantity_was - return line_item.update_attributes(quantity: sli.quantity, + return line_item.update(quantity: sli.quantity, skip_stock_check: skip_stock_check?(line_item.order)) end line_item.quantity == sli.quantity diff --git a/app/services/order_factory.rb b/app/services/order_factory.rb index a7845618b0..bb2a99d018 100644 --- a/app/services/order_factory.rb +++ b/app/services/order_factory.rb @@ -66,7 +66,7 @@ class OrderFactory end def set_addresses - @order.update_attributes(attrs.slice(:bill_address_attributes, :ship_address_attributes)) + @order.update(attrs.slice(:bill_address_attributes, :ship_address_attributes)) end def create_shipment diff --git a/app/services/order_syncer.rb b/app/services/order_syncer.rb index 97f8066a03..98e4fc9a53 100644 --- a/app/services/order_syncer.rb +++ b/app/services/order_syncer.rb @@ -49,7 +49,7 @@ class OrderSyncer return order_update_issues.add(order, I18n.t('bill_address')) end - order.bill_address.update_attributes(bill_address.attributes.slice(*relevant_address_attrs)) + order.bill_address.update(bill_address.attributes.slice(*relevant_address_attrs)) end def update_payment_for(order) @@ -123,7 +123,7 @@ class OrderSyncer def save_ship_address_in_order(order) return unless ship_address_updatable?(order) - order.ship_address.update_attributes(ship_address.attributes.slice(*relevant_address_attrs)) + order.ship_address.update(ship_address.attributes.slice(*relevant_address_attrs)) end def pending_shipment_with?(order, shipping_method_id) diff --git a/app/services/user_default_address_setter.rb b/app/services/user_default_address_setter.rb index 812af8f61b..7a83078290 100644 --- a/app/services/user_default_address_setter.rb +++ b/app/services/user_default_address_setter.rb @@ -26,13 +26,13 @@ class UserDefaultAddressSetter private def set_bill_address_attributes(object, new_address) - object.update_attributes( + object.update( bill_address_attributes: new_address.merge('id' => object.bill_address.andand.id) ) end def set_ship_address_attributes(object, new_address) - object.update_attributes( + object.update( ship_address_attributes: new_address.merge('id' => object.ship_address.andand.id) ) end diff --git a/lib/open_food_network/order_cycle_form_applicator.rb b/lib/open_food_network/order_cycle_form_applicator.rb index f42fd427a9..960508f06d 100644 --- a/lib/open_food_network/order_cycle_form_applicator.rb +++ b/lib/open_food_network/order_cycle_form_applicator.rb @@ -83,7 +83,7 @@ module OpenFoodNetwork remove_unauthorized_exchange_attributes(exchange, attrs) variant_ids = attrs.delete :variant_ids - exchange.update_attributes!(attrs) + exchange.update!(attrs) ExchangeVariantBulkUpdater.new(exchange).update!(variant_ids) unless variant_ids.nil? @touched_exchanges << exchange diff --git a/lib/stripe/profile_storer.rb b/lib/stripe/profile_storer.rb index eb5212a1d2..f3176fcf9a 100644 --- a/lib/stripe/profile_storer.rb +++ b/lib/stripe/profile_storer.rb @@ -15,7 +15,7 @@ module Stripe if response.success? attrs = source_attrs_from(response) - @payment.source.update_attributes!(attrs) + @payment.source.update!(attrs) else @payment.__send__(:gateway_error, response.message) end diff --git a/spec/controllers/admin/proxy_orders_controller_spec.rb b/spec/controllers/admin/proxy_orders_controller_spec.rb index d827732558..1d612e2c57 100644 --- a/spec/controllers/admin/proxy_orders_controller_spec.rb +++ b/spec/controllers/admin/proxy_orders_controller_spec.rb @@ -27,7 +27,7 @@ describe Admin::ProxyOrdersController, type: :controller do context 'as an enterprise user' do context "without authorisation" do let!(:shop2) { create(:distributor_enterprise) } - before { shop2.update_attributes(owner: user) } + before { shop2.update(owner: user) } it 'redirects to unauthorized' do spree_put :cancel, params @@ -36,7 +36,7 @@ describe Admin::ProxyOrdersController, type: :controller do end context "with authorisation" do - before { shop.update_attributes(owner: user) } + before { shop.update(owner: user) } context "when cancellation succeeds" do it 'renders the cancelled proxy_order as json' do @@ -49,7 +49,7 @@ describe Admin::ProxyOrdersController, type: :controller do end context "when cancellation fails" do - before { order_cycle.update_attributes(orders_close_at: 1.day.ago) } + before { order_cycle.update(orders_close_at: 1.day.ago) } it "shows an error" do spree_get :cancel, params @@ -96,7 +96,7 @@ describe Admin::ProxyOrdersController, type: :controller do context 'as an enterprise user' do context "without authorisation" do let!(:shop2) { create(:distributor_enterprise) } - before { shop2.update_attributes(owner: user) } + before { shop2.update(owner: user) } it 'redirects to unauthorized' do spree_put :resume, params @@ -105,7 +105,7 @@ describe Admin::ProxyOrdersController, type: :controller do end context "with authorisation" do - before { shop.update_attributes(owner: user) } + before { shop.update(owner: user) } context "when resuming succeeds" do it 'renders the resumed proxy_order as json' do @@ -118,7 +118,7 @@ describe Admin::ProxyOrdersController, type: :controller do end context "when resuming fails" do - before { order_cycle.update_attributes(orders_close_at: 1.day.ago) } + before { order_cycle.update(orders_close_at: 1.day.ago) } it "shows an error" do spree_get :resume, params diff --git a/spec/controllers/admin/subscriptions_controller_spec.rb b/spec/controllers/admin/subscriptions_controller_spec.rb index 445ec70ff7..c7f0e207a4 100644 --- a/spec/controllers/admin/subscriptions_controller_spec.rb +++ b/spec/controllers/admin/subscriptions_controller_spec.rb @@ -23,7 +23,7 @@ describe Admin::SubscriptionsController, type: :controller do end context 'as an enterprise user' do - before { shop.update_attributes(owner: user) } + before { shop.update(owner: user) } let!(:not_enabled_shop) { create(:distributor_enterprise, owner: user) } context "where I manage a shop that is set up for subscriptions" do @@ -60,7 +60,7 @@ describe Admin::SubscriptionsController, type: :controller do end context 'as an enterprise user' do - before { shop.update_attributes(owner: user) } + before { shop.update(owner: user) } let!(:shop2) { create(:distributor_enterprise, owner: user) } let!(:subscription2) { create(:subscription, shop: shop2) } @@ -357,7 +357,7 @@ describe Admin::SubscriptionsController, type: :controller do end context 'where the specified variants are available from the shop' do - before { outgoing_exchange.update_attributes(variants: [variant1, variant2]) } + before { outgoing_exchange.update(variants: [variant1, variant2]) } it 'creates subscription line items for the subscription' do expect{ spree_post :update, params }.to change{ subscription.subscription_line_items.count }.by(1) @@ -397,7 +397,7 @@ describe Admin::SubscriptionsController, type: :controller do context 'as an enterprise user' do context "without authorisation" do let!(:shop2) { create(:distributor_enterprise) } - before { shop2.update_attributes(owner: user) } + before { shop2.update(owner: user) } it 'redirects to unauthorized' do spree_put :cancel, params @@ -406,7 +406,7 @@ describe Admin::SubscriptionsController, type: :controller do end context "with authorisation" do - before { shop.update_attributes(owner: user) } + before { shop.update(owner: user) } context "when at least one associated order is still 'open'" do let(:order_cycle) { subscription.order_cycles.first } @@ -496,7 +496,7 @@ describe Admin::SubscriptionsController, type: :controller do context 'as an enterprise user' do context "without authorisation" do let!(:shop2) { create(:distributor_enterprise) } - before { shop2.update_attributes(owner: user) } + before { shop2.update(owner: user) } it 'redirects to unauthorized' do spree_put :pause, params @@ -505,7 +505,7 @@ describe Admin::SubscriptionsController, type: :controller do end context "with authorisation" do - before { shop.update_attributes(owner: user) } + before { shop.update(owner: user) } context "when at least one associated order is still 'open'" do let(:order_cycle) { subscription.order_cycles.first } @@ -595,7 +595,7 @@ describe Admin::SubscriptionsController, type: :controller do context 'as an enterprise user' do context "without authorisation" do let!(:shop2) { create(:distributor_enterprise) } - before { shop2.update_attributes(owner: user) } + before { shop2.update(owner: user) } it 'redirects to unauthorized' do spree_put :unpause, params @@ -604,7 +604,7 @@ describe Admin::SubscriptionsController, type: :controller do end context "with authorisation" do - before { shop.update_attributes(owner: user) } + before { shop.update(owner: user) } context "when at least one order in an open order cycle is 'complete'" do let(:order_cycle) { subscription.order_cycles.first } diff --git a/spec/controllers/api/orders_controller_spec.rb b/spec/controllers/api/orders_controller_spec.rb index 4189ccc650..726756734d 100644 --- a/spec/controllers/api/orders_controller_spec.rb +++ b/spec/controllers/api/orders_controller_spec.rb @@ -212,7 +212,7 @@ module Api before { allow(controller).to receive(:spree_current_user) { order.distributor.owner } } it "can view an order not in a standard state" do - order.update_attributes(completed_at: nil, state: 'shipped') + order.update(completed_at: nil, state: 'shipped') get :show, id: order.number expect_order end diff --git a/spec/controllers/line_items_controller_spec.rb b/spec/controllers/line_items_controller_spec.rb index 116a05ef2f..815903abc0 100644 --- a/spec/controllers/line_items_controller_spec.rb +++ b/spec/controllers/line_items_controller_spec.rb @@ -132,7 +132,7 @@ describe LineItemsController, type: :controller do let!(:exchange) { create(:exchange, incoming: true, sender: variant.product.supplier, receiver: order_cycle.coordinator, variants: [variant], enterprise_fees: [enterprise_fee]) } let!(:order) do order = create(:completed_order_with_totals, user: user, distributor: distributor, order_cycle: order_cycle, line_items_count: 1) - order.reload.line_items.first.update_attributes(variant_id: variant.id) + order.reload.line_items.first.update(variant_id: variant.id) while !order.completed? do break unless order.next! end order.update_distribution_charge! order diff --git a/spec/controllers/spree/admin/payment_methods_controller_spec.rb b/spec/controllers/spree/admin/payment_methods_controller_spec.rb index ff23298c44..dfc7dd307e 100644 --- a/spec/controllers/spree/admin/payment_methods_controller_spec.rb +++ b/spec/controllers/spree/admin/payment_methods_controller_spec.rb @@ -69,7 +69,7 @@ module Spree end context "as a user that manages the existing stripe account holder" do - before { enterprise2.update_attributes!(owner_id: user.id) } + before { enterprise2.update!(owner_id: user.id) } it "allows the stripe account holder to be updated" do spree_put :update, params diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index 783c868366..2917b1a8ab 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -155,7 +155,7 @@ describe Spree::OrdersController, type: :controller do describe "when an item has insufficient stock" do before do - variant.update_attributes! on_hand: 3 + variant.update! on_hand: 3 end it "displays a flash message when we view the cart" do @@ -279,7 +279,7 @@ describe Spree::OrdersController, type: :controller do let!(:exchange) { create(:exchange, incoming: true, sender: variant.product.supplier, receiver: order_cycle.coordinator, variants: [variant], enterprise_fees: [enterprise_fee]) } let!(:order) do order = create(:completed_order_with_totals, line_items_count: 1, user: user, distributor: distributor, order_cycle: order_cycle) - order.reload.line_items.first.update_attributes(variant_id: variant.id) + order.reload.line_items.first.update(variant_id: variant.id) while !order.completed? do break unless order.next! end order.update_distribution_charge! order diff --git a/spec/features/admin/subscriptions_spec.rb b/spec/features/admin/subscriptions_spec.rb index a8dc01ed22..61d5f59bcd 100644 --- a/spec/features/admin/subscriptions_spec.rb +++ b/spec/features/admin/subscriptions_spec.rb @@ -19,9 +19,9 @@ feature 'Subscriptions' do let!(:subscription_unmanaged) { create(:subscription, shop: shop_unmanaged, with_items: true, with_proxy_orders: true) } before do - subscription.update_attributes(shipping_fee_estimate: 3.5) + subscription.update(shipping_fee_estimate: 3.5) subscription.subscription_line_items.each do |sli| - sli.update_attributes(price_estimate: 5) + sli.update(price_estimate: 5) end end @@ -412,7 +412,7 @@ feature 'Subscriptions' do let(:order) { proxy_order.initialise_order! } let(:line_item) { order.line_items.first } - before { line_item.update_attributes(quantity: 3) } + before { line_item.update(quantity: 3) } it "reports issues encountered during the update" do visit edit_admin_subscription_path(subscription) diff --git a/spec/features/admin/variant_overrides_spec.rb b/spec/features/admin/variant_overrides_spec.rb index 5f48c35fd2..1fb6e15981 100644 --- a/spec/features/admin/variant_overrides_spec.rb +++ b/spec/features/admin/variant_overrides_spec.rb @@ -471,8 +471,8 @@ feature " end first_variant = inventory_items.first.variant last_variant = inventory_items.last.variant - first_variant.product.update_attributes!(name: "A First Product") - last_variant.product.update_attributes!(name: "Z Last Product") + first_variant.product.update!(name: "A First Product") + last_variant.product.update!(name: "Z Last Product") quick_login_as supplier.users.first visit admin_inventory_path diff --git a/spec/features/admin/variants_spec.rb b/spec/features/admin/variants_spec.rb index 450fb96621..700c375954 100644 --- a/spec/features/admin/variants_spec.rb +++ b/spec/features/admin/variants_spec.rb @@ -29,7 +29,7 @@ feature ' # Given a product with unit-related option types, with a variant product = create(:simple_product, variant_unit: "weight", variant_unit_scale: "1") variant = product.variants.first - variant.update_attributes( unit_value: 1, unit_description: 'foo' ) + variant.update( unit_value: 1, unit_description: 'foo' ) # And the product has option types for the unit-related and non-unit-related option values product.option_types << variant.option_values.first.option_type @@ -60,7 +60,7 @@ feature ' scenario "can update unit_description when variant_unit is items" do product = create(:simple_product, variant_unit: "items", variant_unit_name: "bunches") variant = product.variants.first - variant.update_attributes(unit_description: 'foo') + variant.update(unit_description: 'foo') login_to_admin_section visit spree.edit_admin_product_variant_path(product, variant) diff --git a/spec/features/consumer/account_spec.rb b/spec/features/consumer/account_spec.rb index 8985aaeee3..bdba76c971 100644 --- a/spec/features/consumer/account_spec.rb +++ b/spec/features/consumer/account_spec.rb @@ -76,7 +76,7 @@ feature ' context "when there is at least one changeable order" do before do - distributor1.update_attributes(allow_order_changes: true) + distributor1.update(allow_order_changes: true) end it "shows such orders in a section labelled 'Open Orders'" do diff --git a/spec/features/consumer/registration_spec.rb b/spec/features/consumer/registration_spec.rb index ed0c2f96b1..0e9f1b221c 100644 --- a/spec/features/consumer/registration_spec.rb +++ b/spec/features/consumer/registration_spec.rb @@ -132,7 +132,7 @@ feature "Registration", js: true do context "when the user has no more remaining enterprises" do before do - user.update_attributes(enterprise_limit: 0) + user.update(enterprise_limit: 0) end it "displays the limit reached page" do diff --git a/spec/features/consumer/shopping/cart_spec.rb b/spec/features/consumer/shopping/cart_spec.rb index e7785dcdb4..194b202d26 100644 --- a/spec/features/consumer/shopping/cart_spec.rb +++ b/spec/features/consumer/shopping/cart_spec.rb @@ -123,8 +123,8 @@ feature "full-page cart", js: true do } before do - product_with_fee.variants.first.update_attributes(unit_value: '2000.0') - product_with_tax.variants.first.update_attributes(unit_value: '5000.0') + product_with_fee.variants.first.update(unit_value: '2000.0') + product_with_tax.variants.first.update(unit_value: '5000.0') add_enterprise_fee admin_fee @@ -167,7 +167,7 @@ feature "full-page cart", js: true do describe "when on_hand is zero but variant is on demand" do it "allows updating the quantity" do - variant.update_attributes!(on_hand: 0, on_demand: true) + variant.update!(on_hand: 0, on_demand: true) visit main_app.cart_path fill_in "order_line_items_attributes_0_quantity", with: '5' @@ -179,8 +179,8 @@ feature "full-page cart", js: true do it "prevents user from entering invalid values" do add_product_to_cart order, product_with_fee - variant.update_attributes!(on_hand: 2, on_demand: false) - variant2.update_attributes!(on_hand: 3, on_demand: false) + variant.update!(on_hand: 2, on_demand: false) + variant2.update!(on_hand: 3, on_demand: false) visit main_app.cart_path accept_alert 'Insufficient stock available, only 2 remaining' do @@ -200,10 +200,10 @@ feature "full-page cart", js: true do it "shows the quantities saved, not those submitted" do # Given we load the page with 3 on hand, then the number available drops to 2 - variant.update_attributes! on_demand: false - variant.update_attributes! on_hand: 3 + variant.update! on_demand: false + variant.update! on_hand: 3 visit main_app.cart_path - variant.update_attributes! on_hand: 2 + variant.update! on_hand: 2 accept_alert do fill_in "order_line_items_attributes_0_quantity", with: '4' @@ -217,7 +217,7 @@ feature "full-page cart", js: true do describe "full UX for correcting selected quantities with insufficient stock" do before do add_product_to_cart order, product_with_tax, quantity: 5 - variant.update_attributes! on_hand: 4, on_demand: false + variant.update! on_hand: 4, on_demand: false end it "gives clear user feedback during the correcting process" do diff --git a/spec/features/consumer/shopping/orders_spec.rb b/spec/features/consumer/shopping/orders_spec.rb index 2bb40d6dd5..4f2a379c12 100644 --- a/spec/features/consumer/shopping/orders_spec.rb +++ b/spec/features/consumer/shopping/orders_spec.rb @@ -105,7 +105,7 @@ feature "Order Management", js: true do let!(:item3) { create(:line_item, order: order) } before do - order.shipment.shipping_method.calculator.update_attributes(preferred_amount: 5.0) + order.shipment.shipping_method.calculator.update(preferred_amount: 5.0) order.save order.reload @@ -119,7 +119,7 @@ feature "Order Management", js: true do context "when the distributor doesn't allow changes to be made to orders" do before do - order.distributor.update_attributes(allow_order_changes: false) + order.distributor.update(allow_order_changes: false) end it "doesn't show form elements for editing the order" do @@ -136,7 +136,7 @@ feature "Order Management", js: true do setup_email end before do - order.distributor.update_attributes(allow_order_changes: true) + order.distributor.update(allow_order_changes: true) end it "allows quantity to be changed, items to be removed and the order to be cancelled" do diff --git a/spec/features/consumer/shopping/shopping_spec.rb b/spec/features/consumer/shopping/shopping_spec.rb index b5a0769e8c..b947b23d3d 100644 --- a/spec/features/consumer/shopping/shopping_spec.rb +++ b/spec/features/consumer/shopping/shopping_spec.rb @@ -222,7 +222,7 @@ feature "As a consumer I want to shop with a distributor", js: true do context "when the distributor has no available payment/shipping methods" do before do - distributor.update_attributes shipping_methods: [], payment_methods: [] + distributor.update shipping_methods: [], payment_methods: [] end # Display only shops are a very useful hack that is described in the user guide @@ -310,7 +310,7 @@ feature "As a consumer I want to shop with a distributor", js: true do end it "lets us add a quantity greater than on_hand value if product is on_demand" do - variant.update_attributes on_hand: 5, on_demand: true + variant.update on_hand: 5, on_demand: true visit shop_path fill_in "variants[#{variant.id}]", with: '10' @@ -319,7 +319,7 @@ feature "As a consumer I want to shop with a distributor", js: true do end it "alerts us when we enter a quantity greater than the stock available" do - variant.update_attributes on_hand: 5 + variant.update on_hand: 5 visit shop_path accept_alert 'Insufficient stock available, only 5 remaining' do @@ -333,7 +333,7 @@ feature "As a consumer I want to shop with a distributor", js: true do it "stops the attempt, shows an error message and refreshes the products asynchronously" do expect(page).to have_content "Product" - variant.update_attributes! on_hand: 0 + variant.update! on_hand: 0 # -- Messaging expect(page).to have_input "variants[#{variant.id}]" @@ -360,7 +360,7 @@ feature "As a consumer I want to shop with a distributor", js: true do it 'does not show out of stock modal if product is on_demand' do expect(page).to have_content "Product" - variant.update_attributes! on_hand: 0, on_demand: true + variant.update! on_hand: 0, on_demand: true expect(page).to have_input "variants[#{variant.id}]" fill_in "variants[#{variant.id}]", with: '1' @@ -376,7 +376,7 @@ feature "As a consumer I want to shop with a distributor", js: true do # -- Place in cart so we can set max_quantity, then make out of stock fill_in "variants[#{variant.id}]", with: '1' wait_until { !cart_dirty } - variant.update_attributes! on_hand: 0 + variant.update! on_hand: 0 # -- Messaging fill_in "variant_attributes[#{variant.id}][max_quantity]", with: '1' @@ -403,7 +403,7 @@ feature "As a consumer I want to shop with a distributor", js: true do fill_in "variants[#{variant.id}]", with: '2' wait_until { !cart_dirty } - variant.update_attributes! on_hand: 1 + variant.update! on_hand: 1 fill_in "variants[#{variant2.id}]", with: '1' wait_until { !cart_dirty } @@ -421,7 +421,7 @@ feature "As a consumer I want to shop with a distributor", js: true do fill_in "variants[#{variant.id}]", with: '2' fill_in "variant_attributes[#{variant.id}][max_quantity]", with: '3' wait_until { !cart_dirty } - variant.update_attributes! on_hand: 1 + variant.update! on_hand: 1 fill_in "variants[#{variant2.id}]", with: '1' wait_until { !cart_dirty } diff --git a/spec/jobs/subscription_confirm_job_spec.rb b/spec/jobs/subscription_confirm_job_spec.rb index a061d0fbd4..603da10a10 100644 --- a/spec/jobs/subscription_confirm_job_spec.rb +++ b/spec/jobs/subscription_confirm_job_spec.rb @@ -27,22 +27,22 @@ describe SubscriptionConfirmJob do end it "returns proxy orders for paused subscriptions" do - subscription.update_attributes!(paused_at: 1.minute.ago) + subscription.update!(paused_at: 1.minute.ago) expect(proxy_orders).to include proxy_order end it "returns proxy orders for cancelled subscriptions" do - subscription.update_attributes!(canceled_at: 1.minute.ago) + subscription.update!(canceled_at: 1.minute.ago) expect(proxy_orders).to include proxy_order end it "ignores proxy orders where the OC closed more than 1 hour ago" do - proxy_order.update_attributes!(order_cycle_id: order_cycle2.id) + proxy_order.update!(order_cycle_id: order_cycle2.id) expect(proxy_orders).to_not include proxy_order end it "ignores cancelled proxy orders" do - proxy_order.update_attributes!(canceled_at: 5.minutes.ago) + proxy_order.update!(canceled_at: 5.minutes.ago) expect(proxy_orders).to_not include proxy_order end @@ -53,17 +53,17 @@ describe SubscriptionConfirmJob do end it "ignores proxy orders without an associated order" do - proxy_order.update_attributes!(order_id: nil) + proxy_order.update!(order_id: nil) expect(proxy_orders).to_not include proxy_order end it "ignores proxy orders that haven't been placed yet" do - proxy_order.update_attributes!(placed_at: nil) + proxy_order.update!(placed_at: nil) expect(proxy_orders).to_not include proxy_order end it "ignores proxy orders that have already been confirmed" do - proxy_order.update_attributes!(confirmed_at: 1.second.ago) + proxy_order.update!(confirmed_at: 1.second.ago) expect(proxy_orders).to_not include proxy_order end diff --git a/spec/jobs/subscription_placement_job_spec.rb b/spec/jobs/subscription_placement_job_spec.rb index e43343e795..fc7ca9177c 100644 --- a/spec/jobs/subscription_placement_job_spec.rb +++ b/spec/jobs/subscription_placement_job_spec.rb @@ -13,27 +13,27 @@ describe SubscriptionPlacementJob do it "ignores proxy orders where the OC has closed" do expect(job.send(:proxy_orders)).to include proxy_order - proxy_order.update_attributes!(order_cycle_id: order_cycle2.id) + proxy_order.update!(order_cycle_id: order_cycle2.id) expect(job.send(:proxy_orders)).to_not include proxy_order end it "ignores proxy orders for paused or cancelled subscriptions" do expect(job.send(:proxy_orders)).to include proxy_order - subscription.update_attributes!(paused_at: 1.minute.ago) + subscription.update!(paused_at: 1.minute.ago) expect(job.send(:proxy_orders)).to_not include proxy_order - subscription.update_attributes!(paused_at: nil) + subscription.update!(paused_at: nil) expect(job.send(:proxy_orders)).to include proxy_order - subscription.update_attributes!(canceled_at: 1.minute.ago) + subscription.update!(canceled_at: 1.minute.ago) expect(job.send(:proxy_orders)).to_not include proxy_order end it "ignores proxy orders that have been marked as cancelled or placed" do expect(job.send(:proxy_orders)).to include proxy_order - proxy_order.update_attributes!(canceled_at: 5.minutes.ago) + proxy_order.update!(canceled_at: 5.minutes.ago) expect(job.send(:proxy_orders)).to_not include proxy_order - proxy_order.update_attributes!(canceled_at: nil) + proxy_order.update!(canceled_at: nil) expect(job.send(:proxy_orders)).to include proxy_order - proxy_order.update_attributes!(placed_at: 5.minutes.ago) + proxy_order.update!(placed_at: 5.minutes.ago) expect(job.send(:proxy_orders)).to_not include proxy_order end end diff --git a/spec/models/customer_spec.rb b/spec/models/customer_spec.rb index 217748bb6d..6a35547e1d 100644 --- a/spec/models/customer_spec.rb +++ b/spec/models/customer_spec.rb @@ -32,7 +32,7 @@ describe Customer, type: :model do phone: "455500146", address1: "U 3/32 Florence Road Surrey Hills2", country_id: 1 } - customer.update_attributes!(ship_address_attributes: ship_address) + customer.update!(ship_address_attributes: ship_address) expect(customer.ship_address.city).to eq 'Melbourne' expect(customer.ship_address.firstname).to eq 'fname' diff --git a/spec/models/enterprise_caching_spec.rb b/spec/models/enterprise_caching_spec.rb index 2fe4bd3f7a..6160481c91 100644 --- a/spec/models/enterprise_caching_spec.rb +++ b/spec/models/enterprise_caching_spec.rb @@ -32,7 +32,7 @@ describe Enterprise do it "touches enterprise when the supplier of a product changes" do expect { - product.update_attributes!(supplier: supplier2) + product.update!(supplier: supplier2) }.to change { enterprise.reload.updated_at } end end @@ -67,7 +67,7 @@ describe Enterprise do it "touches enterprise when the supplier of a product changes" do expect { - product.update_attributes!(supplier: supplier2) + product.update!(supplier: supplier2) }.to change { enterprise.reload.updated_at } end end diff --git a/spec/models/exchange_spec.rb b/spec/models/exchange_spec.rb index bb34404469..b6c2f80b9c 100644 --- a/spec/models/exchange_spec.rb +++ b/spec/models/exchange_spec.rb @@ -152,8 +152,8 @@ describe Exchange do end it "correctly determines direction of exchanges between the same enterprise" do - incoming_exchange.update_attributes sender: coordinator, incoming: true - outgoing_exchange.update_attributes receiver: coordinator, incoming: false + incoming_exchange.update sender: coordinator, incoming: true + outgoing_exchange.update receiver: coordinator, incoming: false expect(Exchange.incoming).to eq([incoming_exchange]) expect(Exchange.outgoing).to eq([outgoing_exchange]) end diff --git a/spec/models/order_cycle_spec.rb b/spec/models/order_cycle_spec.rb index 21cad530a9..e329297f91 100644 --- a/spec/models/order_cycle_spec.rb +++ b/spec/models/order_cycle_spec.rb @@ -319,7 +319,7 @@ describe OrderCycle do end it "reports status when an order cycle is undated" do - oc.update_attributes!(orders_open_at: nil, orders_close_at: nil) + oc.update!(orders_open_at: nil, orders_close_at: nil) expect(oc).to be_undated expect(oc).not_to be_dated @@ -329,7 +329,7 @@ describe OrderCycle do end it "reports status when an order cycle is partially dated - opening time only" do - oc.update_attributes!(orders_close_at: nil) + oc.update!(orders_close_at: nil) expect(oc).to be_undated expect(oc).not_to be_dated @@ -339,7 +339,7 @@ describe OrderCycle do end it "reports status when an order cycle is partially dated - closing time only" do - oc.update_attributes!(orders_open_at: nil) + oc.update!(orders_open_at: nil) expect(oc).to be_undated expect(oc).not_to be_dated diff --git a/spec/models/proxy_order_spec.rb b/spec/models/proxy_order_spec.rb index 77bd5a989c..ee6e30cbdc 100644 --- a/spec/models/proxy_order_spec.rb +++ b/spec/models/proxy_order_spec.rb @@ -12,7 +12,7 @@ describe ProxyOrder, type: :model do context "when the order cycle is not yet closed" do let(:proxy_order) { create(:proxy_order, subscription: subscription, order: order, order_cycle: order_cycle) } - before { order_cycle.update_attributes(orders_open_at: 1.day.ago, orders_close_at: 3.days.from_now) } + before { order_cycle.update(orders_open_at: 1.day.ago, orders_close_at: 3.days.from_now) } context "and an order has not been initialised" do let(:order) { nil } @@ -50,7 +50,7 @@ describe ProxyOrder, type: :model do context "when the order cycle is already closed" do let(:proxy_order) { create(:proxy_order, subscription: subscription, order: order, order_cycle: order_cycle) } - before { order_cycle.update_attributes(orders_open_at: 3.days.ago, orders_close_at: 1.minute.ago) } + before { order_cycle.update(orders_open_at: 3.days.ago, orders_close_at: 1.minute.ago) } context "and an order has not been initialised" do let(:order) { nil } @@ -91,7 +91,7 @@ describe ProxyOrder, type: :model do end context "when the order cycle is not yet closed" do - before { order_cycle.update_attributes(orders_open_at: 1.day.ago, orders_close_at: 3.days.from_now) } + before { order_cycle.update(orders_open_at: 1.day.ago, orders_close_at: 3.days.from_now) } context "and the order has not been initialised" do let(:order) { nil } @@ -131,7 +131,7 @@ describe ProxyOrder, type: :model do end context "when the order cycle is already closed" do - before { order_cycle.update_attributes(orders_open_at: 3.days.ago, orders_close_at: 1.minute.ago) } + before { order_cycle.update(orders_open_at: 3.days.ago, orders_close_at: 1.minute.ago) } context "and the order has not been initialised" do let(:order) { nil } @@ -188,7 +188,7 @@ describe ProxyOrder, type: :model do let(:existing_order) { create(:order) } before do - proxy_order.update_attributes(order: existing_order) + proxy_order.update(order: existing_order) end it "returns the existing order" do diff --git a/spec/models/spree/adjustment_spec.rb b/spec/models/spree/adjustment_spec.rb index bed9737151..57047457ac 100644 --- a/spec/models/spree/adjustment_spec.rb +++ b/spec/models/spree/adjustment_spec.rb @@ -117,7 +117,7 @@ module Spree end it "records 0% tax on shipments when the distributor does not charge sales tax" do - order.distributor.update_attributes! charges_sales_tax: false + order.distributor.update! charges_sales_tax: false order.shipments = [shipment] expect(order.adjustments.first.included_tax).to eq(0) diff --git a/spec/models/spree/credit_card_spec.rb b/spec/models/spree/credit_card_spec.rb index 99f04e1362..845b1dd84a 100644 --- a/spec/models/spree/credit_card_spec.rb +++ b/spec/models/spree/credit_card_spec.rb @@ -46,7 +46,7 @@ module Spree context "without specifying it as the default" do it "keeps the existing default" do - card2.update_attributes!(stored_card_attrs) + card2.update!(stored_card_attrs) expect(card1.reload.is_default).to be true expect(card2.reload.is_default).to be false @@ -55,7 +55,7 @@ module Spree context "and I specify it as the default" do it "switches the default to the updated card" do - card2.update_attributes!(stored_default_card_attrs) + card2.update!(stored_default_card_attrs) expect(card1.reload.is_default).to be false expect(card2.reload.is_default).to be true @@ -101,7 +101,7 @@ module Spree # The checkout first creates a one-time card and then converts it # to a re-usable card. # This imitates Stripe::ProfileStorer. - card1.update_attributes!(store_card_profile_attrs) + card1.update!(store_card_profile_attrs) expect(card1.reload.is_default).to be true end end diff --git a/spec/models/spree/line_item_spec.rb b/spec/models/spree/line_item_spec.rb index 136381f881..ca4a5353d9 100644 --- a/spec/models/spree/line_item_spec.rb +++ b/spec/models/spree/line_item_spec.rb @@ -67,7 +67,7 @@ module Spree let!(:li) { create(:line_item, variant: v, quantity: 10, max_quantity: 10) } before do - v.update_attributes! on_hand: 5 + v.update! on_hand: 5 end it "caps quantity" do @@ -89,7 +89,7 @@ module Spree end it "does nothing for on_demand items" do - v.update_attributes! on_demand: true + v.update! on_demand: true li.cap_quantity_at_stock! li.reload expect(li.quantity).to eq 10 @@ -97,7 +97,7 @@ module Spree end it "caps at zero when stock is negative" do - v.update_attributes! on_hand: -2 + v.update! on_hand: -2 li.cap_quantity_at_stock! expect(li.reload.quantity).to eq 0 end @@ -107,7 +107,7 @@ module Spree let!(:vo) { create(:variant_override, hub: hub, variant: v, count_on_hand: 2) } before do - li.order.update_attributes(distributor_id: hub.id) + li.order.update(distributor_id: hub.id) # li#scoper is memoised, and this makes it difficult to update test conditions # so we reset it after the line_item is created for each spec @@ -120,10 +120,10 @@ module Spree end context "when count on hand is negative" do - before { vo.update_attributes(count_on_hand: -3) } + before { vo.update(count_on_hand: -3) } it "caps at zero" do - v.update_attributes(on_hand: -2) + v.update(on_hand: -2) li.cap_quantity_at_stock! expect(li.reload.quantity).to eq 0 end @@ -260,7 +260,7 @@ module Spree end context "when the stock on the variant is not sufficient" do - before { v.update_attributes(on_hand: 4) } + before { v.update(on_hand: 4) } context "when no variant override is in place" do it { expect(li.sufficient_stock?).to be false } @@ -274,7 +274,7 @@ module Spree end context "and stock on the variant override is not sufficient" do - before { vo.update_attributes(count_on_hand: 4) } + before { vo.update(count_on_hand: 4) } it { expect(li.sufficient_stock?).to be false } end @@ -375,7 +375,7 @@ module Spree context "and quantity is not changed" do before do - li.update_attributes(attrs) + li.update(attrs) end it "uses the value given" do @@ -386,7 +386,7 @@ module Spree context "and quantity is changed" do before do attrs[:quantity] = 4 - li.update_attributes(attrs) + li.update(attrs) end it "uses the value given" do @@ -400,7 +400,7 @@ module Spree context "and quantity is not changed" do before do - li.update_attributes(attrs) + li.update(attrs) end it "does not change final_weight_volume" do @@ -414,7 +414,7 @@ module Spree before do expect(li.final_weight_volume).to eq 3000 attrs[:quantity] = 4 - li.update_attributes(attrs) + li.update(attrs) end it "scales the final_weight_volume based on the change in quantity" do @@ -424,9 +424,9 @@ module Spree context "and a final_weight_volume has not been set" do before do - li.update_attributes(final_weight_volume: nil) + li.update(final_weight_volume: nil) attrs[:quantity] = 1 - li.update_attributes(attrs) + li.update(attrs) end it "calculates a final_weight_volume from the variants unit_value" do @@ -436,13 +436,13 @@ module Spree end context "from 0" do - before { li.update_attributes(quantity: 0) } + before { li.update(quantity: 0) } context "and a final_weight_volume has been set" do before do expect(li.final_weight_volume).to eq 0 attrs[:quantity] = 4 - li.update_attributes(attrs) + li.update(attrs) end it "recalculates a final_weight_volume from the variants unit_value" do @@ -452,9 +452,9 @@ module Spree context "and a final_weight_volume has not been set" do before do - li.update_attributes(final_weight_volume: nil) + li.update(final_weight_volume: nil) attrs[:quantity] = 1 - li.update_attributes(attrs) + li.update(attrs) end it "calculates a final_weight_volume from the variants unit_value" do diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 2151634bde..11ac15fa27 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -658,7 +658,7 @@ describe Spree::Order do end it "does not attempt to update such adjustments" do - order.update_attributes(line_items_attributes: [{ id: order.line_items.first.id, quantity: 0 }]) + order.update(line_items_attributes: [{ id: order.line_items.first.id, quantity: 0 }]) # Check if fees got updated order.reload @@ -685,7 +685,7 @@ describe Spree::Order do it "removes transaction fees" do # Change the payment method - order.payments.first.update_attributes(payment_method_id: payment_method.id) + order.payments.first.update(payment_method_id: payment_method.id) order.save # Check if fees got updated @@ -780,7 +780,7 @@ describe Spree::Order do let!(:order_cycle) { proxy_order.order_cycle } context "and order_cycle has no order_close_at set" do - before { order.order_cycle.update_attributes(orders_close_at: nil) } + before { order.order_cycle.update(orders_close_at: nil) } it "requires a payment" do expect(order.payment_required?).to be true @@ -788,7 +788,7 @@ describe Spree::Order do end context "and the order_cycle has closed" do - before { order.order_cycle.update_attributes(orders_close_at: 5.minutes.ago) } + before { order.order_cycle.update(orders_close_at: 5.minutes.ago) } it "returns the payments on the order" do expect(order.payment_required?).to be true @@ -796,7 +796,7 @@ describe Spree::Order do end context "and the order_cycle has not yet closed" do - before { order.order_cycle.update_attributes(orders_close_at: 5.minutes.from_now) } + before { order.order_cycle.update(orders_close_at: 5.minutes.from_now) } it "returns an empty array" do expect(order.payment_required?).to be false diff --git a/spec/models/spree/product_spec.rb b/spec/models/spree/product_spec.rb index 4309d105c9..95504faf3a 100644 --- a/spec/models/spree/product_spec.rb +++ b/spec/models/spree/product_spec.rb @@ -531,13 +531,13 @@ module Spree let!(:ot_volume) { create(:option_type, name: 'unit_volume', presentation: 'Volume') } it "removes the old option type and assigns the new one" do - p.update_attributes!(variant_unit: 'volume', variant_unit_scale: 0.001) + p.update!(variant_unit: 'volume', variant_unit_scale: 0.001) expect(p.option_types).to eq([ot_volume]) end it "does not remove and re-add the option type if it is not changed" do expect(p.option_types).to receive(:delete).never - p.update_attributes!(name: 'foo') + p.update!(name: 'foo') end it "removes the related option values from all its variants and replaces them" do @@ -548,7 +548,7 @@ module Spree expect(v.option_values.map(&:name).include?("1L")).to eq(false) expect(v.option_values.map(&:name).include?("1g")).to eq(true) expect { - p.update_attributes!(variant_unit: 'volume', variant_unit_scale: 0.001) + p.update!(variant_unit: 'volume', variant_unit_scale: 0.001) }.to change(p.master.option_values(true), :count).by(0) v.reload expect(v.option_values.map(&:name).include?("1L")).to eq(true) @@ -557,13 +557,13 @@ module Spree it "removes the related option values from its master variant and replaces them" do ot = Spree::OptionType.find_by name: 'unit_weight' - p.master.update_attributes!(unit_value: 1) + p.master.update!(unit_value: 1) p.reload expect(p.master.option_values.map(&:name).include?("1L")).to eq(false) expect(p.master.option_values.map(&:name).include?("1g")).to eq(true) expect { - p.update_attributes!(variant_unit: 'volume', variant_unit_scale: 0.001) + p.update!(variant_unit: 'volume', variant_unit_scale: 0.001) }.to change(p.master.option_values(true), :count).by(0) p.reload expect(p.master.option_values.map(&:name).include?("1L")).to eq(true) diff --git a/spec/models/spree/user_spec.rb b/spec/models/spree/user_spec.rb index 0a5d8c439b..0e48621452 100644 --- a/spec/models/spree/user_spec.rb +++ b/spec/models/spree/user_spec.rb @@ -13,7 +13,7 @@ describe Spree.user_class do old_bill_address = user.bill_address new_bill_address = create(:address, firstname: 'abc') - user.update_attributes(bill_address_attributes: new_bill_address.clone.attributes.merge('id' => old_bill_address.id)) + user.update(bill_address_attributes: new_bill_address.clone.attributes.merge('id' => old_bill_address.id)) expect(user.bill_address.id).to eq old_bill_address.id expect(user.bill_address.firstname).to eq new_bill_address.firstname @@ -22,7 +22,7 @@ describe Spree.user_class do it 'creates new shipping address' do new_ship_address = create(:address, firstname: 'abc') - user.update_attributes(ship_address_attributes: new_ship_address.clone.attributes) + user.update(ship_address_attributes: new_ship_address.clone.attributes) expect(user.ship_address.id).not_to eq new_ship_address.id expect(user.ship_address.firstname).to eq new_ship_address.firstname diff --git a/spec/models/spree/variant_spec.rb b/spec/models/spree/variant_spec.rb index d4889e6b4f..7a3b2ac85c 100644 --- a/spec/models/spree/variant_spec.rb +++ b/spec/models/spree/variant_spec.rb @@ -366,8 +366,8 @@ module Spree p = create(:simple_product, variant_unit: 'volume') v = create(:variant, product: p, weight: nil) - p.update_attributes! variant_unit: 'weight', variant_unit_scale: 1 - v.update_attributes! unit_value: 10, unit_description: 'foo' + p.update! variant_unit: 'weight', variant_unit_scale: 1 + v.update! unit_value: 10, unit_description: 'foo' expect(v.reload.weight).to eq(0.01) end @@ -376,8 +376,8 @@ module Spree p = create(:simple_product, variant_unit: 'volume') v = create(:variant, product: p, weight: 123) - p.update_attributes! variant_unit: 'volume', variant_unit_scale: 1 - v.update_attributes! unit_value: 10, unit_description: 'foo' + p.update! variant_unit: 'volume', variant_unit_scale: 1 + v.update! unit_value: 10, unit_description: 'foo' expect(v.reload.weight).to eq(123) end @@ -386,11 +386,11 @@ module Spree p = create(:simple_product, variant_unit: 'volume') v = create(:variant, product: p, weight: 123) - p.update_attributes! variant_unit: 'weight', variant_unit_scale: 1 + p.update! variant_unit: 'weight', variant_unit_scale: 1 # Although invalid, this calls the before_validation callback, which would # error if not handling unit_value == nil case - expect(v.update_attributes(unit_value: nil, unit_description: 'foo')).to be false + expect(v.update(unit_value: nil, unit_description: 'foo')).to be false expect(v.reload.weight).to eq(123) end @@ -404,7 +404,7 @@ module Spree ov_orig = v.option_values.last expect { - v.update_attributes!(unit_value: 10, unit_description: 'foo') + v.update!(unit_value: 10, unit_description: 'foo') }.to change(Spree::OptionValue, :count).by(1) expect(v.option_values).not_to include ov_orig @@ -423,7 +423,7 @@ module Spree ov_new = v0.option_values.last expect { - v.update_attributes!(unit_value: 10, unit_description: 'foo') + v.update!(unit_value: 10, unit_description: 'foo') }.to change(Spree::OptionValue, :count).by(0) expect(v.option_values).not_to include ov_orig @@ -437,7 +437,7 @@ module Spree it "requests the name of the new option_value from OptionValueName" do expect_any_instance_of(OpenFoodNetwork::OptionValueNamer).to receive(:name).exactly(1).times.and_call_original - v.update_attributes(unit_value: 10, unit_description: 'foo') + v.update(unit_value: 10, unit_description: 'foo') ov = v.option_values.last expect(ov.name).to eq("10g foo") end @@ -449,7 +449,7 @@ module Spree it "does not request the name of the new option_value from OptionValueName" do expect_any_instance_of(OpenFoodNetwork::OptionValueNamer).not_to receive(:name) - v.update_attributes!(unit_value: 10, unit_description: 'foo') + v.update!(unit_value: 10, unit_description: 'foo') ov = v.option_values.last expect(ov.name).to eq("FOOS!") end @@ -500,7 +500,7 @@ module Spree end it "saves without infinite loop" do - expect(variant1.update_attributes(cost_price: 1)).to be_truthy + expect(variant1.update(cost_price: 1)).to be_truthy end end end diff --git a/spec/requests/checkout/stripe_connect_spec.rb b/spec/requests/checkout/stripe_connect_spec.rb index 697664b806..5c1561c13c 100644 --- a/spec/requests/checkout/stripe_connect_spec.rb +++ b/spec/requests/checkout/stripe_connect_spec.rb @@ -67,7 +67,7 @@ describe "checking out an order with a Stripe Connect payment method", type: :re allow(order_cycle_distributed_variants).to receive(:distributes_order_variants?) { true } allow(Stripe).to receive(:api_key) { "sk_test_12345" } - order.update_attributes(distributor_id: enterprise.id, order_cycle_id: order_cycle.id) + order.update(distributor_id: enterprise.id, order_cycle_id: order_cycle.id) order.reload.update_totals set_order order end diff --git a/spec/services/order_syncer_spec.rb b/spec/services/order_syncer_spec.rb index 21790656ad..9990425f6a 100644 --- a/spec/services/order_syncer_spec.rb +++ b/spec/services/order_syncer_spec.rb @@ -175,7 +175,7 @@ describe OrderSyncer do context "when the bill_address on the order doesn't match that on the subscription" do before do - order.bill_address.update_attributes!(firstname: "Jane") + order.bill_address.update!(firstname: "Jane") order.update! end @@ -220,7 +220,7 @@ describe OrderSyncer do context "when the bill_address on the order doesn't match that on the subscription" do before do - order.bill_address.update_attributes!(firstname: "Jane") + order.bill_address.update!(firstname: "Jane") order.update! end @@ -348,7 +348,7 @@ describe OrderSyncer do context "when the ship address on the order doesn't match that on the subscription" do before do - order.ship_address.update_attributes(firstname: "Jane") + order.ship_address.update(firstname: "Jane") order.update! end @@ -441,7 +441,7 @@ describe OrderSyncer do before { variant.update_attribute(:on_hand, 3) } context "when the changed line_item quantity matches the new quantity on the subscription line item" do - before { changed_line_item.update_attributes(quantity: 3) } + before { changed_line_item.update(quantity: 3) } it "does not change the quantity, and doesn't add the order to order_update_issues" do expect(order.reload.total.to_f).to eq 99.95 @@ -454,7 +454,7 @@ describe OrderSyncer do end context "when the changed line_item quantity doesn't match the new quantity on the subscription line item" do - before { changed_line_item.update_attributes(quantity: 2) } + before { changed_line_item.update(quantity: 2) } it "does not change the quantity, and adds the order to order_update_issues" do expect(order.reload.total.to_f).to eq 79.96