mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-17 00:07:24 +00:00
Merge pull request #12407 from cyrillefr/RedundantPresenceValidationOnBelongs_part_I
Fix RedundantPresenceValidationOnBelongs on some files
This commit is contained in:
@@ -660,15 +660,10 @@ Rails/RedundantActiveRecordAllMethod:
|
||||
- 'app/models/spree/variant.rb'
|
||||
- 'spec/system/admin/product_import_spec.rb'
|
||||
|
||||
# Offense count: 20
|
||||
# Offense count: 14
|
||||
# This cop supports unsafe autocorrection (--autocorrect-all).
|
||||
Rails/RedundantPresenceValidationOnBelongsTo:
|
||||
Exclude:
|
||||
- 'app/models/enterprise_fee.rb'
|
||||
- 'app/models/exchange.rb'
|
||||
- 'app/models/inventory_item.rb'
|
||||
- 'app/models/order_cycle.rb'
|
||||
- 'app/models/spree/address.rb'
|
||||
- 'app/models/spree/line_item.rb'
|
||||
- 'app/models/spree/order.rb'
|
||||
- 'app/models/spree/product_property.rb'
|
||||
|
||||
@@ -21,7 +21,6 @@ class EnterpriseFee < ApplicationRecord
|
||||
|
||||
validates :fee_type, inclusion: { in: FEE_TYPES }
|
||||
validates :name, presence: true
|
||||
validates :enterprise_id, presence: true
|
||||
|
||||
before_save :ensure_valid_tax_category_settings
|
||||
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
# shopfront (outgoing products). But the set of shown products can be smaller
|
||||
# than all incoming products.
|
||||
class Exchange < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
acts_as_taggable
|
||||
|
||||
belongs_to :order_cycle
|
||||
@@ -24,7 +22,6 @@ class Exchange < ApplicationRecord
|
||||
has_many :exchange_fees, dependent: :destroy
|
||||
has_many :enterprise_fees, through: :exchange_fees
|
||||
|
||||
validates :order_cycle, :sender, :receiver, presence: true
|
||||
validates :sender_id, uniqueness: { scope: [:order_cycle_id, :receiver_id, :incoming] }
|
||||
|
||||
before_destroy :delete_related_exchange_variants, prepend: true
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class InventoryItem < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :enterprise
|
||||
belongs_to :variant, class_name: "Spree::Variant"
|
||||
|
||||
validates :variant_id, uniqueness: { scope: :enterprise_id }
|
||||
validates :enterprise, presence: true
|
||||
validates :variant, presence: true
|
||||
validates :visible,
|
||||
inclusion: { in: [true, false], message: I18n.t(:inventory_item_visibility_error) }
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
require 'open_food_network/scope_variant_to_hub'
|
||||
|
||||
class OrderCycle < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
searchable_attributes :orders_open_at, :orders_close_at, :coordinator_id
|
||||
searchable_scopes :active, :inactive, :active_or_complete, :upcoming, :closed, :not_closed,
|
||||
:dated, :undated, :soonest_opening, :soonest_closing, :most_recently_closed
|
||||
@@ -44,7 +42,7 @@ class OrderCycle < ApplicationRecord
|
||||
before_update :reset_processed_at, if: :will_save_change_to_orders_close_at?
|
||||
after_save :sync_subscriptions, if: :opening?
|
||||
|
||||
validates :name, :coordinator_id, presence: true
|
||||
validates :name, presence: true
|
||||
validate :orders_close_at_after_orders_open_at?
|
||||
|
||||
preference :product_selection_from_coordinator_inventory_only, :boolean, default: false
|
||||
|
||||
@@ -4,19 +4,17 @@ module Spree
|
||||
class Address < ApplicationRecord
|
||||
include AddressDisplay
|
||||
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
searchable_attributes :firstname, :lastname, :phone, :full_name, :full_name_reversed,
|
||||
:full_name_with_comma, :full_name_with_comma_reversed
|
||||
searchable_associations :country, :state
|
||||
|
||||
belongs_to :country, class_name: "Spree::Country"
|
||||
belongs_to :state, class_name: "Spree::State"
|
||||
belongs_to :state, class_name: "Spree::State", optional: true
|
||||
|
||||
has_one :enterprise, dependent: :restrict_with_exception
|
||||
has_many :shipments
|
||||
|
||||
validates :address1, :city, :country, :phone, presence: true
|
||||
validates :address1, :city, :phone, presence: true
|
||||
validates :company, presence: true, unless: -> { first_name.blank? || last_name.blank? }
|
||||
validates :firstname, :lastname, presence: true, if: -> do
|
||||
company.blank? || company == 'unused'
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class RequireOrderCycleAndSenderAndReceiverOnExchange < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
change_column_null :exchanges, :order_cycle_id, false
|
||||
change_column_null :exchanges, :sender_id, false
|
||||
change_column_null :exchanges, :receiver_id, false
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class RequireNameAndCoordinatorOnOrderCycle < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
change_column_null :order_cycles, :name, false
|
||||
change_column_null :order_cycles, :coordinator_id, false
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
class RequireAddress1AndCityAndPhoneAndCountryAndOnAddress < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
change_column_null :spree_addresses, :address1, false
|
||||
change_column_null :spree_addresses, :city, false
|
||||
change_column_null :spree_addresses, :phone, false
|
||||
change_column_null :spree_addresses, :country_id, false
|
||||
end
|
||||
end
|
||||
20
db/schema.rb
20
db/schema.rb
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.0].define(version: 2024_02_13_044159) do
|
||||
ActiveRecord::Schema[7.0].define(version: 2024_04_22_150502) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pg_stat_statements"
|
||||
enable_extension "plpgsql"
|
||||
@@ -258,9 +258,9 @@ ActiveRecord::Schema[7.0].define(version: 2024_02_13_044159) do
|
||||
end
|
||||
|
||||
create_table "exchanges", id: :serial, force: :cascade do |t|
|
||||
t.integer "order_cycle_id"
|
||||
t.integer "sender_id"
|
||||
t.integer "receiver_id"
|
||||
t.integer "order_cycle_id", null: false
|
||||
t.integer "sender_id", null: false
|
||||
t.integer "receiver_id", null: false
|
||||
t.text "pickup_time"
|
||||
t.text "pickup_instructions"
|
||||
t.datetime "created_at", precision: nil, null: false
|
||||
@@ -330,10 +330,10 @@ ActiveRecord::Schema[7.0].define(version: 2024_02_13_044159) do
|
||||
end
|
||||
|
||||
create_table "order_cycles", id: :serial, force: :cascade do |t|
|
||||
t.string "name", limit: 255
|
||||
t.string "name", limit: 255, null: false
|
||||
t.datetime "orders_open_at", precision: nil
|
||||
t.datetime "orders_close_at", precision: nil
|
||||
t.integer "coordinator_id"
|
||||
t.integer "coordinator_id", null: false
|
||||
t.datetime "created_at", precision: nil, null: false
|
||||
t.datetime "updated_at", precision: nil, null: false
|
||||
t.datetime "processed_at", precision: nil
|
||||
@@ -420,15 +420,15 @@ ActiveRecord::Schema[7.0].define(version: 2024_02_13_044159) do
|
||||
create_table "spree_addresses", id: :serial, force: :cascade do |t|
|
||||
t.string "firstname", limit: 255
|
||||
t.string "lastname", limit: 255
|
||||
t.string "address1", limit: 255
|
||||
t.string "address1", limit: 255, null: false
|
||||
t.string "address2", limit: 255
|
||||
t.string "city", limit: 255
|
||||
t.string "city", limit: 255, null: false
|
||||
t.string "zipcode", limit: 255
|
||||
t.string "phone", limit: 255
|
||||
t.string "phone", limit: 255, null: false
|
||||
t.string "state_name", limit: 255
|
||||
t.string "alternative_phone", limit: 255
|
||||
t.integer "state_id"
|
||||
t.integer "country_id"
|
||||
t.integer "country_id", null: false
|
||||
t.datetime "created_at", precision: nil, null: false
|
||||
t.datetime "updated_at", precision: nil, null: false
|
||||
t.string "company", limit: 255
|
||||
|
||||
Reference in New Issue
Block a user