From 96a351ad0e293d1ecfe1cdef42a79bebf455be91 Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Sat, 31 Oct 2020 21:20:35 +0000 Subject: [PATCH] Adapt usage of Sets to their new location --- app/controllers/admin/column_preferences_controller.rb | 2 +- app/controllers/admin/enterprise_fees_controller.rb | 4 ++-- app/controllers/admin/enterprises_controller.rb | 4 ++-- app/controllers/admin/order_cycles_controller.rb | 2 +- app/controllers/admin/variant_overrides_controller.rb | 2 +- app/controllers/spree/admin/products_controller.rb | 2 +- app/services/sets/product_set.rb | 2 +- .../enterprise_fees/_calculator_settings.html.haml | 2 +- spec/controllers/admin/enterprises_controller_spec.rb | 2 +- spec/services/sets/model_set_spec.rb | 10 +++++----- spec/services/sets/product_set_spec.rb | 2 +- 11 files changed, 17 insertions(+), 17 deletions(-) diff --git a/app/controllers/admin/column_preferences_controller.rb b/app/controllers/admin/column_preferences_controller.rb index d8a5ca3e6a..90ba1bd37e 100644 --- a/app/controllers/admin/column_preferences_controller.rb +++ b/app/controllers/admin/column_preferences_controller.rb @@ -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 diff --git a/app/controllers/admin/enterprise_fees_controller.rb b/app/controllers/admin/enterprise_fees_controller.rb index 0aaa2957be..9d1536856e 100644 --- a/app/controllers/admin/enterprise_fees_controller.rb +++ b/app/controllers/admin/enterprise_fees_controller.rb @@ -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 diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index c61ab9f30e..b62bb9ddf5 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -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 diff --git a/app/controllers/admin/order_cycles_controller.rb b/app/controllers/admin/order_cycles_controller.rb index f7de30662a..3482be399f 100644 --- a/app/controllers/admin/order_cycles_controller.rb +++ b/app/controllers/admin/order_cycles_controller.rb @@ -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 diff --git a/app/controllers/admin/variant_overrides_controller.rb b/app/controllers/admin/variant_overrides_controller.rb index 333455c57b..c4fd99a766 100644 --- a/app/controllers/admin/variant_overrides_controller.rb +++ b/app/controllers/admin/variant_overrides_controller.rb @@ -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 diff --git a/app/controllers/spree/admin/products_controller.rb b/app/controllers/spree/admin/products_controller.rb index 3f9cdd92ac..1cc3f5ae6d 100644 --- a/app/controllers/spree/admin/products_controller.rb +++ b/app/controllers/spree/admin/products_controller.rb @@ -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 diff --git a/app/services/sets/product_set.rb b/app/services/sets/product_set.rb index dc53224d9b..b6054e7125 100644 --- a/app/services/sets/product_set.rb +++ b/app/services/sets/product_set.rb @@ -1,5 +1,5 @@ module Sets - class Spree::ProductSet < ModelSet + class ProductSet < ModelSet def initialize(attributes = {}) super(Spree::Product, [], attributes) end diff --git a/app/views/admin/enterprise_fees/_calculator_settings.html.haml b/app/views/admin/enterprise_fees/_calculator_settings.html.haml index f505f0c38a..4936ee35b2 100644 --- a/app/views/admin/enterprise_fees/_calculator_settings.html.haml +++ b/app/views/admin/enterprise_fees/_calculator_settings.html.haml @@ -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| diff --git a/spec/controllers/admin/enterprises_controller_spec.rb b/spec/controllers/admin/enterprises_controller_spec.rb index 3b4cd1428c..8343ca0d9e 100644 --- a/spec/controllers/admin/enterprises_controller_spec.rb +++ b/spec/controllers/admin/enterprises_controller_spec.rb @@ -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' } } } } diff --git a/spec/services/sets/model_set_spec.rb b/spec/services/sets/model_set_spec.rb index 2dd5e12c8e..00b71e5d19 100644 --- a/spec/services/sets/model_set_spec.rb +++ b/spec/services/sets/model_set_spec.rb @@ -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) diff --git a/spec/services/sets/product_set_spec.rb b/spec/services/sets/product_set_spec.rb index c296ed7a73..a5576d9caa 100644 --- a/spec/services/sets/product_set_spec.rb +++ b/spec/services/sets/product_set_spec.rb @@ -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