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 3077aa8a11..3f28b27f9f 100644 --- a/app/assets/javascripts/admin/order_cycles/controllers/create.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/controllers/create.js.coffee @@ -41,10 +41,6 @@ angular.module('admin.orderCycles') $scope.enterprisesWithFees = -> $scope.enterprises[id] for id in OrderCycle.participatingEnterpriseIds() when $scope.enterpriseFeesForEnterprise(id).length > 0 - $scope.toggleProducts = ($event, exchange) -> - $event.preventDefault() - OrderCycle.toggleProducts(exchange) - $scope.enterpriseFeesForEnterprise = (enterprise_id) -> EnterpriseFee.forEnterprise(parseInt(enterprise_id)) diff --git a/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee b/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee index 2f3b2db5e0..c0818acafa 100644 --- a/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee @@ -45,10 +45,6 @@ angular.module('admin.orderCycles') $scope.enterprisesWithFees = -> $scope.enterprises[id] for id in OrderCycle.participatingEnterpriseIds() when $scope.enterpriseFeesForEnterprise(id).length > 0 - $scope.toggleProducts = ($event, exchange) -> - $event.preventDefault() - OrderCycle.toggleProducts(exchange) - $scope.enterpriseFeesForEnterprise = (enterprise_id) -> EnterpriseFee.forEnterprise(parseInt(enterprise_id)) diff --git a/app/assets/javascripts/admin/order_cycles/order_cycles.js.coffee b/app/assets/javascripts/admin/order_cycles/order_cycles.js.coffee index a75fdad58c..6ea3f76984 100644 --- a/app/assets/javascripts/admin/order_cycles/order_cycles.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/order_cycles.js.coffee @@ -1,4 +1,4 @@ -angular.module('admin.orderCycles', ['ngResource', 'admin.utils', 'admin.indexUtils']) +angular.module('admin.orderCycles', ['ngResource', 'admin.utils', 'admin.indexUtils', 'ngTagsInput']) .config ($httpProvider) -> $httpProvider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content') diff --git a/app/assets/javascripts/admin/order_cycles/services/order_cycle.js.coffee b/app/assets/javascripts/admin/order_cycles/services/order_cycle.js.coffee index 662201c9f5..5ab14dfdcd 100644 --- a/app/assets/javascripts/admin/order_cycles/services/order_cycle.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/services/order_cycle.js.coffee @@ -1,4 +1,4 @@ -angular.module('admin.orderCycles').factory 'OrderCycle', ($resource, $window, StatusMessage) -> +angular.module('admin.orderCycles').factory 'OrderCycle', ($resource, $window, StatusMessage, Panels) -> OrderCycleResource = $resource '/admin/order_cycles/:action_name/:order_cycle_id.json', {}, { 'index': { method: 'GET', isArray: true} 'new' : { method: 'GET', params: { action_name: "new" } } @@ -30,23 +30,25 @@ angular.module('admin.orderCycles').factory 'OrderCycle', ($resource, $window, S exchangeDirection: (exchange) -> if this.order_cycle.incoming_exchanges.indexOf(exchange) == -1 then 'outgoing' else 'incoming' - toggleProducts: (exchange) -> - exchange.showProducts = !exchange.showProducts - toggleAllProducts: (direction) -> this.showProducts[direction] = !this.showProducts[direction] - exchange.showProducts = this.showProducts[direction] for exchange in this.exchangesByDirection(direction) + state = if this.showProducts[direction] then "open" else "closed" + exchanges = this.exchangesByDirection(direction) + Panels.toggle(exchange,'products',state) for exchange in exchanges setExchangeVariants: (exchange, variants, selected) -> direction = if exchange.incoming then "incoming" else "outgoing" editable = @order_cycle["editable_variants_for_#{direction}_exchanges"][exchange.enterprise_id] || [] - exchange.variants[variant] = selected for variant in variants when variant in editable + for variant in variants when variant in editable + exchange.variants[variant] = selected + @removeDistributionOfVariant(variant.id) if exchange.incoming + addSupplier: (new_supplier_id) -> this.order_cycle.incoming_exchanges.push({enterprise_id: new_supplier_id, incoming: true, active: true, variants: {}, enterprise_fees: []}) addDistributor: (new_distributor_id) -> - this.order_cycle.outgoing_exchanges.push({enterprise_id: new_distributor_id, incoming: false, active: true, variants: {}, enterprise_fees: []}) + this.order_cycle.outgoing_exchanges.push({enterprise_id: new_distributor_id, incoming: false, active: true, variants: {}, enterprise_fees: [], tags: [], tag_list: ""}) removeExchange: (exchange) -> if exchange.incoming diff --git a/app/assets/javascripts/templates/admin/panels/exchange_distributed_products.html.haml b/app/assets/javascripts/templates/admin/panels/exchange_distributed_products.html.haml new file mode 100644 index 0000000000..4c6a86e926 --- /dev/null +++ b/app/assets/javascripts/templates/admin/panels/exchange_distributed_products.html.haml @@ -0,0 +1,31 @@ +.row.exchange-distributed-products + .sixteen.columns.alpha.omega + .exchange-select-all-variants + %label + %input{ type: 'checkbox', name: 'order_cycle_outgoing_exchange_{{ $parent.$index }}_select_all_variants', + value: 1, + 'ng-model' => 'exchange.select_all_variants', + 'ng-change' => 'setExchangeVariants(exchange, incomingExchangeVariantsFor(exchange.enterprise_id), exchange.select_all_variants)', + 'id' => 'order_cycle_outgoing_exchange_{{ $parent.$index }}_select_all_variants' } + Select all + + .exchange-products + -# Scope product list based on permissions the current user has to view variants in this exchange + .exchange-product{'ng-repeat' => 'product in supplied_products | filter:productSuppliedToOrderCycle | visibleProducts:exchange:order_cycle.visible_variants_for_outgoing_exchanges | orderBy:"name"' } + .exchange-product-details + %label + -# MASTER_VARIANTS: No longer required + -# = check_box_tag 'order_cycle_outgoing_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}', 1, 1, 'ng-hide' => 'product.variants.length > 0', 'ng-model' => 'exchange.variants[product.master_id]', 'id' => 'order_cycle_outgoing_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}', + -# 'ng-disabled' => 'product.variants.length > 0 || !order_cycle.editable_variants_for_outgoing_exchanges.hasOwnProperty(exchange.enterprise_id) || order_cycle.editable_variants_for_outgoing_exchanges[exchange.enterprise_id].indexOf(product.master_id) < 0' + %img{'ng-src' => '{{ product.image_url }}'} + .name {{ product.name }} + .supplier {{ product.supplier_name }} + + .exchange-product-variant{'ng-repeat' => 'variant in product.variants | visibleVariants:exchange:order_cycle.visible_variants_for_outgoing_exchanges | filter:variantSuppliedToOrderCycle'} + %label + %input{ type: 'checkbox', name: 'order_cycle_outgoing_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}', + value: 1, + 'ng-model' => 'exchange.variants[variant.id]', + 'id' => 'order_cycle_outgoing_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}', + 'ng-disabled' => '!order_cycle.editable_variants_for_outgoing_exchanges.hasOwnProperty(exchange.enterprise_id) || order_cycle.editable_variants_for_outgoing_exchanges[exchange.enterprise_id].indexOf(variant.id) < 0' } + {{ variant.label }} diff --git a/app/assets/javascripts/templates/admin/panels/exchange_supplied_products.html.haml b/app/assets/javascripts/templates/admin/panels/exchange_supplied_products.html.haml new file mode 100644 index 0000000000..04e191fcf0 --- /dev/null +++ b/app/assets/javascripts/templates/admin/panels/exchange_supplied_products.html.haml @@ -0,0 +1,49 @@ +.row.exchange-supplied-products + .sixteen.columns.alpha.omega + .exchange-select-all-variants + %label + %input{ type: 'checkbox', name: 'order_cycle_incoming_exchange_{{ $index }}_select_all_variants', + value: 1, + 'ng-model' => 'exchange.select_all_variants', + 'ng-change' => 'setExchangeVariants(exchange, suppliedVariants(exchange.enterprise_id), exchange.select_all_variants)', + 'id' => 'order_cycle_incoming_exchange_{{ $index }}_select_all_variants' } + Select all + + .exchange-products + -# No need to scope product list based on permissions, because if an incoming exchange is visible, + -# then all of the variants within it should be visible. May change in the future? + .exchange-product{'ng-repeat' => 'product in enterprises[exchange.enterprise_id].supplied_products'} + + .exchange-product-details + %label + %input{ type: 'checkbox', name: 'order_cycle_incoming_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}', + value: 1, + 'ng-hide' => 'product.variants.length > 0', + 'ng-model' => 'exchange.variants[product.master_id]', + 'ofn-sync-distributions' => '{{ product.master_id }}', + 'id' => 'order_cycle_incoming_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}', + 'ng-disabled' => 'product.variants.length > 0 || !order_cycle.editable_variants_for_incoming_exchanges.hasOwnProperty(exchange.enterprise_id) || order_cycle.editable_variants_for_incoming_exchanges[exchange.enterprise_id].indexOf(product.master_id) < 0' } + %img{'ng-src' => '{{ product.image_url }}'} + {{ product.name }} + + -# When the master variant is in the order cycle but the product has variants, we want to + -# be able to remove the master variant, since it serves no purpose. Display a checkbox to do so. + .exchange-product-variant{'ng-show' => 'exchange.variants[product.master_id] && product.variants.length > 0'} + %label + %input{ type: 'checkbox', name: 'order_cycle_incoming_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}', + value: 1, + 'ng-model' => 'exchange.variants[product.master_id]', + 'ofn-sync-distributions' => '{{ product.master_id }}', + 'id' => 'order_cycle_incoming_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}', + 'ng-disabled' => '!order_cycle.editable_variants_for_incoming_exchanges.hasOwnProperty(exchange.enterprise_id) || order_cycle.editable_variants_for_incoming_exchanges[exchange.enterprise_id].indexOf(product.master_id) < 0' } + Obsolete master + + .exchange-product-variant{'ng-repeat' => 'variant in product.variants'} + %label + %input{ type: 'checkbox', name: 'order_cycle_incoming_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}', + value: 1, + 'ng-model' => 'exchange.variants[variant.id]', + 'ofn-sync-distributions' => '{{ variant.id }}', + 'id' => 'order_cycle_incoming_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}', + 'ng-disabled' => '!order_cycle.editable_variants_for_incoming_exchanges.hasOwnProperty(exchange.enterprise_id) || order_cycle.editable_variants_for_incoming_exchanges[exchange.enterprise_id].indexOf(variant.id) < 0' } + {{ variant.label }} diff --git a/app/assets/javascripts/templates/admin/panels/exchange_tags.html.haml b/app/assets/javascripts/templates/admin/panels/exchange_tags.html.haml new file mode 100644 index 0000000000..0963c480c0 --- /dev/null +++ b/app/assets/javascripts/templates/admin/panels/exchange_tags.html.haml @@ -0,0 +1,5 @@ +.row.exchange-tags + .sixteen.columns.alpha.omega + %span.text-normal Tags + %br + %tags-with-translation.fullwidth{ object: 'object' } diff --git a/app/assets/stylesheets/admin/openfoodnetwork.css.scss b/app/assets/stylesheets/admin/openfoodnetwork.css.scss index 8d77015af7..1532ea8520 100644 --- a/app/assets/stylesheets/admin/openfoodnetwork.css.scss +++ b/app/assets/stylesheets/admin/openfoodnetwork.css.scss @@ -79,10 +79,6 @@ form.order_cycle { width: 20px; } - tr.supplier td { - border-bottom: 2px solid #C3D9FF; - } - .exchange-select-all-variants { clear: both; margin: 5px; diff --git a/app/models/exchange.rb b/app/models/exchange.rb index ad290f6c26..3d0e6417e6 100644 --- a/app/models/exchange.rb +++ b/app/models/exchange.rb @@ -1,4 +1,6 @@ class Exchange < ActiveRecord::Base + acts_as_taggable + belongs_to :order_cycle belongs_to :sender, :class_name => 'Enterprise' belongs_to :receiver, :class_name => 'Enterprise' @@ -58,6 +60,7 @@ class Exchange < ActiveRecord::Base exchange.order_cycle = new_order_cycle exchange.enterprise_fee_ids = self.enterprise_fee_ids exchange.variant_ids = self.variant_ids + exchange.tag_ids = self.tag_ids exchange.save! exchange end diff --git a/app/serializers/api/admin/exchange_serializer.rb b/app/serializers/api/admin/exchange_serializer.rb index 615d49f695..e1c15c5210 100644 --- a/app/serializers/api/admin/exchange_serializer.rb +++ b/app/serializers/api/admin/exchange_serializer.rb @@ -1,5 +1,6 @@ class Api::Admin::ExchangeSerializer < ActiveModel::Serializer attributes :id, :sender_id, :receiver_id, :incoming, :variants, :receival_instructions, :pickup_time, :pickup_instructions + attributes :tags, :tag_list has_many :enterprise_fees, serializer: Api::Admin::BasicEnterpriseFeeSerializer @@ -35,4 +36,12 @@ class Api::Admin::ExchangeSerializer < ActiveModel::Serializer OpenFoodNetwork::OrderCyclePermissions.new(options[:current_user], object.order_cycle) .visible_variants_for_outgoing_exchanges_to(object.receiver) end + + def tag_list + object.tag_list.join(",") + end + + def tags + object.tag_list.map{ |t| { text: t } } + end end diff --git a/app/views/admin/order_cycles/_exchange_distributed_products_form.html.haml b/app/views/admin/order_cycles/_exchange_distributed_products_form.html.haml deleted file mode 100644 index e2218599ce..0000000000 --- a/app/views/admin/order_cycles/_exchange_distributed_products_form.html.haml +++ /dev/null @@ -1,23 +0,0 @@ -%td{:colspan => 4} - .exchange-select-all-variants - %label - = check_box_tag 'order_cycle_outgoing_exchange_{{ $parent.$index }}_select_all_variants', 1, 1, 'ng-model' => 'exchange.select_all_variants', 'ng-change' => 'setExchangeVariants(exchange, incomingExchangeVariantsFor(exchange.enterprise_id), exchange.select_all_variants)', 'id' => 'order_cycle_outgoing_exchange_{{ $parent.$index }}_select_all_variants' - Select all - - .exchange-products - -# Scope product list based on permissions the current user has to view variants in this exchange - .exchange-product{'ng-repeat' => 'product in supplied_products | filter:productSuppliedToOrderCycle | visibleProducts:exchange:order_cycle.visible_variants_for_outgoing_exchanges | orderBy:"name"' } - .exchange-product-details - %label - -# MASTER_VARIANTS: No longer required - -# = check_box_tag 'order_cycle_outgoing_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}', 1, 1, 'ng-hide' => 'product.variants.length > 0', 'ng-model' => 'exchange.variants[product.master_id]', 'id' => 'order_cycle_outgoing_exchange_{{ $parent.$index }}_variants_{{ product.master_id }}', - -# 'ng-disabled' => 'product.variants.length > 0 || !order_cycle.editable_variants_for_outgoing_exchanges.hasOwnProperty(exchange.enterprise_id) || order_cycle.editable_variants_for_outgoing_exchanges[exchange.enterprise_id].indexOf(product.master_id) < 0' - %img{'ng-src' => '{{ product.image_url }}'} - .name {{ product.name }} - .supplier {{ product.supplier_name }} - - .exchange-product-variant{'ng-repeat' => 'variant in product.variants | visibleVariants:exchange:order_cycle.visible_variants_for_outgoing_exchanges | filter:variantSuppliedToOrderCycle'} - %label - = check_box_tag 'order_cycle_outgoing_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}', 1, 1, 'ng-model' => 'exchange.variants[variant.id]', 'id' => 'order_cycle_outgoing_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}', - 'ng-disabled' => '!order_cycle.editable_variants_for_outgoing_exchanges.hasOwnProperty(exchange.enterprise_id) || order_cycle.editable_variants_for_outgoing_exchanges[exchange.enterprise_id].indexOf(variant.id) < 0' - {{ variant.label }} diff --git a/app/views/admin/order_cycles/_exchange_form.html.haml b/app/views/admin/order_cycles/_exchange_form.html.haml index ed3e43fd6b..0e3dbb4340 100644 --- a/app/views/admin/order_cycles/_exchange_form.html.haml +++ b/app/views/admin/order_cycles/_exchange_form.html.haml @@ -1,29 +1,42 @@ -%td{:class => "#{type}_name"} {{ enterprises[exchange.enterprise_id].name }} -%td.products - = f.submit 'Products', 'ng-click' => 'toggleProducts($event, exchange)' - {{ exchangeSelectedVariants(exchange) }} / +%tr{ ng: { class: "'#{type} #{type}-{{ exchange.enterprise_id }}'" } } + %td{:class => "#{type}_name"} {{ enterprises[exchange.enterprise_id].name }} + %td.products.panel-toggle.text-center{ name: "products" } + {{ exchangeSelectedVariants(exchange) }} / + - if type == 'supplier' + {{ enterpriseTotalVariants(enterprises[exchange.enterprise_id]) }} + - else + {{ (incomingExchangeVariantsFor(exchange.enterprise_id)).length }} + selected - if type == 'supplier' - {{ enterpriseTotalVariants(enterprises[exchange.enterprise_id]) }} - - else - {{ (incomingExchangeVariantsFor(exchange.enterprise_id)).length }} - selected + %td.receival-details + = text_field_tag 'order_cycle_incoming_exchange_{{ $index }}_receival_instructions', '', 'id' => 'order_cycle_incoming_exchange_{{ $index }}_receival_instructions', 'placeholder' => 'Receival instructions', 'ng-model' => 'exchange.receival_instructions' + - if type == 'distributor' + %td.tags.panel-toggle.text-center{ name: "tags", ng: { if: 'enterprises[exchange.enterprise_id].managed || order_cycle.viewing_as_coordinator' } } + {{ exchange.tags.length }} + %td.collection-details + = text_field_tag 'order_cycle_outgoing_exchange_{{ $index }}_pickup_time', '', 'id' => 'order_cycle_outgoing_exchange_{{ $index }}_pickup_time', 'placeholder' => 'Ready for (ie. Date / Time)', 'ng-model' => 'exchange.pickup_time', 'ng-disabled' => '!enterprises[exchange.enterprise_id].managed && !order_cycle.viewing_as_coordinator' + %br/ + = text_field_tag 'order_cycle_outgoing_exchange_{{ $index }}_pickup_instructions', '', 'id' => 'order_cycle_outgoing_exchange_{{ $index }}_pickup_instructions', 'placeholder' => 'Pick-up instructions', 'ng-model' => 'exchange.pickup_instructions', 'ng-disabled' => '!enterprises[exchange.enterprise_id].managed && !order_cycle.viewing_as_coordinator' + %td.fees + %ol{ ng: { show: 'enterprises[exchange.enterprise_id].managed || order_cycle.viewing_as_coordinator' } } + %li{'ng-repeat' => 'enterprise_fee in exchange.enterprise_fees'} + = select_tag 'order_cycle_{{ exchangeDirection(exchange) }}_exchange_{{ $parent.$index }}_enterprise_fees_{{ $index }}_enterprise_id', nil, {'id' => 'order_cycle_{{ exchangeDirection(exchange) }}_exchange_{{ $parent.$index }}_enterprise_fees_{{ $index }}_enterprise_id', 'ng-model' => 'enterprise_fee.enterprise_id', 'ng-options' => 'enterprise.id as enterprise.name for enterprise in enterprisesWithFees()'} + + = select_tag 'order_cycle_{{ exchangeDirection(exchange) }}_exchange_{{ $parent.$index }}_enterprise_fees_{{ $index }}_enterprise_fee_id', nil, {'id' => 'order_cycle_{{ exchangeDirection(exchange) }}_exchange_{{ $parent.$index }}_enterprise_fees_{{ $index }}_enterprise_fee_id', 'ng-model' => 'enterprise_fee.id', 'ng-options' => 'enterprise_fee.id as enterprise_fee.name for enterprise_fee in enterpriseFeesForEnterprise(enterprise_fee.enterprise_id)'} + + = link_to 'Remove', '#', {'id' => 'order_cycle_{{ exchangeDirection(exchange) }}_exchange_{{ $parent.$index }}_enterprise_fees_{{ $index }}_remove', 'ng-click' => 'removeExchangeFee($event, exchange, $index)'} + + = f.submit 'Add fee', 'ng-click' => 'addExchangeFee($event, exchange)', 'ng-hide' => '!enterprises[exchange.enterprise_id].managed && !order_cycle.viewing_as_coordinator' + %td.actions + %a{'ng-click' => 'removeExchange($event, exchange)', :class => "icon-trash no-text remove-exchange"} + - if type == 'supplier' - %td.receival-details - = text_field_tag 'order_cycle_incoming_exchange_{{ $index }}_receival_instructions', '', 'id' => 'order_cycle_incoming_exchange_{{ $index }}_receival_instructions', 'placeholder' => 'Receival instructions', 'ng-model' => 'exchange.receival_instructions' + %tr.panel-row{ object: "exchange", + panels: "{products: 'exchange_supplied_products'}", + locals: "$index,order_cycle,exchange,enterprises,setExchangeVariants,suppliedVariants,removeDistributionOfVariant", + colspan: 4 } - if type == 'distributor' - %td.collection-details - = text_field_tag 'order_cycle_outgoing_exchange_{{ $index }}_pickup_time', '', 'id' => 'order_cycle_outgoing_exchange_{{ $index }}_pickup_time', 'placeholder' => 'Ready for (ie. Date / Time)', 'ng-model' => 'exchange.pickup_time', 'ng-disabled' => '!enterprises[exchange.enterprise_id].managed && !order_cycle.viewing_as_coordinator' - %br/ - = text_field_tag 'order_cycle_outgoing_exchange_{{ $index }}_pickup_instructions', '', 'id' => 'order_cycle_outgoing_exchange_{{ $index }}_pickup_instructions', 'placeholder' => 'Pick-up instructions', 'ng-model' => 'exchange.pickup_instructions', 'ng-disabled' => '!enterprises[exchange.enterprise_id].managed && !order_cycle.viewing_as_coordinator' -%td.fees - %ol{ ng: { show: 'enterprises[exchange.enterprise_id].managed || order_cycle.viewing_as_coordinator' } } - %li{'ng-repeat' => 'enterprise_fee in exchange.enterprise_fees'} - = select_tag 'order_cycle_{{ exchangeDirection(exchange) }}_exchange_{{ $parent.$index }}_enterprise_fees_{{ $index }}_enterprise_id', nil, {'id' => 'order_cycle_{{ exchangeDirection(exchange) }}_exchange_{{ $parent.$index }}_enterprise_fees_{{ $index }}_enterprise_id', 'ng-model' => 'enterprise_fee.enterprise_id', 'ng-options' => 'enterprise.id as enterprise.name for enterprise in enterprisesWithFees()'} - - = select_tag 'order_cycle_{{ exchangeDirection(exchange) }}_exchange_{{ $parent.$index }}_enterprise_fees_{{ $index }}_enterprise_fee_id', nil, {'id' => 'order_cycle_{{ exchangeDirection(exchange) }}_exchange_{{ $parent.$index }}_enterprise_fees_{{ $index }}_enterprise_fee_id', 'ng-model' => 'enterprise_fee.id', 'ng-options' => 'enterprise_fee.id as enterprise_fee.name for enterprise_fee in enterpriseFeesForEnterprise(enterprise_fee.enterprise_id)'} - - = link_to 'Remove', '#', {'id' => 'order_cycle_{{ exchangeDirection(exchange) }}_exchange_{{ $parent.$index }}_enterprise_fees_{{ $index }}_remove', 'ng-click' => 'removeExchangeFee($event, exchange, $index)'} - - = f.submit 'Add fee', 'ng-click' => 'addExchangeFee($event, exchange)', 'ng-hide' => '!enterprises[exchange.enterprise_id].managed && !order_cycle.viewing_as_coordinator' -%td.actions - %a{'ng-click' => 'removeExchange($event, exchange)', :class => "icon-trash no-text remove-exchange"} + %tr.panel-row{ object: "exchange", + panels: "{products: 'exchange_distributed_products', tags: 'exchange_tags'}", + locals: "$index,order_cycle,exchange,supplied_products,setExchangeVariants,incomingExchangeVariantsFor,productSuppliedToOrderCycle,variantSuppliedToOrderCycle", + colspan: 5 } diff --git a/app/views/admin/order_cycles/_form.html.haml b/app/views/admin/order_cycles/_form.html.haml index e53fd515b0..a0f0a178c8 100644 --- a/app/views/admin/order_cycles/_form.html.haml +++ b/app/views/admin/order_cycles/_form.html.haml @@ -17,11 +17,8 @@ %th Receival details %th Fees %th.actions - %tbody{'ng-repeat' => 'exchange in order_cycle.incoming_exchanges'} - %tr{'class' => "supplier supplier-{{ exchange.enterprise_id }}"} - = render 'exchange_form', :f => f, :type => 'supplier' - %tr.products{'ng-show' => 'exchange.showProducts'} - = render 'exchange_supplied_products_form' + %tbody.panel-ctrl{ object: 'exchange', 'ng-repeat' => 'exchange in order_cycle.incoming_exchanges'} + = render 'exchange_form', :f => f, :type => 'supplier' - if Enterprise.managed_by(spree_current_user).include? @order_cycle.coordinator = render 'add_exchange_form', f: f, type: 'supplier' @@ -37,14 +34,13 @@ %a{href: '#', 'ng-click' => "OrderCycle.toggleAllProducts('outgoing')"} %span{'ng-show' => "OrderCycle.showProducts['outgoing']"} Collapse all %span{'ng-hide' => "OrderCycle.showProducts['outgoing']"} Expand all + %th{ ng: { if: 'enterprises[exchange.enterprise_id].managed || order_cycle.viewing_as_coordinator' } } Tags %th Pickup / Delivery details %th Fees %th.actions - %tbody{'ng-repeat' => 'exchange in order_cycle.outgoing_exchanges'} - %tr{'class' => "distributor distributor-{{ exchange.enterprise_id }}"} - = render 'exchange_form', :f => f, :type => 'distributor' - %tr.products{'ng-show' => 'exchange.showProducts'} - = render 'exchange_distributed_products_form' + %tbody.panel-ctrl{ object: 'exchange', 'ng-repeat' => 'exchange in order_cycle.outgoing_exchanges'} + = render 'exchange_form', :f => f, :type => 'distributor' + - if Enterprise.managed_by(spree_current_user).include? @order_cycle.coordinator = render 'add_exchange_form', f: f, type: 'distributor' diff --git a/app/views/admin/order_cycles/_simple_form.html.haml b/app/views/admin/order_cycles/_simple_form.html.haml index ba28526f7b..6bb0034c73 100644 --- a/app/views/admin/order_cycles/_simple_form.html.haml +++ b/app/views/admin/order_cycles/_simple_form.html.haml @@ -14,7 +14,7 @@ %table.exchanges %tbody{ng: {repeat: "exchange in order_cycle.incoming_exchanges"}} %tr.products - = render 'exchange_supplied_products_form' + %td{ ng: { include: "'admin/panels/exchange_supplied_products.html'" } } %br/ = label_tag 'Fees' diff --git a/lib/open_food_network/order_cycle_form_applicator.rb b/lib/open_food_network/order_cycle_form_applicator.rb index 6d2e3e3e53..2cccc4a4fa 100644 --- a/lib/open_food_network/order_cycle_form_applicator.rb +++ b/lib/open_food_network/order_cycle_form_applicator.rb @@ -42,13 +42,15 @@ module OpenFoodNetwork {variant_ids: variant_ids, enterprise_fee_ids: enterprise_fee_ids, pickup_time: exchange[:pickup_time], - pickup_instructions: exchange[:pickup_instructions]}) + pickup_instructions: exchange[:pickup_instructions], + tag_list: exchange[:tag_list]}) else add_exchange(@order_cycle.coordinator_id, exchange[:enterprise_id], false, {variant_ids: variant_ids, enterprise_fee_ids: enterprise_fee_ids, pickup_time: exchange[:pickup_time], - pickup_instructions: exchange[:pickup_instructions]}) + pickup_instructions: exchange[:pickup_instructions], + tag_list: exchange[:tag_list]}) end end @@ -81,6 +83,7 @@ module OpenFoodNetwork attrs.delete :enterprise_fee_ids attrs.delete :pickup_time attrs.delete :pickup_instructions + attrs.delete :tag_list end if permission_for exchange diff --git a/spec/features/admin/order_cycles_spec.rb b/spec/features/admin/order_cycles_spec.rb index 874c8342b5..e17ace2580 100644 --- a/spec/features/admin/order_cycles_spec.rb +++ b/spec/features/admin/order_cycles_spec.rb @@ -103,7 +103,7 @@ feature %q{ select 'My supplier', from: 'new_supplier_id' click_button 'Add supplier' fill_in 'order_cycle_incoming_exchange_0_receival_instructions', with: 'receival instructions' - page.find('table.exchanges tr.supplier td.products input').click + page.find('table.exchanges tr.supplier td.products').click check "order_cycle_incoming_exchange_0_variants_#{v1.id}" check "order_cycle_incoming_exchange_0_variants_#{v2.id}" @@ -124,10 +124,15 @@ feature %q{ fill_in 'order_cycle_outgoing_exchange_0_pickup_time', with: 'pickup time' fill_in 'order_cycle_outgoing_exchange_0_pickup_instructions', with: 'pickup instructions' - page.find('table.exchanges tr.distributor td.products input').click + page.find('table.exchanges tr.distributor td.products').click check "order_cycle_outgoing_exchange_0_variants_#{v1.id}" check "order_cycle_outgoing_exchange_0_variants_#{v2.id}" + page.find('table.exchanges tr.distributor td.tags').click + within ".exchange-tags" do + find(:css, "tags-input .tags input").set "wholesale\n" + end + # And I add a distributor fee within("tr.distributor-#{distributor.id}") { click_button 'Add fee' } select 'My distributor', from: 'order_cycle_outgoing_exchange_0_enterprise_fees_0_enterprise_id' @@ -165,6 +170,7 @@ feature %q{ exchange = oc.exchanges.outgoing.first exchange.pickup_time.should == 'pickup time' exchange.pickup_instructions.should == 'pickup instructions' + exchange.tag_list.should == ['wholesale'] end @@ -196,13 +202,13 @@ feature %q{ page.should have_field 'order_cycle_incoming_exchange_1_receival_instructions', with: 'instructions 1' # And the suppliers should have products - page.all('table.exchanges tbody tr.supplier').each do |row| - row.find('td.products input').click + page.all('table.exchanges tbody tr.supplier').each_with_index do |row, i| + row.find('td.products').click - products_row = page.all('table.exchanges tr.products').select { |r| r.visible? }.first - products_row.should have_selector "input[type='checkbox'][checked='checked']" + products_panel = page.all('table.exchanges tr.panel-row .exchange-supplied-products').select { |r| r.visible? }.first + products_panel.should have_selector "input[name='order_cycle_incoming_exchange_#{i}_select_all_variants']" - row.find('td.products input').click + row.find('td.products').click end # And the suppliers should have fees @@ -227,13 +233,13 @@ feature %q{ page.driver.resize(1280, 3600) # And the distributors should have products - page.all('table.exchanges tbody tr.distributor').each do |row| - row.find('td.products input').click + page.all('table.exchanges tbody tr.distributor').each_with_index do |row, i| + row.find('td.products').click - products_row = page.all('table.exchanges tr.products').select { |r| r.visible? }.first - products_row.should have_selector "input[type='checkbox'][checked='checked']" + products_panel = page.all('table.exchanges tr.panel-row .exchange-distributed-products').select { |r| r.visible? }.first + products_panel.should have_selector "input[name='order_cycle_outgoing_exchange_#{i}_select_all_variants']" - row.find('td.products input').click + row.find('td.products').click end # And the distributors should have fees @@ -323,7 +329,7 @@ feature %q{ # And I add a supplier and some products select 'My supplier', from: 'new_supplier_id' click_button 'Add supplier' - page.all("table.exchanges tr.supplier td.products input").each { |e| e.click } + page.all("table.exchanges tr.supplier td.products").each { |e| e.click } page.should have_selector "#order_cycle_incoming_exchange_1_variants_#{initial_variants.last.id}", visible: true page.find("#order_cycle_incoming_exchange_1_variants_#{initial_variants.last.id}", visible: true).click # uncheck (with visible:true filter) @@ -349,7 +355,12 @@ feature %q{ fill_in 'order_cycle_outgoing_exchange_1_pickup_time', with: 'New time 1' fill_in 'order_cycle_outgoing_exchange_1_pickup_instructions', with: 'New instructions 1' - page.all("table.exchanges tr.distributor td.products input").each { |e| e.click } + page.find("table.exchanges tr.distributor-#{distributor.id} td.tags").click + within ".exchange-tags" do + find(:css, "tags-input .tags input").set "wholesale\n" + end + + page.all("table.exchanges tr.distributor td.products").each { |e| e.click } uncheck "order_cycle_outgoing_exchange_2_variants_#{v1.id}" check "order_cycle_outgoing_exchange_2_variants_#{v2.id}" @@ -389,6 +400,9 @@ feature %q{ # And my distributor fees should have been configured OrderCycle.last.exchanges.outgoing.last.enterprise_fee_ids.should == [distributor_fee2.id] + # And my tags should have been save + OrderCycle.last.exchanges.outgoing.last.tag_list.should == ['wholesale'] + # And it should have some variants selected selected_initial_variants = initial_variants.take initial_variants.size - 1 OrderCycle.last.variants.map(&:id).should match_array (selected_initial_variants.map(&:id) + [v1.id, v2.id]) @@ -465,7 +479,7 @@ feature %q{ login_to_admin_section click_link 'Order Cycles' click_link oc.name - within("table.exchanges tbody tr.supplier") { page.find('td.products input').click } + within("table.exchanges tbody tr.supplier") { page.find('td.products').click } page.find("#order_cycle_incoming_exchange_0_variants_#{p.master.id}", visible: true).trigger('click') # uncheck click_button "Update" @@ -591,6 +605,11 @@ feature %q{ page.should_not have_select 'order_cycle_coordinator_id', with_options: [enterprise_name] end + page.find("table.exchanges tr.distributor-#{distributor_managed.id} td.tags").click + within ".exchange-tags" do + find(:css, "tags-input .tags input").set "wholesale\n" + end + click_button 'Create' flash_message.should == "Your order cycle has been created." @@ -598,6 +617,8 @@ feature %q{ order_cycle.suppliers.should match_array [supplier_managed, supplier_permitted] order_cycle.coordinator.should == distributor_managed order_cycle.distributors.should match_array [distributor_managed, distributor_permitted] + exchange = order_cycle.exchanges.outgoing.to_enterprise(distributor_managed).first + exchange.tag_list.should == ["wholesale"] end scenario "editing an order cycle we can see (and for now, edit) all exchanges in the order cycle" do @@ -614,12 +635,17 @@ feature %q{ expect(page).to have_selector "tr.supplier-#{supplier_managed.id}" expect(page).to have_selector "tr.supplier-#{supplier_permitted.id}" expect(page).to have_selector "tr.supplier-#{supplier_unmanaged.id}" - expect(page.all('tr.supplier').count).to be 3 + expect(page).to have_selector 'tr.supplier', count: 3 expect(page).to have_selector "tr.distributor-#{distributor_managed.id}" expect(page).to have_selector "tr.distributor-#{distributor_permitted.id}" expect(page).to have_selector "tr.distributor-#{distributor_unmanaged.id}" - expect(page.all('tr.distributor').count).to be 3 + expect(page).to have_selector 'tr.distributor', count: 3 + + + # When I save, then those exchanges should remain + click_button 'Update' + page.should have_content "Your order cycle has been updated." oc.reload oc.suppliers.should match_array [supplier_managed, supplier_permitted, supplier_unmanaged] @@ -640,7 +666,6 @@ feature %q{ page.find("tr.supplier-#{supplier_permitted.id} a.remove-exchange").click page.find("tr.distributor-#{distributor_managed.id} a.remove-exchange").click page.find("tr.distributor-#{distributor_permitted.id} a.remove-exchange").click - click_button 'Update' # Then the exchanges should be removed @@ -707,7 +732,7 @@ feature %q{ # Open the products list for managed_supplier's incoming exchange within "tr.distributor-#{distributor_managed.id}" do - page.find("td.products input").click + page.find("td.products").click end # I should be able to see and toggle v1 @@ -716,6 +741,12 @@ feature %q{ # I should be able to see but not toggle v2, because I don't have permission expect(page).to have_field "order_cycle_outgoing_exchange_0_variants_#{v2.id}", disabled: true + page.should_not have_selector "table.exchanges tr.distributor-#{distributor_managed.id} td.tags" + + # When I save, any exchanges that I can't manage remain + click_button 'Update' + page.should have_content "Your order cycle has been updated." + oc.reload oc.suppliers.should match_array [supplier_managed, supplier_permitted, supplier_unmanaged] oc.coordinator.should == distributor_managed @@ -759,7 +790,7 @@ feature %q{ # Open the products list for managed_supplier's incoming exchange within "tr.supplier-#{supplier_managed.id}" do - page.find("td.products input").click + page.find("td.products").click end # I should be able to see and toggle v1 @@ -768,6 +799,12 @@ feature %q{ # I should be able to see but not toggle v2, because I don't have permission expect(page).to have_field "order_cycle_incoming_exchange_0_variants_#{v2.id}", disabled: true + page.should have_selector "table.exchanges tr.distributor-#{my_distributor.id} td.tags" + + # When I save, any exchange that I can't manage remains + click_button 'Update' + page.should have_content "Your order cycle has been updated." + oc.reload oc.suppliers.should match_array [supplier_managed, supplier_permitted, supplier_unmanaged] oc.coordinator.should == distributor_managed @@ -956,7 +993,7 @@ feature %q{ private def select_incoming_variant(supplier, exchange_no, variant) - page.find("table.exchanges tr.supplier-#{supplier.id} td.products input").click + page.find("table.exchanges tr.supplier-#{supplier.id} td.products").click check "order_cycle_incoming_exchange_#{exchange_no}_variants_#{variant.id}" end end diff --git a/spec/javascripts/unit/order_cycle_spec.js.coffee b/spec/javascripts/unit/order_cycle_spec.js.coffee index bbbff7d82b..df227c7960 100644 --- a/spec/javascripts/unit/order_cycle_spec.js.coffee +++ b/spec/javascripts/unit/order_cycle_spec.js.coffee @@ -106,11 +106,6 @@ describe 'OrderCycle controllers', -> {id: 2, name: 'Pepper Tree Place'} ]) - it 'Delegates toggleProducts to OrderCycle', -> - scope.toggleProducts(event, 'exchange') - expect(event.preventDefault).toHaveBeenCalled() - expect(OrderCycle.toggleProducts).toHaveBeenCalledWith('exchange') - it 'Delegates enterpriseFeesForEnterprise to EnterpriseFee', -> scope.enterpriseFeesForEnterprise('123') expect(EnterpriseFee.forEnterprise).toHaveBeenCalledWith(123) @@ -272,11 +267,6 @@ describe 'OrderCycle controllers', -> {id: 2, name: 'Pepper Tree Place'} ]) - it 'Delegates toggleProducts to OrderCycle', -> - scope.toggleProducts(event, 'exchange') - expect(event.preventDefault).toHaveBeenCalled() - expect(OrderCycle.toggleProducts).toHaveBeenCalledWith('exchange') - it 'Delegates enterpriseFeesForEnterprise to EnterpriseFee', -> scope.enterpriseFeesForEnterprise('123') expect(EnterpriseFee.forEnterprise).toHaveBeenCalledWith(123) @@ -534,26 +524,6 @@ describe 'OrderCycle services', -> OrderCycle.order_cycle.outgoing_exchanges = [exchange] expect(OrderCycle.exchangeDirection(exchange)).toEqual 'outgoing' - describe 'toggling products', -> - exchange = null - - beforeEach -> - exchange = {} - - it 'sets a blank value to true', -> - OrderCycle.toggleProducts(exchange) - expect(exchange.showProducts).toEqual(true) - - it 'sets a true value to false', -> - exchange.showProducts = true - OrderCycle.toggleProducts(exchange) - expect(exchange.showProducts).toEqual(false) - - it 'sets a false value to true', -> - exchange.showProducts = false - OrderCycle.toggleProducts(exchange) - expect(exchange.showProducts).toEqual(true) - describe "setting exchange variants", -> describe "when I have permissions to edit the variants", -> beforeEach -> @@ -598,7 +568,7 @@ describe 'OrderCycle services', -> it 'adds the distributor to outgoing exchanges', -> OrderCycle.addDistributor('123') expect(OrderCycle.order_cycle.outgoing_exchanges).toEqual [ - {enterprise_id: '123', incoming: false, active: true, variants: {}, enterprise_fees: []} + {enterprise_id: '123', incoming: false, active: true, variants: {}, enterprise_fees: [], tags: [], tag_list: ""} ] describe 'removing exchanges', -> diff --git a/spec/lib/open_food_network/order_cycle_form_applicator_spec.rb b/spec/lib/open_food_network/order_cycle_form_applicator_spec.rb index 89dcb364b8..fe3155c5e5 100644 --- a/spec/lib/open_food_network/order_cycle_form_applicator_spec.rb +++ b/spec/lib/open_food_network/order_cycle_form_applicator_spec.rb @@ -29,7 +29,7 @@ module OpenFoodNetwork coordinator_id = 123 distributor_id = 456 - outgoing_exchange = {:enterprise_id => distributor_id, :incoming => false, :variants => {'1' => true, '2' => false, '3' => true}, :enterprise_fee_ids => [1, 2], :pickup_time => 'pickup time', :pickup_instructions => 'pickup instructions'} + outgoing_exchange = {:enterprise_id => distributor_id, :incoming => false, :variants => {'1' => true, '2' => false, '3' => true}, :enterprise_fee_ids => [1, 2], :pickup_time => 'pickup time', :pickup_instructions => 'pickup instructions', tag_list: 'wholesale'} oc = double(:order_cycle, :coordinator_id => coordinator_id, :exchanges => [], :incoming_exchanges => [], :outgoing_exchanges => [outgoing_exchange]) @@ -37,7 +37,7 @@ module OpenFoodNetwork applicator.should_receive(:outgoing_exchange_variant_ids).with(outgoing_exchange).and_return([1, 3]) applicator.should_receive(:exchange_exists?).with(coordinator_id, distributor_id, false).and_return(false) - applicator.should_receive(:add_exchange).with(coordinator_id, distributor_id, false, {:variant_ids => [1, 3], :enterprise_fee_ids => [1, 2], :pickup_time => 'pickup time', :pickup_instructions => 'pickup instructions'}) + applicator.should_receive(:add_exchange).with(coordinator_id, distributor_id, false, {:variant_ids => [1, 3], :enterprise_fee_ids => [1, 2], :pickup_time => 'pickup time', :pickup_instructions => 'pickup instructions', tag_list: 'wholesale'}) applicator.should_receive(:destroy_untouched_exchanges) applicator.go! @@ -69,7 +69,7 @@ module OpenFoodNetwork coordinator_id = 123 distributor_id = 456 - outgoing_exchange = {:enterprise_id => distributor_id, :incoming => false, :variants => {'1' => true, '2' => false, '3' => true}, :enterprise_fee_ids => [1, 2], :pickup_time => 'pickup time', :pickup_instructions => 'pickup instructions'} + outgoing_exchange = {:enterprise_id => distributor_id, :incoming => false, :variants => {'1' => true, '2' => false, '3' => true}, :enterprise_fee_ids => [1, 2], :pickup_time => 'pickup time', :pickup_instructions => 'pickup instructions', tag_list: 'wholesale'} oc = double(:order_cycle, :coordinator_id => coordinator_id, @@ -81,7 +81,7 @@ module OpenFoodNetwork applicator.should_receive(:outgoing_exchange_variant_ids).with(outgoing_exchange).and_return([1, 3]) applicator.should_receive(:exchange_exists?).with(coordinator_id, distributor_id, false).and_return(true) - applicator.should_receive(:update_exchange).with(coordinator_id, distributor_id, false, {:variant_ids => [1, 3], :enterprise_fee_ids => [1, 2], :pickup_time => 'pickup time', :pickup_instructions => 'pickup instructions'}) + applicator.should_receive(:update_exchange).with(coordinator_id, distributor_id, false, {:variant_ids => [1, 3], :enterprise_fee_ids => [1, 2], :pickup_time => 'pickup time', :pickup_instructions => 'pickup instructions', tag_list: 'wholesale'}) applicator.should_receive(:destroy_untouched_exchanges) applicator.go! @@ -375,15 +375,16 @@ module OpenFoodNetwork allow(applicator).to receive(:manager_for) { false } allow(applicator).to receive(:permission_for) { true } applicator.send(:touched_exchanges=, []) - applicator.send(:update_exchange, sender.id, receiver.id, incoming, {:variant_ids => [variant1.id, variant3.id], :enterprise_fee_ids => [enterprise_fee2.id, enterprise_fee3.id], :pickup_time => 'New Pickup Time', :pickup_instructions => 'New Pickup Instructions'}) + applicator.send(:update_exchange, sender.id, receiver.id, incoming, {:variant_ids => [variant1.id, variant3.id], :enterprise_fee_ids => [enterprise_fee2.id, enterprise_fee3.id], :pickup_time => 'New Pickup Time', :pickup_instructions => 'New Pickup Instructions', tag_list: 'wholesale'}) end - it "updates the variants, enterprise fees and pickup information of the exchange" do + it "updates the variants, enterprise fees tags, and pickup information of the exchange" do exchange.reload expect(exchange.variants).to match_array [variant1, variant3] expect(exchange.enterprise_fees).to match_array [enterprise_fee2, enterprise_fee3] expect(exchange.pickup_time).to eq 'New Pickup Time' expect(exchange.pickup_instructions).to eq 'New Pickup Instructions' + expect(exchange.tag_list).to eq ['wholesale'] expect(applicator.send(:touched_exchanges)).to eq [exchange] end end @@ -394,15 +395,16 @@ module OpenFoodNetwork allow(applicator).to receive(:manager_for) { true } allow(applicator).to receive(:permission_for) { true } applicator.send(:touched_exchanges=, []) - applicator.send(:update_exchange, sender.id, receiver.id, incoming, {:variant_ids => [variant1.id, variant3.id], :enterprise_fee_ids => [enterprise_fee2.id, enterprise_fee3.id], :pickup_time => 'New Pickup Time', :pickup_instructions => 'New Pickup Instructions'}) + applicator.send(:update_exchange, sender.id, receiver.id, incoming, {:variant_ids => [variant1.id, variant3.id], :enterprise_fee_ids => [enterprise_fee2.id, enterprise_fee3.id], :pickup_time => 'New Pickup Time', :pickup_instructions => 'New Pickup Instructions', tag_list: 'wholesale'}) end - it "updates the variants, enterprise fees and pickup information of the exchange" do + it "updates the variants, enterprise fees, tags and pickup information of the exchange" do exchange.reload expect(exchange.variants).to match_array [variant1, variant3] expect(exchange.enterprise_fees).to match_array [enterprise_fee2, enterprise_fee3] expect(exchange.pickup_time).to eq 'New Pickup Time' expect(exchange.pickup_instructions).to eq 'New Pickup Instructions' + expect(exchange.tag_list).to eq ['wholesale'] expect(applicator.send(:touched_exchanges)).to eq [exchange] end end @@ -413,15 +415,16 @@ module OpenFoodNetwork allow(applicator).to receive(:manager_for) { false } allow(applicator).to receive(:permission_for) { true } applicator.send(:touched_exchanges=, []) - applicator.send(:update_exchange, sender.id, receiver.id, incoming, {:variant_ids => [variant1.id, variant3.id], :enterprise_fee_ids => [enterprise_fee2.id, enterprise_fee3.id], :pickup_time => 'New Pickup Time', :pickup_instructions => 'New Pickup Instructions'}) + applicator.send(:update_exchange, sender.id, receiver.id, incoming, {:variant_ids => [variant1.id, variant3.id], :enterprise_fee_ids => [enterprise_fee2.id, enterprise_fee3.id], :pickup_time => 'New Pickup Time', :pickup_instructions => 'New Pickup Instructions', tag_list: 'wholesale'}) end - it "updates the variants in the exchange, but not the fees or pickup information" do + it "updates the variants in the exchange, but not the fees, tags or pickup information" do exchange.reload expect(exchange.variants).to match_array [variant1, variant3] expect(exchange.enterprise_fees).to match_array [enterprise_fee1, enterprise_fee2] expect(exchange.pickup_time).to_not eq 'New Pickup Time' expect(exchange.pickup_instructions).to_not eq 'New Pickup Instructions' + expect(exchange.tag_list).to eq [] expect(applicator.send(:touched_exchanges)).to eq [exchange] end end diff --git a/spec/models/exchange_spec.rb b/spec/models/exchange_spec.rb index 4b8f0ed1a3..1a4a4f7e3f 100644 --- a/spec/models/exchange_spec.rb +++ b/spec/models/exchange_spec.rb @@ -282,9 +282,11 @@ describe Exchange do new_oc = create(:simple_order_cycle) ex1 = oc.exchanges.last + ex1.update_attribute(:tag_list, "wholesale") ex2 = ex1.clone! new_oc ex1.eql?(ex2).should be_true + expect(ex2.reload.tag_list).to eq ["wholesale"] end describe "converting to hash" do