1
0
Fork 0
mirror of https://github.com/drapergem/draper synced 2023-03-27 23:21:17 -04:00

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 Draper
module ViewContext module ViewContext
def self.current def self.current
Thread.current[:current_view_context] || view_context Thread.current[:current_view_context] || ApplicationController.new.view_context
end end
def self.current=(input) def self.current=(input)

View file

@ -2,6 +2,10 @@ require 'spec_helper'
require 'draper/test/view_context' require 'draper/test/view_context'
describe Draper::ViewContext do describe Draper::ViewContext do
before(:each) do
Thread.current[:current_view_context] = nil
end
let(:app_controller) { ApplicationController } let(:app_controller) { ApplicationController }
let(:app_controller_instance) { app_controller.new } let(:app_controller_instance) { app_controller.new }
@ -13,4 +17,14 @@ describe Draper::ViewContext do
ctx = app_controller_instance.view_context ctx = app_controller_instance.view_context
Draper::ViewContext.current.should == ctx Draper::ViewContext.current.should == ctx
end 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 end