diff --git a/lib/draper/test/minitest_integration.rb b/lib/draper/test/minitest_integration.rb index cd55f74..6b0d0f4 100755 --- a/lib/draper/test/minitest_integration.rb +++ b/lib/draper/test/minitest_integration.rb @@ -1,26 +1,5 @@ require 'draper/test/view_context' -module MiniTest - class Spec - class Decorator < Spec - before { Draper::ViewContext.infect!(self) } - end - end -end - -class MiniTest::Unit::DecoratorTestCase < MiniTest::Unit::TestCase - if method_defined?(:before_setup) - # for minitext >= 2.11 - def before_setup - super - Draper::ViewContext.infect!(self) - end - else - # for older minitest, like what ships w/Ruby 1.9 - add_setup_hook { Draper::ViewContext.infect!(self) } - end -end - MiniTest::Spec.register_spec_type(MiniTest::Spec::Decorator) do |desc| desc.superclass == Draper::Base end diff --git a/lib/draper/test/rspec_integration.rb b/lib/draper/test/rspec_integration.rb index 816c26a..6cbb988 100755 --- a/lib/draper/test/rspec_integration.rb +++ b/lib/draper/test/rspec_integration.rb @@ -1,5 +1,3 @@ -require 'draper/test/view_context' - module Draper module DecoratorExampleGroup extend ActiveSupport::Concern @@ -13,10 +11,6 @@ RSpec.configure do |config| :file_path => /spec[\\\/]decorators/ } - # Specs tagged type: :decorator set the Draper view context - config.before :type => :decorator do - Draper::ViewContext.infect!(self) - end end if defined?(Capybara) diff --git a/lib/draper/test/view_context.rb b/lib/draper/test/view_context.rb deleted file mode 100644 index 422e7c7..0000000 --- a/lib/draper/test/view_context.rb +++ /dev/null @@ -1,12 +0,0 @@ -module Draper - module ViewContext - def self.infect!(context) - context.instance_eval do - 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 ||= {} - end - end - end -end diff --git a/lib/draper/view_context.rb b/lib/draper/view_context.rb index e9d3a8f..2c53fc8 100644 --- a/lib/draper/view_context.rb +++ b/lib/draper/view_context.rb @@ -1,7 +1,12 @@ module Draper module ViewContext def self.current - Thread.current[:current_view_context] || ApplicationController.new.view_context + Thread.current[:current_view_context].tap do |context| + context ||= ApplicationController.new.view_context + context.controller.request ||= ActionController::TestRequest.new + context.request ||= context.controller.request + context.params ||= {} + end end def self.current=(input) diff --git a/spec/draper/helper_support_spec.rb b/spec/draper/helper_support_spec.rb deleted file mode 100644 index eaf346c..0000000 --- a/spec/draper/helper_support_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -require 'spec_helper' - -describe Draper::HelperSupport do - let(:product){ Product.new } - - context '#decorate' do - it 'renders a block' do - output = ApplicationController.decorate(product){|p| p.model.object_id } - output.should == product.object_id - end - - it 'uses #capture so Rails only renders the content once' do - ApplicationController.decorate(product){|p| p.model.object_id } - ApplicationController.capture_triggered.should be - end - end - -end diff --git a/spec/draper/view_context_spec.rb b/spec/draper/view_context_spec.rb deleted file mode 100644 index 25e7ce9..0000000 --- a/spec/draper/view_context_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'spec_helper' -require 'draper/test/view_context' - -describe Draper::ViewContext do - before(:each) do - Thread.current[:current_view_context] = nil - end - - let(:app_controller) { ApplicationController } - let(:app_controller_instance) { app_controller.new } - - it "provides a method to create a view context while testing" do - Draper::ViewContext.should respond_to(:infect!) - end - - it "copies the controller's view context to draper" do - ctx = app_controller_instance.view_context - Draper::ViewContext.current.should == ctx - end - - describe "view_context priming" do - let(:app_controller_instance) { double(ApplicationController, :view_context => view_context) } - let(:view_context) { double("ApplicationController#view_context") } - - it "primes the view_context when nil" do - app_controller.should_receive(:new).and_return(app_controller_instance) - Draper::ViewContext.current.should == view_context - end - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a59c1e2..345fab9 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,8 +3,6 @@ require 'ammeter/init' require 'rails' require 'action_view' -require './spec/support/samples/application_controller' - Bundler.require require './spec/support/samples/active_model' @@ -29,6 +27,9 @@ require './spec/support/samples/some_thing_decorator' require './spec/support/samples/widget' require './spec/support/samples/widget_decorator' +require 'action_controller' +require 'action_controller/test_case' + module ActionController class Base Draper::System.setup(self) @@ -39,3 +40,14 @@ module ActiveRecord class Relation end end + +require './spec/support/samples/application_helper' +class ApplicationController < ActionController::Base + include ApplicationHelper + helper_method :hello_world +end + + +class << Rails + undef application # Avoid silly Rails bug: https://github.com/rails/rails/pull/6429 +end