diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index db04a52e171..6f3bbb554b3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -368,84 +368,6 @@ Rails/ApplicationMailer: Exclude: - 'app/mailers/spree/base_mailer.rb' -# Offense count: 73 -# Cop supports --auto-correct. -Rails/ApplicationRecord: - Exclude: - - 'app/models/adjustment_metadata.rb' - - 'app/models/column_preference.rb' - - 'app/models/coordinator_fee.rb' - - 'app/models/customer.rb' - - 'app/models/distributor_shipping_method.rb' - - 'app/models/enterprise.rb' - - 'app/models/enterprise_fee.rb' - - 'app/models/enterprise_group.rb' - - 'app/models/enterprise_relationship.rb' - - 'app/models/enterprise_relationship_permission.rb' - - 'app/models/enterprise_role.rb' - - 'app/models/exchange.rb' - - 'app/models/exchange_fee.rb' - - 'app/models/exchange_variant.rb' - - 'app/models/inventory_item.rb' - - 'app/models/order_cycle.rb' - - 'app/models/order_cycle_schedule.rb' - - 'app/models/producer_property.rb' - - 'app/models/proxy_order.rb' - - 'app/models/schedule.rb' - - 'app/models/spree/address.rb' - - 'app/models/spree/adjustment.rb' - - 'app/models/spree/asset.rb' - - 'app/models/spree/calculator.rb' - - 'app/models/spree/classification.rb' - - 'app/models/spree/country.rb' - - 'app/models/spree/credit_card.rb' - - 'app/models/spree/inventory_unit.rb' - - 'app/models/spree/line_item.rb' - - 'app/models/spree/log_entry.rb' - - 'app/models/spree/option_type.rb' - - 'app/models/spree/option_value.rb' - - 'app/models/spree/option_values_line_item.rb' - - 'app/models/spree/order.rb' - - 'app/models/spree/order/checkout.rb' - - 'app/models/spree/payment.rb' - - 'app/models/spree/payment/processing.rb' - - 'app/models/spree/payment_method.rb' - - 'app/models/spree/paypal_express_checkout.rb' - - 'app/models/spree/preference.rb' - - 'app/models/spree/price.rb' - - 'app/models/spree/product.rb' - - 'app/models/spree/product_option_type.rb' - - 'app/models/spree/product_property.rb' - - 'app/models/spree/property.rb' - - 'app/models/spree/return_authorization.rb' - - 'app/models/spree/role.rb' - - 'app/models/spree/shipment.rb' - - 'app/models/spree/shipping_category.rb' - - 'app/models/spree/shipping_method.rb' - - 'app/models/spree/shipping_method_category.rb' - - 'app/models/spree/shipping_rate.rb' - - 'app/models/spree/state.rb' - - 'app/models/spree/state_change.rb' - - 'app/models/spree/stock_item.rb' - - 'app/models/spree/stock_location.rb' - - 'app/models/spree/stock_movement.rb' - - 'app/models/spree/tax_category.rb' - - 'app/models/spree/tax_rate.rb' - - 'app/models/spree/taxon.rb' - - 'app/models/spree/taxonomy.rb' - - 'app/models/spree/tokenized_permission.rb' - - 'app/models/spree/user.rb' - - 'app/models/spree/variant.rb' - - 'app/models/spree/zone.rb' - - 'app/models/spree/zone_member.rb' - - 'app/models/stripe_account.rb' - - 'app/models/subscription.rb' - - 'app/models/subscription_line_item.rb' - - 'app/models/tag_rule.rb' - - 'app/models/variant_override.rb' - - 'lib/tasks/data/remove_transient_data.rb' - - 'spec/models/spree/preferences/preferable_spec.rb' - # Offense count: 3 # Cop supports --auto-correct. # Configuration parameters: NilOrEmpty, NotPresent, UnlessPresent. diff --git a/app/models/adjustment_metadata.rb b/app/models/adjustment_metadata.rb index d8315a3c71a..c282368acad 100644 --- a/app/models/adjustment_metadata.rb +++ b/app/models/adjustment_metadata.rb @@ -1,4 +1,4 @@ -class AdjustmentMetadata < ActiveRecord::Base +class AdjustmentMetadata < ApplicationRecord belongs_to :adjustment, class_name: 'Spree::Adjustment' belongs_to :enterprise end diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 00000000000..e4478b15594 --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class ApplicationRecord < ActiveRecord::Base + include DelegateBelongsTo + include Spree::Core::Permalinks + include Spree::Preferences::Preferable + + self.abstract_class = true +end diff --git a/app/models/column_preference.rb b/app/models/column_preference.rb index ae5cdd91279..0b608315416 100644 --- a/app/models/column_preference.rb +++ b/app/models/column_preference.rb @@ -1,6 +1,6 @@ require 'open_food_network/column_preference_defaults' -class ColumnPreference < ActiveRecord::Base +class ColumnPreference < ApplicationRecord extend OpenFoodNetwork::ColumnPreferenceDefaults # Non-persisted attributes that only have one diff --git a/app/models/coordinator_fee.rb b/app/models/coordinator_fee.rb index f15a1941587..92238cbebef 100644 --- a/app/models/coordinator_fee.rb +++ b/app/models/coordinator_fee.rb @@ -1,4 +1,4 @@ -class CoordinatorFee < ActiveRecord::Base +class CoordinatorFee < ApplicationRecord belongs_to :order_cycle belongs_to :enterprise_fee end diff --git a/app/models/customer.rb b/app/models/customer.rb index 71025435ffa..e128bde4916 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -1,4 +1,4 @@ -class Customer < ActiveRecord::Base +class Customer < ApplicationRecord acts_as_taggable belongs_to :enterprise diff --git a/app/models/distributor_shipping_method.rb b/app/models/distributor_shipping_method.rb index 5c69cefbc04..87aba1b139c 100644 --- a/app/models/distributor_shipping_method.rb +++ b/app/models/distributor_shipping_method.rb @@ -1,4 +1,4 @@ -class DistributorShippingMethod < ActiveRecord::Base +class DistributorShippingMethod < ApplicationRecord self.table_name = "distributors_shipping_methods" belongs_to :shipping_method, class_name: "Spree::ShippingMethod", touch: true belongs_to :distributor, class_name: "Enterprise", touch: true diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 135358fdc7b..5acfd8d3a94 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -2,7 +2,7 @@ require 'spree/core/s3_support' -class Enterprise < ActiveRecord::Base +class Enterprise < ApplicationRecord SELLS = %w(unspecified none own any).freeze ENTERPRISE_SEARCH_RADIUS = 100 diff --git a/app/models/enterprise_fee.rb b/app/models/enterprise_fee.rb index 6406ad68688..ff173835985 100644 --- a/app/models/enterprise_fee.rb +++ b/app/models/enterprise_fee.rb @@ -1,4 +1,4 @@ -class EnterpriseFee < ActiveRecord::Base +class EnterpriseFee < ApplicationRecord include Spree::Core::CalculatedAdjustments acts_as_paranoid diff --git a/app/models/enterprise_group.rb b/app/models/enterprise_group.rb index b2bbfba1984..cde5d60e7c8 100644 --- a/app/models/enterprise_group.rb +++ b/app/models/enterprise_group.rb @@ -4,7 +4,7 @@ require 'open_food_network/permalink_generator' require 'spree/core/s3_support' -class EnterpriseGroup < ActiveRecord::Base +class EnterpriseGroup < ApplicationRecord include PermalinkGenerator acts_as_list diff --git a/app/models/enterprise_relationship.rb b/app/models/enterprise_relationship.rb index 3aa98751230..87e745f3c45 100644 --- a/app/models/enterprise_relationship.rb +++ b/app/models/enterprise_relationship.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class EnterpriseRelationship < ActiveRecord::Base +class EnterpriseRelationship < ApplicationRecord belongs_to :parent, class_name: 'Enterprise', touch: true belongs_to :child, class_name: 'Enterprise', touch: true has_many :permissions, class_name: 'EnterpriseRelationshipPermission', dependent: :destroy diff --git a/app/models/enterprise_relationship_permission.rb b/app/models/enterprise_relationship_permission.rb index 5bd40bf70c3..55d70d57a8b 100644 --- a/app/models/enterprise_relationship_permission.rb +++ b/app/models/enterprise_relationship_permission.rb @@ -1,3 +1,3 @@ -class EnterpriseRelationshipPermission < ActiveRecord::Base +class EnterpriseRelationshipPermission < ApplicationRecord default_scope { order('name') } end diff --git a/app/models/enterprise_role.rb b/app/models/enterprise_role.rb index 773cb6013ca..72071eb69ee 100644 --- a/app/models/enterprise_role.rb +++ b/app/models/enterprise_role.rb @@ -1,4 +1,4 @@ -class EnterpriseRole < ActiveRecord::Base +class EnterpriseRole < ApplicationRecord belongs_to :user, class_name: Spree.user_class.to_s belongs_to :enterprise diff --git a/app/models/exchange.rb b/app/models/exchange.rb index 282173e622a..a05e7cb2018 100644 --- a/app/models/exchange.rb +++ b/app/models/exchange.rb @@ -7,7 +7,7 @@ # in its shopfront. Any incoming product can be selected to be shown in the # shopfront (outgoing products). But the set of shown products can be smaller # than all incoming products. -class Exchange < ActiveRecord::Base +class Exchange < ApplicationRecord acts_as_taggable belongs_to :order_cycle diff --git a/app/models/exchange_fee.rb b/app/models/exchange_fee.rb index ff9f12e8ddf..7d9fa492693 100644 --- a/app/models/exchange_fee.rb +++ b/app/models/exchange_fee.rb @@ -1,4 +1,4 @@ -class ExchangeFee < ActiveRecord::Base +class ExchangeFee < ApplicationRecord belongs_to :exchange belongs_to :enterprise_fee end diff --git a/app/models/exchange_variant.rb b/app/models/exchange_variant.rb index 69e7bec7bae..01b792734e7 100644 --- a/app/models/exchange_variant.rb +++ b/app/models/exchange_variant.rb @@ -1,4 +1,4 @@ -class ExchangeVariant < ActiveRecord::Base +class ExchangeVariant < ApplicationRecord belongs_to :exchange belongs_to :variant, class_name: 'Spree::Variant' end diff --git a/app/models/inventory_item.rb b/app/models/inventory_item.rb index 186f87522f7..91ba0f6d10c 100644 --- a/app/models/inventory_item.rb +++ b/app/models/inventory_item.rb @@ -1,4 +1,4 @@ -class InventoryItem < ActiveRecord::Base +class InventoryItem < ApplicationRecord belongs_to :enterprise belongs_to :variant, class_name: "Spree::Variant" diff --git a/app/models/order_cycle.rb b/app/models/order_cycle.rb index 91230b3aec5..37073c3628b 100644 --- a/app/models/order_cycle.rb +++ b/app/models/order_cycle.rb @@ -1,6 +1,6 @@ require 'open_food_network/scope_variant_to_hub' -class OrderCycle < ActiveRecord::Base +class OrderCycle < ApplicationRecord belongs_to :coordinator, class_name: 'Enterprise' has_many :coordinator_fee_refs, class_name: 'CoordinatorFee' diff --git a/app/models/order_cycle_schedule.rb b/app/models/order_cycle_schedule.rb index bff4da5fc3d..b3087cf11bb 100644 --- a/app/models/order_cycle_schedule.rb +++ b/app/models/order_cycle_schedule.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class OrderCycleSchedule < ActiveRecord::Base +class OrderCycleSchedule < ApplicationRecord belongs_to :schedule belongs_to :order_cycle end diff --git a/app/models/producer_property.rb b/app/models/producer_property.rb index 278118871d8..1d3ba6eb0e2 100644 --- a/app/models/producer_property.rb +++ b/app/models/producer_property.rb @@ -1,4 +1,4 @@ -class ProducerProperty < ActiveRecord::Base +class ProducerProperty < ApplicationRecord belongs_to :producer, class_name: 'Enterprise', touch: true belongs_to :property, class_name: 'Spree::Property' diff --git a/app/models/proxy_order.rb b/app/models/proxy_order.rb index bece28a65dc..c58d58528f4 100644 --- a/app/models/proxy_order.rb +++ b/app/models/proxy_order.rb @@ -2,7 +2,7 @@ # Proxy pattern allows for deferral of initialization until absolutely required # This reduces the need to keep Orders in sync with their parent Subscriptions -class ProxyOrder < ActiveRecord::Base +class ProxyOrder < ApplicationRecord belongs_to :order, class_name: 'Spree::Order', dependent: :destroy belongs_to :subscription belongs_to :order_cycle diff --git a/app/models/schedule.rb b/app/models/schedule.rb index 9450b160b5a..1a11305ede0 100644 --- a/app/models/schedule.rb +++ b/app/models/schedule.rb @@ -1,4 +1,4 @@ -class Schedule < ActiveRecord::Base +class Schedule < ApplicationRecord has_paper_trail meta: { custom_data: proc { |schedule| schedule.order_cycle_ids.to_s } } has_many :order_cycle_schedules, dependent: :destroy diff --git a/app/models/spree/address.rb b/app/models/spree/address.rb index 855cfa67d1e..061f55f1dcb 100644 --- a/app/models/spree/address.rb +++ b/app/models/spree/address.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class Address < ActiveRecord::Base + class Address < ApplicationRecord include AddressDisplay belongs_to :country, class_name: "Spree::Country" diff --git a/app/models/spree/adjustment.rb b/app/models/spree/adjustment.rb index fbdb0a86975..405775474e2 100644 --- a/app/models/spree/adjustment.rb +++ b/app/models/spree/adjustment.rb @@ -28,7 +28,7 @@ # total. This allows an adjustment to be preserved if it becomes ineligible so # it might be reinstated. module Spree - class Adjustment < ActiveRecord::Base + class Adjustment < ApplicationRecord extend Spree::LocalizedNumber # Deletion of metadata is handled in the database. diff --git a/app/models/spree/asset.rb b/app/models/spree/asset.rb index d5eb00d506e..168435c12fe 100644 --- a/app/models/spree/asset.rb +++ b/app/models/spree/asset.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class Asset < ActiveRecord::Base + class Asset < ApplicationRecord belongs_to :viewable, polymorphic: true, touch: true acts_as_list scope: :viewable end diff --git a/app/models/spree/calculator.rb b/app/models/spree/calculator.rb index 40bea838f52..fa7880f3ecc 100644 --- a/app/models/spree/calculator.rb +++ b/app/models/spree/calculator.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class Calculator < ActiveRecord::Base + class Calculator < ApplicationRecord belongs_to :calculable, polymorphic: true # This method must be overriden in concrete calculator. diff --git a/app/models/spree/classification.rb b/app/models/spree/classification.rb index b4e78214a36..696595a033c 100644 --- a/app/models/spree/classification.rb +++ b/app/models/spree/classification.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class Classification < ActiveRecord::Base + class Classification < ApplicationRecord self.table_name = 'spree_products_taxons' belongs_to :product, class_name: "Spree::Product", touch: true belongs_to :taxon, class_name: "Spree::Taxon", touch: true diff --git a/app/models/spree/country.rb b/app/models/spree/country.rb index e0a69f3ae6c..ee949685569 100644 --- a/app/models/spree/country.rb +++ b/app/models/spree/country.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class Country < ActiveRecord::Base + class Country < ApplicationRecord has_many :states, -> { order('name ASC') } validates :name, :iso_name, presence: true diff --git a/app/models/spree/credit_card.rb b/app/models/spree/credit_card.rb index 5a4efea485c..ef51c4898b4 100644 --- a/app/models/spree/credit_card.rb +++ b/app/models/spree/credit_card.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class CreditCard < ActiveRecord::Base + class CreditCard < ApplicationRecord belongs_to :payment_method belongs_to :user diff --git a/app/models/spree/inventory_unit.rb b/app/models/spree/inventory_unit.rb index f0acfc10ea6..7bad1f998ca 100644 --- a/app/models/spree/inventory_unit.rb +++ b/app/models/spree/inventory_unit.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class InventoryUnit < ActiveRecord::Base + class InventoryUnit < ApplicationRecord belongs_to :variant, -> { with_deleted }, class_name: "Spree::Variant" belongs_to :order, class_name: "Spree::Order" belongs_to :shipment, class_name: "Spree::Shipment" diff --git a/app/models/spree/line_item.rb b/app/models/spree/line_item.rb index 5e32be41f39..97cd7dd8883 100644 --- a/app/models/spree/line_item.rb +++ b/app/models/spree/line_item.rb @@ -4,7 +4,7 @@ require 'variant_units/variant_and_line_item_naming' module Spree - class LineItem < ActiveRecord::Base + class LineItem < ApplicationRecord include VariantUnits::VariantAndLineItemNaming include LineItemStockChanges diff --git a/app/models/spree/log_entry.rb b/app/models/spree/log_entry.rb index 85b65fe8e7f..449df8c4ecf 100644 --- a/app/models/spree/log_entry.rb +++ b/app/models/spree/log_entry.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class LogEntry < ActiveRecord::Base + class LogEntry < ApplicationRecord belongs_to :source, polymorphic: true # Fix for Spree #1767 diff --git a/app/models/spree/option_type.rb b/app/models/spree/option_type.rb index 91b65c97bb9..3c03976ec3d 100644 --- a/app/models/spree/option_type.rb +++ b/app/models/spree/option_type.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class OptionType < ActiveRecord::Base + class OptionType < ApplicationRecord has_many :products, through: :product_option_types has_many :option_values, -> { order(:position) }, dependent: :destroy has_many :product_option_types, dependent: :destroy diff --git a/app/models/spree/option_value.rb b/app/models/spree/option_value.rb index b21eed19ba6..f03301a5e5e 100644 --- a/app/models/spree/option_value.rb +++ b/app/models/spree/option_value.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class OptionValue < ActiveRecord::Base + class OptionValue < ApplicationRecord belongs_to :option_type acts_as_list scope: :option_type has_and_belongs_to_many :variants, join_table: 'spree_option_values_variants', diff --git a/app/models/spree/option_values_line_item.rb b/app/models/spree/option_values_line_item.rb index 4f1ab992a81..0b6632e7e3b 100644 --- a/app/models/spree/option_values_line_item.rb +++ b/app/models/spree/option_values_line_item.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class OptionValuesLineItem < ActiveRecord::Base + class OptionValuesLineItem < ApplicationRecord belongs_to :line_item, class_name: 'Spree::LineItem' belongs_to :option_value, class_name: 'Spree::OptionValue' end diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index ba4e819d000..2a919c54639 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -7,7 +7,7 @@ require 'concerns/order_shipment' module Spree - class Order < ActiveRecord::Base + class Order < ApplicationRecord prepend OrderShipment include Checkout diff --git a/app/models/spree/order/checkout.rb b/app/models/spree/order/checkout.rb index bcdac0c617a..4d34f091ca2 100644 --- a/app/models/spree/order/checkout.rb +++ b/app/models/spree/order/checkout.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class Order < ActiveRecord::Base + class Order < ApplicationRecord module Checkout def self.included(klass) klass.class_eval do diff --git a/app/models/spree/payment.rb b/app/models/spree/payment.rb index a94e1ab32d5..d16e428922f 100644 --- a/app/models/spree/payment.rb +++ b/app/models/spree/payment.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class Payment < ActiveRecord::Base + class Payment < ApplicationRecord include Spree::Payment::Processing extend Spree::LocalizedNumber diff --git a/app/models/spree/payment/processing.rb b/app/models/spree/payment/processing.rb index 9e9c0d959f0..a40a0798dad 100644 --- a/app/models/spree/payment/processing.rb +++ b/app/models/spree/payment/processing.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class Payment < ActiveRecord::Base + class Payment < ApplicationRecord module Processing def process! return unless validate! diff --git a/app/models/spree/payment_method.rb b/app/models/spree/payment_method.rb index 4204632b91f..c055842951f 100644 --- a/app/models/spree/payment_method.rb +++ b/app/models/spree/payment_method.rb @@ -4,7 +4,7 @@ require 'spree/core/calculated_adjustments' module Spree - class PaymentMethod < ActiveRecord::Base + class PaymentMethod < ApplicationRecord include Spree::Core::CalculatedAdjustments include PaymentMethodDistributors diff --git a/app/models/spree/paypal_express_checkout.rb b/app/models/spree/paypal_express_checkout.rb index 93e0b0e6d0a..d7965589592 100644 --- a/app/models/spree/paypal_express_checkout.rb +++ b/app/models/spree/paypal_express_checkout.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true module Spree - class PaypalExpressCheckout < ActiveRecord::Base + class PaypalExpressCheckout < ApplicationRecord end end diff --git a/app/models/spree/preference.rb b/app/models/spree/preference.rb index b877f460ce3..dfef2a146da 100644 --- a/app/models/spree/preference.rb +++ b/app/models/spree/preference.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class Preference < ActiveRecord::Base + class Preference < ApplicationRecord serialize :value validates :key, presence: true diff --git a/app/models/spree/price.rb b/app/models/spree/price.rb index 3fbc619bd35..871b7886e3d 100644 --- a/app/models/spree/price.rb +++ b/app/models/spree/price.rb @@ -1,7 +1,7 @@ # frozen_string_literal: false module Spree - class Price < ActiveRecord::Base + class Price < ApplicationRecord acts_as_paranoid without_default_scope: true belongs_to :variant, -> { with_deleted }, class_name: 'Spree::Variant' diff --git a/app/models/spree/product.rb b/app/models/spree/product.rb index 50e909bd4f6..6bd6cbc3dd0 100755 --- a/app/models/spree/product.rb +++ b/app/models/spree/product.rb @@ -24,7 +24,7 @@ # Sum of on_hand each variant's inventory level determine "on_hand" level for the product. # module Spree - class Product < ActiveRecord::Base + class Product < ApplicationRecord include PermalinkGenerator include ProductStock diff --git a/app/models/spree/product_option_type.rb b/app/models/spree/product_option_type.rb index b02db6a4403..9ef54964809 100644 --- a/app/models/spree/product_option_type.rb +++ b/app/models/spree/product_option_type.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class ProductOptionType < ActiveRecord::Base + class ProductOptionType < ApplicationRecord after_destroy :remove_option_values belongs_to :product, class_name: 'Spree::Product' diff --git a/app/models/spree/product_property.rb b/app/models/spree/product_property.rb index a86a12f1a92..2f67dbcd9ba 100644 --- a/app/models/spree/product_property.rb +++ b/app/models/spree/product_property.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class ProductProperty < ActiveRecord::Base + class ProductProperty < ApplicationRecord belongs_to :product, class_name: "Spree::Product", touch: true belongs_to :property, class_name: 'Spree::Property' diff --git a/app/models/spree/property.rb b/app/models/spree/property.rb index 18f24977867..900519aa6c4 100644 --- a/app/models/spree/property.rb +++ b/app/models/spree/property.rb @@ -1,5 +1,5 @@ module Spree - class Property < ActiveRecord::Base + class Property < ApplicationRecord has_many :product_properties, dependent: :destroy has_many :products, through: :product_properties has_many :producer_properties diff --git a/app/models/spree/return_authorization.rb b/app/models/spree/return_authorization.rb index 37394e69d68..0361aaf0819 100644 --- a/app/models/spree/return_authorization.rb +++ b/app/models/spree/return_authorization.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class ReturnAuthorization < ActiveRecord::Base + class ReturnAuthorization < ApplicationRecord acts_as_paranoid belongs_to :order, class_name: 'Spree::Order', inverse_of: :return_authorizations diff --git a/app/models/spree/role.rb b/app/models/spree/role.rb index 1c8f575835e..01b67044325 100644 --- a/app/models/spree/role.rb +++ b/app/models/spree/role.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class Role < ActiveRecord::Base + class Role < ApplicationRecord has_and_belongs_to_many :users, join_table: 'spree_roles_users', class_name: Spree.user_class.to_s end diff --git a/app/models/spree/shipment.rb b/app/models/spree/shipment.rb index 9dff6d6cac6..b5f7516f064 100644 --- a/app/models/spree/shipment.rb +++ b/app/models/spree/shipment.rb @@ -3,7 +3,7 @@ require 'ostruct' module Spree - class Shipment < ActiveRecord::Base + class Shipment < ApplicationRecord belongs_to :order, class_name: 'Spree::Order' belongs_to :address, class_name: 'Spree::Address' belongs_to :stock_location, class_name: 'Spree::StockLocation' diff --git a/app/models/spree/shipping_category.rb b/app/models/spree/shipping_category.rb index b28031d026d..6bbfb7f603e 100644 --- a/app/models/spree/shipping_category.rb +++ b/app/models/spree/shipping_category.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class ShippingCategory < ActiveRecord::Base + class ShippingCategory < ApplicationRecord validates :name, presence: true has_many :products has_many :shipping_method_categories, inverse_of: :shipping_method diff --git a/app/models/spree/shipping_method.rb b/app/models/spree/shipping_method.rb index a910bf55ef4..efff8c56bc0 100644 --- a/app/models/spree/shipping_method.rb +++ b/app/models/spree/shipping_method.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class ShippingMethod < ActiveRecord::Base + class ShippingMethod < ApplicationRecord include Spree::Core::CalculatedAdjustments DISPLAY = [:both, :front_end, :back_end].freeze diff --git a/app/models/spree/shipping_method_category.rb b/app/models/spree/shipping_method_category.rb index e8fa1498ffb..0a32c66125a 100644 --- a/app/models/spree/shipping_method_category.rb +++ b/app/models/spree/shipping_method_category.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class ShippingMethodCategory < ActiveRecord::Base + class ShippingMethodCategory < ApplicationRecord belongs_to :shipping_method, class_name: 'Spree::ShippingMethod' belongs_to :shipping_category, class_name: 'Spree::ShippingCategory', inverse_of: :shipping_method_categories diff --git a/app/models/spree/shipping_rate.rb b/app/models/spree/shipping_rate.rb index 31fcec4c055..710a8a25b4d 100644 --- a/app/models/spree/shipping_rate.rb +++ b/app/models/spree/shipping_rate.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class ShippingRate < ActiveRecord::Base + class ShippingRate < ApplicationRecord belongs_to :shipment, class_name: 'Spree::Shipment' belongs_to :shipping_method, class_name: 'Spree::ShippingMethod', inverse_of: :shipping_rates diff --git a/app/models/spree/state.rb b/app/models/spree/state.rb index 7b3c5ff057d..55bd4b5ae62 100644 --- a/app/models/spree/state.rb +++ b/app/models/spree/state.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class State < ActiveRecord::Base + class State < ApplicationRecord belongs_to :country, class_name: 'Spree::Country' validates :country, :name, presence: true diff --git a/app/models/spree/state_change.rb b/app/models/spree/state_change.rb index 9f527770952..0e770096b55 100644 --- a/app/models/spree/state_change.rb +++ b/app/models/spree/state_change.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class StateChange < ActiveRecord::Base + class StateChange < ApplicationRecord belongs_to :user belongs_to :stateful, polymorphic: true before_create :assign_user diff --git a/app/models/spree/stock_item.rb b/app/models/spree/stock_item.rb index 128a0e9cbe0..96950899b2c 100644 --- a/app/models/spree/stock_item.rb +++ b/app/models/spree/stock_item.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class StockItem < ActiveRecord::Base + class StockItem < ApplicationRecord acts_as_paranoid belongs_to :stock_location, class_name: 'Spree::StockLocation', inverse_of: :stock_items diff --git a/app/models/spree/stock_location.rb b/app/models/spree/stock_location.rb index e0da35e6855..7cf9e26d518 100644 --- a/app/models/spree/stock_location.rb +++ b/app/models/spree/stock_location.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class StockLocation < ActiveRecord::Base + class StockLocation < ApplicationRecord has_many :stock_items, dependent: :delete_all, inverse_of: :stock_location has_many :stock_movements, through: :stock_items diff --git a/app/models/spree/stock_movement.rb b/app/models/spree/stock_movement.rb index f435ed1f506..1409c8a606f 100644 --- a/app/models/spree/stock_movement.rb +++ b/app/models/spree/stock_movement.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class StockMovement < ActiveRecord::Base + class StockMovement < ApplicationRecord belongs_to :stock_item, class_name: 'Spree::StockItem' belongs_to :originator, polymorphic: true diff --git a/app/models/spree/tax_category.rb b/app/models/spree/tax_category.rb index 864e97e53a2..c69a744cee4 100644 --- a/app/models/spree/tax_category.rb +++ b/app/models/spree/tax_category.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class TaxCategory < ActiveRecord::Base + class TaxCategory < ApplicationRecord acts_as_paranoid validates :name, presence: true, uniqueness: { scope: :deleted_at } diff --git a/app/models/spree/tax_rate.rb b/app/models/spree/tax_rate.rb index 5d90c1d7bcb..cce477b29d9 100644 --- a/app/models/spree/tax_rate.rb +++ b/app/models/spree/tax_rate.rb @@ -13,7 +13,7 @@ def validate(record) end module Spree - class TaxRate < ActiveRecord::Base + class TaxRate < ApplicationRecord acts_as_paranoid include Spree::Core::CalculatedAdjustments belongs_to :zone, class_name: "Spree::Zone", inverse_of: :tax_rates diff --git a/app/models/spree/taxon.rb b/app/models/spree/taxon.rb index 4e29c068ce6..2c9b3177da1 100644 --- a/app/models/spree/taxon.rb +++ b/app/models/spree/taxon.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class Taxon < ActiveRecord::Base + class Taxon < ApplicationRecord acts_as_nested_set dependent: :destroy belongs_to :taxonomy, class_name: 'Spree::Taxonomy', touch: true diff --git a/app/models/spree/taxonomy.rb b/app/models/spree/taxonomy.rb index f4e45765051..11364fda0c9 100644 --- a/app/models/spree/taxonomy.rb +++ b/app/models/spree/taxonomy.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class Taxonomy < ActiveRecord::Base + class Taxonomy < ApplicationRecord validates :name, presence: true has_many :taxons diff --git a/app/models/spree/tokenized_permission.rb b/app/models/spree/tokenized_permission.rb index 58c5882c3a6..e2d5329dec2 100644 --- a/app/models/spree/tokenized_permission.rb +++ b/app/models/spree/tokenized_permission.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class TokenizedPermission < ActiveRecord::Base + class TokenizedPermission < ApplicationRecord belongs_to :permissable, polymorphic: true end end diff --git a/app/models/spree/user.rb b/app/models/spree/user.rb index a2982181e75..372a29bf29b 100644 --- a/app/models/spree/user.rb +++ b/app/models/spree/user.rb @@ -1,5 +1,5 @@ module Spree - class User < ActiveRecord::Base + class User < ApplicationRecord devise :database_authenticatable, :token_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :encryptable, :confirmable, encryptor: 'authlogic_sha512', reconfirmable: true diff --git a/app/models/spree/variant.rb b/app/models/spree/variant.rb index d4f3c3aadea..8268d783369 100644 --- a/app/models/spree/variant.rb +++ b/app/models/spree/variant.rb @@ -6,7 +6,7 @@ require 'spree/localized_number' module Spree - class Variant < ActiveRecord::Base + class Variant < ApplicationRecord extend Spree::LocalizedNumber include VariantUnits::VariantAndLineItemNaming include VariantStock diff --git a/app/models/spree/zone.rb b/app/models/spree/zone.rb index b2dd4bf69a4..db5286c9bd8 100644 --- a/app/models/spree/zone.rb +++ b/app/models/spree/zone.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class Zone < ActiveRecord::Base + class Zone < ApplicationRecord has_many :zone_members, dependent: :destroy, class_name: "Spree::ZoneMember", inverse_of: :zone has_many :tax_rates, dependent: :destroy, inverse_of: :zone has_and_belongs_to_many :shipping_methods, join_table: 'spree_shipping_methods_zones' diff --git a/app/models/spree/zone_member.rb b/app/models/spree/zone_member.rb index 46c6c4c43bf..45a28efebda 100644 --- a/app/models/spree/zone_member.rb +++ b/app/models/spree/zone_member.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Spree - class ZoneMember < ActiveRecord::Base + class ZoneMember < ApplicationRecord belongs_to :zone, class_name: 'Spree::Zone', counter_cache: true, inverse_of: :zone_members belongs_to :zoneable, polymorphic: true diff --git a/app/models/stripe_account.rb b/app/models/stripe_account.rb index 1b2840ffe6d..2065bc14ecf 100644 --- a/app/models/stripe_account.rb +++ b/app/models/stripe_account.rb @@ -1,4 +1,4 @@ -class StripeAccount < ActiveRecord::Base +class StripeAccount < ApplicationRecord belongs_to :enterprise validates :stripe_user_id, :stripe_publishable_key, presence: true validates :enterprise_id, uniqueness: true diff --git a/app/models/subscription.rb b/app/models/subscription.rb index dbb5a8bf23c..c8f6901816a 100644 --- a/app/models/subscription.rb +++ b/app/models/subscription.rb @@ -1,4 +1,4 @@ -class Subscription < ActiveRecord::Base +class Subscription < ApplicationRecord ALLOWED_PAYMENT_METHOD_TYPES = ["Spree::PaymentMethod::Check", "Spree::Gateway::StripeConnect", "Spree::Gateway::StripeSCA"].freeze diff --git a/app/models/subscription_line_item.rb b/app/models/subscription_line_item.rb index 9c04dc9a76b..795d5996cec 100644 --- a/app/models/subscription_line_item.rb +++ b/app/models/subscription_line_item.rb @@ -1,4 +1,4 @@ -class SubscriptionLineItem < ActiveRecord::Base +class SubscriptionLineItem < ApplicationRecord belongs_to :subscription, inverse_of: :subscription_line_items belongs_to :variant, -> { with_deleted }, class_name: 'Spree::Variant' diff --git a/app/models/tag_rule.rb b/app/models/tag_rule.rb index 404c449e501..6f61d4a31a0 100644 --- a/app/models/tag_rule.rb +++ b/app/models/tag_rule.rb @@ -1,4 +1,4 @@ -class TagRule < ActiveRecord::Base +class TagRule < ApplicationRecord belongs_to :enterprise preference :customer_tags, :string, default: "" diff --git a/app/models/variant_override.rb b/app/models/variant_override.rb index 6836eb4afd8..9fd26b1ed4d 100644 --- a/app/models/variant_override.rb +++ b/app/models/variant_override.rb @@ -2,7 +2,7 @@ require 'spree/localized_number' -class VariantOverride < ActiveRecord::Base +class VariantOverride < ApplicationRecord extend Spree::LocalizedNumber include StockSettingsOverrideValidation diff --git a/config/application.rb b/config/application.rb index 1dd47734afa..0996f747474 100644 --- a/config/application.rb +++ b/config/application.rb @@ -39,10 +39,6 @@ class Application < Rails::Application Spree::Config = app.config.spree.preferences # legacy access end - initializer "spree.load_preferences", before: "spree.environment" do - ::ActiveRecord::Base.include Spree::Preferences::Preferable - end - initializer "spree.register.payment_methods" do |app| app.config.spree.payment_methods = [ Spree::Gateway::Bogus, diff --git a/lib/spree/core/delegate_belongs_to.rb b/lib/spree/core/delegate_belongs_to.rb index 6c96134b1e8..f2e4fda7700 100644 --- a/lib/spree/core/delegate_belongs_to.rb +++ b/lib/spree/core/delegate_belongs_to.rb @@ -90,5 +90,3 @@ def delegator_for(association) end protected :delegator_for end - -ActiveRecord::Base.include(DelegateBelongsTo) diff --git a/lib/spree/core/permalinks.rb b/lib/spree/core/permalinks.rb index b9d8a832749..b667de7b2c0 100644 --- a/lib/spree/core/permalinks.rb +++ b/lib/spree/core/permalinks.rb @@ -23,14 +23,6 @@ def make_permalink(options = {}) before_validation(on: :create) { save_permalink } end - def find_by_param(value, *args) - __send__("find_by_#{permalink_field}", value, *args) - end - - def find_by_param!(value, *args) - __send__("find_by_#{permalink_field}!", value, *args) - end - def permalink_field permalink_options[:field] end @@ -70,6 +62,3 @@ def save_permalink(permalink_value = to_param) end end end - -ActiveRecord::Base.include(Spree::Core::Permalinks) -ActiveRecord::Relation.include(Spree::Core::Permalinks) diff --git a/spec/models/spree/preferences/preferable_spec.rb b/spec/models/spree/preferences/preferable_spec.rb index b355ba415cb..8b7edba9f07 100644 --- a/spec/models/spree/preferences/preferable_spec.rb +++ b/spec/models/spree/preferences/preferable_spec.rb @@ -238,7 +238,7 @@ def self.down ActiveRecord::Migration.verbose = false CreatePrefTest.migrate(:up) - class PrefTest < ActiveRecord::Base + class PrefTest < ApplicationRecord preference :pref_test_pref, :string, default: 'abc' preference :pref_test_any, :any, default: [] end