mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Fixing up the tests with some refactoring
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
angular.module("Shop").controller "ProductsCtrl", ($scope, $rootScope, Product) ->
|
||||
$scope.products = Product.all()
|
||||
$scope.data = Product.data
|
||||
Product.update()
|
||||
|
||||
|
||||
#$scope.order_cycle = OrderCycle.order_cycle
|
||||
|
||||
@@ -4,7 +4,8 @@ Shop.factory 'OrderCycle', ($resource, Product) ->
|
||||
order_cycle_id: null
|
||||
}
|
||||
|
||||
@set_order_cycle: ->
|
||||
new $resource("/shop/order_cycle").save {order_cycle_id: @order_cycle.order_cycle_id}, ->
|
||||
@set_order_cycle: (id)->
|
||||
@order_cycle.order_cycle_id = id
|
||||
new $resource("/shop/order_cycle").save {order_cycle_id: id}, ->
|
||||
Product.update()
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
Shop.factory 'Product', ($resource) ->
|
||||
new class Product
|
||||
@products: null
|
||||
data: {
|
||||
products: null
|
||||
}
|
||||
update: ->
|
||||
@products = $resource("/shop/products").query()
|
||||
console.log @products
|
||||
@products
|
||||
@data.products = $resource("/shop/products").query =>
|
||||
#console.log @products
|
||||
@data
|
||||
all: ->
|
||||
@products || @update()
|
||||
@data.products || @update()
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
= @distributor.long_description.andand.html_safe
|
||||
|
||||
%products{"ng-controller" => "ProductsCtrl"}
|
||||
%pre {{ products | json }}
|
||||
%pre {{ data.products | json }}
|
||||
|
||||
= render partial: "enterprises/contact_us"
|
||||
= render partial: "enterprises/about_us"
|
||||
|
||||
@@ -10,14 +10,16 @@ describe 'All controllers', ->
|
||||
module('Shop')
|
||||
Product =
|
||||
all: ->
|
||||
'testy mctest'
|
||||
update: ->
|
||||
data: "testy mctest"
|
||||
|
||||
inject ($controller, $rootScope) ->
|
||||
rootScope = $rootScope
|
||||
scope = $rootScope.$new()
|
||||
ctrl = $controller 'ProductsCtrl', {$scope: scope, Product : Product}
|
||||
|
||||
it 'Fetches products from Product', ->
|
||||
expect(scope.products).toEqual 'testy mctest'
|
||||
expect(scope.data).toEqual 'testy mctest'
|
||||
|
||||
#it "updates products when the changeOrderCycle event is seen", ->
|
||||
#spyOn(scope, "updateProducts")
|
||||
|
||||
@@ -21,3 +21,5 @@ describe 'OrderCycle service', ->
|
||||
OrderCycle.set_order_cycle(10)
|
||||
$httpBackend.flush()
|
||||
expect(mockProduct.update).toHaveBeenCalled()
|
||||
|
||||
|
||||
|
||||
@@ -12,4 +12,3 @@ describe 'Product service', ->
|
||||
$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