kill set_current_view_context

This commit is contained in:
Steve Klabnik 2012-07-17 14:23:31 -07:00
parent 19ecb66d07
commit 1d6491b4c7
4 changed files with 6 additions and 6 deletions

View File

@ -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.

View File

@ -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 ||= {}

View File

@ -19,7 +19,7 @@ RSpec.configure do |config|
end
config.before :type => :view do
controller.set_current_view_context
controller.view_context
end
end

View File

@ -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