WIP: BOM Refactor, adding for_line_items action to enterprises controller

This commit is contained in:
Rob Harrington
2015-11-04 15:02:29 +11:00
parent 625e0888ea
commit ae7e744644
14 changed files with 79 additions and 64 deletions

View File

@@ -4,32 +4,33 @@ describe "Enterprises service", ->
beforeEach ->
module 'admin.enterprises'
this.addMatchers
toDeepEqual: (expected) ->
return angular.equals(this.actual, expected)
inject ($q, _$httpBackend_, _Enterprises_, _EnterpriseResource_) ->
Enterprises = _Enterprises_
EnterpriseResource = _EnterpriseResource_
$httpBackend = _$httpBackend_
describe "#index", ->
result = null
result = response = null
beforeEach ->
$httpBackend.expectGET('/admin/enterprises.json').respond 200, [{ id: 5, name: 'Enterprise 1'}]
expect(Enterprises.loaded).toBe false
response = [{ id: 5, name: 'Enterprise 1'}]
$httpBackend.expectGET('/admin/enterprises.json').respond 200, response
result = Enterprises.index()
$httpBackend.flush()
it "stores returned data in @enterprises, with ids as keys", ->
# This is super weird and freaking annoying. I think resource results have extra
# properties ($then, $promise) that cause them to not be equal to the reponse object
# provided to the expectGET clause above.
expect(Enterprises.enterprises).toEqual [ new EnterpriseResource({ id: 5, name: 'Enterprise 1'}) ]
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 @enterprises", ->
expect(result).toEqual Enterprises.enterprises
it "stores returned data in @pristineByID, with ids as keys", ->
expect(Enterprises.pristineByID).toDeepEqual { 5: response[0] }
it "sets @loaded to true", ->
expect(Enterprises.loaded).toBe true
it "returns an array of enterprises", ->
expect(result).toDeepEqual response
describe "#save", ->
@@ -40,7 +41,7 @@ describe "Enterprises service", ->
resolved = false
beforeEach ->
enterprise = new EnterpriseResource( { id: 15, permalink: 'enterprise1', name: 'Enterprise 1' } )
enterprise = new EnterpriseResource({ id: 15, permalink: 'enterprise1', name: 'Enterprise 1' })
$httpBackend.expectPUT('/admin/enterprises/enterprise1.json').respond 200, { id: 15, name: 'Enterprise 1'}
Enterprises.save(enterprise).then( -> resolved = true)
$httpBackend.flush()
@@ -48,7 +49,7 @@ describe "Enterprises service", ->
it "updates the pristine copy of the enterprise", ->
# Resource results have extra properties ($then, $promise) that cause them to not
# be exactly equal to the response object provided to the expectPUT clause above.
expect(Enterprises.pristine_by_id[15]).toEqual enterprise
expect(Enterprises.pristineByID[15]).toEqual enterprise
it "resolves the promise", ->
expect(resolved).toBe(true);
@@ -65,7 +66,7 @@ describe "Enterprises service", ->
$httpBackend.flush()
it "does not update the pristine copy of the enterprise", ->
expect(Enterprises.pristine_by_id[15]).toBeUndefined()
expect(Enterprises.pristineByID[15]).toBeUndefined()
it "rejects the promise", ->
expect(rejected).toBe(true);
@@ -88,7 +89,7 @@ describe "Enterprises service", ->
describe "diff", ->
beforeEach ->
Enterprises.pristine_by_id = { 23: { id: 23, name: "ent1", is_primary_producer: true } }
Enterprises.pristineByID = { 23: { id: 23, name: "ent1", is_primary_producer: true } }
it "returns a list of properties that have been altered", ->
expect(Enterprises.diff({ id: 23, name: "enterprise123", is_primary_producer: true })).toEqual ["name"]
@@ -98,7 +99,7 @@ describe "Enterprises service", ->
enterprise = { id: 23, name: "ent1", is_primary_producer: true }
beforeEach ->
Enterprises.pristine_by_id = { 23: { id: 23, name: "enterprise1", is_primary_producer: true } }
Enterprises.pristineByID = { 23: { id: 23, name: "enterprise1", is_primary_producer: true } }
it "resets the specified value according to the pristine record", ->
Enterprises.resetAttribute(enterprise, "name")