WIP: remove unneeded representative-based data request infrastructure

This commit is contained in:
Rob H
2013-07-11 23:39:41 +05:30
committed by Rohan Mitchell
parent 961d63ec4c
commit 3c973178fd
5 changed files with 0 additions and 114 deletions

View File

@@ -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

View File

@@ -1,4 +0,0 @@
r.list_of :suppliers, @suppliers do
r.element :id
r.element :name
end

View File

@@ -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

View File

@@ -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

View File

@@ -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