Starting to partialize and test the RABL partials

This commit is contained in:
Will Marshall
2014-04-30 13:52:06 +10:00
parent 0f6bd7049c
commit e901f3439a
7 changed files with 42 additions and 13 deletions

View File

@@ -0,0 +1,10 @@
# DON'T USE DIRECTLY - for inheritance
attributes :name, :id
child :taxons => :taxons do
attributes :name, :id
end
child :address do
extends "json/partials/address"
end

View File

@@ -1,16 +1,5 @@
collection Enterprise.is_distributor
attributes :name, :id
child :taxons do
attributes :name, :id
end
child :address do
attributes :city, :zipcode
node :state do |address|
address.state.abbr
end
end
extends 'json/enterprises'
node :pickup do |hub|
not hub.shipping_methods.where(:require_ship_address => false).empty?

View File

@@ -1,5 +1,5 @@
collection @producers
attributes :name, :id
extends 'json/enterprises'
node :path do |producer|
producer_path(producer)

View File

@@ -0,0 +1,4 @@
attributes :city, :zipcode
node :state do |address|
address.state.abbr
end

View File

@@ -2,6 +2,8 @@
:javascript
angular.module('Darkswarm').value('producers', #{render partial: "json/producers", object: @producers})
-#%pre
-#{{ Producers.producers | json }}
.row{bindonce: true}
.small-12.columns
.active_table

View File

@@ -0,0 +1,9 @@
module RablHelper
# See https://github.com/nesquena/rabl/issues/231
# Allows us to test RABL views using URL helpers
class FakeContext
include Singleton
include Rails.application.routes.url_helpers
end
end

View File

@@ -0,0 +1,15 @@
require 'spec_helper'
describe 'json/_producers.json.rabl' do
let!(:producer) { create(:supplier_enterprise) }
let(:render) { Rabl.render([producer], 'json/producers', view_path: 'app/views', scope: RablHelper::FakeContext.instance) }
it "renders a list of producers" do
render.should have_json_type(Array).at_path ''
render.should have_json_type(Object).at_path '0'
end
it "renders names" do
render.should be_json_eql(producer.name.to_json).at_path '0/name'
end
end