Added a cucumber feature to paginate through models.
This commit is contained in:
parent
c3c5d8e754
commit
ad0adc7153
8
features/engine/pagination.feature
Normal file
8
features/engine/pagination.feature
Normal file
@ -0,0 +1,8 @@
|
||||
Feature: Pagination
|
||||
As a designer
|
||||
In order to display a sensible amount of items per page
|
||||
I want to be able to paginate through models
|
||||
|
||||
Scenario: Paginating through a model
|
||||
Given I have a site setup
|
||||
Then I should be able to display paginated models
|
35
features/step_definitions/pagination_steps.rb
Normal file
35
features/step_definitions/pagination_steps.rb
Normal file
@ -0,0 +1,35 @@
|
||||
Then /^I should be able to display paginated models$/ do
|
||||
# Create our article model and three articles
|
||||
@article_model = FactoryGirl.build(:content_type, :site => @site, :name => 'Articles').tap do |ct|
|
||||
ct.content_custom_fields.build :label => 'Body', :kind => 'string', :required => false
|
||||
ct.save!
|
||||
end
|
||||
|
||||
%w(First Second Third).each do |body|
|
||||
@article_model.contents.create!(:body => body)
|
||||
end
|
||||
|
||||
# Create a page with template
|
||||
raw_template = %{
|
||||
{% paginate contents.articles by 2 %}
|
||||
{% for article in paginate.collection %}
|
||||
{{ article.body }}
|
||||
{% endfor %}
|
||||
{{ paginate | default_pagination }}
|
||||
{% endpaginate %}
|
||||
}
|
||||
FactoryGirl.create(:page, :site => @site, :slug => 'hello', :raw_template => raw_template)
|
||||
|
||||
# The page should have the first two articles
|
||||
visit '/hello'
|
||||
page.should have_content 'First'
|
||||
page.should have_content 'Second'
|
||||
page.should_not have_content 'Third'
|
||||
|
||||
# The second page should have the last article
|
||||
click_link '2'
|
||||
page.should_not have_content 'First'
|
||||
page.should_not have_content 'Second'
|
||||
page.should have_content 'Third'
|
||||
end
|
||||
|
@ -13,6 +13,10 @@ Given /^I have the site: "([^"]*)" set up(?: with #{capture_fields})?$/ do |site
|
||||
@admin.should_not be_nil
|
||||
end
|
||||
|
||||
Given /^I have a site setup$/ do
|
||||
Given %{I have the site: "test site" set up}
|
||||
end
|
||||
|
||||
Given /^I have a designer and an author$/ do
|
||||
FactoryGirl.create(:designer, :site => Site.first)
|
||||
FactoryGirl.create(:author, :site => Site.first)
|
||||
|
@ -64,16 +64,7 @@ module Locomotive
|
||||
protected
|
||||
|
||||
def paginate(options = {})
|
||||
@collection = self.collection.paginate(options)
|
||||
{
|
||||
:collection => @collection,
|
||||
:current_page => @collection.current_page,
|
||||
:previous_page => @collection.previous_page,
|
||||
:next_page => @collection.next_page,
|
||||
:total_entries => @collection.total_entries,
|
||||
:total_pages => @collection.total_pages,
|
||||
:per_page => @collection.per_page
|
||||
}
|
||||
@collection = Kaminari.paginate_array(self.collection).page(options[:page]).per(options[:per_page])
|
||||
end
|
||||
|
||||
def collection
|
||||
|
@ -1,7 +1,7 @@
|
||||
class Kaminari::PaginatableArray
|
||||
def to_liquid(options = {})
|
||||
{
|
||||
:collection => self.to_a,
|
||||
:collection => to_a,
|
||||
:current_page => current_page,
|
||||
:previous_page => first_page? ? nil : current_page - 1,
|
||||
:next_page => last_page? ? nil : current_page + 1,
|
||||
|
Loading…
Reference in New Issue
Block a user