Reworking the RABL templates for simplicity AND fixing up all the tests

This commit is contained in:
Will Marshall
2014-06-18 13:05:44 +10:00
parent b7e19ca290
commit c8384f1a71
15 changed files with 146 additions and 87 deletions

View File

@@ -0,0 +1,5 @@
Darkswarm.factory 'Enterprises', (enterprises)->
new class Enterprises
constructor: ->
@enterprises = enterprises
@dereference()

View File

@@ -1,4 +1,4 @@
Darkswarm.factory 'Hubs', ($location, hubs, $filter, CurrentHub) ->
Darkswarm.factory 'Hubs', (hubs, $filter) ->
new class Hubs
constructor: ->
@hubs = $filter('orderBy')(hubs, ['-active', '+orders_close_at'])

View File

@@ -2,11 +2,4 @@ Darkswarm.factory 'Producers', (producers) ->
new class Producers
constructor: ->
@producers = producers
# TODO: start adding functionality to producers like so
#@producers = (@extend(producer) for producer in producers)
#extend: (producer)->
#new class Producer
#constructor: ->
#@[k] = v for k, v of Producer

View File

@@ -1,18 +1,5 @@
# DON'T USE DIRECTLY - for inheritance
collection Enterprise.visible
attributes :name, :id, :description
node :email do |enterprise|
enterprise.email.to_s.reverse
end
child :address do
extends "json/partials/address"
end
node :path do |enterprise|
shop_enterprise_path(enterprise)
end
node :hash do |enterprise|
enterprise.to_param
end
extends 'json/partials/enterprise'
extends 'json/partials/producer'
extends 'json/partials/hub'

View File

@@ -1,26 +1,4 @@
collection Enterprise.visible.is_distributor
extends 'json/enterprises'
extends 'json/partials/enterprise'
extends 'json/partials/hub'
child distributed_taxons: :taxons do
extends "json/taxon"
end
child suppliers: :producers do
extends "json/producer"
end
node :pickup do |hub|
not hub.shipping_methods.where(:require_ship_address => false).empty?
end
node :delivery do |hub|
not hub.shipping_methods.where(:require_ship_address => true).empty?
end
node :active do |hub|
@active_distributors.include?(hub)
end
node :orders_close_at do |hub|
OrderCycle.first_closing_for(hub).andand.orders_close_at
end

View File

@@ -1,21 +1,3 @@
collection @producers
extends 'json/enterprises'
child supplied_taxons: :taxons do
extends 'json/taxon'
end
child distributors: :distributors do
attributes :name, :id
node :path do |distributor|
shop_enterprise_path(distributor)
end
end
node :path do |producer|
producer_path(producer)
end
node :hash do |producer|
producer.to_param
end
extends 'json/partials/enterprise'
extends 'json/partials/producer'

View File

@@ -1,6 +1,16 @@
collection @enterprises
extends 'json/enterprises'
attributes :latitude, :longitude, :long_description, :website, :instagram, :linkedin, :twitter, :facebook, :is_primary_producer?, :is_distributor?
attributes :name, :id, :description, :latitude, :longitude, :long_description, :website, :instagram, :linkedin, :twitter, :facebook, :is_primary_producer?, :is_distributor?
node :email do |enterprise|
enterprise.email.to_s.reverse
end
child :address do
extends "json/partials/address"
end
node :hash do |enterprise|
enterprise.to_param
end
node :logo do |enterprise|
enterprise.logo(:medium) if enterprise.logo.exists?
@@ -10,18 +20,6 @@ node :promo_image do |enterprise|
enterprise.promo_image(:large) if enterprise.promo_image.exists?
end
node :active do |enterprise|
@active_distributors.include?(enterprise)
end
child distributors: :hubs do
extends 'json/enterprises'
node :active do |hub|
@active_distributors.include?(hub)
end
end
node :icon do |e|
if e.is_primary_producer? and e.is_distributor?
image_path "map-icon-both.svg"

View File

@@ -0,0 +1,21 @@
child distributed_taxons: :taxons do
extends "json/taxon"
end
child suppliers: :producers do
attributes :id
end
node :path do |enterprise|
shop_enterprise_path(enterprise)
end
node :pickup do |hub|
not hub.shipping_methods.where(:require_ship_address => false).empty?
end
node :delivery do |hub|
not hub.shipping_methods.where(:require_ship_address => true).empty?
end
node :active do |hub|
@active_distributors.include?(hub)
end
node :orders_close_at do |hub|
OrderCycle.first_closing_for(hub).andand.orders_close_at
end

View File

@@ -0,0 +1,9 @@
child supplied_taxons: :taxons do
extends 'json/taxon'
end
child distributors: :hubs do
attributes :id
end
node :path do |producer|
producer_path(producer)
end

