diff --git a/Readme.markdown b/Readme.markdown index fb2def6..5e64e10 100644 --- a/Readme.markdown +++ b/Readme.markdown @@ -244,19 +244,19 @@ Use the new methods in your views like any other model method (ex: `@article.pub ### Using in Mailers -To use decorators in mailers that use helpers, you have to call `set_current_view_context` in your +To use decorators in mailers that use helpers, you have to call `view_context` in your ActionMailer class. ```ruby class ArticleMailer < ActionMailer::Base - default 'init-draper' => Proc.new { set_current_view_context } + default 'init-draper' => Proc.new { ArticleMailer.new.view_context } end ``` ### Integration with RSpec Using the provided generator, Draper will place specs for your new decorator in `spec/decorators/`. -By default, specs in `spec/decorators` will be tagged as `type => :decorator`. Any spec tagged as `decorator` will run `ApplicationController.new.set_current_view_context` which makes helpers available to the decorator. +By default, specs in `spec/decorators` will be tagged as `type => :decorator`. Any spec tagged as `decorator` will make helpers available to the decorator. If your decorator specs live somewhere else, which they shouldn't, make sure to tag them with `type => :decorator`. If you don't tag them, Draper's helpers won't be available to your decorator while testing. diff --git a/lib/draper/railtie.rb b/lib/draper/railtie.rb index 6033165..aa25c94 100644 --- a/lib/draper/railtie.rb +++ b/lib/draper/railtie.rb @@ -36,7 +36,7 @@ module Draper console do require 'action_controller/test_case' - ApplicationController.new.set_current_view_context + ApplicationController.new.view_context Draper::ViewContext.current.controller.request ||= ActionController::TestRequest.new Draper::ViewContext.current.request ||= Draper::ViewContext.current.controller.request Draper::ViewContext.current.params ||= {} diff --git a/lib/draper/test/rspec_integration.rb b/lib/draper/test/rspec_integration.rb index 53ef273..cb64490 100755 --- a/lib/draper/test/rspec_integration.rb +++ b/lib/draper/test/rspec_integration.rb @@ -19,7 +19,7 @@ RSpec.configure do |config| end config.before :type => :view do - controller.set_current_view_context + controller.view_context end end diff --git a/lib/generators/test_unit/templates/decorator_test.rb b/lib/generators/test_unit/templates/decorator_test.rb index 164ea01..029c861 100644 --- a/lib/generators/test_unit/templates/decorator_test.rb +++ b/lib/generators/test_unit/templates/decorator_test.rb @@ -2,6 +2,6 @@ require 'test_helper' class <%= class_name %>DecoratorTest < ActiveSupport::TestCase def setup - ApplicationController.new.set_current_view_context + ApplicationController.new.view_context end end