diff --git a/app/assets/images/browser-logos/chrome.png b/app/assets/images/browser-logos/chrome.png index 79a0b8e064..a55fcfec96 100644 Binary files a/app/assets/images/browser-logos/chrome.png and b/app/assets/images/browser-logos/chrome.png differ diff --git a/app/assets/images/browser-logos/firefox.png b/app/assets/images/browser-logos/firefox.png index c77db6ebbf..91c1f85a95 100644 Binary files a/app/assets/images/browser-logos/firefox.png and b/app/assets/images/browser-logos/firefox.png differ diff --git a/app/assets/images/browser-logos/internet-explorer.png b/app/assets/images/browser-logos/internet-explorer.png index c67631a65e..af4739dd89 100644 Binary files a/app/assets/images/browser-logos/internet-explorer.png and b/app/assets/images/browser-logos/internet-explorer.png differ diff --git a/app/assets/images/case-studies/South_East_Food_Hub.png b/app/assets/images/case-studies/South_East_Food_Hub.png index 1760a68d72..1eaed1a657 100644 Binary files a/app/assets/images/case-studies/South_East_Food_Hub.png and b/app/assets/images/case-studies/South_East_Food_Hub.png differ diff --git a/app/assets/images/case-studies/baw-baw.png b/app/assets/images/case-studies/baw-baw.png index 56dd2c94f1..aac409ea35 100644 Binary files a/app/assets/images/case-studies/baw-baw.png and b/app/assets/images/case-studies/baw-baw.png differ diff --git a/app/assets/images/case-studies/bfc_logo_square.png b/app/assets/images/case-studies/bfc_logo_square.png index 90f54df507..30d0c4e935 100644 Binary files a/app/assets/images/case-studies/bfc_logo_square.png and b/app/assets/images/case-studies/bfc_logo_square.png differ diff --git a/app/assets/images/case-studies/bonnie-beef-growers.png b/app/assets/images/case-studies/bonnie-beef-growers.png index ad9f5b14ad..9845874aea 100644 Binary files a/app/assets/images/case-studies/bonnie-beef-growers.png and b/app/assets/images/case-studies/bonnie-beef-growers.png differ diff --git a/app/assets/images/case-studies/jindivick.jpg b/app/assets/images/case-studies/jindivick.jpg index b94ab00166..be3fac1851 100644 Binary files a/app/assets/images/case-studies/jindivick.jpg and b/app/assets/images/case-studies/jindivick.jpg differ diff --git a/app/assets/images/case-studies/jonai.png b/app/assets/images/case-studies/jonai.png index 6cdf7dd20b..0364e26dad 100644 Binary files a/app/assets/images/case-studies/jonai.png and b/app/assets/images/case-studies/jonai.png differ diff --git a/app/assets/images/case-studies/longley.png b/app/assets/images/case-studies/longley.png index 0d20ae93df..ead3b3d2f9 100644 Binary files a/app/assets/images/case-studies/longley.png and b/app/assets/images/case-studies/longley.png differ diff --git a/app/assets/images/case-studies/mt-alexander.png b/app/assets/images/case-studies/mt-alexander.png index efb86d2463..4bb0e54652 100644 Binary files a/app/assets/images/case-studies/mt-alexander.png and b/app/assets/images/case-studies/mt-alexander.png differ diff --git a/app/assets/images/case-studies/wandiful.png b/app/assets/images/case-studies/wandiful.png index f7c4469022..d50cca0d49 100644 Binary files a/app/assets/images/case-studies/wandiful.png and b/app/assets/images/case-studies/wandiful.png differ diff --git a/app/assets/images/collapse.png b/app/assets/images/collapse.png index 1ac2122d8a..d2f5fc73a9 100644 Binary files a/app/assets/images/collapse.png and b/app/assets/images/collapse.png differ diff --git a/app/assets/images/countdown.png b/app/assets/images/countdown.png index 31e2ae2193..12c4877a78 100644 Binary files a/app/assets/images/countdown.png and b/app/assets/images/countdown.png differ diff --git a/app/assets/images/eaterprises_logo.jpg b/app/assets/images/eaterprises_logo.jpg index 1e2bee0a2e..a38c7b72c5 100644 Binary files a/app/assets/images/eaterprises_logo.jpg and b/app/assets/images/eaterprises_logo.jpg differ diff --git a/app/assets/images/enterprise-type.png b/app/assets/images/enterprise-type.png index 0c5741a82f..bee6ee1a13 100644 Binary files a/app/assets/images/enterprise-type.png and b/app/assets/images/enterprise-type.png differ diff --git a/app/assets/images/expand.png b/app/assets/images/expand.png index aa3fc20f39..012b3ea8fa 100644 Binary files a/app/assets/images/expand.png and b/app/assets/images/expand.png differ diff --git a/app/assets/images/gray_jean.png b/app/assets/images/gray_jean.png index 1de7cafdda..d911ae617e 100644 Binary files a/app/assets/images/gray_jean.png and b/app/assets/images/gray_jean.png differ diff --git a/app/assets/images/gray_jean_light.png b/app/assets/images/gray_jean_light.png index ba0f0dc240..2ee033a20a 100644 Binary files a/app/assets/images/gray_jean_light.png and b/app/assets/images/gray_jean_light.png differ diff --git a/app/assets/images/home/background-blurred-oranges.jpg b/app/assets/images/home/background-blurred-oranges.jpg index 61019198e3..611a466132 100644 Binary files a/app/assets/images/home/background-blurred-oranges.jpg and b/app/assets/images/home/background-blurred-oranges.jpg differ diff --git a/app/assets/images/home/home-apples.jpg b/app/assets/images/home/home-apples.jpg index 5cf22d4a50..91bfd4cfa5 100644 Binary files a/app/assets/images/home/home-apples.jpg and b/app/assets/images/home/home-apples.jpg differ diff --git a/app/assets/images/home/home-oranges.jpg b/app/assets/images/home/home-oranges.jpg index 6cd547c97f..671f02d979 100644 Binary files a/app/assets/images/home/home-oranges.jpg and b/app/assets/images/home/home-oranges.jpg differ diff --git a/app/assets/images/home/home-strawberries.jpg b/app/assets/images/home/home-strawberries.jpg index e837c69065..cb2bf15c0e 100644 Binary files a/app/assets/images/home/home-strawberries.jpg and b/app/assets/images/home/home-strawberries.jpg differ diff --git a/app/assets/images/home/home.jpg b/app/assets/images/home/home.jpg index cb59fbef31..0c5c22c6f1 100644 Binary files a/app/assets/images/home/home.jpg and b/app/assets/images/home/home.jpg differ diff --git a/app/assets/images/home/home1.jpg b/app/assets/images/home/home1.jpg index 0e37397127..015b203bcf 100644 Binary files a/app/assets/images/home/home1.jpg and b/app/assets/images/home/home1.jpg differ diff --git a/app/assets/images/home/home2.jpg b/app/assets/images/home/home2.jpg index fa548cb519..4e5cf61b08 100644 Binary files a/app/assets/images/home/home2.jpg and b/app/assets/images/home/home2.jpg differ diff --git a/app/assets/images/home/home3.jpg b/app/assets/images/home/home3.jpg index 26fdf1037c..307ad38c1b 100644 Binary files a/app/assets/images/home/home3.jpg and b/app/assets/images/home/home3.jpg differ diff --git a/app/assets/images/home/macbook.png b/app/assets/images/home/macbook.png index b322681273..ab0d7dfe07 100644 Binary files a/app/assets/images/home/macbook.png and b/app/assets/images/home/macbook.png differ diff --git a/app/assets/images/hubs-bg.jpg b/app/assets/images/hubs-bg.jpg index 2d1c49e230..021ead1074 100644 Binary files a/app/assets/images/hubs-bg.jpg and b/app/assets/images/hubs-bg.jpg differ diff --git a/app/assets/images/icon-mask-apple.png b/app/assets/images/icon-mask-apple.png index 87bfa91bb8..236e0a78e8 100644 Binary files a/app/assets/images/icon-mask-apple.png and b/app/assets/images/icon-mask-apple.png differ diff --git a/app/assets/images/icon-mask-bread.png b/app/assets/images/icon-mask-bread.png index d5c29d96ff..5b7e3a1c79 100644 Binary files a/app/assets/images/icon-mask-bread.png and b/app/assets/images/icon-mask-bread.png differ diff --git a/app/assets/images/icon-mask-magnifier.png b/app/assets/images/icon-mask-magnifier.png index 7f53b7db9d..701f3918f7 100644 Binary files a/app/assets/images/icon-mask-magnifier.png and b/app/assets/images/icon-mask-magnifier.png differ diff --git a/app/assets/images/icon-mask-truck.png b/app/assets/images/icon-mask-truck.png index 40550f98c2..e15c54a3b3 100644 Binary files a/app/assets/images/icon-mask-truck.png and b/app/assets/images/icon-mask-truck.png differ diff --git a/app/assets/images/logo-australia.png b/app/assets/images/logo-australia.png index 46b8ef071a..b4e8dce42b 100644 Binary files a/app/assets/images/logo-australia.png and b/app/assets/images/logo-australia.png differ diff --git a/app/assets/images/logo-black.png b/app/assets/images/logo-black.png index 31ec1422f1..2a33dc3610 100644 Binary files a/app/assets/images/logo-black.png and b/app/assets/images/logo-black.png differ diff --git a/app/assets/images/logo-color.png b/app/assets/images/logo-color.png index e464781a54..fd709b46e9 100644 Binary files a/app/assets/images/logo-color.png and b/app/assets/images/logo-color.png differ diff --git a/app/assets/images/logo-global-white.png b/app/assets/images/logo-global-white.png index 8761bafe9d..c24b525bd2 100644 Binary files a/app/assets/images/logo-global-white.png and b/app/assets/images/logo-global-white.png differ diff --git a/app/assets/images/logo-white-notext.png b/app/assets/images/logo-white-notext.png index bfd590c621..c8f2fb0098 100644 Binary files a/app/assets/images/logo-white-notext.png and b/app/assets/images/logo-white-notext.png differ diff --git a/app/assets/images/logo-white.png b/app/assets/images/logo-white.png index ffd1c6f73a..87cbfa518a 100644 Binary files a/app/assets/images/logo-white.png and b/app/assets/images/logo-white.png differ diff --git a/app/assets/images/matte.png b/app/assets/images/matte.png index 845642cab2..0f6a26429c 100644 Binary files a/app/assets/images/matte.png and b/app/assets/images/matte.png differ diff --git a/app/assets/images/noimage/group.png b/app/assets/images/noimage/group.png index db71856deb..e061134891 100644 Binary files a/app/assets/images/noimage/group.png and b/app/assets/images/noimage/group.png differ diff --git a/app/assets/images/noimage/large.png b/app/assets/images/noimage/large.png index 166a74488a..b345fbf004 100644 Binary files a/app/assets/images/noimage/large.png and b/app/assets/images/noimage/large.png differ diff --git a/app/assets/images/noimage/mini.png b/app/assets/images/noimage/mini.png index db94c3ce7f..1bc901a176 100644 Binary files a/app/assets/images/noimage/mini.png and b/app/assets/images/noimage/mini.png differ diff --git a/app/assets/images/noimage/product.png b/app/assets/images/noimage/product.png index 6ca94eadb2..beeb0b3072 100644 Binary files a/app/assets/images/noimage/product.png and b/app/assets/images/noimage/product.png differ diff --git a/app/assets/images/noimage/small.png b/app/assets/images/noimage/small.png index 02088d8da0..aa17b73ed8 100644 Binary files a/app/assets/images/noimage/small.png and b/app/assets/images/noimage/small.png differ diff --git a/app/assets/images/ofn-logo-footer.png b/app/assets/images/ofn-logo-footer.png index f612d5aa87..8fba44b4a6 100644 Binary files a/app/assets/images/ofn-logo-footer.png and b/app/assets/images/ofn-logo-footer.png differ diff --git a/app/assets/images/ofn-logo.png b/app/assets/images/ofn-logo.png index f53680c342..6058b26a75 100644 Binary files a/app/assets/images/ofn-logo.png and b/app/assets/images/ofn-logo.png differ diff --git a/app/assets/images/ofn-o.png b/app/assets/images/ofn-o.png index d6498ddb4d..8a5d24f41b 100644 Binary files a/app/assets/images/ofn-o.png and b/app/assets/images/ofn-o.png differ diff --git a/app/assets/images/potatoes.png b/app/assets/images/potatoes.png index c0be04200e..baea478c9b 100644 Binary files a/app/assets/images/potatoes.png and b/app/assets/images/potatoes.png differ diff --git a/app/assets/images/producers/producers-pg-bg.jpg b/app/assets/images/producers/producers-pg-bg.jpg index 2df73f0641..612e2d9404 100644 Binary files a/app/assets/images/producers/producers-pg-bg.jpg and b/app/assets/images/producers/producers-pg-bg.jpg differ diff --git a/app/assets/images/select2.png b/app/assets/images/select2.png old mode 100755 new mode 100644 index 9790e029f0..7cef1c04f8 Binary files a/app/assets/images/select2.png and b/app/assets/images/select2.png differ diff --git a/app/assets/images/select2x2.png b/app/assets/images/select2x2.png old mode 100755 new mode 100644 index 7e737c98cf..62628d1302 Binary files a/app/assets/images/select2x2.png and b/app/assets/images/select2x2.png differ diff --git a/app/assets/images/tile-wide.png b/app/assets/images/tile-wide.png index f4e348b73c..b802d0a334 100644 Binary files a/app/assets/images/tile-wide.png and b/app/assets/images/tile-wide.png differ diff --git a/app/assets/javascripts/admin/bulk_product_update.js.coffee b/app/assets/javascripts/admin/bulk_product_update.js.coffee index 751734a899..7a9d2677b9 100644 --- a/app/assets/javascripts/admin/bulk_product_update.js.coffee +++ b/app/assets/javascripts/admin/bulk_product_update.js.coffee @@ -1,4 +1,4 @@ -angular.module("ofn.admin").controller "AdminProductEditCtrl", ($scope, $timeout, $http, BulkProducts, DisplayProperties, dataFetcher, DirtyProducts, VariantUnitManager, StatusMessage, producers, Taxons, SpreeApiAuth, Columns, tax_categories) -> +angular.module("ofn.admin").controller "AdminProductEditCtrl", ($scope, $timeout, $http, $window, BulkProducts, DisplayProperties, dataFetcher, DirtyProducts, VariantUnitManager, StatusMessage, producers, Taxons, SpreeApiAuth, Columns, tax_categories) -> $scope.loading = true $scope.StatusMessage = StatusMessage @@ -206,6 +206,8 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", ($scope, $timeout else $scope.displayFailure t("products_update_error_data") + status + $scope.cancel = (destination) -> + $window.location = destination $scope.packProduct = (product) -> if product.variant_unit_with_scale @@ -247,6 +249,7 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", ($scope, $timeout $scope.displaySuccess = -> StatusMessage.display 'success',t("products_changes_saved") + $scope.bulk_product_form.$setPristine() $scope.displayFailure = (failMessage) -> diff --git a/app/assets/javascripts/admin/customers/controllers/customers_controller.js.coffee b/app/assets/javascripts/admin/customers/controllers/customers_controller.js.coffee index 23bfb37738..7c70a8baa5 100644 --- a/app/assets/javascripts/admin/customers/controllers/customers_controller.js.coffee +++ b/app/assets/javascripts/admin/customers/controllers/customers_controller.js.coffee @@ -13,6 +13,20 @@ angular.module("admin.customers").controller "customersCtrl", ($scope, $q, Custo Customers.index({enterprise_id: $scope.CurrentShop.shop.id}).then (data) -> $scope.customers = data + $scope.checkForDuplicateCodes = -> + delete this.customer.code unless this.customer.code + this.duplicate = $scope.isDuplicateCode(this.customer.code) + + $scope.isDuplicateCode = (code) -> + return false unless code + customers = $scope.findByCode(code) + customers.length > 1 + + $scope.findByCode = (code) -> + if $scope.customers + $scope.customers.filter (customer) -> + customer.code == code + $scope.findTags = (query) -> defer = $q.defer() params = diff --git a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee index a806691465..f21c96a27e 100644 --- a/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee +++ b/app/assets/javascripts/admin/enterprises/controllers/enterprise_controller.js.coffee @@ -1,5 +1,5 @@ angular.module("admin.enterprises") - .controller "enterpriseCtrl", ($scope, NavigationCheck, enterprise, EnterprisePaymentMethods, EnterpriseShippingMethods, SideMenu) -> + .controller "enterpriseCtrl", ($scope, $window, NavigationCheck, enterprise, EnterprisePaymentMethods, EnterpriseShippingMethods, SideMenu, StatusMessage) -> $scope.Enterprise = enterprise $scope.PaymentMethods = EnterprisePaymentMethods.paymentMethods $scope.ShippingMethods = EnterpriseShippingMethods.shippingMethods @@ -8,6 +8,23 @@ angular.module("admin.enterprises") $scope.menu = SideMenu $scope.newManager = { id: '', email: (t('add_manager')) } + $scope.StatusMessage = StatusMessage + + $scope.$watch 'enterprise_form.$dirty', (newValue) -> + StatusMessage.display 'notice', 'You have unsaved changes' if newValue + + $scope.setFormDirty = -> + $scope.$apply -> + $scope.enterprise_form.$setDirty() + + $scope.cancel = (destination) -> + $window.location = destination + + $scope.submit = -> + $scope.navClear() + enterprise_form.submit() + + # Provide a callback for generating warning messages displayed before leaving the page. This is passed in # from a directive "nav-check" in the page - if we pass it here it will be called in the test suite, # and on all new uses of this contoller, and we might not want that . diff --git a/app/assets/javascripts/admin/order_cycles/controllers/create.js.coffee b/app/assets/javascripts/admin/order_cycles/controllers/create.js.coffee index 3f28b27f9f..e0f7cf96b6 100644 --- a/app/assets/javascripts/admin/order_cycles/controllers/create.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/controllers/create.js.coffee @@ -1,5 +1,5 @@ angular.module('admin.orderCycles') - .controller 'AdminCreateOrderCycleCtrl', ($scope, $filter, OrderCycle, Enterprise, EnterpriseFee, ocInstance, StatusMessage) -> + .controller 'AdminCreateOrderCycleCtrl', ($scope, $filter, $window, OrderCycle, Enterprise, EnterpriseFee, ocInstance, StatusMessage) -> $scope.enterprises = Enterprise.index(coordinator_id: ocInstance.coordinator_id) $scope.supplier_enterprises = Enterprise.producer_enterprises $scope.distributor_enterprises = Enterprise.hub_enterprises @@ -11,6 +11,9 @@ angular.module('admin.orderCycles') $scope.StatusMessage = StatusMessage + $scope.$watch 'order_cycle_form.$dirty', (newValue) -> + StatusMessage.display 'notice', 'You have unsaved changes' if newValue + $scope.loaded = -> Enterprise.loaded && EnterpriseFee.loaded && OrderCycle.loaded @@ -55,6 +58,7 @@ angular.module('admin.orderCycles') $scope.removeExchange = ($event, exchange) -> $event.preventDefault() OrderCycle.removeExchange(exchange) + $scope.order_cycle_form.$dirty = true $scope.addCoordinatorFee = ($event) -> $event.preventDefault() @@ -77,4 +81,9 @@ angular.module('admin.orderCycles') $scope.submit = ($event, destination) -> $event.preventDefault() + StatusMessage.display 'progress', "Saving..." OrderCycle.create(destination) + + $scope.cancel = (destination) -> + $window.location = destination + diff --git a/app/assets/javascripts/admin/order_cycles/controllers/simple_create.js.coffee b/app/assets/javascripts/admin/order_cycles/controllers/simple_create.js.coffee index dfa8011167..7a0a03f2bf 100644 --- a/app/assets/javascripts/admin/order_cycles/controllers/simple_create.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/controllers/simple_create.js.coffee @@ -1,4 +1,4 @@ -angular.module('admin.orderCycles').controller "AdminSimpleCreateOrderCycleCtrl", ($scope, OrderCycle, Enterprise, EnterpriseFee, StatusMessage, ocInstance) -> +angular.module('admin.orderCycles').controller "AdminSimpleCreateOrderCycleCtrl", ($scope, $window, OrderCycle, Enterprise, EnterpriseFee, StatusMessage, ocInstance) -> $scope.StatusMessage = StatusMessage $scope.OrderCycle = OrderCycle $scope.order_cycle = OrderCycle.new {coordinator_id: ocInstance.coordinator_id}, => @@ -7,6 +7,9 @@ angular.module('admin.orderCycles').controller "AdminSimpleCreateOrderCycleCtrl" $scope.init(enterprises) $scope.enterprise_fees = EnterpriseFee.index(coordinator_id: ocInstance.coordinator_id) + $scope.$watch 'order_cycle_form.$dirty', (newValue) -> + StatusMessage.display 'notice', 'You have unsaved changes' if newValue + $scope.init = (enterprises) -> enterprise = enterprises[Object.keys(enterprises)[0]] OrderCycle.addSupplier enterprise.id @@ -43,5 +46,9 @@ angular.module('admin.orderCycles').controller "AdminSimpleCreateOrderCycleCtrl" $scope.submit = ($event, destination) -> $event.preventDefault() + StatusMessage.display 'progress', "Saving..." OrderCycle.mirrorIncomingToOutgoingProducts() OrderCycle.create(destination) + + $scope.cancel = (destination) -> + $window.location = destination diff --git a/app/assets/javascripts/admin/order_cycles/controllers/simple_edit.js.coffee b/app/assets/javascripts/admin/order_cycles/controllers/simple_edit.js.coffee index f5bae5a4d8..7df7ddff34 100644 --- a/app/assets/javascripts/admin/order_cycles/controllers/simple_edit.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/controllers/simple_edit.js.coffee @@ -1,4 +1,4 @@ -angular.module('admin.orderCycles').controller "AdminSimpleEditOrderCycleCtrl", ($scope, $location, OrderCycle, Enterprise, EnterpriseFee, StatusMessage) -> +angular.module('admin.orderCycles').controller "AdminSimpleEditOrderCycleCtrl", ($scope, $location, $window, OrderCycle, Enterprise, EnterpriseFee, StatusMessage) -> $scope.orderCycleId = -> $location.absUrl().match(/\/admin\/order_cycles\/(\d+)/)[1] @@ -42,3 +42,6 @@ angular.module('admin.orderCycles').controller "AdminSimpleEditOrderCycleCtrl", StatusMessage.display 'progress', "Saving..." OrderCycle.mirrorIncomingToOutgoingProducts() OrderCycle.update(destination, $scope.order_cycle_form) + + $scope.cancel = (destination) -> + $window.location = destination diff --git a/app/assets/javascripts/admin/tag_rules/controllers/tag_rules_controller.js.coffee b/app/assets/javascripts/admin/tag_rules/controllers/tag_rules_controller.js.coffee index 45f98a2b57..460d8565eb 100644 --- a/app/assets/javascripts/admin/tag_rules/controllers/tag_rules_controller.js.coffee +++ b/app/assets/javascripts/admin/tag_rules/controllers/tag_rules_controller.js.coffee @@ -38,6 +38,7 @@ angular.module("admin.tagRules").controller "TagRulesCtrl", ($scope, $http, $fil newRule.peferred_exchange_tags = [] newRule.preferred_matched_order_cycles_visibility = "visible" tagGroup.rules.push(newRule) + $scope.enterprise_form.$setDirty() $scope.updateRuleCounts() $scope.addNewTag = -> diff --git a/app/assets/javascripts/admin/utils/directives/sortable.js.coffee b/app/assets/javascripts/admin/utils/directives/sortable.js.coffee index 2f2f100e31..19f527bc0f 100644 --- a/app/assets/javascripts/admin/utils/directives/sortable.js.coffee +++ b/app/assets/javascripts/admin/utils/directives/sortable.js.coffee @@ -20,17 +20,18 @@ angular.module("admin.utils").directive "ofnSortable", ($timeout, $parse) -> items: scope.items appendTo: element update: (event, ui) -> - sortableSiblings = ($(ss) for ss in ui.item.siblings(scope.items)) - offset = Math.min(ui.item.index(), sortableSiblings[0].index()) - newPos = ui.item.index() - offset + 1 - oldPos = getScopePos(ui.item.scope()) - if newPos < oldPos - for sibScope in sortableSiblings.map((ss) -> ss.scope()) - pos = getScopePos(sibScope) - setScopePos(sibScope, pos + 1) if pos >= newPos && pos < oldPos - else if newPos > oldPos - for sibScope in sortableSiblings.map((ss) -> ss.scope()) - pos = getScopePos(sibScope) - setScopePos(sibScope, pos - 1) if pos > oldPos && pos <= newPos - setScopePos(ui.item.scope(), newPos) - scope.afterSort() + scope.$apply -> + sortableSiblings = ($(ss) for ss in ui.item.siblings(scope.items)) + offset = Math.min(ui.item.index(), sortableSiblings[0].index()) + newPos = ui.item.index() - offset + 1 + oldPos = getScopePos(ui.item.scope()) + if newPos < oldPos + for sibScope in sortableSiblings.map((ss) -> ss.scope()) + pos = getScopePos(sibScope) + setScopePos(sibScope, pos + 1) if pos >= newPos && pos < oldPos + else if newPos > oldPos + for sibScope in sortableSiblings.map((ss) -> ss.scope()) + pos = getScopePos(sibScope) + setScopePos(sibScope, pos - 1) if pos > oldPos && pos <= newPos + setScopePos(ui.item.scope(), newPos) + scope.afterSort() diff --git a/app/mailers/producer_mailer.rb b/app/mailers/producer_mailer.rb index 30fad48f58..102ac60417 100644 --- a/app/mailers/producer_mailer.rb +++ b/app/mailers/producer_mailer.rb @@ -33,7 +33,7 @@ class ProducerMailer < Spree::BaseMailer joins(:order => :order_cycle, :variant => :product). where('order_cycles.id = ?', order_cycle). merge(Spree::Product.in_supplier(producer)). - merge(Spree::Order.complete) + merge(Spree::Order.by_state('complete')) end def total_from_line_items(line_items) diff --git a/app/models/customer.rb b/app/models/customer.rb index 34f62a6aa6..b2141df9ec 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -5,8 +5,9 @@ class Customer < ActiveRecord::Base belongs_to :user, class_name: Spree.user_class before_validation :downcase_email + before_validation :empty_code - validates :code, uniqueness: { scope: :enterprise_id, allow_blank: true, allow_nil: true } + validates :code, uniqueness: { scope: :enterprise_id, allow_nil: true } validates :email, presence: true, uniqueness: { scope: :enterprise_id, message: I18n.t('validation_msg_is_associated_with_an_exising_customer') } validates :enterprise_id, presence: true @@ -20,6 +21,10 @@ class Customer < ActiveRecord::Base email.andand.downcase! end + def empty_code + self.code = nil if code.blank? + end + def associate_user self.user = user || Spree::User.find_by_email(email) end diff --git a/app/views/admin/customers/index.html.haml b/app/views/admin/customers/index.html.haml index c570632c64..02248923d1 100644 --- a/app/views/admin/customers/index.html.haml +++ b/app/views/admin/customers/index.html.haml @@ -64,7 +64,9 @@ -# %input{ :type => "checkbox", :name => 'bulk', 'ng-model' => 'customer.checked' } %td.email{ 'ng-show' => 'columns.email.visible', "ng-bind" => '::customer.email' } %td.code{ 'ng-show' => 'columns.code.visible' } - %input{ :type => 'text', :name => 'code', :id => 'code', 'ng-model' => 'customer.code', 'obj-for-update' => "customer", "attr-for-update" => "code" } + %input{ type: 'text', name: 'code', ng: {model: 'customer.code', change: 'checkForDuplicateCodes()'}, "obj-for-update" => "customer", "attr-for-update" => "code" } + %i.icon-warning-sign{ ng: {if: 'duplicate'} } + = t('.duplicate_code') %td.tags{ 'ng-show' => 'columns.tags.visible' } .tag_watcher{ 'obj-for-update' => "customer", "attr-for-update" => "tag_list"} %tags_with_translation{ object: 'customer', 'find-tags' => 'findTags(query)' } diff --git a/app/views/admin/enterprises/_ng_form.html.haml b/app/views/admin/enterprises/_ng_form.html.haml index a19bc43314..ca38b7eca4 100644 --- a/app/views/admin/enterprises/_ng_form.html.haml +++ b/app/views/admin/enterprises/_ng_form.html.haml @@ -1,12 +1,18 @@ -# Not all inputs are ng inputs, they don't make the ng-form dirty on change. -# ng-change is only valid for inputs, not for a form. -# So we use onchange and have to get the scope to access the ng controller -= form_for [main_app, :admin, @enterprise], html: { name: "enterprise", += form_for [main_app, :admin, @enterprise], html: { name: "enterprise_form", "ng-app" => 'admin.enterprises', - "ng-submit" => "navClear()", "ng-controller" => 'enterpriseCtrl', - 'onchange' => 'angular.element(enterprise).scope().enterprise.$setDirty()', + 'onchange' => 'angular.element(enterprise_form).scope().setFormDirty()', } do |f| + + %save-bar{ dirty: "enterprise_form.$dirty", persist: "true" } + %input.red{ type: "button", value: "Update", ng: { click: "submit()", disabled: "!enterprise_form.$dirty" } } + %input{ type: "button", ng: { value: "enterprise_form.$dirty ? 'Cancel' : 'Close'", click: "cancel('#{main_app.admin_enterprises_path}')" } } + + + .row .sixteen.columns.alpha .four.columns.alpha @@ -14,8 +20,3 @@ .one.column   .eleven.columns.omega.fullwidth_inputs = render 'form', f: f - .row - .five.columns.alpha -   - .eleven.columns.alpha - = render partial: "spree/admin/shared/#{action}_resource_links" diff --git a/app/views/admin/order_cycles/_form.html.haml b/app/views/admin/order_cycles/_form.html.haml index a0f0a178c8..ebe9e45905 100644 --- a/app/views/admin/order_cycles/_form.html.haml +++ b/app/views/admin/order_cycles/_form.html.haml @@ -46,9 +46,6 @@ = render 'add_exchange_form', f: f, type: 'distributor' .actions - - if @order_cycle.new_record? - = f.submit 'Create', 'ng-click' => "submit($event, '#{main_app.admin_order_cycles_path}')", 'ng-disabled' => '!loaded()' - %span{'ng-hide' => 'loaded()'} Loading... diff --git a/app/views/admin/order_cycles/_simple_form.html.haml b/app/views/admin/order_cycles/_simple_form.html.haml index 6bb0034c73..a7a0363cd3 100644 --- a/app/views/admin/order_cycles/_simple_form.html.haml +++ b/app/views/admin/order_cycles/_simple_form.html.haml @@ -21,7 +21,4 @@ = render 'coordinator_fees', f: f .actions - - if @order_cycle.new_record? - = f.submit 'Create', 'ng-click' => "submit($event, '#{main_app.admin_order_cycles_path}')", 'ng-disabled' => '!loaded()' - %span{'ng-hide' => 'loaded()'} Loading... diff --git a/app/views/admin/order_cycles/new.html.haml b/app/views/admin/order_cycles/new.html.haml index a257bf3c0b..4e5a95544c 100644 --- a/app/views/admin/order_cycles/new.html.haml +++ b/app/views/admin/order_cycles/new.html.haml @@ -4,7 +4,12 @@ - ng_controller = order_cycles_simple_form ? 'AdminSimpleCreateOrderCycleCtrl' : 'AdminCreateOrderCycleCtrl' = admin_inject_order_cycle_instance -= form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng order_cycle', 'ng-app' => 'admin.orderCycles', 'ng-controller' => ng_controller} do |f| += form_for [main_app, :admin, @order_cycle], :url => '', :html => {:class => 'ng order_cycle', 'ng-app' => 'admin.orderCycles', 'ng-controller' => ng_controller, name: 'order_cycle_form'} do |f| + + %save-bar{ dirty: "order_cycle_form.$dirty", persist: "true" } + %input.red{ type: "button", value: "Create", ng: { click: "submit($event, '#{main_app.admin_order_cycles_path}')", disabled: "!order_cycle_form.$dirty" } } + %input{ type: "button", ng: { value: "order_cycle_form.$dirty ? 'Cancel' : 'Close'", click: "cancel('#{main_app.admin_order_cycles_path}')" } } + - if order_cycles_simple_form = render 'simple_form', f: f - else diff --git a/app/views/spree/admin/overview/_order_cycles.html.haml b/app/views/spree/admin/overview/_order_cycles.html.haml index 8628837a47..1a00bd5102 100644 --- a/app/views/spree/admin/overview/_order_cycles.html.haml +++ b/app/views/spree/admin/overview/_order_cycles.html.haml @@ -6,9 +6,8 @@ %a.three.columns.omega.icon-plus.button.blue{ href: "#{main_app.new_admin_order_cycle_path}" } = t "spree_admin_enterprises_create_new" - else - %a.with-tip{ title: t(:spree_admin_order_cycles_tip) } + %a{ "ofn-with-tip" => t(:spree_admin_order_cycles_tip) } = t "admin.whats_this" - %a{ "ofn-with-tip" => "Order cycles determine when and where your products are available to customers." } What's this? %div.seven.columns.alpha.list - if @order_cycle_count > 0 %div.seven.columns.alpha.list-item diff --git a/app/views/spree/admin/products/bulk_edit.html.haml b/app/views/spree/admin/products/bulk_edit.html.haml index 235544cb8a..4e6cf8c704 100644 --- a/app/views/spree/admin/products/bulk_edit.html.haml +++ b/app/views/spree/admin/products/bulk_edit.html.haml @@ -8,4 +8,3 @@ = render 'spree/admin/products/bulk_edit/actions' = render 'spree/admin/products/bulk_edit/indicators' = render 'spree/admin/products/bulk_edit/products' - = render 'spree/admin/products/bulk_edit/save_button_row' diff --git a/app/views/spree/admin/products/bulk_edit/_actions.html.haml b/app/views/spree/admin/products/bulk_edit/_actions.html.haml index 40f135d62e..4a0878bd5c 100644 --- a/app/views/spree/admin/products/bulk_edit/_actions.html.haml +++ b/app/views/spree/admin/products/bulk_edit/_actions.html.haml @@ -1,6 +1,3 @@ .controls.sixteen.columns.alpha{ 'ng-hide' => 'loading || products.length == 0' } - .four.columns.alpha - %input.four.columns.alpha{ :type => 'button', :value => 'Save Changes', 'ng-click' => 'submitProducts()'} - .nine.columns - = render 'spree/admin/shared/status_message' + .thirteen.columns %columns-dropdown{ action: "#{controller_name}_#{action_name}" } diff --git a/app/views/spree/admin/products/bulk_edit/_products.html.haml b/app/views/spree/admin/products/bulk_edit/_products.html.haml index 81fb31573b..b8c580af41 100644 --- a/app/views/spree/admin/products/bulk_edit/_products.html.haml +++ b/app/views/spree/admin/products/bulk_edit/_products.html.haml @@ -1,9 +1,14 @@ %div.sixteen.columns.alpha{ 'ng-hide' => 'loading || filteredProducts.length == 0' } - %table.index#listing_products.bulk{ "infinite-scroll" => "incrementLimit()", "infinite-scroll-distance" => "1" } + %form{ name: 'bulk_product_form' } + %save-bar{ dirty: "bulk_product_form.$dirty", persist: "false" } + %input.red{ type: "button", value: "Save Changes", ng: { click: "submitProducts()", disabled: "!bulk_product_form.$dirty" } } + %input{ type: "button", value: "Close", 'ng-click' => "cancel('#{bulk_edit_admin_products_path}')" } - = render 'spree/admin/products/bulk_edit/products_head' + %table.index#listing_products.bulk{ "infinite-scroll" => "incrementLimit()", "infinite-scroll-distance" => "1" } - %tbody{ 'ng-repeat' => 'product in filteredProducts = ( products | filter:query | producer: producerFilter | category: categoryFilter | limitTo:limit )', 'ng-class-even' => "'even'", 'ng-class-odd' => "'odd'" } + = render 'spree/admin/products/bulk_edit/products_head' - = render 'spree/admin/products/bulk_edit/products_product' - = render 'spree/admin/products/bulk_edit/products_variant' + %tbody{ 'ng-repeat' => 'product in filteredProducts = ( products | filter:query | producer: producerFilter | category: categoryFilter | limitTo:limit )', 'ng-class-even' => "'even'", 'ng-class-odd' => "'odd'" } + + = render 'spree/admin/products/bulk_edit/products_product' + = render 'spree/admin/products/bulk_edit/products_variant' diff --git a/config/locales/en.yml b/config/locales/en.yml index 7fd49fc2fe..e103001337 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -113,6 +113,7 @@ en: valid_email_error: Please enter a valid email address add_a_new_customer_for: Add a new customer for %{shop_name} code: Code + duplicate_code: "This code is used already." products: bulk_edit: diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb index f7f32f6523..062735ccff 100644 --- a/spec/features/admin/bulk_product_update_spec.rb +++ b/spec/features/admin/bulk_product_update_spec.rb @@ -367,7 +367,10 @@ feature %q{ fill_in "variant_price", with: "10.0" end - click_button 'Save Changes', match: :first + within "#save-bar" do + click_button 'Save Changes' + end + expect(page.find("#status-message")).to have_content "Changes saved." v.reload @@ -384,7 +387,10 @@ feature %q{ fill_in "product_name", with: "new name 1" - click_button 'Save Changes', match: :first + within "#save-bar" do + click_button 'Save Changes' + end + expect(page.find("#status-message")).to have_content "Changes saved." p.reload expect(p.name).to eq "new name 1" @@ -415,24 +421,15 @@ feature %q{ fill_in "product_name", :with => "new product name" - click_button 'Save Changes', match: :first + within "#save-bar" do + click_button 'Save Changes' + end + expect(page.find("#status-message")).to have_content "Changes saved." p.reload expect(p.name).to eq "new product name" end - scenario "updating when no changes have been made" do - Capybara.using_wait_time(2) do - FactoryGirl.create(:product, :name => "product 1") - login_to_admin_section - - visit '/admin/products/bulk_edit' - - click_button 'Save Changes', match: :first - expect(page.find("#status-message")).to have_content "No changes to save." - end - end - scenario "updating when a filter has been applied" do s1 = create(:supplier_enterprise) s2 = create(:supplier_enterprise) @@ -447,7 +444,10 @@ feature %q{ expect(page).to have_no_field "product_name", with: p2.name fill_in "product_name", :with => "new product1" - click_button 'Save Changes', match: :first + within "#save-bar" do + click_button 'Save Changes' + end + expect(page.find("#status-message")).to have_content "Changes saved." p1.reload expect(p1.name).to eq "new product1" diff --git a/spec/features/admin/customers_spec.rb b/spec/features/admin/customers_spec.rb index 964608510d..d2f3b9b8bf 100644 --- a/spec/features/admin/customers_spec.rb +++ b/spec/features/admin/customers_spec.rb @@ -50,7 +50,7 @@ feature 'Customers' do within "tr#c_#{customer1.id}" do fill_in "code", with: "new-customer-code" - expect(page).to have_css "input#code.update-pending" + expect(page).to have_css "input[name=code].update-pending" end within "tr#c_#{customer1.id}" do find(:css, "tags-input .tags input").set "awesome\n" @@ -59,7 +59,7 @@ feature 'Customers' do click_button "Save Changes" # Every says it updated - expect(page).to have_css "input#code.update-success" + expect(page).to have_css "input[name=code].update-success" expect(page).to have_css ".tag_watcher.update-success" # And it actually did diff --git a/spec/features/admin/enterprises_spec.rb b/spec/features/admin/enterprises_spec.rb index 3579421b84..4d09007584 100644 --- a/spec/features/admin/enterprises_spec.rb +++ b/spec/features/admin/enterprises_spec.rb @@ -61,6 +61,9 @@ feature %q{ end scenario "editing an existing enterprise", js: true do + # Make the page long enough to avoid the save bar overlaying the form + page.driver.resize(1280, 1000) + @enterprise = create(:enterprise) e2 = create(:enterprise) eg1 = create(:enterprise_group, name: 'eg1') @@ -355,6 +358,10 @@ feature %q{ within("tbody#e_#{distributor1.id}") { click_link 'Manage' } fill_in 'enterprise_name', :with => 'Eaterprises' + + # Because poltergist does not support form onchange event + # We need trigger the change manually + page.evaluate_script("angular.element(enterprise_form).scope().setFormDirty()") click_button 'Update' flash_message.should == 'Enterprise "Eaterprises" has been successfully updated!' @@ -367,6 +374,10 @@ feature %q{ within("tbody#e_#{distributor3.id}") { click_link 'Manage' } fill_in 'enterprise_name', :with => 'Eaterprises' + + # Because poltergist does not support form onchange event + # We need trigger the change manually + page.evaluate_script("angular.element(enterprise_form).scope().setFormDirty()") click_button 'Update' flash_message.should == 'Enterprise "Eaterprises" has been successfully updated!' @@ -407,8 +418,14 @@ feature %q{ # -- Update only select2_select "Certified Organic", from: 'enterprise_producer_properties_attributes_0_property_name' + fill_in 'enterprise_producer_properties_attributes_0_value', with: "NASAA 12345" + + # Because poltergist does not support form onchange event + # We need trigger the change manually + page.evaluate_script("angular.element(enterprise_form).scope().setFormDirty()") click_button 'Update' + supplier1.producer_properties(true).count.should == 1 # -- Destroy diff --git a/spec/features/admin/order_cycles_spec.rb b/spec/features/admin/order_cycles_spec.rb index 1fa85f06e7..74b2e88453 100644 --- a/spec/features/admin/order_cycles_spec.rb +++ b/spec/features/admin/order_cycles_spec.rb @@ -59,6 +59,8 @@ feature %q{ end scenario "creating an order cycle", js: true do + page.driver.resize(1280, 2000) + # Given coordinating, supplying and distributing enterprises with some products with variants coordinator = create(:distributor_enterprise, name: 'My coordinator') supplier = create(:supplier_enterprise, name: 'My supplier') @@ -567,6 +569,9 @@ feature %q{ end scenario "creating a new order cycle" do + # Make the page long enough to avoid the save bar overlaying the form + page.driver.resize(1280, 2000) + click_link "Order Cycles" click_link 'New Order Cycle' @@ -839,6 +844,9 @@ feature %q{ end it "creates order cycles", js: true do + # Make the page long enough to avoid the save bar overlaying the form + page.driver.resize(1280, 2000) + # When I go to the new order cycle page visit admin_order_cycles_path click_link 'New Order Cycle' diff --git a/spec/features/admin/tag_rules_spec.rb b/spec/features/admin/tag_rules_spec.rb index d956ff94b6..f8f25ec181 100644 --- a/spec/features/admin/tag_rules_spec.rb +++ b/spec/features/admin/tag_rules_spec.rb @@ -13,6 +13,9 @@ feature 'Tag Rules', js: true do end it "allows creation of rules of each type" do + # Make the whole page visible + page.driver.resize(1280, 2000) + click_link "Tag Rules" # Creating a new tag @@ -120,6 +123,9 @@ feature 'Tag Rules', js: true do end it "saves changes to rules of each type" do + # Make the whole page visible + page.driver.resize(1280, 2000) + click_link "Tag Rules" # Tag groups exist @@ -228,6 +234,9 @@ feature 'Tag Rules', js: true do end it "deletes both default and customer rules from the database" do + # Make the whole page visible + page.driver.resize(1280, 2000) + click_link "Tag Rules" expect do diff --git a/spec/features/consumer/registration_spec.rb b/spec/features/consumer/registration_spec.rb index cab6c7d327..5cd34206a5 100644 --- a/spec/features/consumer/registration_spec.rb +++ b/spec/features/consumer/registration_spec.rb @@ -22,7 +22,8 @@ feature "Registration", js: true do expect(URI.parse(current_url).path).to eq registration_path # Done reading introduction - click_button_and_ensure_content "Let's get started!", "Woot! First we need to know a little bit about your enterprise:" + page.has_content? + click_and_ensure(:button, "Let's get started!", lambda { page.has_content? 'Woot!' }) # Filling in details fill_in 'enterprise_name', with: "My Awesome Enterprise" @@ -33,23 +34,20 @@ feature "Registration", js: true do fill_in 'enterprise_zipcode', with: '3070' select 'Australia', from: 'enterprise_country' select 'VIC', from: 'enterprise_state' - click_button 'Continue' + click_and_ensure(:button, "Continue", lambda { page.has_content? 'Who is responsible for managing My Awesome Enterprise?' }) + # Filling in Contact Details - expect(page).to have_content 'Who is responsible for managing My Awesome Enterprise?' fill_in 'enterprise_contact', with: 'Saskia Munroe' page.should have_field 'enterprise_email_address', with: user.email fill_in 'enterprise_phone', with: '12 3456 7890' - click_button 'Continue' + click_and_ensure(:button, "Continue", lambda { page.has_content? 'Last step to add My Awesome Enterprise!' }) # Choosing a type - expect(page).to have_content 'Last step to add My Awesome Enterprise!' - click_link_and_ensure('producer-panel', lambda { page.has_content? '#producer-panel.selected' } ) - click_button 'Create Profile' + click_and_ensure(:link, 'producer-panel', lambda { page.has_content? '#producer-panel.selected' } ) + click_and_ensure(:button, "Create Profile", lambda { page.has_content? 'Nice one!' }) # Enterprise should be created - # save_screenshot '/Users/rob/Desktop/ss.png' unless page.has_content? "Nice one!" - expect(page).to have_content 'Nice one!' e = Enterprise.find_by_name('My Awesome Enterprise') expect(e.address.address1).to eq "123 Abc Street" expect(e.sells).to eq "unspecified" @@ -62,10 +60,9 @@ feature "Registration", js: true do fill_in 'enterprise_abn', with: '12345' fill_in 'enterprise_acn', with: '54321' choose 'Yes' # enterprise_charges_sales_tax - click_button 'Continue' + click_and_ensure(:button, "Continue", lambda { page.has_content? 'Step 1. Select Logo Image' }) # Enterprise should be updated - expect(page).to have_content "Let's upload some pretty pictures so your profile looks great!" e.reload expect(e.description).to eq "Short description" expect(e.long_description).to eq "Long description" @@ -75,21 +72,20 @@ feature "Registration", js: true do # Images # Move from logo page - click_button 'Continue' + click_and_ensure(:button, "Continue", lambda { page.has_content? 'Step 3. Select Promo Image' }) + # Move from promo page - click_button 'Continue' + click_and_ensure(:button, "Continue", lambda { page.has_content? 'How can people find My Awesome Enterprise online?' }) # Filling in social - expect(page).to have_content 'How can people find My Awesome Enterprise online?' fill_in 'enterprise_website', with: 'www.shop.com' fill_in 'enterprise_facebook', with: 'FaCeBoOk' fill_in 'enterprise_linkedin', with: 'LiNkEdIn' fill_in 'enterprise_twitter', with: '@TwItTeR' fill_in 'enterprise_instagram', with: '@InStAgRaM' - click_button 'Continue' + click_and_ensure(:button, "Continue", lambda { page.has_content? 'Finished!' }) # Done - expect(page).to have_content "Finished!" expect(page).to have_content "We've sent a confirmation email to #{user.email} if it hasn't been activated before." e.reload expect(e.website).to eq "www.shop.com" @@ -121,21 +117,11 @@ feature "Registration", js: true do expect(page).to have_content content end - def click_button_and_ensure_content(button_text, content) + def click_and_ensure(type, text, check) # Buttons appear to be unresponsive for a while, so keep clicking them until content appears using_wait_time 0.5 do 10.times do - click_button button_text - break if page.has_content? content - end - end - end - - def click_link_and_ensure(link_text, check) - # Buttons appear to be unresponsive for a while, so keep clicking them until content appears - using_wait_time 0.5 do - 10.times do - click_link link_text + send("click_#{type}", text) break if check.call end end diff --git a/spec/features/consumer/shopping/shopping_spec.rb b/spec/features/consumer/shopping/shopping_spec.rb index 1e69e97b1c..7dc9f474da 100644 --- a/spec/features/consumer/shopping/shopping_spec.rb +++ b/spec/features/consumer/shopping/shopping_spec.rb @@ -251,6 +251,8 @@ feature "As a consumer I want to shop with a distributor", js: true do describe "when a product goes out of stock just before it's added to the cart" do it "stops the attempt, shows an error message and refreshes the products asynchronously" do + expect(page).to have_content "Product" + variant.update_attributes! on_hand: 0 # -- Messaging diff --git a/spec/features/consumer/shopping/variant_overrides_spec.rb b/spec/features/consumer/shopping/variant_overrides_spec.rb index 92945a60be..b59cb6a613 100644 --- a/spec/features/consumer/shopping/variant_overrides_spec.rb +++ b/spec/features/consumer/shopping/variant_overrides_spec.rb @@ -193,7 +193,7 @@ feature "shopping with variant overrides defined", js: true do end place_order - page.should have_content "Your order has been processed successfully" + expect(page).to have_content "Your order has been processed successfully" end def click_checkout diff --git a/spec/javascripts/unit/admin/customers/controllers/customers_controller_spec.js.coffee b/spec/javascripts/unit/admin/customers/controllers/customers_controller_spec.js.coffee index 7854700dfd..ec884a284b 100644 --- a/spec/javascripts/unit/admin/customers/controllers/customers_controller_spec.js.coffee +++ b/spec/javascripts/unit/admin/customers/controllers/customers_controller_spec.js.coffee @@ -21,7 +21,7 @@ describe "CustomersCtrl", -> expect(scope.CurrentShop.shop).toEqual {} describe "setting the shop on scope", -> - customer = { id: 5, email: 'someone@email.com'} + customer = { id: 5, email: 'someone@email.com', code: 'a'} customers = [customer] beforeEach -> @@ -33,6 +33,12 @@ describe "CustomersCtrl", -> it "retrievs the list of customers", -> expect(scope.customers).toDeepEqual customers + it "finds customers by code", -> + as = scope.findByCode('a') + expect(as).toDeepEqual customers + as = scope.findByCode('b') + expect(as).toDeepEqual [] + describe "scope.add", -> it "creates a new customer", -> email = "customer@example.org" diff --git a/spec/javascripts/unit/admin/order_cycles/controllers/simple_create.js.coffee b/spec/javascripts/unit/admin/order_cycles/controllers/simple_create.js.coffee index 7404bbead2..70508bc519 100644 --- a/spec/javascripts/unit/admin/order_cycles/controllers/simple_create.js.coffee +++ b/spec/javascripts/unit/admin/order_cycles/controllers/simple_create.js.coffee @@ -8,7 +8,8 @@ describe "AdminSimpleCreateOrderCycleCtrl", -> outgoing_exchange = {} beforeEach -> - scope = {} + scope = + $watch: jasmine.createSpy('$watch') order_cycle = coordinator_id: 123 incoming_exchanges: [incoming_exchange] diff --git a/spec/javascripts/unit/admin/tag_rules/controllers/tag_rules_controller_spec.js.coffee b/spec/javascripts/unit/admin/tag_rules/controllers/tag_rules_controller_spec.js.coffee index 2526016d3d..7ac5cc8fbc 100644 --- a/spec/javascripts/unit/admin/tag_rules/controllers/tag_rules_controller_spec.js.coffee +++ b/spec/javascripts/unit/admin/tag_rules/controllers/tag_rules_controller_spec.js.coffee @@ -15,6 +15,7 @@ describe "TagRulesCtrl", -> inject ($rootScope, $controller) -> scope = $rootScope + scope.enterprise_form = jasmine.createSpyObj('enterprise_form', ['$setDirty']) ctrl = $controller 'TagRulesCtrl', {$scope: scope, enterprise: enterprise} describe "tagGroup start indices", -> @@ -27,6 +28,8 @@ describe "TagRulesCtrl", -> scope.addNewRuleTo(scope.tagGroups[0], "DiscountOrder") it "adds a new rule of the specified type to the rules array for the tagGroup", -> + expect(scope.enterprise_form.$setDirty).toHaveBeenCalled() + expect(scope.tagGroups[0].rules.length).toEqual 3 expect(scope.tagGroups[0].rules[2].type).toEqual "TagRule::DiscountOrder" diff --git a/spec/javascripts/unit/bulk_product_update_spec.js.coffee b/spec/javascripts/unit/bulk_product_update_spec.js.coffee index cc0b574f47..c1c34cbe6b 100644 --- a/spec/javascripts/unit/bulk_product_update_spec.js.coffee +++ b/spec/javascripts/unit/bulk_product_update_spec.js.coffee @@ -668,6 +668,9 @@ describe "AdminProductEditCtrl", -> spyOn $scope, "displaySuccess" spyOn BulkProducts, "updateVariantLists" spyOn DirtyProducts, "clear" + + $scope.bulk_product_form = jasmine.createSpyObj('bulk_product_form', ['$setPristine']) + $scope.products = [ { id: 1 @@ -692,6 +695,7 @@ describe "AdminProductEditCtrl", -> $httpBackend.flush() $timeout.flush() expect($scope.displaySuccess).toHaveBeenCalled() + expect($scope.bulk_product_form.$setPristine).toHaveBeenCalled expect(DirtyProducts.clear).toHaveBeenCalled() expect(BulkProducts.updateVariantLists).toHaveBeenCalled() diff --git a/spec/javascripts/unit/order_cycle_spec.js.coffee b/spec/javascripts/unit/order_cycle_spec.js.coffee index 4a924917c8..5fec8b93f5 100644 --- a/spec/javascripts/unit/order_cycle_spec.js.coffee +++ b/spec/javascripts/unit/order_cycle_spec.js.coffee @@ -9,7 +9,9 @@ describe 'OrderCycle controllers', -> EnterpriseFee = null beforeEach -> - scope = {} + scope = + order_cycle_form: jasmine.createSpyObj('order_cycle_form', ['$dirty']) + $watch: jasmine.createSpy('$watch') event = preventDefault: jasmine.createSpy('preventDefault') OrderCycle = diff --git a/spec/mailers/producer_mailer_spec.rb b/spec/mailers/producer_mailer_spec.rb index 7291714e03..c964342073 100644 --- a/spec/mailers/producer_mailer_spec.rb +++ b/spec/mailers/producer_mailer_spec.rb @@ -14,6 +14,7 @@ describe ProducerMailer do let(:p2) { create(:product, price: 23.45, supplier: s2) } let(:p3) { create(:product, price: 34.56, supplier: s1) } let(:p4) { create(:product, price: 45.67, supplier: s1) } + let(:p5) { create(:product, price: 56.78, supplier: s1) } let(:order_cycle) { create(:simple_order_cycle) } let!(:incoming_exchange) { order_cycle.exchanges.create! sender: s1, receiver: d1, incoming: true, receival_instructions: 'Outside shed.' } @@ -33,6 +34,14 @@ describe ProducerMailer do order.save order end + let!(:order_canceled) do + order = create(:order, distributor: d1, order_cycle: order_cycle, state: 'complete') + order.line_items << create(:line_item, variant: p5.variants.first) + order.finalize! + order.cancel + order.save + order + end let(:mail) { ActionMailer::Base.deliveries.last } before do @@ -75,8 +84,11 @@ describe ProducerMailer do mail.body.encoded.should_not include p3.name end + it "does not include canceled orders" do + mail.body.encoded.should_not include p5.name + end + it "includes the total" do - # puts mail.text_part.body.encoded mail.body.encoded.should include 'Total: $50.00' body_as_html(mail).find("tr.total-row") .should have_selector("td", text: "$50.00") diff --git a/spec/models/customer_spec.rb b/spec/models/customer_spec.rb index f2ac14e9b2..32e380f4d3 100644 --- a/spec/models/customer_spec.rb +++ b/spec/models/customer_spec.rb @@ -1,6 +1,23 @@ require 'spec_helper' describe Customer, type: :model do + describe 'an existing customer' do + let(:customer) { create(:customer) } + + it "saves its code" do + code = "code one" + customer.code = code + customer.save + expect(customer.code).to eq code + end + + it "can remove its code" do + customer.code = "" + customer.save + expect(customer.code).to be nil + end + end + describe 'creation callbacks' do let!(:user1) { create(:user) } let!(:user2) { create(:user) } diff --git a/spec/support/request/checkout_workflow.rb b/spec/support/request/checkout_workflow.rb index e08fb031da..4a0f37c0ea 100644 --- a/spec/support/request/checkout_workflow.rb +++ b/spec/support/request/checkout_workflow.rb @@ -8,7 +8,7 @@ module CheckoutWorkflow end def place_order - click_button "Place order now" + find("button", text: "Place order now").trigger "click" end def toggle_accordion(id)