-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jordan Hollinger <[email protected]>
- Loading branch information
1 parent
aea8647
commit c2db5e5
Showing
6 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
module Blueprinter | ||
module Errors | ||
class UnknownPartial < Blueprinter::BlueprinterError; end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
describe "Blueprinter::V2 Partials" do | ||
it "should allow a partial to be used in any view" do | ||
blueprint = Class.new(Blueprinter::V2) do | ||
field :name | ||
|
||
partial :description do | ||
field :description | ||
end | ||
|
||
view :foo do | ||
use :description | ||
end | ||
|
||
view :bar do | ||
use :description | ||
end | ||
end | ||
|
||
expect(blueprint.reflections[:default].fields.keys).to eq %i(name) | ||
expect(blueprint.reflections[:foo].fields.keys.sort).to eq %i( | ||
name | ||
description | ||
).sort | ||
expect(blueprint.reflections[:bar].fields.keys.sort).to eq %i( | ||
name | ||
description | ||
).sort | ||
end | ||
|
||
it "should throw an error for an invalid partial name" do | ||
expect do | ||
Class.new(Blueprinter::V2) do | ||
view :foo do | ||
use :description | ||
end | ||
end | ||
end.to raise_error(Blueprinter::Errors::UnknownPartial) | ||
end | ||
end |