From ea445dd2d381a6c7a9947c3c9959506da3df620a Mon Sep 17 00:00:00 2001 From: Mattias Pfeiffer Date: Thu, 13 Oct 2011 18:12:42 +0200 Subject: [PATCH] Set the view_context properly --- lib/draper/view_context.rb | 2 +- spec/view_context_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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