1616 end
1717 end
1818
19+ let ( :instances ) { Blueprinter ::V2 ::InstanceCache . new }
20+
1921 it 'renders an object to a hash' do
2022 widget = { name : 'Foo' , description : 'About' , category : { n : 'Bar' } }
21- render = described_class . new ( widget , { } , blueprint : widget_blueprint , collection : false )
23+ render = described_class . new ( widget , { } , blueprint : widget_blueprint , collection : false , instances : )
2224
2325 expect ( render . to_hash ) . to eq ( {
2426 name : 'Foo' ,
3234 { name : 'Foo' , description : 'About' , category : { n : 'Bar' } } ,
3335 { name : 'Foo 2' , description : 'About 2' , category : { n : 'Bar 2' } } ,
3436 ]
35- render = described_class . new ( widgets , { } , blueprint : widget_blueprint , collection : true )
37+ render = described_class . new ( widgets , { } , blueprint : widget_blueprint , collection : true , instances : )
3638
3739 expect ( render . to_hash ) . to eq ( [
3840 {
5052
5153 it 'renders an object to JSON' do
5254 widget = { name : 'Foo' , description : 'About' , category : { n : 'Bar' } }
53- render = described_class . new ( widget , { } , blueprint : widget_blueprint , collection : false )
55+ render = described_class . new ( widget , { } , blueprint : widget_blueprint , collection : false , instances : )
5456
5557 expect ( render . to_json ) . to eq ( {
5658 name : 'Foo' ,
6163
6264 it 'renders a collection to JSON' do
6365 widget = { name : 'Foo' , description : 'About' , category : { n : 'Bar' } }
64- render = described_class . new ( [ widget ] , { } , blueprint : widget_blueprint , collection : true )
66+ render = described_class . new ( [ widget ] , { } , blueprint : widget_blueprint , collection : true , instances : )
6567
6668 expect ( render . to_json ) . to eq ( [ {
6769 name : 'Foo' ,
@@ -86,15 +88,15 @@ def json(ctx)
8688 widget_blueprint . extensions << json_ext . new ( 'A' , log )
8789 widget_blueprint . extensions << json_ext . new ( 'B' , log )
8890
89- render = described_class . new ( { name : 'Foo' } , { } , blueprint : widget_blueprint , collection : false )
91+ render = described_class . new ( { name : 'Foo' } , { } , blueprint : widget_blueprint , collection : false , instances : )
9092
9193 expect ( render . to_json ) . to eq '{"name":"Foo"}'
9294 expect ( log ) . to eq [ 'B: custom json!' ]
9395 end
9496
9597 it 'renders to JSON and ignores the arg (for Rails `render json:`)' do
9698 widget = { name : 'Foo' , description : 'About' , category : { n : 'Bar' } }
97- render = described_class . new ( [ widget ] , { } , blueprint : widget_blueprint , collection : true )
99+ render = described_class . new ( [ widget ] , { } , blueprint : widget_blueprint , collection : true , instances : )
98100
99101 expect ( render . to_json ( { junk : 'junk' } ) ) . to eq ( [ {
100102 name : 'Foo' ,
@@ -105,7 +107,7 @@ def json(ctx)
105107
106108 it 'responds to to_str with json' do
107109 widget = { name : 'Foo' , description : 'About' , category : { n : 'Bar' } }
108- render = described_class . new ( widget , { } , blueprint : widget_blueprint , collection : false )
110+ render = described_class . new ( widget , { } , blueprint : widget_blueprint , collection : false , instances : )
109111
110112 expect ( render . to_str ) . to eq ( {
111113 name : 'Foo' ,
@@ -122,7 +124,7 @@ def json(ctx)
122124 end
123125 widget_blueprint . extensions << ext . new
124126 widget = { name : 'Foo' , description : 'About' , category : { n : 'Bar' } }
125- render = described_class . new ( widget , { } , blueprint : widget_blueprint , collection : false )
127+ render = described_class . new ( widget , { } , blueprint : widget_blueprint , collection : false , instances : )
126128
127129 expect ( render . to_json ) . to eq ( {
128130 name : 'Foo' ,
0 commit comments