Fixed view_context priming. Fixes #244, relates to 057ab4e8.

Fix in 057ab4e8 resulted in a "NameError: undefined local variable or method `view_context' for Draper::ViewContext:Module".
This commit is contained in:
Istvan Hoka 2012-08-14 14:18:14 +03:00
parent b80b691d2a
commit 8e505565f9
2 changed files with 15 additions and 1 deletions

View File

@ -1,7 +1,7 @@
module Draper
module ViewContext
def self.current
Thread.current[:current_view_context] || view_context
Thread.current[:current_view_context] || ApplicationController.new.view_context
end
def self.current=(input)

View File

@ -2,6 +2,10 @@ 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 }
@ -13,4 +17,14 @@ describe Draper::ViewContext 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