Merge pull request #7413 from andrewpbrett/rails-5-2-prep

Rails 5 2 prep
This commit is contained in:
Matt-Yorkley
2021-04-14 12:37:02 +02:00
committed by GitHub
88 changed files with 131 additions and 94 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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}';

View File

@@ -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'

View File

@@ -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)

View File

@@ -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

View File

@@ -1,6 +1,6 @@
# frozen_string_literal: true
class OldMigrationsRemoved < ActiveRecord::Migration
class OldMigrationsRemoved < ActiveRecord::Migration[4.2]
def up
raise StandardError, <<-MESSAGE

View File

@@ -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',

View File

@@ -1,4 +1,4 @@
class DeleteAccountInvoicesAdjustments < ActiveRecord::Migration
class DeleteAccountInvoicesAdjustments < ActiveRecord::Migration[4.2]
def up
Spree::Adjustment
.where(source_type: 'BillablePeriod')

View File

@@ -1,4 +1,4 @@
class DropEnterpriseShopTrialStartDate < ActiveRecord::Migration
class DropEnterpriseShopTrialStartDate < ActiveRecord::Migration[4.2]
def up
remove_column :enterprises, :shop_trial_start_date
end

View File

@@ -1,4 +1,4 @@
class DropProductDistributions < ActiveRecord::Migration
class DropProductDistributions < ActiveRecord::Migration[4.2]
def up
drop_table :product_distributions
end

View File

@@ -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

View File

@@ -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

View File

@@ -1,4 +1,4 @@
class DropAccountInvoicesAndBillablePeriods < ActiveRecord::Migration
class DropAccountInvoicesAndBillablePeriods < ActiveRecord::Migration[4.2]
def up
drop_table :billable_periods
drop_table :account_invoices

View File

@@ -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" ||

View File

@@ -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

View File

@@ -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)"

View File

@@ -1,4 +1,4 @@
class RemoveFieldNameFromExchange < ActiveRecord::Migration
class RemoveFieldNameFromExchange < ActiveRecord::Migration[4.2]
def up
remove_column :exchanges, :payment_enterprise_id
end

View File

@@ -1,4 +1,4 @@
class UpdateStockLocationsBackorderableDefault < ActiveRecord::Migration
class UpdateStockLocationsBackorderableDefault < ActiveRecord::Migration[4.2]
def change
Spree::StockLocation.update_all(backorderable_default: false)
end

View File

@@ -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

View File

@@ -1,4 +1,4 @@
class AddDeletedAtToSpreePrices < ActiveRecord::Migration
class AddDeletedAtToSpreePrices < ActiveRecord::Migration[4.2]
def change
add_column :spree_prices, :deleted_at, :datetime
end

View File

@@ -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"

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -1,4 +1,4 @@
class AddLongCompoundIndexOnSpreeOrders < ActiveRecord::Migration
class AddLongCompoundIndexOnSpreeOrders < ActiveRecord::Migration[4.2]
def change
add_index(
:spree_orders,

View File

@@ -1,4 +1,4 @@
class DropCompletedAtIndexOnSpreeOrders < ActiveRecord::Migration
class DropCompletedAtIndexOnSpreeOrders < ActiveRecord::Migration[4.2]
def change
remove_index :spree_orders, :completed_at
end

View File

@@ -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

View File

@@ -1,4 +1,4 @@
class DropOrdersShippingMethodId < ActiveRecord::Migration
class DropOrdersShippingMethodId < ActiveRecord::Migration[4.2]
def up
remove_column :spree_orders, :shipping_method_id
end

View File

@@ -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

View File

@@ -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

View File

@@ -1,4 +1,4 @@
class AddCustomDataToVersions < ActiveRecord::Migration
class AddCustomDataToVersions < ActiveRecord::Migration[4.2]
def change
add_column :versions, :custom_data, :string
end

View File

@@ -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

View File

@@ -1,4 +1,4 @@
class ChangeVersionsCustomDataToText < ActiveRecord::Migration
class ChangeVersionsCustomDataToText < ActiveRecord::Migration[4.2]
def up
change_column :versions, :custom_data, :text
end

View File

@@ -1,4 +1,4 @@
class AddUserIdIndexToSpreeOrders < ActiveRecord::Migration
class AddUserIdIndexToSpreeOrders < ActiveRecord::Migration[4.2]
def change
add_index :spree_orders, :user_id
end

View File

@@ -1,4 +1,4 @@
class AddSupplierIdIndexToSpreeProducts < ActiveRecord::Migration
class AddSupplierIdIndexToSpreeProducts < ActiveRecord::Migration[4.2]
def change
add_index :spree_products, :supplier_id
end

View File

@@ -1,4 +1,4 @@
class DropTrackersTable < ActiveRecord::Migration
class DropTrackersTable < ActiveRecord::Migration[4.2]
def up
drop_table :spree_trackers
end

View File

@@ -1,4 +1,4 @@
class RemoveGaCookiesPreference < ActiveRecord::Migration
class RemoveGaCookiesPreference < ActiveRecord::Migration[4.2]
class Spree::Preference < ActiveRecord::Base; end
def up

View File

@@ -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

View File

@@ -1,4 +1,4 @@
class DropMailMethods < ActiveRecord::Migration
class DropMailMethods < ActiveRecord::Migration[4.2]
def up
drop_table :spree_mail_methods

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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"

View File

@@ -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")

View File

@@ -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

View File

@@ -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

View File

@@ -1,4 +1,4 @@
class RequireTimestamps < ActiveRecord::Migration
class RequireTimestamps < ActiveRecord::Migration[4.2]
def up
current_time = Time.zone.now

View File

@@ -1,4 +1,4 @@
class AddStatefulIdIndexToStateChanges < ActiveRecord::Migration
class AddStatefulIdIndexToStateChanges < ActiveRecord::Migration[4.2]
def change
add_index :spree_state_changes, :stateful_id
end

View File

@@ -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

View File

@@ -1,4 +1,4 @@
class AddTermsAndConditionsToEnterprises < ActiveRecord::Migration
class AddTermsAndConditionsToEnterprises < ActiveRecord::Migration[4.2]
def change
add_attachment :enterprises, :terms_and_conditions
end

View File

@@ -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

View File

@@ -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/%'"

View File

@@ -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")

View File

@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -1,4 +1,4 @@
class AddDeletedAtToEnterpriseFee < ActiveRecord::Migration
class AddDeletedAtToEnterpriseFee < ActiveRecord::Migration[4.2]
def change
add_column :enterprise_fees, :deleted_at, :datetime
end

View File

@@ -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

View File

@@ -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

View File

@@ -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.

View File

@@ -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

View File

@@ -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

View File

@@ -1,4 +1,4 @@
class RenameMigsPaymentMethodsToCheck < ActiveRecord::Migration
class RenameMigsPaymentMethodsToCheck < ActiveRecord::Migration[4.2]
def change
Spree::PaymentMethod
.where(type: "Spree::Gateway::Migs")

View File

@@ -1,4 +1,4 @@
class RenamePinPaymentMethodsToCheck < ActiveRecord::Migration
class RenamePinPaymentMethodsToCheck < ActiveRecord::Migration[4.2]
def change
Spree::PaymentMethod
.where(type: "Spree::Gateway::Pin")

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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 }

View File

@@ -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)

View File

@@ -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?]

View File

@@ -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

View File

@@ -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

View File

@@ -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