From b1416952d07474114e7d1ced833d33f6bb425e31 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 10 Apr 2021 17:03:14 +0100 Subject: [PATCH 01/17] Fix deprecated syntax for reloading `#line_items` association --- app/controllers/spree/orders_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/spree/orders_controller.rb b/app/controllers/spree/orders_controller.rb index 4a81b98a3a..c660c99f6a 100644 --- a/app/controllers/spree/orders_controller.rb +++ b/app/controllers/spree/orders_controller.rb @@ -104,7 +104,7 @@ module Spree else # Show order with original values, not newly entered ones @insufficient_stock_lines = @order.insufficient_stock_lines - @order.line_items(true) + @order.line_items.reload respond_with(@order) end end From 3bce1bad62f59fe241ec7e30bde098a41e4601b7 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 11 Apr 2021 00:10:42 +0100 Subject: [PATCH 02/17] Add missing Stripe API request stub The first time the checkout is submitted here it uses the defaults in CheckoutRequestHelper#fill_out_details --- spec/features/consumer/shopping/checkout_stripe_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/features/consumer/shopping/checkout_stripe_spec.rb b/spec/features/consumer/shopping/checkout_stripe_spec.rb index bd98d198a9..0ff0cfe412 100644 --- a/spec/features/consumer/shopping/checkout_stripe_spec.rb +++ b/spec/features/consumer/shopping/checkout_stripe_spec.rb @@ -219,7 +219,8 @@ feature "Check out with Stripe", js: true do stub_add_metadata_request(payment_method: "pm_123", response: {}) stub_payment_intents_post_request order: order stub_successful_capture_request order: order - stub_customers_post_request email: user.email + stub_customers_post_request email: "test@test.com" # First checkout with default details + stub_customers_post_request email: user.email # Second checkout with saved user details stub_payment_method_attach_request end From fbda3c15ff448c7751162c3c772145c1fc316dcb Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 10 Apr 2021 15:38:21 +0100 Subject: [PATCH 03/17] Fix deprecated use of #stub in payment spec Fixes: Using `stub` from rspec-mocks' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` instead. Called from /home/runner/work/openfoodnetwork/openfoodnetwork/spec/models/spree/payment_spec.rb:10:in `block (3 levels) in '. RuntimeError: stubbed models are not allowed to access the database - Spree::Product#touch(updated_at,{:time=>2021-04-10 14:24:50 UTC}) --- spec/models/spree/payment_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/spree/payment_spec.rb b/spec/models/spree/payment_spec.rb index 1b084adc2a..2f6554a607 100644 --- a/spec/models/spree/payment_spec.rb +++ b/spec/models/spree/payment_spec.rb @@ -7,7 +7,7 @@ describe Spree::Payment do let(:order) { create(:order) } let(:gateway) do gateway = Spree::Gateway::Bogus.new(environment: 'test', active: true) - gateway.stub source_required: true + allow(gateway).to receive(:source_required) { true } gateway end From a0b4925943569603b8a921f3da71c984cd6e9f29 Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Fri, 9 Apr 2021 10:56:56 -0700 Subject: [PATCH 04/17] update migration versions --- db/migrate/20181128054803_old_migrations_removed.rb | 2 +- .../20190221131622_delete_account_invoices_preferences.rb | 2 +- .../20190221131741_delete_account_invoices_adjustments.rb | 2 +- .../20190221214542_drop_enterprise_shop_trial_start_date.rb | 2 +- db/migrate/20190303143409_drop_product_distributions.rb | 2 +- .../20190313142051_set_default_stock_location_on_shipments.rb | 2 +- ...40_add_shipping_category_to_shipping_methods_and_products.rb | 2 +- ...20190315224423_drop_account_invoices_and_billable_periods.rb | 2 +- db/migrate/20190320111312_delete_obsolete_pending_jobs.rb | 2 +- .../20190321203818_add_deleted_at_to_spree_stock_items.rb | 2 +- ...7_migrate_variants_on_demand_to_stock_items_backorderable.rb | 2 +- db/migrate/20190504151144_remove_field_name_from_exchange.rb | 2 +- ...190506194625_update_stock_locations_backorderable_default.rb | 2 +- db/migrate/20190701002454_convert_string_fields_to_text.rb | 2 +- db/migrate/20190830134723_add_deleted_at_to_spree_prices.rb | 2 +- db/migrate/20190906151259_reset_negative_stock_levels.rb | 2 +- db/migrate/20190906165501_remove_broken_variants_from_carts.rb | 2 +- .../20190908183511_set_backordered_inventory_to_on_hand.rb | 2 +- db/migrate/20190913023137_replace_hard_deleted_prices.rb | 2 +- .../20190916105416_add_long_compound_index_on_spree_orders.rb | 2 +- .../20190916110029_drop_completed_at_index_on_spree_orders.rb | 2 +- .../20190918105234_remove_all_master_variants_from_exchanges.rb | 2 +- db/migrate/20190922201034_drop_orders_shipping_method_id.rb | 2 +- db/migrate/20191023105006_drop_prototypes_tables.rb | 2 +- db/migrate/20191023172424_add_indexes_to_spree_orders.rb | 2 +- db/migrate/20191202165700_add_custom_data_to_versions.rb | 2 +- ...549_change_cvv_response_message_to_text_in_spree_payments.rb | 2 +- .../20200327105910_change_versions_custom_data_to_text.rb | 2 +- db/migrate/20200404080853_add_user_id_index_to_spree_orders.rb | 2 +- .../20200404081018_add_supplier_id_index_to_spree_products.rb | 2 +- db/migrate/20200404083008_drop_trackers_table.rb | 2 +- db/migrate/20200404090436_remove_ga_cookies_preference.rb | 2 +- ...200406085833_increase_characters_of_locale_in_spree_users.rb | 2 +- db/migrate/20200429122446_drop_mail_methods.rb | 2 +- .../20200430105459_add_timestamps_to_order_cycle_schedules.rb | 2 +- .../20200508101630_convert_frontend_shipping_method_to_both.rb | 2 +- db/migrate/20200512070717_add_lock_version_to_stock_items.rb | 2 +- ...et_negative_nonbackorderable_count_on_hand_in_stock_items.rb | 2 +- ...16162646_move_all_calculators_outside_the_spree_namespace.rb | 2 +- db/migrate/20200623140437_fix_preferences_keys.rb | 2 +- db/migrate/20200624091611_make_timestamps_nullable.rb | 2 +- db/migrate/20200630070422_require_timestamps.rb | 2 +- .../20200702112157_add_stateful_id_index_to_state_changes.rb | 2 +- ...5726_move_calculators_preferences_outside_spree_namespace.rb | 2 +- .../20200817150002_add_terms_and_conditions_to_enterprises.rb | 2 +- ...20200907140555_add_customer_terms_and_conditions_accepted.rb | 2 +- db/migrate/20200912190210_update_weight_calculators.rb | 2 +- ...5_repeat_move_all_calculators_outside_the_spree_namespace.rb | 2 +- ...peat_move_calculators_preferences_outside_spree_namespace.rb | 2 +- db/migrate/20201219120055_add_order_to_adjustments.rb | 2 +- db/migrate/20201227122327_add_included_to_adjustments.rb | 2 +- db/migrate/20210115143738_add_deleted_at_to_enterprise_fee.rb | 2 +- db/migrate/20210123044336_add_tax_totals_to_order.rb | 2 +- .../20210125123000_remove_enable_mail_delivery_preference.rb | 2 +- db/migrate/20210125171611_populate_order_tax_totals.rb | 2 +- db/migrate/20210127174120_add_cascading_deletes.rb | 2 +- .../20210130135946_increase_precion_on_currency_fields.rb | 2 +- .../20210203214304_rename_migs_payment_methods_to_check.rb | 2 +- .../20210203215049_rename_pin_payment_methods_to_check.rb | 2 +- .../20210207120753_add_tax_category_id_to_shipping_methods.rb | 2 +- db/migrate/20210207120825_set_default_shipment_cost.rb | 2 +- db/migrate/20210207131247_add_tax_totals_to_shipment.rb | 2 +- db/migrate/20210207151520_add_adjustment_total_to_shipment.rb | 2 +- db/migrate/20210211115125_migrate_shipment_fees_to_shipments.rb | 2 +- ...210216203057_remove_cost_price_from_variant_and_line_item.rb | 2 +- db/migrate/20210224190247_migrate_shipping_taxes.rb | 2 +- db/migrate/20210227144926_migrate_payment_fees_to_payments.rb | 2 +- db/migrate/20210228223114_migrate_line_item_fees.rb | 2 +- 68 files changed, 68 insertions(+), 68 deletions(-) diff --git a/db/migrate/20181128054803_old_migrations_removed.rb b/db/migrate/20181128054803_old_migrations_removed.rb index 47d233f0aa..a8dc8b0454 100644 --- a/db/migrate/20181128054803_old_migrations_removed.rb +++ b/db/migrate/20181128054803_old_migrations_removed.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class OldMigrationsRemoved < ActiveRecord::Migration +class OldMigrationsRemoved < ActiveRecord::Migration[4.2] def up raise StandardError, <<-MESSAGE diff --git a/db/migrate/20190221131622_delete_account_invoices_preferences.rb b/db/migrate/20190221131622_delete_account_invoices_preferences.rb index e55a61f721..217078b52c 100644 --- a/db/migrate/20190221131622_delete_account_invoices_preferences.rb +++ b/db/migrate/20190221131622_delete_account_invoices_preferences.rb @@ -1,4 +1,4 @@ -class DeleteAccountInvoicesPreferences < ActiveRecord::Migration +class DeleteAccountInvoicesPreferences < ActiveRecord::Migration[4.2] def up Spree::Preference .where( key: ['spree/app_configuration/accounts_distributor_id', diff --git a/db/migrate/20190221131741_delete_account_invoices_adjustments.rb b/db/migrate/20190221131741_delete_account_invoices_adjustments.rb index 1f1af59594..dcd965cdae 100644 --- a/db/migrate/20190221131741_delete_account_invoices_adjustments.rb +++ b/db/migrate/20190221131741_delete_account_invoices_adjustments.rb @@ -1,4 +1,4 @@ -class DeleteAccountInvoicesAdjustments < ActiveRecord::Migration +class DeleteAccountInvoicesAdjustments < ActiveRecord::Migration[4.2] def up Spree::Adjustment .where(source_type: 'BillablePeriod') diff --git a/db/migrate/20190221214542_drop_enterprise_shop_trial_start_date.rb b/db/migrate/20190221214542_drop_enterprise_shop_trial_start_date.rb index 69dd360e2c..0c77f1a6db 100644 --- a/db/migrate/20190221214542_drop_enterprise_shop_trial_start_date.rb +++ b/db/migrate/20190221214542_drop_enterprise_shop_trial_start_date.rb @@ -1,4 +1,4 @@ -class DropEnterpriseShopTrialStartDate < ActiveRecord::Migration +class DropEnterpriseShopTrialStartDate < ActiveRecord::Migration[4.2] def up remove_column :enterprises, :shop_trial_start_date end diff --git a/db/migrate/20190303143409_drop_product_distributions.rb b/db/migrate/20190303143409_drop_product_distributions.rb index 73318a359d..9de25c9164 100644 --- a/db/migrate/20190303143409_drop_product_distributions.rb +++ b/db/migrate/20190303143409_drop_product_distributions.rb @@ -1,4 +1,4 @@ -class DropProductDistributions < ActiveRecord::Migration +class DropProductDistributions < ActiveRecord::Migration[4.2] def up drop_table :product_distributions end diff --git a/db/migrate/20190313142051_set_default_stock_location_on_shipments.rb b/db/migrate/20190313142051_set_default_stock_location_on_shipments.rb index 45add57fe3..66d5f6cbde 100644 --- a/db/migrate/20190313142051_set_default_stock_location_on_shipments.rb +++ b/db/migrate/20190313142051_set_default_stock_location_on_shipments.rb @@ -1,4 +1,4 @@ -class SetDefaultStockLocationOnShipments < ActiveRecord::Migration +class SetDefaultStockLocationOnShipments < ActiveRecord::Migration[4.2] def up if Spree::Shipment.where('stock_location_id IS NULL').count > 0 location = DefaultStockLocation.find_or_create diff --git a/db/migrate/20190313142540_add_shipping_category_to_shipping_methods_and_products.rb b/db/migrate/20190313142540_add_shipping_category_to_shipping_methods_and_products.rb index b51c9a67b0..f2e0eacf7b 100644 --- a/db/migrate/20190313142540_add_shipping_category_to_shipping_methods_and_products.rb +++ b/db/migrate/20190313142540_add_shipping_category_to_shipping_methods_and_products.rb @@ -1,4 +1,4 @@ -class AddShippingCategoryToShippingMethodsAndProducts < ActiveRecord::Migration +class AddShippingCategoryToShippingMethodsAndProducts < ActiveRecord::Migration[4.2] def up # This is different from the equivalent Spree migration # Here we are creating the default shipping category even if there are already shipping categories diff --git a/db/migrate/20190315224423_drop_account_invoices_and_billable_periods.rb b/db/migrate/20190315224423_drop_account_invoices_and_billable_periods.rb index 4aaa282221..a754dfc0e7 100644 --- a/db/migrate/20190315224423_drop_account_invoices_and_billable_periods.rb +++ b/db/migrate/20190315224423_drop_account_invoices_and_billable_periods.rb @@ -1,4 +1,4 @@ -class DropAccountInvoicesAndBillablePeriods < ActiveRecord::Migration +class DropAccountInvoicesAndBillablePeriods < ActiveRecord::Migration[4.2] def up drop_table :billable_periods drop_table :account_invoices diff --git a/db/migrate/20190320111312_delete_obsolete_pending_jobs.rb b/db/migrate/20190320111312_delete_obsolete_pending_jobs.rb index 043612971c..d753c9ba6b 100644 --- a/db/migrate/20190320111312_delete_obsolete_pending_jobs.rb +++ b/db/migrate/20190320111312_delete_obsolete_pending_jobs.rb @@ -1,4 +1,4 @@ -class DeleteObsoletePendingJobs < ActiveRecord::Migration +class DeleteObsoletePendingJobs < ActiveRecord::Migration[4.2] def up Delayed::Job.all.each do |job| job.delete if job.name == "FinalizeAccountInvoices" || diff --git a/db/migrate/20190321203818_add_deleted_at_to_spree_stock_items.rb b/db/migrate/20190321203818_add_deleted_at_to_spree_stock_items.rb index 3170545118..eade2ba9a6 100644 --- a/db/migrate/20190321203818_add_deleted_at_to_spree_stock_items.rb +++ b/db/migrate/20190321203818_add_deleted_at_to_spree_stock_items.rb @@ -1,4 +1,4 @@ -class AddDeletedAtToSpreeStockItems < ActiveRecord::Migration +class AddDeletedAtToSpreeStockItems < ActiveRecord::Migration[4.2] def up add_column :spree_stock_items, :deleted_at, :datetime end diff --git a/db/migrate/20190501143327_migrate_variants_on_demand_to_stock_items_backorderable.rb b/db/migrate/20190501143327_migrate_variants_on_demand_to_stock_items_backorderable.rb index 86d7a9d3ff..a507603120 100644 --- a/db/migrate/20190501143327_migrate_variants_on_demand_to_stock_items_backorderable.rb +++ b/db/migrate/20190501143327_migrate_variants_on_demand_to_stock_items_backorderable.rb @@ -1,4 +1,4 @@ -class MigrateVariantsOnDemandToStockItemsBackorderable < ActiveRecord::Migration +class MigrateVariantsOnDemandToStockItemsBackorderable < ActiveRecord::Migration[4.2] def up # We use SQL directly here to avoid going through VariantStock.on_demand and VariantStock.on_demand= sql = "update spree_stock_items set backorderable = (select on_demand from spree_variants where spree_variants.id = spree_stock_items.variant_id)" diff --git a/db/migrate/20190504151144_remove_field_name_from_exchange.rb b/db/migrate/20190504151144_remove_field_name_from_exchange.rb index 459c5f0444..5bd06e121e 100644 --- a/db/migrate/20190504151144_remove_field_name_from_exchange.rb +++ b/db/migrate/20190504151144_remove_field_name_from_exchange.rb @@ -1,4 +1,4 @@ -class RemoveFieldNameFromExchange < ActiveRecord::Migration +class RemoveFieldNameFromExchange < ActiveRecord::Migration[4.2] def up remove_column :exchanges, :payment_enterprise_id end diff --git a/db/migrate/20190506194625_update_stock_locations_backorderable_default.rb b/db/migrate/20190506194625_update_stock_locations_backorderable_default.rb index a95aae6eea..456f2b7fa4 100644 --- a/db/migrate/20190506194625_update_stock_locations_backorderable_default.rb +++ b/db/migrate/20190506194625_update_stock_locations_backorderable_default.rb @@ -1,4 +1,4 @@ -class UpdateStockLocationsBackorderableDefault < ActiveRecord::Migration +class UpdateStockLocationsBackorderableDefault < ActiveRecord::Migration[4.2] def change Spree::StockLocation.update_all(backorderable_default: false) end diff --git a/db/migrate/20190701002454_convert_string_fields_to_text.rb b/db/migrate/20190701002454_convert_string_fields_to_text.rb index 9d461c6070..b6c723747c 100644 --- a/db/migrate/20190701002454_convert_string_fields_to_text.rb +++ b/db/migrate/20190701002454_convert_string_fields_to_text.rb @@ -1,4 +1,4 @@ -class ConvertStringFieldsToText < ActiveRecord::Migration +class ConvertStringFieldsToText < ActiveRecord::Migration[4.2] def up change_column :enterprises, :description, :text change_column :enterprises, :pickup_times, :text diff --git a/db/migrate/20190830134723_add_deleted_at_to_spree_prices.rb b/db/migrate/20190830134723_add_deleted_at_to_spree_prices.rb index 949b7c11d9..c1159f8e5a 100644 --- a/db/migrate/20190830134723_add_deleted_at_to_spree_prices.rb +++ b/db/migrate/20190830134723_add_deleted_at_to_spree_prices.rb @@ -1,4 +1,4 @@ -class AddDeletedAtToSpreePrices < ActiveRecord::Migration +class AddDeletedAtToSpreePrices < ActiveRecord::Migration[4.2] def change add_column :spree_prices, :deleted_at, :datetime end diff --git a/db/migrate/20190906151259_reset_negative_stock_levels.rb b/db/migrate/20190906151259_reset_negative_stock_levels.rb index ec0be5a4be..0a060f9ebd 100644 --- a/db/migrate/20190906151259_reset_negative_stock_levels.rb +++ b/db/migrate/20190906151259_reset_negative_stock_levels.rb @@ -1,4 +1,4 @@ -class ResetNegativeStockLevels < ActiveRecord::Migration +class ResetNegativeStockLevels < ActiveRecord::Migration[4.2] def up # Reset stock to zero for all on_demand variants that have negative stock execute "UPDATE spree_stock_items SET count_on_hand = '0' WHERE count_on_hand < 0 AND backorderable IS TRUE" diff --git a/db/migrate/20190906165501_remove_broken_variants_from_carts.rb b/db/migrate/20190906165501_remove_broken_variants_from_carts.rb index 3e6cfaed10..1c1452b42d 100644 --- a/db/migrate/20190906165501_remove_broken_variants_from_carts.rb +++ b/db/migrate/20190906165501_remove_broken_variants_from_carts.rb @@ -1,4 +1,4 @@ -class RemoveBrokenVariantsFromCarts < ActiveRecord::Migration +class RemoveBrokenVariantsFromCarts < ActiveRecord::Migration[4.2] def up # Removes line_items from open carts where the variant has a hard-deleted price diff --git a/db/migrate/20190908183511_set_backordered_inventory_to_on_hand.rb b/db/migrate/20190908183511_set_backordered_inventory_to_on_hand.rb index c743a381ed..3295bb4da6 100644 --- a/db/migrate/20190908183511_set_backordered_inventory_to_on_hand.rb +++ b/db/migrate/20190908183511_set_backordered_inventory_to_on_hand.rb @@ -1,4 +1,4 @@ -class SetBackorderedInventoryToOnHand < ActiveRecord::Migration +class SetBackorderedInventoryToOnHand < ActiveRecord::Migration[4.2] def up execute("UPDATE spree_inventory_units SET state = 'on_hand' WHERE state = 'backordered'") end diff --git a/db/migrate/20190913023137_replace_hard_deleted_prices.rb b/db/migrate/20190913023137_replace_hard_deleted_prices.rb index 15b34c12a7..8f658f50c6 100644 --- a/db/migrate/20190913023137_replace_hard_deleted_prices.rb +++ b/db/migrate/20190913023137_replace_hard_deleted_prices.rb @@ -1,4 +1,4 @@ -class ReplaceHardDeletedPrices < ActiveRecord::Migration +class ReplaceHardDeletedPrices < ActiveRecord::Migration[4.2] def up ActiveRecord::Base.connection.execute( "INSERT into spree_prices (variant_id, amount, currency, deleted_at) diff --git a/db/migrate/20190916105416_add_long_compound_index_on_spree_orders.rb b/db/migrate/20190916105416_add_long_compound_index_on_spree_orders.rb index 5ff04483ec..2564a66488 100644 --- a/db/migrate/20190916105416_add_long_compound_index_on_spree_orders.rb +++ b/db/migrate/20190916105416_add_long_compound_index_on_spree_orders.rb @@ -1,4 +1,4 @@ -class AddLongCompoundIndexOnSpreeOrders < ActiveRecord::Migration +class AddLongCompoundIndexOnSpreeOrders < ActiveRecord::Migration[4.2] def change add_index( :spree_orders, diff --git a/db/migrate/20190916110029_drop_completed_at_index_on_spree_orders.rb b/db/migrate/20190916110029_drop_completed_at_index_on_spree_orders.rb index 47b5517295..2a65208ee3 100644 --- a/db/migrate/20190916110029_drop_completed_at_index_on_spree_orders.rb +++ b/db/migrate/20190916110029_drop_completed_at_index_on_spree_orders.rb @@ -1,4 +1,4 @@ -class DropCompletedAtIndexOnSpreeOrders < ActiveRecord::Migration +class DropCompletedAtIndexOnSpreeOrders < ActiveRecord::Migration[4.2] def change remove_index :spree_orders, :completed_at end diff --git a/db/migrate/20190918105234_remove_all_master_variants_from_exchanges.rb b/db/migrate/20190918105234_remove_all_master_variants_from_exchanges.rb index 1b6de20c30..c6ce2fbce7 100644 --- a/db/migrate/20190918105234_remove_all_master_variants_from_exchanges.rb +++ b/db/migrate/20190918105234_remove_all_master_variants_from_exchanges.rb @@ -1,4 +1,4 @@ -class RemoveAllMasterVariantsFromExchanges < ActiveRecord::Migration +class RemoveAllMasterVariantsFromExchanges < ActiveRecord::Migration[4.2] def up # 1. We add standard variants of the products of "lonely masters" into the Exchanges where the master variants are lonely match_master_variants diff --git a/db/migrate/20190922201034_drop_orders_shipping_method_id.rb b/db/migrate/20190922201034_drop_orders_shipping_method_id.rb index 4f35ec7e99..b5292837e0 100644 --- a/db/migrate/20190922201034_drop_orders_shipping_method_id.rb +++ b/db/migrate/20190922201034_drop_orders_shipping_method_id.rb @@ -1,4 +1,4 @@ -class DropOrdersShippingMethodId < ActiveRecord::Migration +class DropOrdersShippingMethodId < ActiveRecord::Migration[4.2] def up remove_column :spree_orders, :shipping_method_id end diff --git a/db/migrate/20191023105006_drop_prototypes_tables.rb b/db/migrate/20191023105006_drop_prototypes_tables.rb index 974cec87ea..be22c757b4 100644 --- a/db/migrate/20191023105006_drop_prototypes_tables.rb +++ b/db/migrate/20191023105006_drop_prototypes_tables.rb @@ -1,4 +1,4 @@ -class DropPrototypesTables < ActiveRecord::Migration +class DropPrototypesTables < ActiveRecord::Migration[4.2] def up drop_table :spree_option_types_prototypes drop_table :spree_properties_prototypes diff --git a/db/migrate/20191023172424_add_indexes_to_spree_orders.rb b/db/migrate/20191023172424_add_indexes_to_spree_orders.rb index d121049fb4..bf92cc844d 100644 --- a/db/migrate/20191023172424_add_indexes_to_spree_orders.rb +++ b/db/migrate/20191023172424_add_indexes_to_spree_orders.rb @@ -1,4 +1,4 @@ -class AddIndexesToSpreeOrders < ActiveRecord::Migration +class AddIndexesToSpreeOrders < ActiveRecord::Migration[4.2] def change add_index :spree_orders, :order_cycle_id add_index :spree_orders, :distributor_id diff --git a/db/migrate/20191202165700_add_custom_data_to_versions.rb b/db/migrate/20191202165700_add_custom_data_to_versions.rb index 45a10ed67e..ddc2c2f26a 100644 --- a/db/migrate/20191202165700_add_custom_data_to_versions.rb +++ b/db/migrate/20191202165700_add_custom_data_to_versions.rb @@ -1,4 +1,4 @@ -class AddCustomDataToVersions < ActiveRecord::Migration +class AddCustomDataToVersions < ActiveRecord::Migration[4.2] def change add_column :versions, :custom_data, :string end diff --git a/db/migrate/20200209163549_change_cvv_response_message_to_text_in_spree_payments.rb b/db/migrate/20200209163549_change_cvv_response_message_to_text_in_spree_payments.rb index 5e2e8d88ad..0e2fb44b72 100644 --- a/db/migrate/20200209163549_change_cvv_response_message_to_text_in_spree_payments.rb +++ b/db/migrate/20200209163549_change_cvv_response_message_to_text_in_spree_payments.rb @@ -1,4 +1,4 @@ -class ChangeCvvResponseMessageToTextInSpreePayments < ActiveRecord::Migration +class ChangeCvvResponseMessageToTextInSpreePayments < ActiveRecord::Migration[4.2] def up change_column :spree_payments, :cvv_response_message, :text end diff --git a/db/migrate/20200327105910_change_versions_custom_data_to_text.rb b/db/migrate/20200327105910_change_versions_custom_data_to_text.rb index 0a995a85f4..f5b43f9a81 100644 --- a/db/migrate/20200327105910_change_versions_custom_data_to_text.rb +++ b/db/migrate/20200327105910_change_versions_custom_data_to_text.rb @@ -1,4 +1,4 @@ -class ChangeVersionsCustomDataToText < ActiveRecord::Migration +class ChangeVersionsCustomDataToText < ActiveRecord::Migration[4.2] def up change_column :versions, :custom_data, :text end diff --git a/db/migrate/20200404080853_add_user_id_index_to_spree_orders.rb b/db/migrate/20200404080853_add_user_id_index_to_spree_orders.rb index cb8ef67b0e..46e760f04d 100644 --- a/db/migrate/20200404080853_add_user_id_index_to_spree_orders.rb +++ b/db/migrate/20200404080853_add_user_id_index_to_spree_orders.rb @@ -1,4 +1,4 @@ -class AddUserIdIndexToSpreeOrders < ActiveRecord::Migration +class AddUserIdIndexToSpreeOrders < ActiveRecord::Migration[4.2] def change add_index :spree_orders, :user_id end diff --git a/db/migrate/20200404081018_add_supplier_id_index_to_spree_products.rb b/db/migrate/20200404081018_add_supplier_id_index_to_spree_products.rb index eadc5a7c50..dd157c573d 100644 --- a/db/migrate/20200404081018_add_supplier_id_index_to_spree_products.rb +++ b/db/migrate/20200404081018_add_supplier_id_index_to_spree_products.rb @@ -1,4 +1,4 @@ -class AddSupplierIdIndexToSpreeProducts < ActiveRecord::Migration +class AddSupplierIdIndexToSpreeProducts < ActiveRecord::Migration[4.2] def change add_index :spree_products, :supplier_id end diff --git a/db/migrate/20200404083008_drop_trackers_table.rb b/db/migrate/20200404083008_drop_trackers_table.rb index 4dca8c7cfc..7f29258953 100644 --- a/db/migrate/20200404083008_drop_trackers_table.rb +++ b/db/migrate/20200404083008_drop_trackers_table.rb @@ -1,4 +1,4 @@ -class DropTrackersTable < ActiveRecord::Migration +class DropTrackersTable < ActiveRecord::Migration[4.2] def up drop_table :spree_trackers end diff --git a/db/migrate/20200404090436_remove_ga_cookies_preference.rb b/db/migrate/20200404090436_remove_ga_cookies_preference.rb index c509b11e5e..156d308dbe 100644 --- a/db/migrate/20200404090436_remove_ga_cookies_preference.rb +++ b/db/migrate/20200404090436_remove_ga_cookies_preference.rb @@ -1,4 +1,4 @@ -class RemoveGaCookiesPreference < ActiveRecord::Migration +class RemoveGaCookiesPreference < ActiveRecord::Migration[4.2] class Spree::Preference < ActiveRecord::Base; end def up diff --git a/db/migrate/20200406085833_increase_characters_of_locale_in_spree_users.rb b/db/migrate/20200406085833_increase_characters_of_locale_in_spree_users.rb index 5cac7dab5b..e1070cba7f 100644 --- a/db/migrate/20200406085833_increase_characters_of_locale_in_spree_users.rb +++ b/db/migrate/20200406085833_increase_characters_of_locale_in_spree_users.rb @@ -1,4 +1,4 @@ -class IncreaseCharactersOfLocaleInSpreeUsers < ActiveRecord::Migration +class IncreaseCharactersOfLocaleInSpreeUsers < ActiveRecord::Migration[4.2] def up change_column :spree_users, :locale, :string, limit: 6 end diff --git a/db/migrate/20200429122446_drop_mail_methods.rb b/db/migrate/20200429122446_drop_mail_methods.rb index 12dba55bbe..3efdabce91 100644 --- a/db/migrate/20200429122446_drop_mail_methods.rb +++ b/db/migrate/20200429122446_drop_mail_methods.rb @@ -1,4 +1,4 @@ -class DropMailMethods < ActiveRecord::Migration +class DropMailMethods < ActiveRecord::Migration[4.2] def up drop_table :spree_mail_methods diff --git a/db/migrate/20200430105459_add_timestamps_to_order_cycle_schedules.rb b/db/migrate/20200430105459_add_timestamps_to_order_cycle_schedules.rb index 5f57cd13a2..270977ad60 100644 --- a/db/migrate/20200430105459_add_timestamps_to_order_cycle_schedules.rb +++ b/db/migrate/20200430105459_add_timestamps_to_order_cycle_schedules.rb @@ -1,4 +1,4 @@ -class AddTimestampsToOrderCycleSchedules < ActiveRecord::Migration +class AddTimestampsToOrderCycleSchedules < ActiveRecord::Migration[4.2] def change change_table :order_cycle_schedules do |t| t.timestamps diff --git a/db/migrate/20200508101630_convert_frontend_shipping_method_to_both.rb b/db/migrate/20200508101630_convert_frontend_shipping_method_to_both.rb index 5e2418c3b8..c44dd18a1c 100644 --- a/db/migrate/20200508101630_convert_frontend_shipping_method_to_both.rb +++ b/db/migrate/20200508101630_convert_frontend_shipping_method_to_both.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class ConvertFrontendShippingMethodToBoth < ActiveRecord::Migration +class ConvertFrontendShippingMethodToBoth < ActiveRecord::Migration[4.2] def up # The display_on value front_end is not working # (it's not being used in the back office to ignore shipping methods marked as front_end) diff --git a/db/migrate/20200512070717_add_lock_version_to_stock_items.rb b/db/migrate/20200512070717_add_lock_version_to_stock_items.rb index 416a43f62e..24fc2eb9a9 100644 --- a/db/migrate/20200512070717_add_lock_version_to_stock_items.rb +++ b/db/migrate/20200512070717_add_lock_version_to_stock_items.rb @@ -1,4 +1,4 @@ -class AddLockVersionToStockItems < ActiveRecord::Migration +class AddLockVersionToStockItems < ActiveRecord::Migration[4.2] def change add_column :spree_stock_items, :lock_version, :integer, default: 0 end diff --git a/db/migrate/20200514174526_reset_negative_nonbackorderable_count_on_hand_in_stock_items.rb b/db/migrate/20200514174526_reset_negative_nonbackorderable_count_on_hand_in_stock_items.rb index c57730c99a..cc46f82d12 100644 --- a/db/migrate/20200514174526_reset_negative_nonbackorderable_count_on_hand_in_stock_items.rb +++ b/db/migrate/20200514174526_reset_negative_nonbackorderable_count_on_hand_in_stock_items.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class ResetNegativeNonbackorderableCountOnHandInStockItems < ActiveRecord::Migration +class ResetNegativeNonbackorderableCountOnHandInStockItems < ActiveRecord::Migration[4.2] module Spree class StockItem < ActiveRecord::Base self.table_name = "spree_stock_items" diff --git a/db/migrate/20200616162646_move_all_calculators_outside_the_spree_namespace.rb b/db/migrate/20200616162646_move_all_calculators_outside_the_spree_namespace.rb index b357242db2..8514b5e4ee 100644 --- a/db/migrate/20200616162646_move_all_calculators_outside_the_spree_namespace.rb +++ b/db/migrate/20200616162646_move_all_calculators_outside_the_spree_namespace.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class MoveAllCalculatorsOutsideTheSpreeNamespace < ActiveRecord::Migration +class MoveAllCalculatorsOutsideTheSpreeNamespace < ActiveRecord::Migration[4.2] def up convert_calculator("DefaultTax") convert_calculator("FlatPercentItemTotal") diff --git a/db/migrate/20200623140437_fix_preferences_keys.rb b/db/migrate/20200623140437_fix_preferences_keys.rb index 3f024ee278..08819689ff 100644 --- a/db/migrate/20200623140437_fix_preferences_keys.rb +++ b/db/migrate/20200623140437_fix_preferences_keys.rb @@ -1,4 +1,4 @@ -class FixPreferencesKeys < ActiveRecord::Migration +class FixPreferencesKeys < ActiveRecord::Migration[4.2] def up unmigrated_preferences = Spree::Preference.exists?(['key NOT LIKE ?', '/%']) return unless unmigrated_preferences diff --git a/db/migrate/20200624091611_make_timestamps_nullable.rb b/db/migrate/20200624091611_make_timestamps_nullable.rb index 32ea61ac43..545a84eb62 100644 --- a/db/migrate/20200624091611_make_timestamps_nullable.rb +++ b/db/migrate/20200624091611_make_timestamps_nullable.rb @@ -1,4 +1,4 @@ -class MakeTimestampsNullable < ActiveRecord::Migration +class MakeTimestampsNullable < ActiveRecord::Migration[4.2] def up change_column_null :customers, :created_at, true change_column_null :customers, :updated_at, true diff --git a/db/migrate/20200630070422_require_timestamps.rb b/db/migrate/20200630070422_require_timestamps.rb index 2075876bca..8d510288d3 100644 --- a/db/migrate/20200630070422_require_timestamps.rb +++ b/db/migrate/20200630070422_require_timestamps.rb @@ -1,4 +1,4 @@ -class RequireTimestamps < ActiveRecord::Migration +class RequireTimestamps < ActiveRecord::Migration[4.2] def up current_time = Time.zone.now diff --git a/db/migrate/20200702112157_add_stateful_id_index_to_state_changes.rb b/db/migrate/20200702112157_add_stateful_id_index_to_state_changes.rb index 8a52643cff..4cfff94491 100644 --- a/db/migrate/20200702112157_add_stateful_id_index_to_state_changes.rb +++ b/db/migrate/20200702112157_add_stateful_id_index_to_state_changes.rb @@ -1,4 +1,4 @@ -class AddStatefulIdIndexToStateChanges < ActiveRecord::Migration +class AddStatefulIdIndexToStateChanges < ActiveRecord::Migration[4.2] def change add_index :spree_state_changes, :stateful_id end diff --git a/db/migrate/20200721135726_move_calculators_preferences_outside_spree_namespace.rb b/db/migrate/20200721135726_move_calculators_preferences_outside_spree_namespace.rb index 2591550dd1..553288dfe8 100644 --- a/db/migrate/20200721135726_move_calculators_preferences_outside_spree_namespace.rb +++ b/db/migrate/20200721135726_move_calculators_preferences_outside_spree_namespace.rb @@ -1,6 +1,6 @@ # As we moved the calculators outside the Spree namespace in migration MoveAllCalculatorsOutsideTheSpreeNamespace # We need to move their preferences too (currency, value, etc), otherwise they are not used -class MoveCalculatorsPreferencesOutsideSpreeNamespace < ActiveRecord::Migration +class MoveCalculatorsPreferencesOutsideSpreeNamespace < ActiveRecord::Migration[4.2] def up replace_preferences_key("/spree/calculator", "/calculator") end diff --git a/db/migrate/20200817150002_add_terms_and_conditions_to_enterprises.rb b/db/migrate/20200817150002_add_terms_and_conditions_to_enterprises.rb index 57b646abd6..7f08cc2a53 100644 --- a/db/migrate/20200817150002_add_terms_and_conditions_to_enterprises.rb +++ b/db/migrate/20200817150002_add_terms_and_conditions_to_enterprises.rb @@ -1,4 +1,4 @@ -class AddTermsAndConditionsToEnterprises < ActiveRecord::Migration +class AddTermsAndConditionsToEnterprises < ActiveRecord::Migration[4.2] def change add_attachment :enterprises, :terms_and_conditions end diff --git a/db/migrate/20200907140555_add_customer_terms_and_conditions_accepted.rb b/db/migrate/20200907140555_add_customer_terms_and_conditions_accepted.rb index c48b1c19f2..95ed8158ba 100644 --- a/db/migrate/20200907140555_add_customer_terms_and_conditions_accepted.rb +++ b/db/migrate/20200907140555_add_customer_terms_and_conditions_accepted.rb @@ -1,4 +1,4 @@ -class AddCustomerTermsAndConditionsAccepted < ActiveRecord::Migration +class AddCustomerTermsAndConditionsAccepted < ActiveRecord::Migration[4.2] def change add_column :customers, :terms_and_conditions_accepted_at, :datetime end diff --git a/db/migrate/20200912190210_update_weight_calculators.rb b/db/migrate/20200912190210_update_weight_calculators.rb index 2a24138957..60adba69b1 100644 --- a/db/migrate/20200912190210_update_weight_calculators.rb +++ b/db/migrate/20200912190210_update_weight_calculators.rb @@ -1,4 +1,4 @@ -class UpdateWeightCalculators < ActiveRecord::Migration +class UpdateWeightCalculators < ActiveRecord::Migration[4.2] def change Spree::Calculator.connection.execute( "UPDATE spree_preferences SET key = replace( key, 'per_kg', 'per_unit') WHERE key ilike '/calculator/weight/per_kg/%'" diff --git a/db/migrate/20201113163155_repeat_move_all_calculators_outside_the_spree_namespace.rb b/db/migrate/20201113163155_repeat_move_all_calculators_outside_the_spree_namespace.rb index 60b127245f..47f4d76464 100644 --- a/db/migrate/20201113163155_repeat_move_all_calculators_outside_the_spree_namespace.rb +++ b/db/migrate/20201113163155_repeat_move_all_calculators_outside_the_spree_namespace.rb @@ -1,6 +1,6 @@ # For some unkonwn reason, after removing Spree as a dependency, some spree calculators appeared on live DBs # Here we repeat the migration -class RepeatMoveAllCalculatorsOutsideTheSpreeNamespace < ActiveRecord::Migration +class RepeatMoveAllCalculatorsOutsideTheSpreeNamespace < ActiveRecord::Migration[4.2] def up convert_calculator("DefaultTax") convert_calculator("FlatPercentItemTotal") diff --git a/db/migrate/20201113163227_repeat_move_calculators_preferences_outside_spree_namespace.rb b/db/migrate/20201113163227_repeat_move_calculators_preferences_outside_spree_namespace.rb index 24adad016b..84c52d26bf 100644 --- a/db/migrate/20201113163227_repeat_move_calculators_preferences_outside_spree_namespace.rb +++ b/db/migrate/20201113163227_repeat_move_calculators_preferences_outside_spree_namespace.rb @@ -1,6 +1,6 @@ # For some unkonwn reason, after removing Spree as a dependency, some spree calculators appeared on live DBs # Here we repeat the migration -class RepeatMoveCalculatorsPreferencesOutsideSpreeNamespace < ActiveRecord::Migration +class RepeatMoveCalculatorsPreferencesOutsideSpreeNamespace < ActiveRecord::Migration[4.2] def up replace_preferences_key("/spree/calculator", "/calculator") end diff --git a/db/migrate/20201219120055_add_order_to_adjustments.rb b/db/migrate/20201219120055_add_order_to_adjustments.rb index e0d6c32287..e1181c1eae 100644 --- a/db/migrate/20201219120055_add_order_to_adjustments.rb +++ b/db/migrate/20201219120055_add_order_to_adjustments.rb @@ -1,4 +1,4 @@ -class AddOrderToAdjustments < ActiveRecord::Migration +class AddOrderToAdjustments < ActiveRecord::Migration[4.2] class Spree::Adjustment < ActiveRecord::Base belongs_to :adjustable, polymorphic: true belongs_to :order, class_name: "Spree::Order" diff --git a/db/migrate/20201227122327_add_included_to_adjustments.rb b/db/migrate/20201227122327_add_included_to_adjustments.rb index 2ccbeab2a3..9fe8e838d4 100644 --- a/db/migrate/20201227122327_add_included_to_adjustments.rb +++ b/db/migrate/20201227122327_add_included_to_adjustments.rb @@ -1,4 +1,4 @@ -class AddIncludedToAdjustments < ActiveRecord::Migration +class AddIncludedToAdjustments < ActiveRecord::Migration[4.2] class Spree::TaxRate < ActiveRecord::Base; end class Spree::Adjustment < ActiveRecord::Base diff --git a/db/migrate/20210115143738_add_deleted_at_to_enterprise_fee.rb b/db/migrate/20210115143738_add_deleted_at_to_enterprise_fee.rb index f3afbf28d9..42fb42bb55 100644 --- a/db/migrate/20210115143738_add_deleted_at_to_enterprise_fee.rb +++ b/db/migrate/20210115143738_add_deleted_at_to_enterprise_fee.rb @@ -1,4 +1,4 @@ -class AddDeletedAtToEnterpriseFee < ActiveRecord::Migration +class AddDeletedAtToEnterpriseFee < ActiveRecord::Migration[4.2] def change add_column :enterprise_fees, :deleted_at, :datetime end diff --git a/db/migrate/20210123044336_add_tax_totals_to_order.rb b/db/migrate/20210123044336_add_tax_totals_to_order.rb index 64d99da532..b64836588a 100644 --- a/db/migrate/20210123044336_add_tax_totals_to_order.rb +++ b/db/migrate/20210123044336_add_tax_totals_to_order.rb @@ -1,4 +1,4 @@ -class AddTaxTotalsToOrder < ActiveRecord::Migration +class AddTaxTotalsToOrder < ActiveRecord::Migration[4.2] def up add_column :spree_orders, :included_tax_total, :decimal, precision: 10, scale: 2, null: false, default: 0.0 diff --git a/db/migrate/20210125123000_remove_enable_mail_delivery_preference.rb b/db/migrate/20210125123000_remove_enable_mail_delivery_preference.rb index a08642e931..7b9235b0ad 100644 --- a/db/migrate/20210125123000_remove_enable_mail_delivery_preference.rb +++ b/db/migrate/20210125123000_remove_enable_mail_delivery_preference.rb @@ -1,4 +1,4 @@ -class RemoveEnableMailDeliveryPreference < ActiveRecord::Migration +class RemoveEnableMailDeliveryPreference < ActiveRecord::Migration[4.2] def up Spree::Preference.delete_all("key ilike '%enable_mail_delivery%'") end diff --git a/db/migrate/20210125171611_populate_order_tax_totals.rb b/db/migrate/20210125171611_populate_order_tax_totals.rb index b466eca11c..47b206f622 100644 --- a/db/migrate/20210125171611_populate_order_tax_totals.rb +++ b/db/migrate/20210125171611_populate_order_tax_totals.rb @@ -1,4 +1,4 @@ -class PopulateOrderTaxTotals < ActiveRecord::Migration +class PopulateOrderTaxTotals < ActiveRecord::Migration[4.2] def up # Updates new order tax total fields (additional_tax_total and included_tax_total). # Sums the relevant values from associated adjustments and updates the two columns. diff --git a/db/migrate/20210127174120_add_cascading_deletes.rb b/db/migrate/20210127174120_add_cascading_deletes.rb index 3babe886b0..62692b7546 100644 --- a/db/migrate/20210127174120_add_cascading_deletes.rb +++ b/db/migrate/20210127174120_add_cascading_deletes.rb @@ -1,4 +1,4 @@ -class AddCascadingDeletes < ActiveRecord::Migration +class AddCascadingDeletes < ActiveRecord::Migration[4.2] def change # Updates foreign key definitions between orders, shipments, and inventory_units # to allow for cascading deletes at database level. If an order is intentionally diff --git a/db/migrate/20210130135946_increase_precion_on_currency_fields.rb b/db/migrate/20210130135946_increase_precion_on_currency_fields.rb index c2c43531fa..7738f88d60 100644 --- a/db/migrate/20210130135946_increase_precion_on_currency_fields.rb +++ b/db/migrate/20210130135946_increase_precion_on_currency_fields.rb @@ -1,4 +1,4 @@ -class IncreasePrecionOnCurrencyFields < ActiveRecord::Migration +class IncreasePrecionOnCurrencyFields < ActiveRecord::Migration[4.2] def up change_column :spree_line_items, :price, :decimal, precision: 10, scale: 2 change_column :spree_line_items, :cost_price, :decimal, precision: 10, scale: 2 diff --git a/db/migrate/20210203214304_rename_migs_payment_methods_to_check.rb b/db/migrate/20210203214304_rename_migs_payment_methods_to_check.rb index bec8eca69b..0db3dd58d3 100644 --- a/db/migrate/20210203214304_rename_migs_payment_methods_to_check.rb +++ b/db/migrate/20210203214304_rename_migs_payment_methods_to_check.rb @@ -1,4 +1,4 @@ -class RenameMigsPaymentMethodsToCheck < ActiveRecord::Migration +class RenameMigsPaymentMethodsToCheck < ActiveRecord::Migration[4.2] def change Spree::PaymentMethod .where(type: "Spree::Gateway::Migs") diff --git a/db/migrate/20210203215049_rename_pin_payment_methods_to_check.rb b/db/migrate/20210203215049_rename_pin_payment_methods_to_check.rb index bde3427d16..e4c78659a0 100644 --- a/db/migrate/20210203215049_rename_pin_payment_methods_to_check.rb +++ b/db/migrate/20210203215049_rename_pin_payment_methods_to_check.rb @@ -1,4 +1,4 @@ -class RenamePinPaymentMethodsToCheck < ActiveRecord::Migration +class RenamePinPaymentMethodsToCheck < ActiveRecord::Migration[4.2] def change Spree::PaymentMethod .where(type: "Spree::Gateway::Pin") diff --git a/db/migrate/20210207120753_add_tax_category_id_to_shipping_methods.rb b/db/migrate/20210207120753_add_tax_category_id_to_shipping_methods.rb index b330c066e8..cf2db90754 100644 --- a/db/migrate/20210207120753_add_tax_category_id_to_shipping_methods.rb +++ b/db/migrate/20210207120753_add_tax_category_id_to_shipping_methods.rb @@ -1,4 +1,4 @@ -class AddTaxCategoryIdToShippingMethods < ActiveRecord::Migration +class AddTaxCategoryIdToShippingMethods < ActiveRecord::Migration[4.2] def change add_column :spree_shipping_methods, :tax_category_id, :integer end diff --git a/db/migrate/20210207120825_set_default_shipment_cost.rb b/db/migrate/20210207120825_set_default_shipment_cost.rb index ce45e9d2e5..be71748cb1 100644 --- a/db/migrate/20210207120825_set_default_shipment_cost.rb +++ b/db/migrate/20210207120825_set_default_shipment_cost.rb @@ -1,4 +1,4 @@ -class SetDefaultShipmentCost < ActiveRecord::Migration +class SetDefaultShipmentCost < ActiveRecord::Migration[4.2] def up change_column_null :spree_shipments, :cost, false, 0.0 change_column_default :spree_shipments, :cost, 0.0 diff --git a/db/migrate/20210207131247_add_tax_totals_to_shipment.rb b/db/migrate/20210207131247_add_tax_totals_to_shipment.rb index 8627226fda..3e8a701159 100644 --- a/db/migrate/20210207131247_add_tax_totals_to_shipment.rb +++ b/db/migrate/20210207131247_add_tax_totals_to_shipment.rb @@ -1,4 +1,4 @@ -class AddTaxTotalsToShipment < ActiveRecord::Migration +class AddTaxTotalsToShipment < ActiveRecord::Migration[4.2] def up add_column :spree_shipments, :included_tax_total, :decimal, precision: 10, scale: 2, null: false, default: 0.0 diff --git a/db/migrate/20210207151520_add_adjustment_total_to_shipment.rb b/db/migrate/20210207151520_add_adjustment_total_to_shipment.rb index aeee8eac43..1c4139fbb2 100644 --- a/db/migrate/20210207151520_add_adjustment_total_to_shipment.rb +++ b/db/migrate/20210207151520_add_adjustment_total_to_shipment.rb @@ -1,4 +1,4 @@ -class AddAdjustmentTotalToShipment < ActiveRecord::Migration +class AddAdjustmentTotalToShipment < ActiveRecord::Migration[4.2] def up add_column :spree_shipments, :adjustment_total, :decimal, precision: 10, scale: 2, null: false, default: 0.0 diff --git a/db/migrate/20210211115125_migrate_shipment_fees_to_shipments.rb b/db/migrate/20210211115125_migrate_shipment_fees_to_shipments.rb index 46c4f9e55c..4172cd9d93 100644 --- a/db/migrate/20210211115125_migrate_shipment_fees_to_shipments.rb +++ b/db/migrate/20210211115125_migrate_shipment_fees_to_shipments.rb @@ -1,4 +1,4 @@ -class MigrateShipmentFeesToShipments < ActiveRecord::Migration +class MigrateShipmentFeesToShipments < ActiveRecord::Migration[4.2] class Spree::Adjustment < ActiveRecord::Base belongs_to :originator, polymorphic: true end diff --git a/db/migrate/20210216203057_remove_cost_price_from_variant_and_line_item.rb b/db/migrate/20210216203057_remove_cost_price_from_variant_and_line_item.rb index 5c9af2937c..444087ef7e 100644 --- a/db/migrate/20210216203057_remove_cost_price_from_variant_and_line_item.rb +++ b/db/migrate/20210216203057_remove_cost_price_from_variant_and_line_item.rb @@ -1,4 +1,4 @@ -class RemoveCostPriceFromVariantAndLineItem < ActiveRecord::Migration +class RemoveCostPriceFromVariantAndLineItem < ActiveRecord::Migration[4.2] def up remove_column :spree_variants, :cost_price remove_column :spree_line_items, :cost_price diff --git a/db/migrate/20210224190247_migrate_shipping_taxes.rb b/db/migrate/20210224190247_migrate_shipping_taxes.rb index cf536f9cf2..e1d6a34a92 100644 --- a/db/migrate/20210224190247_migrate_shipping_taxes.rb +++ b/db/migrate/20210224190247_migrate_shipping_taxes.rb @@ -1,4 +1,4 @@ -class MigrateShippingTaxes < ActiveRecord::Migration +class MigrateShippingTaxes < ActiveRecord::Migration[4.2] class Spree::Preference < ActiveRecord::Base; end class Spree::TaxCategory < ActiveRecord::Base has_many :tax_rates, class_name: "Spree::TaxRate", inverse_of: :tax_category diff --git a/db/migrate/20210227144926_migrate_payment_fees_to_payments.rb b/db/migrate/20210227144926_migrate_payment_fees_to_payments.rb index 5cd9c24ace..86b1a7857c 100644 --- a/db/migrate/20210227144926_migrate_payment_fees_to_payments.rb +++ b/db/migrate/20210227144926_migrate_payment_fees_to_payments.rb @@ -1,4 +1,4 @@ -class MigratePaymentFeesToPayments < ActiveRecord::Migration +class MigratePaymentFeesToPayments < ActiveRecord::Migration[4.2] class Spree::Adjustment < ActiveRecord::Base belongs_to :originator, polymorphic: true end diff --git a/db/migrate/20210228223114_migrate_line_item_fees.rb b/db/migrate/20210228223114_migrate_line_item_fees.rb index f923a7b7b5..f7e0a0bcf7 100644 --- a/db/migrate/20210228223114_migrate_line_item_fees.rb +++ b/db/migrate/20210228223114_migrate_line_item_fees.rb @@ -1,4 +1,4 @@ -class MigrateLineItemFees < ActiveRecord::Migration +class MigrateLineItemFees < ActiveRecord::Migration[4.2] class Spree::Adjustment < ActiveRecord::Base belongs_to :originator, polymorphic: true belongs_to :source, polymorphic: true From be6fd23ebc30e8994a2948ac254c1f19fb4f8312 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 10 Apr 2021 03:41:17 +0100 Subject: [PATCH 05/17] Fix unpersisted changes in checkout controller specs The test setup left the object with unsaved changes, which doesn't work nicely with the new order locking added recently on the edit action. Fixes ~5 specs including: 5) CheckoutController redirection to cart and stripe redirects when some items are out of stock Failure/Error: order.with_lock do lock_variants_of(order) yield end RuntimeError: Locking a record with unpersisted changes is not supported. Use `save` to persist the changes, or `reload` to discard them explicitly. # ./app/services/current_order_locker.rb:22:in `lock_order_and_variants' # ./app/services/current_order_locker.rb:11:in `around' # ./spec/controllers/checkout_controller_spec.rb:57:in `block (3 levels) in ' --- spec/controllers/checkout_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/controllers/checkout_controller_spec.rb b/spec/controllers/checkout_controller_spec.rb index c9d1a5f353..423c2aa031 100644 --- a/spec/controllers/checkout_controller_spec.rb +++ b/spec/controllers/checkout_controller_spec.rb @@ -46,7 +46,7 @@ describe CheckoutController, type: :controller do before do allow(controller).to receive(:current_order).and_return(order) allow(order).to receive(:distributor).and_return(distributor) - order.order_cycle = order_cycle + order.update(order_cycle: order_cycle) allow(OrderCycleDistributedVariants).to receive(:new).and_return(order_cycle_distributed_variants) end From 3f6fcf3350c52375559ddb65ad6b1bc8443e9c37 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 10 Apr 2021 16:50:07 +0100 Subject: [PATCH 07/17] Fix taxon error handling in Api::TaxonsController Fixes: Api::V0::TaxonsController as an admin cannot create a new taxon with invalid taxonomy_id Failure/Error: expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.") expected: "Invalid resource. Please fix errors and try again." got: nil (compared using ==) # ./spec/controllers/api/v0/taxons_controller_spec.rb:105:in `block (3 levels) in ' --- app/controllers/api/v0/taxons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v0/taxons_controller.rb b/app/controllers/api/v0/taxons_controller.rb index 12ed6a15a4..b3e74d0dac 100644 --- a/app/controllers/api/v0/taxons_controller.rb +++ b/app/controllers/api/v0/taxons_controller.rb @@ -28,7 +28,7 @@ module Api taxonomy = Spree::Taxonomy.find_by(id: params[:taxonomy_id]) if taxonomy.nil? - @taxon.errors[:taxonomy_id] = I18n.t(:invalid_taxonomy_id, scope: 'spree.api') + @taxon.errors.add(:taxonomy_id, I18n.t(:invalid_taxonomy_id, scope: 'spree.api')) invalid_resource!(@taxon) && return end From ab4660ecd0c105ea7748fcbdbd9fb5aabf76ee63 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 10 Apr 2021 17:37:58 +0100 Subject: [PATCH 08/17] Fix callback in Classification and update spec Fixes: 2) Spree::Classification won't destroy if classification is the primary taxon (Used from /home/runner/work/openfoodnetwork/openfoodnetwork/spec/models/enterprise_group_spec.rb:43:in `block (3 levels) in ') Failure/Error: expect(classification.destroy).to be false --- app/models/spree/classification.rb | 2 +- spec/models/spree/classification_spec.rb | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/models/spree/classification.rb b/app/models/spree/classification.rb index 0b668a068b..b4e78214a3 100644 --- a/app/models/spree/classification.rb +++ b/app/models/spree/classification.rb @@ -15,7 +15,7 @@ module Spree errors.add :base, I18n.t(:spree_classification_primary_taxon_error, taxon: taxon.name, product: product.name) - false + throw :abort end end end diff --git a/spec/models/spree/classification_spec.rb b/spec/models/spree/classification_spec.rb index 65407747cc..6a35477f12 100644 --- a/spec/models/spree/classification_spec.rb +++ b/spec/models/spree/classification_spec.rb @@ -4,14 +4,16 @@ require 'spec_helper' module Spree describe Classification do - let(:product) { build_stubbed(:simple_product) } - let(:taxon) { build_stubbed(:taxon) } + let(:product) { create(:simple_product) } + let(:taxon) { create(:taxon) } it "won't destroy if classification is the primary taxon" do - classification = Classification.new(taxon: taxon, product: product) - product.primary_taxon = taxon + classification = Classification.create(taxon: taxon, product: product) + product.update(primary_taxon: taxon) + expect(classification.destroy).to be false expect(classification.errors.messages[:base]).to eq(["Taxon #{taxon.name} is the primary taxon of #{product.name} and cannot be deleted"]) + expect(classification.reload).to be end end end From 049c2b59cadad313613b14d36c5951b2924ed292 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Sat, 10 Apr 2021 15:20:21 +0100 Subject: [PATCH 09/17] Adapt routes and helpers to make view spec green --- app/helpers/spree/admin/orders_helper.rb | 10 +++++----- app/views/spree/admin/orders/_form.html.haml | 4 ++-- app/views/spree/admin/shared/_order_tabs.html.haml | 10 +++++----- spec/views/spree/admin/orders/edit.html.haml_spec.rb | 3 +++ 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/helpers/spree/admin/orders_helper.rb b/app/helpers/spree/admin/orders_helper.rb index ae1877688b..112b264d7f 100644 --- a/app/helpers/spree/admin/orders_helper.rb +++ b/app/helpers/spree/admin/orders_helper.rb @@ -50,13 +50,13 @@ module Spree def edit_order_link { name: t(:edit_order), - url: edit_admin_order_path(@order), + url: spree.edit_admin_order_path(@order), icon: 'icon-edit' } end def resend_confirmation_link { name: t(:resend_confirmation), - url: resend_admin_order_path(@order), + url: spree.resend_admin_order_path(@order), icon: 'icon-email', method: 'post', confirm: t(:confirm_resend_order_confirmation) } @@ -78,7 +78,7 @@ module Spree def print_invoice_link { name: t(:print_invoice), - url: print_admin_order_path(@order), + url: spree.print_admin_order_path(@order), icon: 'icon-print', target: "_blank" } end @@ -99,7 +99,7 @@ module Spree def ship_order_link { name: t(:ship_order), - url: fire_admin_order_path(@order, e: 'ship'), + url: spree.fire_admin_order_path(@order, e: 'ship'), method: 'put', icon: 'icon-truck', confirm: t(:are_you_sure) } @@ -107,7 +107,7 @@ module Spree def cancel_order_link { name: t(:cancel_order), - url: fire_admin_order_path(@order.number, e: 'cancel'), + url: spree.fire_admin_order_path(@order.number, e: 'cancel'), icon: 'icon-trash', confirm: t(:are_you_sure) } end diff --git a/app/views/spree/admin/orders/_form.html.haml b/app/views/spree/admin/orders/_form.html.haml index 6f02721895..a0fac1bef3 100644 --- a/app/views/spree/admin/orders/_form.html.haml +++ b/app/views/spree/admin/orders/_form.html.haml @@ -12,14 +12,14 @@ %legend{ align: 'center' }= t(".order_total") %span.order-total= order.display_total - = form_for @order, url: admin_order_url(@order), method: :put do |f| + = form_for @order, url: spree.admin_order_url(@order), method: :put do |f| = render partial: 'spree/admin/orders/_form/distribution_fields' .filter-actions.actions{"ng-show" => "distributionChosen()"} = button t(:update_and_recalculate_fees), 'icon-refresh' %span.or = t(:or) - = link_to_with_icon 'button icon-arrow-left', t(:back), admin_orders_url + = link_to_with_icon 'button icon-arrow-left', t(:back), spree.admin_orders_url = javascript_tag do var order_number = '#{@order.number}'; diff --git a/app/views/spree/admin/shared/_order_tabs.html.haml b/app/views/spree/admin/shared/_order_tabs.html.haml index f96a5dd140..4f4c70bfca 100644 --- a/app/views/spree/admin/shared/_order_tabs.html.haml +++ b/app/views/spree/admin/shared/_order_tabs.html.haml @@ -46,21 +46,21 @@ %ul - order_details_classes = "active" if current == "Order Details" %li{ class: order_details_classes } - = link_to_with_icon 'icon-edit', t(:order_details), edit_admin_order_url(@order) + = link_to_with_icon 'icon-edit', t(:order_details), spree.edit_admin_order_url(@order) - customer_details_classes = "active" if current == "Customer Details" %li{ class: customer_details_classes } - = link_to_with_icon 'icon-user', t(:customer_details), admin_order_customer_url(@order) + = link_to_with_icon 'icon-user', t(:customer_details), spree.admin_order_customer_url(@order) - adjustments_classes = "active" if current == "Adjustments" %li{ class: adjustments_classes } - = link_to_with_icon 'icon-cogs', t(:adjustments), admin_order_adjustments_url(@order) + = link_to_with_icon 'icon-cogs', t(:adjustments), spree.admin_order_adjustments_url(@order) - payments_classes = "active" if current == "Payments" %li{ class: payments_classes } - = link_to_with_icon 'icon-credit-card', t(:payments), admin_order_payments_url(@order) + = link_to_with_icon 'icon-credit-card', t(:payments), spree.admin_order_payments_url(@order) - if @order.completed? - authorizations_classes = "active" if current == "Return Authorizations" %li{ class: authorizations_classes } - = link_to_with_icon 'icon-share-alt', t(:return_authorizations), admin_order_return_authorizations_url(@order) + = link_to_with_icon 'icon-share-alt', t(:return_authorizations), spree.admin_order_return_authorizations_url(@order) diff --git a/spec/views/spree/admin/orders/edit.html.haml_spec.rb b/spec/views/spree/admin/orders/edit.html.haml_spec.rb index 4394065394..73d62340ab 100644 --- a/spec/views/spree/admin/orders/edit.html.haml_spec.rb +++ b/spec/views/spree/admin/orders/edit.html.haml_spec.rb @@ -4,6 +4,9 @@ require "spec_helper" describe "spree/admin/orders/edit.html.haml" do helper Spree::BaseHelper # required to make pretty_time work + helper Spree::Admin::NavigationHelper + helper Admin::InjectionHelper + helper Admin::OrdersHelper around do |example| original_config = Spree::Config[:enable_invoices?] From 2c05478b2f6e413a8c38985a7e8f8bf977d91ed9 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Sat, 10 Apr 2021 15:25:08 +0100 Subject: [PATCH 10/17] Adapt routes and helpers to make view spec green --- app/views/spree/admin/orders/_filters.html.haml | 2 +- app/views/spree/admin/orders/index.html.haml | 2 +- spec/views/spree/admin/orders/index.html.haml_spec.rb | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/views/spree/admin/orders/_filters.html.haml b/app/views/spree/admin/orders/_filters.html.haml index 0302489fd3..dead6051d9 100644 --- a/app/views/spree/admin/orders/_filters.html.haml +++ b/app/views/spree/admin/orders/_filters.html.haml @@ -1,5 +1,5 @@ %div{"data-hook" => "admin_orders_index_search"} - = form_tag :admin_orders, {name: "orders_form", "ng-submit" => "fetchResults()"} do + = form_tag spree.admin_orders_url, {name: "orders_form", "ng-submit" => "fetchResults()"} do .field-block.alpha.four.columns .date-range-filter.field = label_tag nil, t(:date_range) diff --git a/app/views/spree/admin/orders/index.html.haml b/app/views/spree/admin/orders/index.html.haml index 70f8cf5864..758fc4dd07 100644 --- a/app/views/spree/admin/orders/index.html.haml +++ b/app/views/spree/admin/orders/index.html.haml @@ -3,7 +3,7 @@ - content_for :page_actions do %li - = button_link_to t('.new_order'), new_admin_order_url, icon: 'icon-plus', id: 'admin_new_order' + = button_link_to t('.new_order'), spree.new_admin_order_url, icon: 'icon-plus', id: 'admin_new_order' = render partial: 'spree/admin/shared/order_sub_menu' diff --git a/spec/views/spree/admin/orders/index.html.haml_spec.rb b/spec/views/spree/admin/orders/index.html.haml_spec.rb index d9556bd76a..9087a07b09 100644 --- a/spec/views/spree/admin/orders/index.html.haml_spec.rb +++ b/spec/views/spree/admin/orders/index.html.haml_spec.rb @@ -3,6 +3,9 @@ require "spec_helper" describe "spree/admin/orders/index.html.haml" do + helper Spree::Admin::NavigationHelper + helper EnterprisesHelper + around do |example| original_config = Spree::Config[:enable_invoices?] example.run From abd6faf686a03a11ac3dd470f6c583d14b4c42c1 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Sat, 10 Apr 2021 15:29:49 +0100 Subject: [PATCH 11/17] Adapt routes and helpers to make view spec green --- spec/views/spree/admin/payment_methods/index.html.haml_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb b/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb index 3b6b6d5aba..2fb34ef37e 100644 --- a/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb +++ b/spec/views/spree/admin/payment_methods/index.html.haml_spec.rb @@ -4,6 +4,8 @@ require "spec_helper" describe "spree/admin/payment_methods/index.html.haml" do include AuthenticationHelper + helper Spree::Admin::NavigationHelper + helper Spree::Admin::BaseHelper before do controller.singleton_class.class_eval do From f61c04e3147da94c9b98c704166e62a169b596ad Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Sat, 10 Apr 2021 15:39:23 +0100 Subject: [PATCH 12/17] Adapt helpers to make view spec green --- spec/views/spree/orders/edit.html.haml_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/views/spree/orders/edit.html.haml_spec.rb b/spec/views/spree/orders/edit.html.haml_spec.rb index 38b112a759..f51f3ec05e 100644 --- a/spec/views/spree/orders/edit.html.haml_spec.rb +++ b/spec/views/spree/orders/edit.html.haml_spec.rb @@ -3,6 +3,14 @@ require "spec_helper" describe "spree/orders/edit.html.haml" do + helper InjectionHelper + helper ShopHelper + helper ApplicationHelper + helper CheckoutHelper + helper SharedHelper + helper FooterLinksHelper + helper MarkdownHelper + let(:order) { create(:completed_order_with_fees) } before do From ae7e1677f7d66452e23951f13d1d088488ae6556 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Sat, 10 Apr 2021 16:15:57 +0100 Subject: [PATCH 13/17] Add needed helper to BulkInvoiceService spec --- spec/services/bulk_invoice_service_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/services/bulk_invoice_service_spec.rb b/spec/services/bulk_invoice_service_spec.rb index 3a89609de2..78a324f0f2 100644 --- a/spec/services/bulk_invoice_service_spec.rb +++ b/spec/services/bulk_invoice_service_spec.rb @@ -1,9 +1,11 @@ # frozen_string_literal: false require 'spec_helper' +require 'spree/admin/payments_helper' describe BulkInvoiceService do include ActiveJob::TestHelper + include Spree::Admin::PaymentsHelper let(:service) { BulkInvoiceService.new } From e4a6afab81a12be2c2bf0990e3949dcf220420c6 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Sat, 10 Apr 2021 16:16:48 +0100 Subject: [PATCH 14/17] Add needed helper to BulkInvoiceRenderer spec --- spec/services/invoice_renderer_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/services/invoice_renderer_spec.rb b/spec/services/invoice_renderer_spec.rb index d78f5e97a8..dfa72c4fc1 100644 --- a/spec/services/invoice_renderer_spec.rb +++ b/spec/services/invoice_renderer_spec.rb @@ -1,8 +1,11 @@ # frozen_string_literal: true require 'spec_helper' +require 'spree/admin/payments_helper' describe InvoiceRenderer do + include Spree::Admin::PaymentsHelper + let(:service) { described_class.new } let(:order) do order = create(:completed_order_with_fees) From 39fa315ecca814932cd0c0d417b4891a647676c4 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 13 Mar 2021 16:13:52 +0000 Subject: [PATCH 15/17] Guard against calls to the database during db:create Rails 5.2 has changed the way initializers are called during certain rake tasks including `db:create`. Initializers that were previously not loaded are now loaded (basically the whole app is loaded). This means any calls to #table_exists? that appear in the app will throw fatal errors as the database doesn't exist yet during that task, but those calls are made before `db:create` has even started, which means the database can't be created. There are also a few other places in Spree code where #table_exists? is called, and they already call #connected? first to guard against this issue. --- config/application.rb | 3 ++- lib/spree/localized_number.rb | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/config/application.rb b/config/application.rb index 33638102f5..1dd47734af 100644 --- a/config/application.rb +++ b/config/application.rb @@ -79,7 +79,8 @@ module Openfoodnetwork initializer 'ofn.spree_locale_settings', before: 'spree.promo.environment' do |app| Spree::Config['checkout_zone'] = ENV['CHECKOUT_ZONE'] Spree::Config['currency'] = ENV['CURRENCY'] - if Spree::Country.table_exists? + + if ActiveRecord::Base.connected? && Spree::Country.table_exists? country = Spree::Country.find_by(iso: ENV['DEFAULT_COUNTRY_CODE']) Spree::Config['default_country_id'] = country.id if country.present? else diff --git a/lib/spree/localized_number.rb b/lib/spree/localized_number.rb index f14d4ed176..f6089b2930 100644 --- a/lib/spree/localized_number.rb +++ b/lib/spree/localized_number.rb @@ -9,6 +9,8 @@ module Spree # It also adds a validation on the input format. # It accepts as arguments a variable number of attribute as symbols def localize_number(*attributes) + return unless connected? + validate :validate_localizable_number attributes.each do |attribute| From 67e41f4548460f90a0df05ddec83aa1ef047e890 Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Fri, 9 Apr 2021 14:57:56 -0700 Subject: [PATCH 16/17] remove check for connected? --- lib/spree/localized_number.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/spree/localized_number.rb b/lib/spree/localized_number.rb index f6089b2930..f14d4ed176 100644 --- a/lib/spree/localized_number.rb +++ b/lib/spree/localized_number.rb @@ -9,8 +9,6 @@ module Spree # It also adds a validation on the input format. # It accepts as arguments a variable number of attribute as symbols def localize_number(*attributes) - return unless connected? - validate :validate_localizable_number attributes.each do |attribute| From 4bd7f964d01a898cb40df5d79cf2af2e179fd406 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sat, 10 Apr 2021 15:17:44 +0100 Subject: [PATCH 17/17] Fix LocalizedNumber issues --- lib/spree/localized_number.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/spree/localized_number.rb b/lib/spree/localized_number.rb index f14d4ed176..c248fd98a1 100644 --- a/lib/spree/localized_number.rb +++ b/lib/spree/localized_number.rb @@ -13,7 +13,7 @@ module Spree attributes.each do |attribute| setter = "#{attribute}=" - old_setter = instance_method(setter) if table_exists? && !column_names.include?(attribute.to_s) + old_setter = instance_method(setter) if non_activerecord_attribute?(attribute) define_method(setter) do |number| if Spree::Config.enable_localized_number? && Spree::LocalizedNumber.valid_localizable_number?(number) @@ -24,8 +24,10 @@ module Spree number = nil end if has_attribute?(attribute) + # In this case it's a regular AR attribute with standard setters self[attribute] = number else + # In this case it's a Spree preference, and the interface is very different old_setter.bind(self).call(number) end end @@ -66,5 +68,15 @@ module Spree # If does not end in ,00 / .00 then add trailing 00 to turn it into cents number << "00" unless number =~ /^.*[\.,]\d{2}$/ end + + private + + def non_activerecord_attribute?(attribute) + table_exists? && !column_names.include?(attribute.to_s) + rescue ::ActiveRecord::NoDatabaseError + # This class is now loaded during `rake db:create` (since Rails 5.2), and not only does the + # table not exist, but the database does not even exist yet, and throws a fatal error. + # We can rescue and safely ignore it in that case. + end end end