2011-10-08 01:06:19 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'draper'
|
|
|
|
|
|
|
|
describe Draper::ViewContext do
|
|
|
|
let (:app_controller) do
|
|
|
|
ApplicationController
|
|
|
|
end
|
|
|
|
|
|
|
|
let (:app_controller_instance) do
|
|
|
|
app_controller.new
|
|
|
|
end
|
|
|
|
|
|
|
|
it "implements #set_current_view_context" do
|
|
|
|
app_controller_instance.should respond_to(:set_current_view_context)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "calls #before_filter with #set_current_view_context" do
|
|
|
|
app_controller.before_filters.should include(:set_current_view_context)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "raises an exception if the view_context is fetched without being set" do
|
|
|
|
Thread.current[:current_view_context] = nil
|
|
|
|
expect {app_controller.current_view_context}.should raise_exception(Exception)
|
|
|
|
end
|
2011-10-13 12:12:42 -04:00
|
|
|
|
|
|
|
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
|
2011-10-08 01:06:19 -04:00
|
|
|
end
|