refactor tests for contents

This commit is contained in:
did 2011-06-30 12:41:20 +02:00
parent 187de54962
commit e560c71ee5
4 changed files with 62 additions and 13 deletions

View File

@ -5,7 +5,10 @@ Feature: Editing a content type
Background:
Given I have the site: "test site" set up
And I have a custom project model
And I have a custom model named "Projects" with
| label | kind | required |
| Name | string | true |
| Description | text | false |
And I have a designer and an author
Scenario: As an unauthenticated user

View File

@ -5,7 +5,10 @@ Feature: Pages
Background:
Given I have the site: "test site" set up
And I have a custom project model
And I have a custom model named "Projects" with
| label | kind | required |
| Name | string | true |
| Description | text | false |
And I have a designer and an author
And a page named "hello-world" with the template:
"""

View File

@ -5,9 +5,18 @@ Feature: Manage Contents
Background:
Given I have the site: "test site" set up
And I have a custom project model
And I have a custom model named "Projects" with
| label | kind | required |
| Name | string | true |
| Description | text | false |
| Category | category | false |
And I have "Design, Development" as "Category" values of the "Projects" model
And I am an authenticated user
And I have a project entry with "My sexy project" as name and "Lorem ipsum" as description
And I have entries for "Projects" with
| name | description | category |
| My sexy project | Lorem ipsum | Development |
| Foo project | Lorem ipsum... | Design |
| Bar project | Lorem ipsum... | Design |
Scenario:
When I go to the "Projects" model list page
@ -51,4 +60,11 @@ Scenario: Destroy an entry
Then I should see "Content was successfully deleted."
And I should not see "My sexy project"
Scenario: Group entries by category
Scenario: Group entries by category
When I go to the "Projects" model list page
Then I should not see "Development"
And I should not see "Design"
When I change the presentation of the "Projects" model by grouping items by "Category"
And I go to the "Projects" model list page
Then I should see "Development"
And I should see "Design"

View File

@ -1,12 +1,39 @@
Given /^I have a custom project model/ do
Given %r{^I have a custom model named "([^"]*)" with$} do |name, fields|
site = Site.first
@content_type = Factory.build(:content_type, :site => site, :name => 'Projects')
@content_type.content_custom_fields.build :label => 'Name', :kind => 'string', :required => true
@content_type.content_custom_fields.build :label => 'Description', :kind => 'text'
@content_type.save.should be_true
content_type = Factory.build(:content_type, :site => site, :name => name)
fields.hashes.each do |field|
f = content_type.content_custom_fields.build field
end
content_type.valid?
content_type.save.should be_true
end
Given /^I have a project entry with "(.*)" as name and "(.*)" as description/ do |name, description|
@content = @content_type.contents.build :name => name, :description => description
@content.save.should be_true
Given %r{^I have "([^"]*)" as "([^"]*)" values of the "([^"]*)" model$} do |values, field, name|
content_type = ContentType.where(:name => name).first
field = content_type.content_custom_fields.detect { |f| f.label == field }
field.should_not be_nil
if field.kind == 'category'
values.split(',').collect(&:strip).each do |name|
field.category_items.build :name => name
end
content_type.save.should be_true
else
raise "#{field.kind} field is not supported"
end
end
Given %r{^I have entries for "([^"]*)" with$} do |name, entries|
content_type = ContentType.where(:name => name).first
entries.hashes.each do |entry|
content_type.contents.create(entry)
end
content_type.save.should be_true
end
When %r{^I change the presentation of the "([^"]*)" model by grouping items by "([^"]*)"$} do |name, field|
content_type = ContentType.where(:name => name).first
field = content_type.content_custom_fields.detect { |f| f.label == field }
content_type.group_by_field_name = field._name
content_type.save.should be_true
end