Do not allow re-adding exchange

This commit is contained in:
Rohan Mitchell
2015-11-20 09:46:30 +11:00
parent d4ee20455e
commit ccb23cd186
4 changed files with 23 additions and 9 deletions

View File

@@ -15,10 +15,12 @@ angular.module('admin.orderCycles').factory('OrderCycle', ($resource, $window, $
parseInt(exchange.enterprise_id) for exchange in @exchangesByDirection(direction)
novelSupplier: (enterprise) =>
@exchangeIds('incoming').indexOf(enterprise.id) == -1
id = enterprise?.id || parseInt(enterprise)
@exchangeIds('incoming').indexOf(id) == -1
novelDistributor: (enterprise) =>
@exchangeIds('outgoing').indexOf(enterprise.id) == -1
id = enterprise?.id || parseInt(enterprise)
@exchangeIds('outgoing').indexOf(id) == -1
exchangeSelectedVariants: (exchange) ->
numActiveVariants = 0

View File

@@ -3,4 +3,4 @@
{{ enterprise.name }}
= "{{ enterprise.issues_summary_#{type} ? '('+enterprise.issues_summary_#{type}+')' : '' }}"
= f.submit "Add #{type}", 'ng-click' => "add#{type.capitalize}($event)", 'ng-disabled' => "!new_#{type}_id"
= f.submit "Add #{type}", 'ng-click' => "add#{type.capitalize}($event)", 'ng-disabled' => "!new_#{type}_id || !OrderCycle.novel#{type.capitalize}(new_#{type}_id)"

View File

@@ -108,6 +108,8 @@ feature %q{
# I should not be able to re-add the supplier
page.should_not have_select 'new_supplier_id', with_options: ['My supplier']
page.should have_button 'Add supplier', disabled: true
page.all("td.supplier_name").map(&:text).should == ['My supplier']
# And I add a supplier fee
within("tr.supplier-#{supplier.id}") { click_button 'Add fee' }

View File

@@ -489,20 +489,30 @@ describe 'OrderCycle services', ->
expect(OrderCycle.exchangeIds('incoming')).toEqual [1, 2]
describe "checking for novel enterprises", ->
it "detects novel suppliers", ->
e1 = {id: 1}
e2 = {id: 2}
e1 = {id: 1}
e2 = {id: 2}
beforeEach ->
OrderCycle.order_cycle.incoming_exchanges = [{enterprise_id: 1}]
OrderCycle.order_cycle.outgoing_exchanges = [{enterprise_id: 1}]
it "detects novel suppliers", ->
expect(OrderCycle.novelSupplier(e1)).toBe false
expect(OrderCycle.novelSupplier(e2)).toBe true
it "detects novel suppliers with enterprise as string id", ->
expect(OrderCycle.novelSupplier('1')).toBe false
expect(OrderCycle.novelSupplier('2')).toBe true
it "detects novel distributors", ->
e1 = {id: 1}
e2 = {id: 2}
OrderCycle.order_cycle.outgoing_exchanges = [{enterprise_id: 1}]
expect(OrderCycle.novelDistributor(e1)).toBe false
expect(OrderCycle.novelDistributor(e2)).toBe true
it "detects novel distributors with enterprise as string id", ->
expect(OrderCycle.novelDistributor('1')).toBe false
expect(OrderCycle.novelDistributor('2')).toBe true
describe 'fetching the direction for an exchange', ->
it 'returns "incoming" for incoming exchanges', ->
exchange = {id: 1}