mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-08 22:56:06 +00:00
Starting to partialize and test the RABL partials
This commit is contained in:
10
app/views/json/_enterprises.rabl
Normal file
10
app/views/json/_enterprises.rabl
Normal 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
|
||||
@@ -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?
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
collection @producers
|
||||
attributes :name, :id
|
||||
extends 'json/enterprises'
|
||||
|
||||
node :path do |producer|
|
||||
producer_path(producer)
|
||||
|
||||
4
app/views/json/partials/_address.rabl
Normal file
4
app/views/json/partials/_address.rabl
Normal file
@@ -0,0 +1,4 @@
|
||||
attributes :city, :zipcode
|
||||
node :state do |address|
|
||||
address.state.abbr
|
||||
end
|
||||
@@ -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
|
||||
|
||||
9
spec/support/views/rabl_helper.rb
Normal file
9
spec/support/views/rabl_helper.rb
Normal 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
|
||||
|
||||
15
spec/views/json/producers.json.rabl_spec.rb
Normal file
15
spec/views/json/producers.json.rabl_spec.rb
Normal 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
|
||||
Reference in New Issue
Block a user