mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Clean up specs
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe ShopController do
|
||||
let(:d) { create(:distributor_enterprise) }
|
||||
let(:distributor) { create(:distributor_enterprise) }
|
||||
|
||||
it "redirects to the home page if no distributor is selected" do
|
||||
spree_get :show
|
||||
@@ -11,26 +11,26 @@ describe ShopController do
|
||||
|
||||
describe "with a distributor in place" do
|
||||
before do
|
||||
controller.stub(:current_distributor).and_return d
|
||||
controller.stub(:current_distributor).and_return distributor
|
||||
end
|
||||
|
||||
describe "Selecting order cycles" do
|
||||
describe "selecting an order cycle" do
|
||||
it "should select an order cycle when only one order cycle is open" do
|
||||
oc1 = create(:simple_order_cycle, distributors: [d])
|
||||
oc1 = create(:simple_order_cycle, distributors: [distributor])
|
||||
spree_get :show
|
||||
controller.current_order_cycle.should == oc1
|
||||
end
|
||||
|
||||
it "should not set an order cycle when multiple order cycles are open" do
|
||||
oc1 = create(:simple_order_cycle, distributors: [d])
|
||||
oc2 = create(:simple_order_cycle, distributors: [d])
|
||||
oc1 = create(:simple_order_cycle, distributors: [distributor])
|
||||
oc2 = create(:simple_order_cycle, distributors: [distributor])
|
||||
spree_get :show
|
||||
controller.current_order_cycle.should == nil
|
||||
controller.current_order_cycle.should be_nil
|
||||
end
|
||||
|
||||
it "should allow the user to post to select the current order cycle" do
|
||||
oc1 = create(:simple_order_cycle, distributors: [d])
|
||||
oc2 = create(:simple_order_cycle, distributors: [d])
|
||||
oc1 = create(:simple_order_cycle, distributors: [distributor])
|
||||
oc2 = create(:simple_order_cycle, distributors: [distributor])
|
||||
|
||||
spree_post :order_cycle, order_cycle_id: oc2.id
|
||||
response.should be_success
|
||||
@@ -39,9 +39,10 @@ describe ShopController do
|
||||
|
||||
context "JSON tests" do
|
||||
render_views
|
||||
it "should return the order cycle details when the oc is selected" do
|
||||
oc1 = create(:simple_order_cycle, distributors: [d])
|
||||
oc2 = create(:simple_order_cycle, distributors: [d])
|
||||
|
||||
it "should return the order cycle details when the OC is selected" do
|
||||
oc1 = create(:simple_order_cycle, distributors: [distributor])
|
||||
oc2 = create(:simple_order_cycle, distributors: [distributor])
|
||||
|
||||
spree_post :order_cycle, order_cycle_id: oc2.id
|
||||
response.should be_success
|
||||
@@ -49,7 +50,7 @@ describe ShopController do
|
||||
end
|
||||
|
||||
it "should return the current order cycle when hit with GET" do
|
||||
oc1 = create(:simple_order_cycle, distributors: [d])
|
||||
oc1 = create(:simple_order_cycle, distributors: [distributor])
|
||||
controller.stub(:current_order_cycle).and_return oc1
|
||||
spree_get :order_cycle
|
||||
response.body.should have_content oc1.id
|
||||
@@ -57,13 +58,13 @@ describe ShopController do
|
||||
end
|
||||
|
||||
it "should not allow the user to select an invalid order cycle" do
|
||||
oc1 = create(:simple_order_cycle, distributors: [d])
|
||||
oc2 = create(:simple_order_cycle, distributors: [d])
|
||||
oc1 = create(:simple_order_cycle, distributors: [distributor])
|
||||
oc2 = create(:simple_order_cycle, distributors: [distributor])
|
||||
oc3 = create(:simple_order_cycle, distributors: [create(:distributor_enterprise)])
|
||||
|
||||
spree_post :order_cycle, order_cycle_id: oc3.id
|
||||
response.status.should == 404
|
||||
controller.current_order_cycle.should == nil
|
||||
controller.current_order_cycle.should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
@@ -71,31 +72,32 @@ describe ShopController do
|
||||
describe "producers/suppliers" do
|
||||
let(:supplier) { create(:supplier_enterprise) }
|
||||
let(:product) { create(:product, supplier: supplier) }
|
||||
let(:order_cycle) { create(:simple_order_cycle, distributors: [d], coordinator: create(:distributor_enterprise)) }
|
||||
let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor]) }
|
||||
|
||||
before do
|
||||
exchange = Exchange.find(order_cycle.exchanges.to_enterprises(d).outgoing.first.id)
|
||||
exchange = order_cycle.exchanges.to_enterprises(distributor).outgoing.first
|
||||
exchange.variants << product.master
|
||||
end
|
||||
end
|
||||
|
||||
describe "returning products" do
|
||||
let(:order_cycle) { create(:simple_order_cycle, distributors: [d], coordinator: create(:distributor_enterprise)) }
|
||||
let(:exchange) { Exchange.find(order_cycle.exchanges.to_enterprises(d).outgoing.first.id) }
|
||||
let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor]) }
|
||||
let(:exchange) { order_cycle.exchanges.to_enterprises(distributor).outgoing.first }
|
||||
|
||||
describe "requests and responses" do
|
||||
let(:product) { create(:product) }
|
||||
|
||||
before do
|
||||
exchange.variants << product.variants.first
|
||||
end
|
||||
|
||||
it "returns products via json" do
|
||||
it "returns products via JSON" do
|
||||
controller.stub(:current_order_cycle).and_return order_cycle
|
||||
xhr :get, :products
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it "does not return products if no order_cycle is selected" do
|
||||
it "does not return products if no order cycle is selected" do
|
||||
controller.stub(:current_order_cycle).and_return nil
|
||||
xhr :get, :products
|
||||
response.status.should == 404
|
||||
|
||||
@@ -3,10 +3,10 @@ require 'open_food_network/products_renderer'
|
||||
|
||||
module OpenFoodNetwork
|
||||
describe ProductsRenderer do
|
||||
let(:d) { create(:distributor_enterprise) }
|
||||
let(:order_cycle) { create(:simple_order_cycle, distributors: [d], coordinator: create(:distributor_enterprise)) }
|
||||
let(:exchange) { Exchange.find(order_cycle.exchanges.to_enterprises(d).outgoing.first.id) }
|
||||
let(:pr) { ProductsRenderer.new(d, order_cycle) }
|
||||
let(:distributor) { create(:distributor_enterprise) }
|
||||
let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor]) }
|
||||
let(:exchange) { order_cycle.exchanges.to_enterprises(distributor).outgoing.first }
|
||||
let(:pr) { ProductsRenderer.new(distributor, order_cycle) }
|
||||
|
||||
describe "sorting" do
|
||||
let(:t1) { create(:taxon) }
|
||||
@@ -24,13 +24,13 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
it "sorts products by the distributor's preferred taxon list" do
|
||||
d.stub(:preferred_shopfront_taxon_order) {"#{t1.id},#{t2.id}"}
|
||||
distributor.stub(:preferred_shopfront_taxon_order) {"#{t1.id},#{t2.id}"}
|
||||
products = pr.send(:products_for_shop)
|
||||
products.should == [p2, p4, p1, p3]
|
||||
end
|
||||
|
||||
it "alphabetizes products by name when taxon list is not set" do
|
||||
d.stub(:preferred_shopfront_taxon_order) {""}
|
||||
distributor.stub(:preferred_shopfront_taxon_order) {""}
|
||||
products = pr.send(:products_for_shop)
|
||||
products.should == [p1, p2, p3, p4]
|
||||
end
|
||||
@@ -81,9 +81,9 @@ module OpenFoodNetwork
|
||||
let(:p) { create(:simple_product) }
|
||||
let!(:v1) { create(:variant, product: p, unit_value: 3) }
|
||||
let!(:v2) { create(:variant, product: p, unit_value: 5) }
|
||||
let(:pr) { ProductsRenderer.new(hub, oc) }
|
||||
|
||||
it "scopes variants to distribution" do
|
||||
pr = ProductsRenderer.new(hub, oc)
|
||||
pr.send(:variants_for_shop_by_id).should == {p.id => [v1]}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user