Added a failing test for paginating has many associations.

This commit is contained in:
Mario Visic 2011-10-24 20:52:43 +08:00
parent 99386f8866
commit d574939e2c
4 changed files with 62 additions and 2 deletions

View File

@ -0,0 +1,11 @@
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
Background:
Given I have the site: "test site" set up
Scenario: Paginating a has many association
Given I have an "Articles" model which has many "Comments"
Then I should be able to view a paginated list of "Comments" per "Articles"

View File

@ -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

View File

@ -0,0 +1,47 @@
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 paginated list of "([^"]*)" per "([^"]*)"$/ do |parent_model, child_model|
# Create contents
@parent_model.contents.create!(:slug => 'parent', :body => 'Parent')
@child_model.contents.create!(:slug => 'one', :body => 'One')
@child_model.contents.create!(:slug => 'two', :body => 'Two')
@child_model.contents.create!(:slug => 'three', :body => 'Three')
# 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'
end

View File

@ -138,4 +138,7 @@ FactoryGirl.define do
site { Site.where(:subdomain => "acme").first || Factory(:site) }
end
end
factory :content_instance do
end
end