From d308e2087144d98829ecbb3e860bf15e2ce874b2 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Mon, 10 May 2021 21:03:24 +0100 Subject: [PATCH] Fix deprecation warning in rails 6.0 Warning: Class level methods will no longer inherit scoping from create in Rails 6.1 --- app/models/enterprise.rb | 2 +- app/models/spree/shipment.rb | 2 +- lib/spree/core/permalinks.rb | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index f77e634e96..c6e4a6f272 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -121,7 +121,7 @@ class Enterprise < ApplicationRecord scope :not_ready_for_checkout, lambda { # When ready_for_checkout is empty, return all rows when there are no enterprises ready for # checkout. - ready_enterprises = Enterprise.ready_for_checkout. + ready_enterprises = Enterprise.default_scoped.ready_for_checkout. except(:select). select('DISTINCT enterprises.id') diff --git a/app/models/spree/shipment.rb b/app/models/spree/shipment.rb index 2db789a98d..dd4cb87fe6 100644 --- a/app/models/spree/shipment.rb +++ b/app/models/spree/shipment.rb @@ -309,7 +309,7 @@ module Spree record = true while record random = "H#{Array.new(11) { rand(9) }.join}" - record = self.class.find_by(number: random) + record = self.class.default_scoped.find_by(number: random) end self.number = random end diff --git a/lib/spree/core/permalinks.rb b/lib/spree/core/permalinks.rb index b667de7b2c..70092ef6b7 100644 --- a/lib/spree/core/permalinks.rb +++ b/lib/spree/core/permalinks.rb @@ -49,8 +49,9 @@ module Spree # Do other links exist with this permalink? other = self.class. - where("#{self.class.table_name}.#{field} LIKE ?", "#{permalink_value}%") + default_scoped.where("#{self.class.table_name}.#{field} LIKE ?", "#{permalink_value}%") if other.any? + # Find the existing permalink with the highest number, and increment that number. # (If none of the existing permalinks have a number, this will evaluate to 1.) number = other.map { |o| o.__send__(field)[/-(\d+)$/, 1].to_i }.max + 1