From 3c973178fd01af8838bd76cedc23005b19eed988 Mon Sep 17 00:00:00 2001 From: Rob H Date: Thu, 11 Jul 2013 23:39:41 +0530 Subject: [PATCH] WIP: remove unneeded representative-based data request infrastructure --- .../admin/products_controller_decorator.rb | 8 -- app/views/enterprises/suppliers.rep | 4 - app/views/spree/admin/products/bulk_index.rep | 18 ---- config/routes.rb | 1 - spec/controllers/product_controller_spec.rb | 83 ------------------- 5 files changed, 114 deletions(-) delete mode 100644 app/views/enterprises/suppliers.rep delete mode 100644 app/views/spree/admin/products/bulk_index.rep delete mode 100644 spec/controllers/product_controller_spec.rb diff --git a/app/controllers/spree/admin/products_controller_decorator.rb b/app/controllers/spree/admin/products_controller_decorator.rb index d41614ff66..bbbf8a3a5b 100644 --- a/app/controllers/spree/admin/products_controller_decorator.rb +++ b/app/controllers/spree/admin/products_controller_decorator.rb @@ -1,5 +1,4 @@ Spree::Admin::ProductsController.class_eval do - before_filter :load_product_set, :only => :bulk_index before_filter :load_spree_api_key, :only => :bulk_edit alias_method :location_after_save_original, :location_after_save @@ -8,10 +7,6 @@ Spree::Admin::ProductsController.class_eval do #respond_override :clone => { :json => {:success => lambda { redirect_to bulk_index_admin_products_url+"?q[id_eq]=#{@new.id}" } } } - def bulk_index - respond_to :json - end - def bulk_update collection_hash = Hash[params[:_json].each_with_index.map { |p,i| [i,p] }] product_set = Spree::ProductSet.new({:collection_attributes => collection_hash}) @@ -33,9 +28,6 @@ Spree::Admin::ProductsController.class_eval do end private - def load_product_set - @product_set = Spree::ProductSet.new :collection => collection - end def load_spree_api_key current_user.generate_spree_api_key! unless spree_current_user.spree_api_key diff --git a/app/views/enterprises/suppliers.rep b/app/views/enterprises/suppliers.rep deleted file mode 100644 index 94a1dca310..0000000000 --- a/app/views/enterprises/suppliers.rep +++ /dev/null @@ -1,4 +0,0 @@ -r.list_of :suppliers, @suppliers do - r.element :id - r.element :name -end \ No newline at end of file diff --git a/app/views/spree/admin/products/bulk_index.rep b/app/views/spree/admin/products/bulk_index.rep deleted file mode 100644 index 630fa16c3f..0000000000 --- a/app/views/spree/admin/products/bulk_index.rep +++ /dev/null @@ -1,18 +0,0 @@ -r.list_of :products, @collection.sort_by(&:id) do - r.element :id - r.element :name - r.element :supplier do - r.element :id - r.element :name - end - r.element :available_on, Proc.new{ |product| product.available_on.strftime("%F %T") } - r.element :price - r.element :on_hand - r.list_of :variants, Proc.new{ |product| product.variants.sort { |a,b| a.id <=> b.id } } do - r.element :id - r.element :options_text - r.element :price - r.element :on_hand - end - r.element :permalink_live, Proc.new{ |product| product.permalink } -end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index fc265c96f7..b0c6de223b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -39,7 +39,6 @@ Spree::Core::Engine.routes.prepend do namespace :admin do resources :products do - get :bulk_index, :on => :collection, :as => :bulk_index post :bulk_update, :on => :collection, :as => :bulk_update end end diff --git a/spec/controllers/product_controller_spec.rb b/spec/controllers/product_controller_spec.rb deleted file mode 100644 index 2bcd604895..0000000000 --- a/spec/controllers/product_controller_spec.rb +++ /dev/null @@ -1,83 +0,0 @@ -require 'spec_helper' -require 'spree/core/testing_support/authorization_helpers' - -describe Spree::Admin::ProductsController do - stub_authorization! - render_views - - context "bulk index" do - let(:ability_user) { stub_model(Spree::LegacyUser, :has_spree_role? => true) } - - it "stores the list of products in a collection" do - p1 = FactoryGirl.create(:product) - p2 = FactoryGirl.create(:product) - spree_get :bulk_index, { format: :json } - - assigns[:collection].should_not be_empty - assigns[:collection].should == [ p1, p2 ] - end - - it "collects returns products in an array formatted as json" do - p1 = FactoryGirl.create(:product) - p2 = FactoryGirl.create(:product) - v11 = FactoryGirl.create(:variant, product: p1, on_hand: 1) - v12 = FactoryGirl.create(:variant, product: p1, on_hand: 2) - v13 = FactoryGirl.create(:variant, product: p1, on_hand: 3) - v21 = FactoryGirl.create(:variant, product: p2, on_hand: 4) - spree_get :bulk_index, { format: :json } - - p1r = { - "id" => p1.id, - "name" => p1.name, - "supplier" => { - "id" => p1.supplier_id, - "name" => p1.supplier.name - }, - "available_on" => p1.available_on.strftime("%F %T"), - "price" => p1.price.to_s, - "on_hand" => ( v11.on_hand + v12.on_hand + v13.on_hand ), - "variants" => [ #ordered by id - { "id" => v11.id, "options_text" => v11.options_text, "price" => v11.price.to_s, "on_hand" => v11.on_hand }, - { "id" => v12.id, "options_text" => v12.options_text, "price" => v12.price.to_s, "on_hand" => v12.on_hand }, - { "id" => v13.id, "options_text" => v13.options_text, "price" => v13.price.to_s, "on_hand" => v13.on_hand } - ], - "permalink_live" => p1.permalink - } - p2r = { - "id" => p2.id, - "name" => p2.name, - "supplier" => { - "id" => p2.supplier_id, - "name" => p2.supplier.name - }, - "available_on" => p2.available_on.strftime("%F %T"), - "price" => p2.price.to_s, - "on_hand" => v21.on_hand, - "variants" => [ #ordered by id - { "id" => v21.id, "options_text" => v21.options_text, "price" => v21.price.to_s, "on_hand" => v21.on_hand } - ], - "permalink_live" => p2.permalink - } - json_response = JSON.parse(response.body) - json_response.should == [ p1r, p2r ] - end - end - - context "cloning a product" do - let(:ability_user) { stub_model(Spree::LegacyUser, :has_spree_role? => true) } - - it "renders the newly created product as json" do - p1 = FactoryGirl.create(:product) - p2 = FactoryGirl.create(:product) - - spree_get :clone, { :format => :json, :id => p1.permalink } - - json_response = JSON.parse(response.body) - json_response.keys.should == ["product"] - json_response["product"]["id"].should_not == p1.id; - json_response["product"]["name"].should == "COPY OF #{p1.name}"; - json_response["product"]["available_on"].should == p1.available_on.strftime("%FT%TZ"); - json_response["product"]["supplier_id"].should == p1.supplier_id; - end - end -end \ No newline at end of file