-
-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Add support for rendering multiple scopes by passing string as names #253
base: 2.1.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,31 @@ | |
|
||
expect(scope).to be_an_instance_of scope_class | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 If it helps, in my local patch, I needed a way to test that the cache works as expected and ended up with the following spec: Spec SnippetRSpec.describe Milestoner::Views::ScopeBuilder do
subject(:builder) { described_class }
let :view do
Class.new Hanami::View do
config.paths = Bundler.root.join "lib/milestoner/templates"
config.template = "n/a"
end
end
let(:scope_a) { Class.new Hanami::View::Scope }
let(:scope_b) { Class.new Hanami::View::Scope }
before do
stub_const "TestScopeA", scope_a
stub_const "TestScopeB", scope_b
Hanami::View.cache.cache.clear
end
describe ".call" do
it "caches scope without duplicates" do
builder.call TestScopeA, locals: {}, rendering: view.new.rendering
builder.call TestScopeB, locals: {}, rendering: view.new.rendering
builder.call "TestScopeA", locals: {}, rendering: view.new.rendering
builder.call "TestScopeB", locals: {}, rendering: view.new.rendering
builder.call scope_a, locals: {}, rendering: view.new.rendering
builder.call scope_b, locals: {}, rendering: view.new.rendering
expect(Hanami::View.cache.cache.values).to eq([TestScopeA, TestScopeB])
end
end
end Might be a good idea to add a spec for |
||
context 'when multiple scopes are rendered in the same view' do | ||
|
||
let(:builder) { described_class.new } | ||
|
||
it 'allows to build scopes with different classes' do | ||
FirstScopeClass = Class.new(Hanami::View::Scope) | ||
SecondScopeClass = Class.new(Hanami::View::Scope) | ||
|
||
view = Class.new(Hanami::View) do | ||
config.paths = SPEC_ROOT.join("__ignore__") | ||
config.template = "__ignore__" | ||
|
||
config.scope_class = FirstScopeClass | ||
end.new | ||
|
||
scope = view.rendering.scope({}) | ||
expect(scope).to be_an_instance_of FirstScopeClass | ||
|
||
scope = view.rendering.scope('SecondScopeClass', {}) | ||
expect(scope).to be_an_instance_of SecondScopeClass | ||
|
||
scope = view.rendering.scope('FirstScopeClass', {}) | ||
expect(scope).to be_an_instance_of FirstScopeClass | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 If it helps, in my local patch, I only use
name
which is all you need to store in the cache. Example: