mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-26 20:56:48 +00:00
60 lines
2.3 KiB
Ruby
60 lines
2.3 KiB
Ruby
require 'spec_helper'
|
|
require 'spree/core/testing_support/authorization_helpers'
|
|
require 'pry'
|
|
|
|
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,
|
|
"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,
|
|
"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
|
|
end |