New pattern: blank Options for index drop down filters are added within service

Rather than in the controller after data is loaded
This commit is contained in:
Rob Harrington
2015-11-16 10:30:44 +11:00
parent 76414dedff
commit 767671c3b4
6 changed files with 88 additions and 31 deletions

View File

@@ -18,19 +18,43 @@ describe "Enterprises service", ->
beforeEach ->
response = [{ id: 5, name: 'Enterprise 1'}]
$httpBackend.expectGET('/admin/enterprises.json').respond 200, response
result = Enterprises.index()
$httpBackend.flush()
it "stores returned data in @enterprisesByID, with ids as keys", ->
# EnterpriseResource returns instances of Resource rather than raw objects
expect(Enterprises.enterprisesByID).toDeepEqual { 5: response[0] }
describe "when no params are passed", ->
beforeEach ->
$httpBackend.expectGET('/admin/enterprises.json').respond 200, response
result = Enterprises.index()
$httpBackend.flush()
it "stores returned data in @pristineByID, with ids as keys", ->
expect(Enterprises.pristineByID).toDeepEqual { 5: response[0] }
it "stores returned data in @enterprisesByID, with ids as keys", ->
# EnterpriseResource returns instances of Resource rather than raw objects
expect(Enterprises.enterprisesByID).toDeepEqual { 5: response[0] }
it "returns an array of enterprises", ->
expect(result).toDeepEqual response
it "stores returned data in @pristineByID, with ids as keys", ->
expect(Enterprises.pristineByID).toDeepEqual { 5: response[0] }
it "returns an array of enterprises", ->
expect(result).toDeepEqual response
describe "when params are passed", ->
describe "where includeBlank param is truthy", ->
beforeEach ->
params = {includeBlank: true, someParam: 'someVal'}
$httpBackend.expectGET('/admin/enterprises.json?someParam=someVal').respond 200, response
result = Enterprises.index(params)
$httpBackend.flush()
it "returns an array of enterprises, with a blank option appended to the beginning", ->
expect(result).toDeepEqual [{id: '0', name: 'All'} ,{ id: 5, name: 'Enterprise 1'}]
describe "where includeBlank param is falsey", ->
beforeEach ->
params = {includeBlank: false, someParam: 'someVal'}
$httpBackend.expectGET('/admin/enterprises.json?someParam=someVal').respond 200, response
result = Enterprises.index(params)
$httpBackend.flush()
it "returns an array of enterprises, with a blank option appended to the beginning", ->
expect(result).toDeepEqual response
describe "#save", ->

View File

@@ -18,19 +18,43 @@ describe "OrderCycles service", ->
beforeEach ->
response = [{ id: 5, name: 'OrderCycle 1'}]
$httpBackend.expectGET('/admin/order_cycles.json').respond 200, response
result = OrderCycles.index()
$httpBackend.flush()
it "stores returned data in @orderCyclesByID, with ids as keys", ->
# OrderCycleResource returns instances of Resource rather than raw objects
expect(OrderCycles.orderCyclesByID).toDeepEqual { 5: response[0] }
describe "when no params are passed", ->
beforeEach ->
$httpBackend.expectGET('/admin/order_cycles.json').respond 200, response
result = OrderCycles.index()
$httpBackend.flush()
it "stores returned data in @pristineByID, with ids as keys", ->
expect(OrderCycles.pristineByID).toDeepEqual { 5: response[0] }
it "stores returned data in @orderCyclesByID, with ids as keys", ->
# OrderCycleResource returns instances of Resource rather than raw objects
expect(OrderCycles.orderCyclesByID).toDeepEqual { 5: response[0] }
it "returns an array of orderCycles", ->
expect(result).toDeepEqual response
it "stores returned data in @pristineByID, with ids as keys", ->
expect(OrderCycles.pristineByID).toDeepEqual { 5: response[0] }
it "returns an array of orderCycles", ->
expect(result).toDeepEqual response
describe "when no params are passed", ->
describe "where includeBlank param is truthy", ->
beforeEach ->
params = {includeBlank: true, someParam: 'someVal'}
$httpBackend.expectGET('/admin/order_cycles.json?someParam=someVal').respond 200, response
result = OrderCycles.index(params)
$httpBackend.flush()
it "returns an array of orderCycles", ->
expect(result).toDeepEqual [{id: '0', name: 'All'} ,{ id: 5, name: 'OrderCycle 1'}]
describe "where includeBlank param is falsey", ->
beforeEach ->
params = {includeBlank: false, someParam: 'someVal'}
$httpBackend.expectGET('/admin/order_cycles.json?someParam=someVal').respond 200, response
result = OrderCycles.index(params)
$httpBackend.flush()
it "returns an array of orderCycles", ->
expect(result).toDeepEqual response
describe "#save", ->