1
0
Fork 0
mirror of https://github.com/drapergem/draper synced 2023-03-27 23:21:17 -04:00

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 ### 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. ActionMailer class.
```ruby ```ruby
class ArticleMailer < ActionMailer::Base class ArticleMailer < ActionMailer::Base
default 'init-draper' => Proc.new { set_current_view_context } default 'init-draper' => Proc.new { ArticleMailer.new.view_context }
end end
``` ```
### Integration with RSpec ### Integration with RSpec
Using the provided generator, Draper will place specs for your new decorator in `spec/decorators/`. 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. 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 console do
require 'action_controller/test_case' 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.controller.request ||= ActionController::TestRequest.new
Draper::ViewContext.current.request ||= Draper::ViewContext.current.controller.request Draper::ViewContext.current.request ||= Draper::ViewContext.current.controller.request
Draper::ViewContext.current.params ||= {} Draper::ViewContext.current.params ||= {}

View file

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

View file

@ -2,6 +2,6 @@ require 'test_helper'
class <%= class_name %>DecoratorTest < ActiveSupport::TestCase class <%= class_name %>DecoratorTest < ActiveSupport::TestCase
def setup def setup
ApplicationController.new.set_current_view_context ApplicationController.new.view_context
end end
end end