Skip to content

Commit

Permalink
Paginator should delegate view helper methods to template
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki24 committed Mar 15, 2014
1 parent f63112e commit defc7ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/kaminari/helpers/paginator.rb
Expand Up @@ -106,6 +106,12 @@ def render_partial(event)
end
end

# delegates view helper methods to @template
def method_missing(name, *args, &block)
@template.respond_to?(name) ? @template.send(name, *args, &block) : super
end
private :method_missing

# Wraps a "page number" and provides some utility methods
class PageProxy
include Comparable
Expand Down
9 changes: 9 additions & 0 deletions spec/helpers/helpers_spec.rb
Expand Up @@ -8,10 +8,19 @@
params { {} }
options { {} }
url_for {|h| "/foo?page=#{h[:page]}"}
link_to { "<a href='#'>link</a>" }
end
r
end

describe "view helper methods delegated to template" do
before do
@paginator = Paginator.new(template, :params => {})
end
subject { @paginator.link_to("link", "#") }
it { should == "<a href='#'>link</a>" }
end

describe '#params' do
before do
@paginator = Paginator.new(template, :params => {:controller => 'foo', :action => 'bar'})
Expand Down

0 comments on commit defc7ba

Please sign in to comment.