Skip to content

Commit

Permalink
Merge pull request #281 from sankaranarayanan/master
Browse files Browse the repository at this point in the history
fixed bug build_view_context should be class method
  • Loading branch information
steveklabnik committed Sep 27, 2012
2 parents 8d0f9c2 + 12bf16f commit a4b3922
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/draper/view_context.rb
Expand Up @@ -13,10 +13,10 @@ def view_context
Draper::ViewContext.current = context
end
end

private
def build_view_context

def self.build_view_context
ApplicationController.new.view_context.tap do |context|
context.controller.request ||= ActionController::TestRequest.new
context.request ||= context.controller.request
Expand Down
17 changes: 11 additions & 6 deletions spec/draper/decorated_enumerable_proxy_spec.rb
Expand Up @@ -14,27 +14,32 @@
it "is aliased to .h" do
subject.h.should == subject.helpers
end

it "build a new view context" do
Thread.current[:current_view_context] = nil
subject.helpers.should be
end
end

context(".decorates") do
it "sets the model for the decorated" do
EnumerableProxy.new([source], ProductDecorator).first.model.should == source
end

it "decorates an empty array with the klass" do
EnumerableProxy.decorates([], klass: ProductDecorator).should be
end

it "discerns collection items decorator by the name of the decorator" do
ProductsDecorator.decorates([]).should be
end

it "methods in decorated empty array should work" do
ProductsDecorator.decorates([]).some_method.should == "some method works"
end

it "raises when decorates an empty array without the klass" do
lambda{EnumerableProxy.decorates([])}.should raise_error
end
end
end
end
8 changes: 6 additions & 2 deletions spec/support/samples/products_decorator.rb
@@ -1,6 +1,10 @@
class ProductsDecorator < Draper::DecoratedEnumerableProxy


def link_to
h.link_to 'sample', "#"
end

def some_method
"some method works"
end
end
end

0 comments on commit a4b3922

Please sign in to comment.