From 32a5e7e2a64b5c37f9d0bf03c9f139538ee60aa5 Mon Sep 17 00:00:00 2001 From: Jordan Hollinger Date: Tue, 19 Nov 2024 16:38:10 -0500 Subject: [PATCH] Create an implicit partial for every V2 view Signed-off-by: Jordan Hollinger --- lib/blueprinter/v2/dsl.rb | 4 +++- spec/v2/partials_spec.rb | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/blueprinter/v2/dsl.rb b/lib/blueprinter/v2/dsl.rb index 072bcd3d..fdd277a0 100644 --- a/lib/blueprinter/v2/dsl.rb +++ b/lib/blueprinter/v2/dsl.rb @@ -13,7 +13,9 @@ module DSL def view(name, &definition) raise Errors::InvalidBlueprint, "View name may not contain '.'" if name.to_s =~ /\./ - views[name.to_sym] = definition + name = name.to_sym + partials[name] = definition + views[name] = definition end # diff --git a/spec/v2/partials_spec.rb b/spec/v2/partials_spec.rb index 98dcf391..bed407c1 100644 --- a/spec/v2/partials_spec.rb +++ b/spec/v2/partials_spec.rb @@ -84,4 +84,20 @@ end expect { blueprint[:foo] }.to raise_error(Blueprinter::Errors::UnknownPartial) end + + it 'should create an implicit partial for every view' do + blueprint = Class.new(Blueprinter::V2::Base) do + view :foo do + field :name + end + + view :bar do + use :foo + field :description + end + end + + refs = blueprint.reflections + expect(refs[:bar].fields.keys).to eq %i(name description).sort + end end