Move controller spec to serializer spec

This commit is contained in:
Rohan Mitchell
2014-12-17 14:01:59 +11:00
parent 6c300431d2
commit 2ea7bdbec6
2 changed files with 14 additions and 8 deletions

View File

@@ -111,14 +111,6 @@ describe ShopController do
response.body.should be_empty
end
it "scopes variants for a product to the order cycle and distributor" do
controller.stub(:current_order_cycle).and_return order_cycle
controller.stub(:current_distributor).and_return d
Spree::Product.any_instance.should_receive(:variants_for).with(order_cycle, d).and_return(m = double())
m.stub(:in_stock).and_return []
xhr :get, :products
end
context "RABL tests" do
render_views
before do

View File

@@ -0,0 +1,14 @@
describe Api::ProductSerializer do
let(:hub) { create(:distributor_enterprise) }
let(:oc) { create(:simple_order_cycle, distributors: [hub], variants: [v1]) }
let(:p) { create(:simple_product) }
let!(:v1) { create(:variant, product: p, unit_value: 3) }
let!(:v2) { create(:variant, product: p, unit_value: 5) }
it "scopes variants to distribution" do
s = Api::ProductSerializer.new p, current_distributor: hub, current_order_cycle: oc
json = s.to_json
json.should include v1.options_text
json.should_not include v2.options_text
end
end