From 80cb34df460959b53672e66161af85746e855d5d Mon Sep 17 00:00:00 2001 From: Luiz Felipe Date: Tue, 26 Apr 2011 09:56:36 -0300 Subject: [PATCH] added test and changed paginate method to return a string --- lib/kaminari/helpers/action_view_extension.rb | 3 ++- spec/helpers/action_view_extension_spec.rb | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 spec/helpers/action_view_extension_spec.rb diff --git a/lib/kaminari/helpers/action_view_extension.rb b/lib/kaminari/helpers/action_view_extension.rb index 4597841..01c3889 100644 --- a/lib/kaminari/helpers/action_view_extension.rb +++ b/lib/kaminari/helpers/action_view_extension.rb @@ -18,7 +18,8 @@ module Kaminari # * :remote - Ajax? (false by default) # * :ANY_OTHER_VALUES - Any other hash key & values would be directly passed into each tag as :locals value. def paginate(scope, options = {}, &block) - Kaminari::Helpers::Paginator.new self, options.reverse_merge(:current_page => scope.current_page, :num_pages => scope.num_pages, :per_page => scope.limit_value, :param_name => Kaminari.config.param_name, :remote => false) + paginator = Kaminari::Helpers::Paginator.new self, options.reverse_merge(:current_page => scope.current_page, :num_pages => scope.num_pages, :per_page => scope.limit_value, :param_name => Kaminari.config.param_name, :remote => false) + paginator.to_s end end end diff --git a/spec/helpers/action_view_extension_spec.rb b/spec/helpers/action_view_extension_spec.rb new file mode 100644 index 0000000..6328e86 --- /dev/null +++ b/spec/helpers/action_view_extension_spec.rb @@ -0,0 +1,21 @@ +require File.expand_path('../spec_helper', File.dirname(__FILE__)) +include Kaminari::ActionViewExtension + +describe 'Kaminari::ActionViewExtension' do + describe '#paginate' do + before do + @author = User.create! :name => 'author' + @books = 2.times.map { @author.books_authored.create! } + @books = Book.page(1) + end + subject { paginate( @books ) } + it { should be_a(String) } + + context "escaping the pagination for javascript" do + it "should escape for javascript" do + lambda { escape_javascript( paginate( @books ) ) }.should_not raise_error + end + end + end +end +