mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-02 21:57:17 +00:00
Update deprecated #scoped calls
Model#scoped is now deprecated. Model#where(nil) in Rails 4 returns the same result as Model#scoped in Rails 3
This commit is contained in:
@@ -119,7 +119,7 @@ module Api
|
||||
end
|
||||
|
||||
def paged_products_for_producers(producers)
|
||||
Spree::Product.scoped.
|
||||
Spree::Product.where(nil).
|
||||
merge(product_scope).
|
||||
where(supplier_id: producers).
|
||||
by_producer.by_name.
|
||||
|
||||
@@ -58,7 +58,7 @@ module Api
|
||||
@product.variants_including_master
|
||||
end
|
||||
else
|
||||
variants = Spree::Variant.scoped
|
||||
variants = Spree::Variant.where(nil)
|
||||
if current_api_user.has_spree_role?("admin")
|
||||
unless params[:show_deleted]
|
||||
variants = Spree::Variant.active
|
||||
|
||||
@@ -69,7 +69,7 @@ module Spree
|
||||
model_class.accessible_by(current_ability, action)
|
||||
|
||||
else
|
||||
model_class.scoped
|
||||
model_class.where(nil)
|
||||
end
|
||||
|
||||
collection = collection.managed_by(spree_current_user).by_name # This line added
|
||||
|
||||
@@ -131,7 +131,7 @@ module Spree
|
||||
end
|
||||
|
||||
def load_roles
|
||||
@roles = Spree::Role.scoped
|
||||
@roles = Spree::Role.where(nil)
|
||||
end
|
||||
|
||||
def new_email_unconfirmed?
|
||||
|
||||
@@ -123,7 +123,7 @@ class Enterprise < ActiveRecord::Base
|
||||
if ready_enterprises.present?
|
||||
where("enterprises.id NOT IN (?)", ready_enterprises)
|
||||
else
|
||||
where("TRUE")
|
||||
where(nil)
|
||||
end
|
||||
}
|
||||
scope :is_primary_producer, -> { where(is_primary_producer: true) }
|
||||
@@ -182,7 +182,7 @@ class Enterprise < ActiveRecord::Base
|
||||
|
||||
scope :managed_by, lambda { |user|
|
||||
if user.has_spree_role?('admin')
|
||||
scoped
|
||||
where(nil)
|
||||
else
|
||||
joins(:enterprise_roles).where('enterprise_roles.user_id = ?', user.id)
|
||||
end
|
||||
|
||||
@@ -25,7 +25,7 @@ class EnterpriseFee < ActiveRecord::Base
|
||||
|
||||
scope :managed_by, lambda { |user|
|
||||
if user.has_spree_role?('admin')
|
||||
scoped
|
||||
where(nil)
|
||||
else
|
||||
where('enterprise_id IN (?)', user.enterprises)
|
||||
end
|
||||
|
||||
@@ -51,7 +51,7 @@ class EnterpriseGroup < ActiveRecord::Base
|
||||
scope :on_front_page, -> { where(on_front_page: true) }
|
||||
scope :managed_by, lambda { |user|
|
||||
if user.has_spree_role?('admin')
|
||||
scoped
|
||||
where(nil)
|
||||
else
|
||||
where('owner_id = ?', user.id)
|
||||
end
|
||||
|
||||
@@ -67,7 +67,7 @@ class Exchange < ActiveRecord::Base
|
||||
|
||||
scope :managed_by, lambda { |user|
|
||||
if user.has_spree_role?('admin')
|
||||
scoped
|
||||
where(nil)
|
||||
else
|
||||
joins("LEFT JOIN enterprises senders ON senders.id = exchanges.sender_id").
|
||||
joins("LEFT JOIN enterprises receivers ON receivers.id = exchanges.receiver_id").
|
||||
|
||||
@@ -61,7 +61,7 @@ class OrderCycle < ActiveRecord::Base
|
||||
|
||||
scope :managed_by, lambda { |user|
|
||||
if user.has_spree_role?('admin')
|
||||
scoped
|
||||
where(nil)
|
||||
else
|
||||
where(coordinator_id: user.enterprises)
|
||||
end
|
||||
@@ -70,7 +70,7 @@ class OrderCycle < ActiveRecord::Base
|
||||
# Return order cycles that user coordinates, sends to or receives from
|
||||
scope :accessible_by, lambda { |user|
|
||||
if user.has_spree_role?('admin')
|
||||
scoped
|
||||
where(nil)
|
||||
else
|
||||
with_exchanging_enterprises_outer.
|
||||
where('order_cycles.coordinator_id IN (?) OR enterprises.id IN (?)',
|
||||
|
||||
@@ -26,7 +26,7 @@ Spree::LineItem.class_eval do
|
||||
# -- Scopes
|
||||
scope :managed_by, lambda { |user|
|
||||
if user.has_spree_role?('admin')
|
||||
scoped
|
||||
where(nil)
|
||||
else
|
||||
# Find line items that are from orders distributed by the user or supplied by the user
|
||||
joins(variant: :product).
|
||||
|
||||
@@ -50,7 +50,7 @@ Spree::Order.class_eval do
|
||||
# -- Scopes
|
||||
scope :managed_by, lambda { |user|
|
||||
if user.has_spree_role?('admin')
|
||||
scoped
|
||||
where(nil)
|
||||
else
|
||||
# Find orders that are distributed by the user or have products supplied by the user
|
||||
# WARNING: This only filters orders, you'll need to filter line items separately using LineItem.managed_by
|
||||
@@ -62,7 +62,7 @@ Spree::Order.class_eval do
|
||||
|
||||
scope :distributed_by_user, lambda { |user|
|
||||
if user.has_spree_role?('admin')
|
||||
scoped
|
||||
where(nil)
|
||||
else
|
||||
where('spree_orders.distributor_id IN (?)', user.enterprises)
|
||||
end
|
||||
|
||||
@@ -17,7 +17,7 @@ Spree::PaymentMethod.class_eval do
|
||||
# -- Scopes
|
||||
scope :managed_by, lambda { |user|
|
||||
if user.has_spree_role?('admin')
|
||||
scoped
|
||||
where(nil)
|
||||
else
|
||||
joins(:distributors).
|
||||
where('distributors_payment_methods.distributor_id IN (?)', user.enterprises).
|
||||
|
||||
@@ -115,7 +115,7 @@ Spree::Product.class_eval do
|
||||
|
||||
scope :managed_by, lambda { |user|
|
||||
if user.has_spree_role?('admin')
|
||||
scoped
|
||||
where(nil)
|
||||
else
|
||||
where('supplier_id IN (?)', user.enterprises.select("enterprises.id"))
|
||||
end
|
||||
|
||||
@@ -12,7 +12,7 @@ Spree::ShippingMethod.class_eval do
|
||||
|
||||
scope :managed_by, lambda { |user|
|
||||
if user.has_spree_role?('admin')
|
||||
scoped
|
||||
where(nil)
|
||||
else
|
||||
joins(:distributors).
|
||||
where('distributors_shipping_methods.distributor_id IN (?)', user.enterprises).
|
||||
|
||||
@@ -81,7 +81,7 @@ module Spree
|
||||
|
||||
def known_users
|
||||
if admin?
|
||||
Spree::User.scoped
|
||||
Spree::User.where(nil)
|
||||
else
|
||||
Spree::User
|
||||
.includes(:enterprises)
|
||||
|
||||
@@ -61,7 +61,7 @@ class OrderAdjustmentsFetcher
|
||||
match_by_scope(adjustment, adjustment_scope)
|
||||
end
|
||||
else
|
||||
adjustments.scoped.public_send scope
|
||||
adjustments.where(nil).public_send scope
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ module PermalinkGenerator
|
||||
if self.class.respond_to?(:with_deleted)
|
||||
self.class.with_deleted
|
||||
else
|
||||
self.class.scoped
|
||||
end
|
||||
self.class.where(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -147,7 +147,7 @@ module OpenFoodNetwork
|
||||
|
||||
def managed_and_related_enterprises_granting(permission)
|
||||
if admin?
|
||||
Enterprise.scoped
|
||||
Enterprise.where(nil)
|
||||
else
|
||||
Enterprise.where(
|
||||
id: managed_enterprises.select("enterprises.id") |
|
||||
@@ -158,7 +158,7 @@ module OpenFoodNetwork
|
||||
|
||||
def managed_and_related_enterprises_with(permission)
|
||||
if admin?
|
||||
Enterprise.scoped
|
||||
Enterprise.where(nil)
|
||||
else
|
||||
managed_enterprise_ids = managed_enterprises.select("enterprises.id")
|
||||
granting_enterprise_ids = related_enterprises_granting(permission)
|
||||
|
||||
@@ -55,7 +55,7 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
def remove_orphaned_proxy_orders!
|
||||
orphaned_proxy_orders.scoped.delete_all
|
||||
orphaned_proxy_orders.where(nil).delete_all
|
||||
end
|
||||
|
||||
def orphaned_proxy_orders
|
||||
|
||||
@@ -113,7 +113,7 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
describe "filtering orders" do
|
||||
let(:orders) { Spree::Order.scoped }
|
||||
let(:orders) { Spree::Order.where(nil) }
|
||||
let(:supplier) { create(:supplier_enterprise) }
|
||||
|
||||
it "returns all orders sans-params" do
|
||||
|
||||
@@ -70,7 +70,7 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
describe "filtering orders" do
|
||||
let!(:orders) { Spree::Order.scoped }
|
||||
let!(:orders) { Spree::Order.where(nil) }
|
||||
let!(:supplier) { create(:supplier_enterprise) }
|
||||
|
||||
let!(:oc1) { create(:simple_order_cycle) }
|
||||
|
||||
@@ -95,18 +95,18 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
describe "Filtering variants" do
|
||||
let(:variants) { Spree::Variant.scoped.joins(:product).where(is_master: false) }
|
||||
let(:variants) { Spree::Variant.where(nil).joins(:product).where(is_master: false) }
|
||||
it "should return unfiltered variants sans-params" do
|
||||
product1 = create(:simple_product, supplier: supplier)
|
||||
product2 = create(:simple_product, supplier: supplier)
|
||||
|
||||
expect(subject.filter(Spree::Variant.scoped)).to match_array [product1.master, product1.variants.first, product2.master, product2.variants.first]
|
||||
expect(subject.filter(Spree::Variant.where(nil))).to match_array [product1.master, product1.variants.first, product2.master, product2.variants.first]
|
||||
end
|
||||
it "should filter deleted products" do
|
||||
product1 = create(:simple_product, supplier: supplier)
|
||||
product2 = create(:simple_product, supplier: supplier)
|
||||
product2.destroy
|
||||
expect(subject.filter(Spree::Variant.scoped)).to match_array [product1.master, product1.variants.first]
|
||||
expect(subject.filter(Spree::Variant.where(nil))).to match_array [product1.master, product1.variants.first]
|
||||
end
|
||||
describe "based on report type" do
|
||||
it "returns only variants on hand" do
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
# leaves them there when deleting the rest (see spec/spec_helper.rb).
|
||||
# You can add more entries here if you need them for your tests.
|
||||
|
||||
if Spree::Country.scoped.empty?
|
||||
if Spree::Country.where(nil).empty?
|
||||
Spree::Country.create!({ "name" => "Australia", "iso3" => "AUS", "iso" => "AU", "iso_name" => "AUSTRALIA", "numcode" => "36" }, without_protection: true)
|
||||
country = Spree::Country.find_by(name: 'Australia')
|
||||
Spree::State.create!({ "name" => "Victoria", "abbr" => "Vic", :country => country }, without_protection: true)
|
||||
|
||||
Reference in New Issue
Block a user