Added a failing test for paginating has many associations.
This commit is contained in:
parent
99386f8866
commit
d574939e2c
11
features/engine/has_many.feature
Normal file
11
features/engine/has_many.feature
Normal 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"
|
@ -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
|
||||
|
||||
|
47
features/step_definitions/has_many_steps.rb
Normal file
47
features/step_definitions/has_many_steps.rb
Normal 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
|
@ -138,4 +138,7 @@ FactoryGirl.define do
|
||||
site { Site.where(:subdomain => "acme").first || Factory(:site) }
|
||||
end
|
||||
|
||||
end
|
||||
factory :content_instance do
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user