mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #12514 from cyrillefr/RedundantPresenceValidationOnBelongs_part_V
Fix redundant presence validation on belongs part V
This commit is contained in:
@@ -642,14 +642,12 @@ Rails/RedundantActiveRecordAllMethod:
|
||||
- 'app/models/spree/variant.rb'
|
||||
- 'spec/system/admin/product_import_spec.rb'
|
||||
|
||||
# Offense count: 7
|
||||
# Offense count: 4
|
||||
# This cop supports unsafe autocorrection (--autocorrect-all).
|
||||
Rails/RedundantPresenceValidationOnBelongsTo:
|
||||
Exclude:
|
||||
- 'app/models/spree/line_item.rb'
|
||||
- 'app/models/spree/order.rb'
|
||||
- 'app/models/subscription_line_item.rb'
|
||||
- 'app/models/tag_rule.rb'
|
||||
|
||||
# Offense count: 1
|
||||
# This cop supports unsafe autocorrection (--autocorrect-all).
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SubscriptionLineItem < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :subscription, inverse_of: :subscription_line_items
|
||||
belongs_to :variant, -> { with_deleted }, class_name: 'Spree::Variant'
|
||||
|
||||
validates :subscription, presence: true
|
||||
validates :variant, presence: true
|
||||
validates :quantity, presence: true, numericality: { only_integer: true }
|
||||
|
||||
default_scope { order('id ASC') }
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TagRule < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
|
||||
belongs_to :enterprise
|
||||
|
||||
preference :customer_tags, :string, default: ""
|
||||
|
||||
validates :enterprise, presence: true
|
||||
|
||||
scope :for, ->(enterprise) { where(enterprise_id: enterprise) }
|
||||
scope :prioritised, -> { order('priority ASC') }
|
||||
|
||||
|
||||
@@ -5,11 +5,11 @@ require 'spec_helper'
|
||||
RSpec.describe SubscriptionLineItem, model: true do
|
||||
describe "validations" do
|
||||
it "requires a subscription" do
|
||||
expect(subject).to validate_presence_of :subscription
|
||||
expect(subject).to belong_to :subscription
|
||||
end
|
||||
|
||||
it "requires a variant" do
|
||||
expect(subject).to validate_presence_of :variant
|
||||
expect(subject).to belong_to :variant
|
||||
end
|
||||
|
||||
it "requires a integer for quantity" do
|
||||
|
||||
@@ -5,7 +5,7 @@ require 'spec_helper'
|
||||
RSpec.describe TagRule, type: :model do
|
||||
describe "validations" do
|
||||
it "requires a enterprise" do
|
||||
expect(subject).to validate_presence_of(:enterprise)
|
||||
expect(subject).to belong_to(:enterprise)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user