mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Adapt usage of Sets to their new location
This commit is contained in:
@@ -29,7 +29,7 @@ module Admin
|
||||
collection_hash = Hash[permitted_params[:column_preferences].
|
||||
each_with_index.map { |cp, i| [i, cp] }]
|
||||
collection_hash.select!{ |_i, cp| cp[:action_name] == permitted_params[:action_name] }
|
||||
@cp_set = ColumnPreferenceSet.new @column_preferences, collection_attributes: collection_hash
|
||||
@cp_set = Sets::ColumnPreferenceSet.new @column_preferences, collection_attributes: collection_hash
|
||||
end
|
||||
|
||||
def collection
|
||||
|
||||
@@ -27,7 +27,7 @@ module Admin
|
||||
end
|
||||
|
||||
def bulk_update
|
||||
@enterprise_fee_set = EnterpriseFeeSet.new(enterprise_fee_bulk_params)
|
||||
@enterprise_fee_set = Sets::EnterpriseFeeSet.new(enterprise_fee_bulk_params)
|
||||
|
||||
if @enterprise_fee_set.save
|
||||
redirect_to redirect_path, notice: I18n.t(:enterprise_fees_update_notice)
|
||||
@@ -40,7 +40,7 @@ module Admin
|
||||
private
|
||||
|
||||
def load_enterprise_fee_set
|
||||
@enterprise_fee_set = EnterpriseFeeSet.new collection: collection
|
||||
@enterprise_fee_set = Sets::EnterpriseFeeSet.new collection: collection
|
||||
end
|
||||
|
||||
def load_data
|
||||
|
||||
@@ -81,7 +81,7 @@ module Admin
|
||||
end
|
||||
|
||||
def bulk_update
|
||||
@enterprise_set = EnterpriseSet.new(collection, bulk_params)
|
||||
@enterprise_set = Sets::EnterpriseSet.new(collection, bulk_params)
|
||||
if @enterprise_set.save
|
||||
flash[:success] = I18n.t(:enterprise_bulk_update_success_notice)
|
||||
|
||||
@@ -129,7 +129,7 @@ module Admin
|
||||
private
|
||||
|
||||
def load_enterprise_set
|
||||
@enterprise_set = EnterpriseSet.new(collection) if spree_current_user.admin?
|
||||
@enterprise_set = Sets::EnterpriseSet.new(collection) if spree_current_user.admin?
|
||||
end
|
||||
|
||||
def load_countries
|
||||
|
||||
@@ -223,7 +223,7 @@ module Admin
|
||||
end
|
||||
|
||||
def order_cycle_set
|
||||
@order_cycle_set ||= OrderCycleSet.new(@order_cycles, order_cycle_bulk_params)
|
||||
@order_cycle_set ||= Sets::OrderCycleSet.new(@order_cycles, order_cycle_bulk_params)
|
||||
end
|
||||
|
||||
def require_order_cycle_set_params
|
||||
|
||||
@@ -67,7 +67,7 @@ module Admin
|
||||
|
||||
def load_collection
|
||||
collection_hash = Hash[variant_overrides_params.each_with_index.map { |vo, i| [i, vo] }]
|
||||
@vo_set = VariantOverrideSet.new @variant_overrides, collection_attributes: collection_hash
|
||||
@vo_set = Sets::VariantOverrideSet.new @variant_overrides, collection_attributes: collection_hash
|
||||
end
|
||||
|
||||
def collection
|
||||
|
||||
@@ -163,7 +163,7 @@ module Spree
|
||||
|
||||
def product_set_from_params(_params)
|
||||
collection_hash = Hash[products_params.each_with_index.map { |p, i| [i, p] }]
|
||||
Spree::ProductSet.new(collection_attributes: collection_hash)
|
||||
Sets::ProductSet.new(collection_attributes: collection_hash)
|
||||
end
|
||||
|
||||
def products_params
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
module Sets
|
||||
class Spree::ProductSet < ModelSet
|
||||
class ProductSet < ModelSet
|
||||
def initialize(attributes = {})
|
||||
super(Spree::Product, [], attributes)
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
-# Render only the calculator settings and not the surrounding form
|
||||
- enterprise_fee_set = ModelSet.new(EnterpriseFee, EnterpriseFee.where(:id => enterprise_fee.id))
|
||||
- enterprise_fee_set = Sets::ModelSet.new(EnterpriseFee, EnterpriseFee.where(:id => enterprise_fee.id))
|
||||
- calculator_form_string = nil
|
||||
- form_for enterprise_fee_set, :as => :enterprise_fee_set, :url => '' do |form|
|
||||
- form.fields_for :collection do |f|
|
||||
|
||||
@@ -397,7 +397,7 @@ describe Admin::EnterprisesController, type: :controller do
|
||||
end
|
||||
|
||||
it "cuts down the list of enterprises displayed when error received on bulk update" do
|
||||
allow_any_instance_of(EnterpriseSet).to receive(:save) { false }
|
||||
allow_any_instance_of(Sets::EnterpriseSet).to receive(:save) { false }
|
||||
profile_enterprise1.enterprise_roles.build(user: new_owner).save
|
||||
allow(controller).to receive_messages spree_current_user: new_owner
|
||||
bulk_enterprise_params = { enterprise_set: { collection_attributes: { '0' => { id: profile_enterprise1.id, visible: 'false' } } } }
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe ModelSet do
|
||||
describe Sets::ModelSet do
|
||||
describe "updating" do
|
||||
it "creates new models" do
|
||||
attrs = { collection_attributes: { '1' => { name: 's1' },
|
||||
'2' => { name: 's2' } } }
|
||||
|
||||
ms = ModelSet.new(EnterpriseRelationshipPermission, EnterpriseRelationshipPermission.all, attrs)
|
||||
ms = Sets::ModelSet.new(EnterpriseRelationshipPermission, EnterpriseRelationshipPermission.all, attrs)
|
||||
|
||||
expect { ms.save }.to change(EnterpriseRelationshipPermission, :count).by(2)
|
||||
|
||||
@@ -22,7 +22,7 @@ describe ModelSet do
|
||||
attrs = { collection_attributes: { '1' => { id: e1.id, name: 'e1zz', description: 'foo' },
|
||||
'2' => { id: e2.id, name: 'e2yy', description: 'bar' } } }
|
||||
|
||||
ms = ModelSet.new(EnterpriseGroup, EnterpriseGroup.all, attrs)
|
||||
ms = Sets::ModelSet.new(EnterpriseGroup, EnterpriseGroup.all, attrs)
|
||||
|
||||
expect { ms.save }.to change(EnterpriseGroup, :count).by(0)
|
||||
|
||||
@@ -36,7 +36,7 @@ describe ModelSet do
|
||||
attributes = { collection_attributes: { '1' => { id: e1.id, name: 'deleteme' },
|
||||
'2' => { id: e2.id, name: 'e2' } } }
|
||||
|
||||
ms = ModelSet.new(Enterprise, Enterprise.all, attributes, nil,
|
||||
ms = Sets::ModelSet.new(Enterprise, Enterprise.all, attributes, nil,
|
||||
proc { |attrs| attrs['name'] == 'deleteme' })
|
||||
|
||||
expect { ms.save }.to change(Enterprise, :count).by(-1)
|
||||
@@ -48,7 +48,7 @@ describe ModelSet do
|
||||
it "ignores deletable new records" do
|
||||
attributes = { collection_attributes: { '1' => { name: 'deleteme' } } }
|
||||
|
||||
ms = ModelSet.new(Enterprise, Enterprise.all, attributes, nil,
|
||||
ms = Sets::ModelSet.new(Enterprise, Enterprise.all, attributes, nil,
|
||||
proc { |attrs| attrs['name'] == 'deleteme' })
|
||||
|
||||
expect { ms.save }.to change(Enterprise, :count).by(0)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::ProductSet do
|
||||
describe Sets::ProductSet do
|
||||
describe '#save' do
|
||||
context 'when passing :collection_attributes' do
|
||||
let(:product_set) do
|
||||
|
||||
Reference in New Issue
Block a user