From 17bb1f9d25d6ec73a477690be2ef4216bdff7d8d Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Thu, 27 Mar 2014 12:07:38 +1100 Subject: [PATCH] Getting the tests working once more --- .../controllers/tabs_controller.js.coffee | 28 +------------------ .../darkswarm/services/order_cycle.js.coffee | 10 ++++++- app/views/shop/shop/show.html.haml | 2 +- config/ng-test.conf.js | 1 + .../sidebar_controller_spec.js.coffee | 6 ++-- .../unit/darkswarm/order_cycle_spec.js.coffee | 10 +++++++ 6 files changed, 25 insertions(+), 32 deletions(-) diff --git a/app/assets/javascripts/darkswarm/controllers/tabs_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/tabs_controller.js.coffee index 0788cc96ec..cb1abb71ff 100644 --- a/app/assets/javascripts/darkswarm/controllers/tabs_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/tabs_controller.js.coffee @@ -1,4 +1,4 @@ -Darkswarm.controller "TabsCtrl", ($scope, $rootScope, $location) -> +Darkswarm.controller "TabsCtrl", ($scope, $rootScope, $location, OrderCycle) -> $scope.active = (path)-> $location.hash() == path @@ -12,29 +12,3 @@ Darkswarm.controller "TabsCtrl", ($scope, $rootScope, $location) -> $location.hash "/" else $location.hash tab.path - - -# directive -> ng-click -> scope method (not isolated) -> toggle active | change location -# watch active expression -> change tab appearance - -#select = -> - #$location.path(tab.path) - -#active expression: - #"$location.path() == tab.path" - - -# directive -> ng-click -> set active (on isolated scope) -# ng-class -> change tab appearance -# two-way binding active attr <-> tab.active - -# directive attr (select) -> scope.selectExpression -# scope.select -> $parse ... -# -# in Directive -# scope.select = $parse(attrs.select) -# $scope.select($scope) -# -# 1: remove reverse binding on tab.active -# 2: put $parse(attrs.select) onto tab -# 3: override TabsetController/select to run tab.select() against original tab.$parent diff --git a/app/assets/javascripts/darkswarm/services/order_cycle.js.coffee b/app/assets/javascripts/darkswarm/services/order_cycle.js.coffee index 84d09a9a13..58d4d11946 100644 --- a/app/assets/javascripts/darkswarm/services/order_cycle.js.coffee +++ b/app/assets/javascripts/darkswarm/services/order_cycle.js.coffee @@ -1,7 +1,15 @@ Darkswarm.factory 'OrderCycle', ($resource, Product, orderCycleData) -> class OrderCycle - @order_cycle = orderCycleData || {orders_close_at: ""} + @order_cycle = orderCycleData || null @push_order_cycle: -> new $resource("/shop/order_cycle").save {order_cycle_id: @order_cycle.order_cycle_id}, (order_data)-> OrderCycle.order_cycle.orders_close_at = order_data.orders_close_at Product.update() + + @orders_close_at: -> + if @order_cycle + @order_cycle.orders_close_at + else + "" + @selected: -> + @order_cycle != null diff --git a/app/views/shop/shop/show.html.haml b/app/views/shop/shop/show.html.haml index 250942357c..bb969b319b 100644 --- a/app/views/shop/shop/show.html.haml +++ b/app/views/shop/shop/show.html.haml @@ -8,7 +8,7 @@ %closing -#%img{src: "/icon/goes/here"} Orders close - %strong {{ order_cycle.orders_close_at | date_in_words }} + %strong {{ order_cycle.orders_close_at() | date_in_words }} = render partial: "shop/details" %products.row diff --git a/config/ng-test.conf.js b/config/ng-test.conf.js index 47c41afd67..b1bddd6532 100644 --- a/config/ng-test.conf.js +++ b/config/ng-test.conf.js @@ -9,6 +9,7 @@ module.exports = function(config) { 'app/assets/javascripts/shared/angular.js', 'app/assets/javascripts/shared/angular-*.js', 'app/assets/javascripts/shared/jquery.timeago.js', + 'app/assets/javascripts/shared/mm-foundation-tpls-0.2.0-SNAPSHOT.js', 'app/assets/javascripts/admin/shared_directives.js.coffee', 'app/assets/javascripts/admin/shared_services.js.coffee', diff --git a/spec/javascripts/unit/darkswarm/controllers/sidebar_controller_spec.js.coffee b/spec/javascripts/unit/darkswarm/controllers/sidebar_controller_spec.js.coffee index f13de505d9..0d051a8cfa 100644 --- a/spec/javascripts/unit/darkswarm/controllers/sidebar_controller_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/controllers/sidebar_controller_spec.js.coffee @@ -6,8 +6,8 @@ describe "SidebarCtrl", -> beforeEach -> module("Darkswarm") location = - hash: -> - "sidebar" + path: -> + "/login" inject ($controller, $rootScope) -> scope = $rootScope ctrl = $controller 'SidebarCtrl', {$scope: scope, $location: location} @@ -17,6 +17,6 @@ describe "SidebarCtrl", -> expect(scope.active()).toEqual true it 'is inactive no location is set', -> - location.hash = -> + location.path = -> null expect(scope.active()).toEqual false diff --git a/spec/javascripts/unit/darkswarm/order_cycle_spec.js.coffee b/spec/javascripts/unit/darkswarm/order_cycle_spec.js.coffee index 395b51512e..9687e72380 100644 --- a/spec/javascripts/unit/darkswarm/order_cycle_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/order_cycle_spec.js.coffee @@ -32,3 +32,13 @@ describe 'OrderCycle service', -> $httpBackend.flush() expect(OrderCycle.order_cycle.orders_close_at).toEqual(datestring) + it "tells us when the order cycle closes", -> + OrderCycle.order_cycle.orders_close_at = "test" + expect(OrderCycle.orders_close_at()).toEqual "test" + + it "tells us when no order cycle is selected", -> + OrderCycle.order_cycle = null + expect(OrderCycle.selected()).toEqual false + OrderCycle.order_cycle = {test: "blah"} + expect(OrderCycle.selected()).toEqual true +