mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-02 02:11:33 +00:00
Getting an order cycle update function in place like a boss
This commit is contained in:
@@ -15,6 +15,15 @@ class ShopController < BaseController
|
||||
end
|
||||
end
|
||||
|
||||
def order_cycle
|
||||
if oc = OrderCycle.with_distributor(@distributor).active.find_by_id(params[:order_cycle_id])
|
||||
current_order(true).set_order_cycle! oc
|
||||
render status: 200, json: ""
|
||||
else
|
||||
render status: 404, json: ""
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_distributor
|
||||
|
||||
@@ -4,6 +4,7 @@ Openfoodnetwork::Application.routes.draw do
|
||||
|
||||
resource :shop, controller: :shop do
|
||||
get :products
|
||||
post :order_cycle
|
||||
end
|
||||
|
||||
resources :enterprises do
|
||||
|
||||
@@ -19,8 +19,29 @@ describe ShopController do
|
||||
spree_get :show
|
||||
controller.current_order_cycle.should == nil
|
||||
end
|
||||
|
||||
it "should allow the user to post to select the current order cycle" do
|
||||
oc1 = create(:order_cycle, distributors: [d])
|
||||
oc2 = create(:order_cycle, distributors: [d])
|
||||
|
||||
spree_post :order_cycle, order_cycle_id: oc2.id
|
||||
response.should be_success
|
||||
controller.current_order_cycle.should == oc2
|
||||
end
|
||||
|
||||
it "should not allow the user to select an invalid order cycle" do
|
||||
oc1 = create(:order_cycle, distributors: [d])
|
||||
oc2 = create(:order_cycle, distributors: [d])
|
||||
oc3 = create(: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
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe "returning products" do
|
||||
let(:product) { create(:product) }
|
||||
let(:order_cycle) { create(:order_cycle, distributors: [d]) }
|
||||
|
||||
30
spec/javascripts/unit/darkswarm/controllers_spec.js.coffee
Normal file
30
spec/javascripts/unit/darkswarm/controllers_spec.js.coffee
Normal file
@@ -0,0 +1,30 @@
|
||||
describe 'Shop controllers', ->
|
||||
describe 'ProductsCtrl', ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
event = null
|
||||
Product = null
|
||||
|
||||
beforeEach ->
|
||||
module('Shop')
|
||||
scope = {}
|
||||
Product =
|
||||
all: ->
|
||||
'testy mctest'
|
||||
inject ($controller) ->
|
||||
ctrl = $controller 'ProductsCtrl', {$scope: scope, Product : Product}
|
||||
|
||||
it 'Fetches products from Product', ->
|
||||
expect(scope.products).toEqual 'testy mctest'
|
||||
|
||||
describe 'OrderCycleCtrl', ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
event = null
|
||||
OrderCycle = null
|
||||
|
||||
beforeEach ->
|
||||
module 'Shop'
|
||||
scope = {}
|
||||
inject ($controller) ->
|
||||
ctrl = $controller 'OrderCycleCtrl'
|
||||
15
spec/javascripts/unit/darkswarm/product_spec.js.coffee
Normal file
15
spec/javascripts/unit/darkswarm/product_spec.js.coffee
Normal file
@@ -0,0 +1,15 @@
|
||||
describe 'Product service', ->
|
||||
$httpBackend = null
|
||||
Product = null
|
||||
|
||||
beforeEach ->
|
||||
module 'Shop'
|
||||
inject ($injector, _$httpBackend_)->
|
||||
Product = $injector.get("Product")
|
||||
$httpBackend = _$httpBackend_
|
||||
|
||||
it "Fetches products from the backend", ->
|
||||
$httpBackend.expectGET("/shop/products").respond([{test : "cats"}])
|
||||
products = Product.all()
|
||||
$httpBackend.flush()
|
||||
expect(products[0].test).toEqual "cats"
|
||||
Reference in New Issue
Block a user