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

@@ -515,6 +515,21 @@ module Admin
end
end
describe "for_line_items" do
let!(:user) { create(:user) }
let!(:enterprise) { create(:enterprise, sells: 'any', owner: user) }
before do
# As a user with permission
controller.stub spree_current_user: user
end
it "initializes permissions with the existing OrderCycle" do
# expect(controller).to receive(:render_as_json).with([enterprise], {ams_prefix: 'basic', spree_current_user: user})
spree_get :for_line_items, format: :json
end
end
describe "index" do
context "as super admin" do
let(:super_admin) { create(:admin_user) }

View File

@@ -90,7 +90,7 @@ describe Spree::Admin::BaseController do
before do
class Api::Admin::AllowedPrefixAnonymouSerializer;end;
class Api::Admin::AnonymouSerializer;end;
allow(controller).to receive(:ams_prefix_whitelist) { ['allowed_prefix'] }
allow(controller).to receive(:ams_prefix_whitelist) { [:allowed_prefix] }
end
context "when a prefix is passed in" do

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")

View File

@@ -65,7 +65,7 @@ module OpenFoodNetwork
end
end
describe "finding enterprises that can be added to an order cycle" do
describe "finding visible enterprises" do
let(:e) { double(:enterprise) }
it "returns managed and related enterprises with add_to_order_cycle permission" do
@@ -73,7 +73,7 @@ module OpenFoodNetwork
with(:add_to_order_cycle).
and_return([e])
expect(permissions.order_cycle_enterprises).to eq [e]
expect(permissions.visible_enterprises).to eq [e]
end
end