diff --git a/lib/draper/view_context.rb b/lib/draper/view_context.rb index 83807f7..249876a 100644 --- a/lib/draper/view_context.rb +++ b/lib/draper/view_context.rb @@ -1,7 +1,7 @@ module Draper module ViewContext def set_current_view_context - Thread.current[:current_view_context] ||= self.view_context + Thread.current[:current_view_context] = self.view_context end def self.included(source) diff --git a/spec/view_context_spec.rb b/spec/view_context_spec.rb index cbc6ff1..a221a97 100644 --- a/spec/view_context_spec.rb +++ b/spec/view_context_spec.rb @@ -22,4 +22,14 @@ describe Draper::ViewContext do Thread.current[:current_view_context] = nil expect {app_controller.current_view_context}.should raise_exception(Exception) end + + it "sets view_context every time" do + app_controller_instance.stub(:view_context) { 'first' } + app_controller_instance.set_current_view_context + Thread.current[:current_view_context].should == 'first' + + app_controller_instance.stub(:view_context) { 'second' } + app_controller_instance.set_current_view_context + Thread.current[:current_view_context].should == 'second' + end end \ No newline at end of file