View File

@@ -26,6 +26,7 @@
= inject_json "currentHub", "current_hub"
= inject_json "enterprises", "enterprises"
= inject_json "currentOrder", "current_order"
= inject_json "user", "current_user"
= inject_json "railsFlash", "flash"

View File

@@ -5,7 +5,10 @@
//= require angular-mocks
//= require angular-cookies
//= require angular-backstretch.js
//= require lodash.underscore.js
//= require angular-flash.min.js
//= require moment
angular.module('templates', [])
angular.module('google-maps', []);
angular.module('duScroll', []);

View File

@@ -0,0 +1,68 @@
@google =
maps:
event:
addDomListener: ->
addDomListenerOnce: ->
addListener: ->
addListenerOnce: ->
bind: ->
clearInstanceListeners: ->
clearListeners: ->
forward: ->
removeListener: ->
trigger: ->
vf: ->
class google.maps.LatLng
constructor: (lat, lng) ->
@latitude = parseFloat(lat)
@longitude = parseFloat(lng)
lat: -> @latitude
lng: -> @longitude
class google.maps.LatLngBounds
constructor: (@ne, @sw) ->
getSouthWest: -> @sw
getNorthEast: -> @ne
class google.maps.OverlayView
class google.maps.Marker
getAnimation: ->
getClickable: ->
getCursor: ->
getDraggable: ->
getFlat: ->
getIcon: ->
getPosition: ->
getShadow: ->
getShape: ->
getTitle: ->
getVisible: ->
getZIndex: ->
setAnimation: ->
setClickable: ->
setCursor: ->
setDraggable: ->
setFlat: ->
setIcon: ->
setPosition: ->
setShadow: ->
setShape: ->
setTitle: ->
setVisible: ->
setZIndex: ->
setMap: ->
getMap: ->
class google.maps.MarkerImage
class google.maps.Map
class google.maps.Point
class google.maps.Size
class google.maps.InfoWindow

View File

@@ -1,9 +1,14 @@
describe "AccordionCtrl", ->
ctrl = null
scope = null
CurrentHubMock =
id: 1
beforeEach ->
module "Darkswarm"
module ($provide)->
$provide.value "CurrentHub", CurrentHubMock
null
localStorage.clear()
describe "loading incomplete form", ->

View File

@@ -6,6 +6,10 @@ describe 'Order service', ->
flash = null
storage = null
scope = null
CurrentHubMock =
id: 1
FlashLoaderMock =
loadFlash: (arg)->
beforeEach ->
orderData =
@@ -36,6 +40,10 @@ describe 'Order service', ->
angular.module('Darkswarm').value('order', orderData)
module 'Darkswarm'
module ($provide)->
$provide.value "CurrentHub", CurrentHubMock
$provide.value "RailsFlashLoader", FlashLoaderMock
null
inject ($injector, _$httpBackend_, _storage_, $rootScope)->
$httpBackend = _$httpBackend_
@@ -58,13 +66,13 @@ describe 'Order service', ->
spyOn(storage, "bind")
Order.fieldsToBind = ["testy"]
Order.bindFieldsToLocalStorage({})
prefix = "order_#{Order.order.id}#{Order.order.user_id}"
prefix = "order_#{Order.order.id}#{Order.order.user_id}#{CurrentHubMock.id}"
expect(storage.bind).toHaveBeenCalledWith({}, "Order.order.testy", {storeName: "#{prefix}_testy"})
expect(storage.bind).toHaveBeenCalledWith({}, "Order.ship_address_same_as_billing", {storeName: "#{prefix}_sameasbilling", defaultValue: true})
it "binds order to local storage", ->
Order.bindFieldsToLocalStorage(scope)
prefix = "order_#{Order.order.id}#{Order.order.user_id}"
prefix = "order_#{Order.order.id}#{Order.order.user_id}#{CurrentHubMock.id}"
expect(localStorage.getItem("#{prefix}_email")).toMatch "test@test.com"
it "does not store secrets in local storage", ->
@@ -100,10 +108,11 @@ describe 'Order service', ->
$httpBackend.flush()
it "sends flash messages to the flash service", ->
spyOn(FlashLoaderMock, "loadFlash") # Stubbing out writes to window.location
$httpBackend.expectPUT("/checkout").respond 400, {flash: {error: "frogs"}}
Order.submit()
$httpBackend.flush()
expect(flash.error).toEqual "frogs"
expect(FlashLoaderMock.loadFlash).toHaveBeenCalledWith {error: "frogs"}
it "puts errors into the scope", ->
$httpBackend.expectPUT("/checkout").respond 400, {errors: {error: "frogs"}}