Merge remote-tracking branch 'origin/master' into rails_3_1
Conflicts: Gemfile Gemfile.lock config/initializers/will_paginate.rb lib/locomotive/engine.rb lib/locomotive/hosting/bushido/account_ext.rb lib/locomotive/hosting/bushido/enabler.rb lib/locomotive/hosting/bushido/hooks.rb
This commit is contained in:
commit
5f893d51c0
config/initializers
features
engine
step_definitions
lib
locomotive.rb
locomotive_cms.gemspeclocomotive
spec
@ -1 +0,0 @@
|
||||
# require 'will_paginate/array'
|
8
features/engine/has_many.feature
Normal file
8
features/engine/has_many.feature
Normal file
@ -0,0 +1,8 @@
|
||||
Feature: Has Many Association
|
||||
As a designer
|
||||
In order to make dealing with models easier
|
||||
I want to be able to display other models that have a has many association
|
||||
|
||||
Scenario: Paginating a has many association
|
||||
Given I have a site set up
|
||||
Then I should be able to view a paginaed list of a has many association
|
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 set up
|
||||
Then I should be able to display paginated models
|
@ -66,4 +66,3 @@ end
|
||||
Then %r{^I should see once the "([^"]*)" field$} do |field|
|
||||
page.should have_css("#content_#{field.underscore.downcase}_input", :count => 1)
|
||||
end
|
||||
|
||||
|
61
features/step_definitions/has_many_steps.rb
Normal file
61
features/step_definitions/has_many_steps.rb
Normal file
@ -0,0 +1,61 @@
|
||||
Given %r{^I have an? "([^"]*)" model which has many "([^"]*)"$} do |parent_model, child_model|
|
||||
@parent_model = FactoryGirl.build(:content_type, :site => @site, :name => parent_model).tap do |ct|
|
||||
ct.content_custom_fields.build :label => 'Body', :kind => 'string', :required => false
|
||||
ct.save!
|
||||
end
|
||||
@child_model = FactoryGirl.build(:content_type, :site => @site, :name => child_model).tap do |ct|
|
||||
ct.content_custom_fields.build :label => 'Body', :kind => 'string', :required => false
|
||||
ct.content_custom_fields.build :label => parent_model.singularize, :kind => 'has_one', :required => false, :target => parent_model
|
||||
ct.save!
|
||||
end
|
||||
|
||||
@parent_model.content_custom_fields.build({
|
||||
:label => child_model,
|
||||
:kind => 'has_many',
|
||||
:target => @child_model.content_klass.to_s,
|
||||
:reverse_lookup => @child_model.content_klass.custom_field_alias_to_name(parent_model.downcase.singularize)
|
||||
})
|
||||
end
|
||||
|
||||
Then /^I should be able to view a paginaed list of a has many association$/ do
|
||||
# Create models
|
||||
Given %{I have an "Articles" model which has many "Comments"}
|
||||
|
||||
# Create contents
|
||||
article = @parent_model.contents.create!(:slug => 'parent', :body => 'Parent')
|
||||
@child_model.contents.create!(:slug => 'one', :body => 'One', :custom_field_2 => article.id.to_s)
|
||||
@child_model.contents.create!(:slug => 'two', :body => 'Two', :custom_field_2 => article.id.to_s)
|
||||
@child_model.contents.create!(:slug => 'three', :body => 'Three', :custom_field_2 => article.id.to_s)
|
||||
|
||||
@child_model.contents.each do |comment|
|
||||
article.comments << comment
|
||||
end
|
||||
|
||||
# Create a page
|
||||
raw_template = %{
|
||||
{% for article in contents.articles %}
|
||||
{% paginate article.comments by 2 %}
|
||||
{% for comment in paginate.collection %}
|
||||
{{ comment.body }}
|
||||
{% endfor %}
|
||||
{{ paginate | default_pagination }}
|
||||
{% endpaginate %}
|
||||
{% endfor %}
|
||||
}
|
||||
|
||||
# Create a page
|
||||
FactoryGirl.create(:page, :site => @site, :slug => 'hello', :raw_template => raw_template)
|
||||
|
||||
# The page should have the first two comments
|
||||
visit '/hello'
|
||||
page.should have_content 'One'
|
||||
page.should have_content 'Two'
|
||||
page.should_not have_content 'Three'
|
||||
|
||||
|
||||
# The second page should have the last comment
|
||||
click_link '2'
|
||||
page.should_not have_content 'One'
|
||||
page.should_not have_content 'Two'
|
||||
page.should have_content 'Three'
|
||||
end
|
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 set up$/ 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)
|
||||
|
@ -9,6 +9,7 @@ require 'locomotive/logger'
|
||||
|
||||
require 'locomotive/formtastic'
|
||||
require 'locomotive/dragonfly'
|
||||
require 'locomotive/kaminari'
|
||||
require 'locomotive/liquid'
|
||||
require 'locomotive/mongoid'
|
||||
require 'locomotive/carrierwave'
|
||||
|
17
lib/locomotive/kaminari.rb
Normal file
17
lib/locomotive/kaminari.rb
Normal file
@ -0,0 +1,17 @@
|
||||
require 'kaminari'
|
||||
|
||||
module Kaminari
|
||||
class PaginatableArray < Array
|
||||
def to_liquid(options = {})
|
||||
{
|
||||
:collection => to_a,
|
||||
:current_page => current_page,
|
||||
:previous_page => first_page? ? nil : current_page - 1,
|
||||
:next_page => last_page? ? nil : current_page + 1,
|
||||
:total_entries => total_count,
|
||||
:total_pages => num_pages,
|
||||
:per_page => limit_value
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
@ -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
|
||||
|
@ -36,13 +36,16 @@ module Locomotive
|
||||
|
||||
raise ::Liquid::ArgumentError.new("Cannot paginate array '#{@collection_name}'. Not found.") if collection.nil?
|
||||
|
||||
pagination = collection.send(:paginate, {
|
||||
:page => context['current_page'],
|
||||
:per_page => @per_page }).stringify_keys
|
||||
|
||||
if collection.is_a? Array
|
||||
pagination = Kaminari.paginate_array(collection).page(context['current_page']).per(@per_page).to_liquid.stringify_keys
|
||||
else
|
||||
pagination = collection.send(:paginate, {
|
||||
:page => context['current_page'],
|
||||
:per_page => @per_page }).to_liquid.stringify_keys
|
||||
end
|
||||
page_count, current_page = pagination['total_pages'], pagination['current_page']
|
||||
|
||||
path = context.registers[:page].fullpath
|
||||
path = context['path']
|
||||
|
||||
pagination['previous'] = link(I18n.t('pagination.previous'), current_page - 1, path) if pagination['previous_page']
|
||||
pagination['next'] = link(I18n.t('pagination.next'), current_page + 1, path) if pagination['next_page']
|
||||
|
@ -65,6 +65,7 @@ module Locomotive
|
||||
'contents' => Locomotive::Liquid::Drops::Contents.new,
|
||||
'current_page' => self.params[:page],
|
||||
'params' => self.params,
|
||||
'path' => request.path,
|
||||
'url' => request.url,
|
||||
'now' => Time.now.utc,
|
||||
'today' => Date.today
|
||||
|
@ -39,7 +39,7 @@ module Locomotive
|
||||
end
|
||||
|
||||
def render_no_site_error
|
||||
render :template => '/admin/errors/no_site', :layout => false
|
||||
render :template => '/admin/errors/no_site', :layout => false, :status => :not_found
|
||||
end
|
||||
|
||||
def validate_site_membership
|
||||
|
@ -21,10 +21,14 @@ Gem::Specification.new do |s|
|
||||
s.add_dependency 'warden'
|
||||
s.add_dependency 'devise', '1.3.4'
|
||||
s.add_dependency 'devise_bushido_authenticatable', '1.0.0.alpha10'
|
||||
|
||||
s.add_dependency 'mongo', '~> 1.3.1'
|
||||
s.add_dependency 'bson', '~> 1.3.1'
|
||||
s.add_dependency 'bson_ext', '~> 1.3.1'
|
||||
s.add_dependency 'mongoid', '~> 2.0.2'
|
||||
s.add_dependency 'bson_ext', '~> 1.4.0'
|
||||
|
||||
s.add_dependency 'locomotive_mongoid_acts_as_tree', '0.1.5.7'
|
||||
s.add_dependency 'will_paginate', '~> 3.0.0'
|
||||
s.add_dependency 'kaminari'
|
||||
|
||||
s.add_dependency 'haml', '3.1.2'
|
||||
s.add_dependency 'sass', '3.1.2'
|
||||
|
@ -138,4 +138,7 @@ FactoryGirl.define do
|
||||
site { Site.where(:subdomain => "acme").first || Factory(:site) }
|
||||
end
|
||||
|
||||
end
|
||||
factory :content_instance do
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -52,7 +52,8 @@ describe Locomotive::Liquid::Tags::Paginate do
|
||||
{},
|
||||
{
|
||||
'projects' => options.has_key?(:collection) ? options[:collection] : PaginatedCollection.new(['Ruby on Rails', 'jQuery', 'mongodb', 'Liquid', 'sqlite3']),
|
||||
'current_page' => options[:page] || 1
|
||||
'current_page' => options[:page] || 1,
|
||||
'path' => '/'
|
||||
}, {
|
||||
:page => FactoryGirl.build(:page)
|
||||
}, true)
|
||||
|
@ -147,11 +147,19 @@ describe Locomotive::Routing::SiteDispatcher do
|
||||
|
||||
describe '#render_no_site_error' do
|
||||
|
||||
it 'renders the no site template with no layout' do
|
||||
@controller.expects(:render).with(:template => '/admin/errors/no_site', :layout => false)
|
||||
before :each do
|
||||
@controller.instance_variable_set('@_response', ActionDispatch::Response.new)
|
||||
@controller.send(:render_no_site_error)
|
||||
end
|
||||
|
||||
it 'should have a no site error message' do
|
||||
@controller.response.body.should include 'No Site'
|
||||
end
|
||||
|
||||
it 'should have a 404 not found status' do
|
||||
@controller.response.should be_not_found
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe '#validate_site_membership' do
|
||||
|
Loading…
Reference in New Issue
Block a user