Skip to content

Commit

Permalink
Merge pull request #7425 from mkllnk/application-record
Browse files Browse the repository at this point in the history
Add ApplicationRecord for customisations of models
  • Loading branch information
Matt-Yorkley authored Apr 21, 2021
2 parents 479897f + 5c0cdce commit 6dc2380
Show file tree
Hide file tree
Showing 77 changed files with 81 additions and 167 deletions.
78 changes: 0 additions & 78 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion app/models/adjustment_metadata.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AdjustmentMetadata < ActiveRecord::Base
class AdjustmentMetadata < ApplicationRecord
belongs_to :adjustment, class_name: 'Spree::Adjustment'
belongs_to :enterprise
end
9 changes: 9 additions & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion app/models/column_preference.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/coordinator_fee.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CoordinatorFee < ActiveRecord::Base
class CoordinatorFee < ApplicationRecord
belongs_to :order_cycle
belongs_to :enterprise_fee
end
2 changes: 1 addition & 1 deletion app/models/customer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Customer < ActiveRecord::Base
class Customer < ApplicationRecord
acts_as_taggable

belongs_to :enterprise
Expand Down
2 changes: 1 addition & 1 deletion app/models/distributor_shipping_method.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/enterprise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/models/enterprise_fee.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class EnterpriseFee < ActiveRecord::Base
class EnterpriseFee < ApplicationRecord
include Spree::Core::CalculatedAdjustments

acts_as_paranoid
Expand Down
2 changes: 1 addition & 1 deletion app/models/enterprise_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/models/enterprise_relationship.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/enterprise_relationship_permission.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class EnterpriseRelationshipPermission < ActiveRecord::Base
class EnterpriseRelationshipPermission < ApplicationRecord
default_scope { order('name') }
end
2 changes: 1 addition & 1 deletion app/models/enterprise_role.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class EnterpriseRole < ActiveRecord::Base
class EnterpriseRole < ApplicationRecord
belongs_to :user, class_name: Spree.user_class.to_s
belongs_to :enterprise

Expand Down
2 changes: 1 addition & 1 deletion app/models/exchange.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/exchange_fee.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ExchangeFee < ActiveRecord::Base
class ExchangeFee < ApplicationRecord
belongs_to :exchange
belongs_to :enterprise_fee
end
2 changes: 1 addition & 1 deletion app/models/exchange_variant.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ExchangeVariant < ActiveRecord::Base
class ExchangeVariant < ApplicationRecord
belongs_to :exchange
belongs_to :variant, class_name: 'Spree::Variant'
end
2 changes: 1 addition & 1 deletion app/models/inventory_item.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class InventoryItem < ActiveRecord::Base
class InventoryItem < ApplicationRecord
belongs_to :enterprise
belongs_to :variant, class_name: "Spree::Variant"

Expand Down
2 changes: 1 addition & 1 deletion app/models/order_cycle.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion app/models/order_cycle_schedule.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class OrderCycleSchedule < ActiveRecord::Base
class OrderCycleSchedule < ApplicationRecord
belongs_to :schedule
belongs_to :order_cycle
end
2 changes: 1 addition & 1 deletion app/models/producer_property.rb
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
2 changes: 1 addition & 1 deletion app/models/proxy_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/schedule.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/address.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/adjustment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/asset.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/calculator.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/classification.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/country.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/credit_card.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Spree
class CreditCard < ActiveRecord::Base
class CreditCard < ApplicationRecord
belongs_to :payment_method
belongs_to :user

Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/inventory_unit.rb
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/log_entry.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/option_type.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/option_value.rb
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/option_values_line_item.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
require 'concerns/order_shipment'

module Spree
class Order < ActiveRecord::Base
class Order < ApplicationRecord
prepend OrderShipment

include Checkout
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/order/checkout.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/payment.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Spree
class Payment < ActiveRecord::Base
class Payment < ApplicationRecord
include Spree::Payment::Processing
extend Spree::LocalizedNumber

Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/payment/processing.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Spree
class Payment < ActiveRecord::Base
class Payment < ApplicationRecord
module Processing
def process!
return unless validate!
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/payment_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require 'spree/core/calculated_adjustments'

module Spree
class PaymentMethod < ActiveRecord::Base
class PaymentMethod < ApplicationRecord
include Spree::Core::CalculatedAdjustments
include PaymentMethodDistributors

Expand Down
Loading

0 comments on commit 6dc2380

Please sign in to comment.