engine/features/step_definitions/content_types_steps.rb

52 lines
1.9 KiB
Ruby
Raw Normal View History

2011-06-30 10:41:20 +00:00
Given %r{^I have a custom model named "([^"]*)" with$} do |name, fields|
site = Locomotive::Site.first
content_type = FactoryGirl.build(:content_type, :site => site, :name => name, :order_by => '_position')
2011-06-30 10:41:20 +00:00
fields.hashes.each do |field|
# found a belongs_to association
if field['type'] == 'belongs_to'
target_name = field.delete('target')
target_model = @site.content_types.where(:name => target_name).first
field['class_name'] = target_model.klass_with_custom_fields(:entries).to_s
end
content_type.entries_custom_fields.build field
2011-06-30 10:41:20 +00:00
end
content_type.valid?
content_type.save.should be_true
end
2011-06-30 10:41:20 +00:00
Given %r{^I have "([^"]*)" as "([^"]*)" values of the "([^"]*)" model$} do |values, field, name|
content_type = Locomotive::ContentType.where(:name => name).first
field = content_type.entries_custom_fields.detect { |f| f.label == field }
2011-06-30 10:41:20 +00:00
field.should_not be_nil
if field.type == 'select'
2011-06-30 10:41:20 +00:00
values.split(',').collect(&:strip).each do |name|
field.select_options.build :name => name
2011-06-30 10:41:20 +00:00
end
content_type.save.should be_true
else
raise "#{field.type} field is not supported"
2011-06-30 10:41:20 +00:00
end
end
Given %r{^I have entries for "([^"]*)" with$} do |name, entries|
content_type = Locomotive::ContentType.where(:name => name).first
2011-06-30 10:41:20 +00:00
entries.hashes.each do |entry|
content_type.entries.create(entry)
2011-06-30 10:41:20 +00:00
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 = Locomotive::ContentType.where(:name => name).first
field = content_type.entries_custom_fields.detect { |f| f.label == field }
2012-02-29 01:11:56 +00:00
content_type.group_by_field_id = field._id
2011-06-30 10:41:20 +00:00
content_type.save.should be_true
end
Then %r{^I should not see (\d+) times the "([^"]*)" field$} do |n, field|
page.all(:css, "#content_#{field.underscore.downcase}_input").size.should_not == n.to_i
end