diff --git a/lib/draper/view_context.rb b/lib/draper/view_context.rb index 0be6d4e..59e06f0 100644 --- a/lib/draper/view_context.rb +++ b/lib/draper/view_context.rb @@ -1,4 +1,3 @@ -require 'pry' module Draper module ViewContext def self.current diff --git a/spec/draper/decorated_enumerable_proxy_spec.rb b/spec/draper/decorated_enumerable_proxy_spec.rb index bfcfe84..c07caa3 100644 --- a/spec/draper/decorated_enumerable_proxy_spec.rb +++ b/spec/draper/decorated_enumerable_proxy_spec.rb @@ -1,57 +1,45 @@ require 'spec_helper' describe Draper::DecoratedEnumerableProxy do - describe "View context" do - before(:each){ ApplicationController.new.view_context } - subject{ ProductsDecorator.new(source, ProductDecorator) } - let(:source){ Product.new } - let(:non_active_model_source){ NonActiveModelProduct.new } + before(:each){ ApplicationController.new.view_context } + subject{ ProductsDecorator.new(source, ProductDecorator) } + let(:source){ Product.new } + let(:non_active_model_source){ NonActiveModelProduct.new } - context(".helpers") do - it "have a valid view_context" do - subject.helpers.should be - end - - it "is aliased to .h" do - subject.h.should == subject.helpers - end + context(".helpers") do + it "have a valid view_context" do + subject.helpers.should be end - context(".decorates") do - it "sets the model for the decorated" do - EnumerableProxy.new([source], ProductDecorator).first.model.should == source - end + it "is aliased to .h" do + subject.h.should == subject.helpers + end - it "decorates an empty array with the klass" do - EnumerableProxy.decorates([], klass: ProductDecorator).should be - end - - it "discerns collection items decorator by the name of the decorator" do - ProductsDecorator.decorates([]).should be - end - - it "methods in decorated empty array should work" do - ProductsDecorator.decorates([]).some_method.should == "some method works" - end - - it "raises when decorates an empty array without the klass" do - lambda{EnumerableProxy.decorates([])}.should raise_error - end + it "build a new view context" do + Thread.current[:current_view_context] = nil + subject.helpers.should be end end - describe "No View Context" do - subject{ ProductsDecorator.new(source, ProductDecorator) } - let(:source){ Product.new } + context(".decorates") do + it "sets the model for the decorated" do + EnumerableProxy.new([source], ProductDecorator).first.model.should == source + end - context(".helpers") do - it "have a valid view_context" do - subject.helpers.should be - end + it "decorates an empty array with the klass" do + EnumerableProxy.decorates([], klass: ProductDecorator).should be + end - it "is aliased to .h" do - subject.h.should == subject.helpers - end + it "discerns collection items decorator by the name of the decorator" do + ProductsDecorator.decorates([]).should be + end + + it "methods in decorated empty array should work" do + ProductsDecorator.decorates([]).some_method.should == "some method works" + end + + it "raises when decorates an empty array without the klass" do + lambda{EnumerableProxy.decorates([])}.should raise_error end end end