spec/spec_helper.rb in curly-templates-2.3.2 vs spec/spec_helper.rb in curly-templates-2.4.0
- old
+ new
@@ -12,26 +12,33 @@
presenter_class = Class.new(Curly::Presenter, &block)
stub_const(name, presenter_class)
presenter_class
end
- def render(source, locals = {}, presenter_class = nil, &block)
- if presenter_class.nil?
- unless defined?(ShowPresenter)
- define_presenter("ShowPresenter")
- end
+ def render(source, options = {}, &block)
+ presenter = options.fetch(:presenter) do
+ define_presenter("ShowPresenter") unless defined?(ShowPresenter)
+ "ShowPresenter"
+ end.constantize
- presenter_class = ShowPresenter
+ virtual_path = options.fetch(:virtual_path) do
+ presenter.name.underscore.gsub(/_presenter\z/, "")
end
- identifier = "show"
+ identifier = options.fetch(:identifier) do
+ defined?(Rails.root) ? "#{Rails.root}/#{virtual_path}.html.curly" : virtual_path
+ end
+
+ details = { virtual_path: virtual_path }
+ details.merge! options.fetch(:details, {})
+
handler = Curly::TemplateHandler
- details = { virtual_path: 'show' }
template = ActionView::Template.new(source, identifier, handler, details)
view = ActionView::Base.new
+ view.lookup_context.stub(:find_template) { source }
begin
- template.render(view, locals, &block)
+ template.render(view, options.fetch(:locals, {}), &block)
rescue ActionView::Template::Error => e
raise e.original_exception
end
end
end