2011-06-30 10:41:20 +00:00
|
|
|
Given %r{^I have a custom model named "([^"]*)" with$} do |name, fields|
|
2011-12-06 14:46:21 +00:00
|
|
|
site = Locomotive::Site.first
|
2012-03-01 10:07:22 +00:00
|
|
|
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|
|
2012-03-01 10:07:22 +00:00
|
|
|
# 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
|
2011-08-11 20:45:46 +00:00
|
|
|
end
|
|
|
|
|
2011-12-22 23:45:32 +00:00
|
|
|
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
|
2011-06-29 12:00:26 +00:00
|
|
|
end
|
|
|
|
|
2011-06-30 10:41:20 +00:00
|
|
|
Given %r{^I have "([^"]*)" as "([^"]*)" values of the "([^"]*)" model$} do |values, field, name|
|
2011-12-06 14:46:21 +00:00
|
|
|
content_type = Locomotive::ContentType.where(:name => name).first
|
2011-12-22 23:45:32 +00:00
|
|
|
field = content_type.entries_custom_fields.detect { |f| f.label == field }
|
2011-06-30 10:41:20 +00:00
|
|
|
field.should_not be_nil
|
|
|
|
|
2011-12-22 23:45:32 +00:00
|
|
|
if field.type == 'select'
|
2011-06-30 10:41:20 +00:00
|
|
|
values.split(',').collect(&:strip).each do |name|
|
2011-12-22 23:45:32 +00:00
|
|
|
field.select_options.build :name => name
|
2011-06-30 10:41:20 +00:00
|
|
|
end
|
|
|
|
content_type.save.should be_true
|
|
|
|
else
|
2011-12-22 23:45:32 +00:00
|
|
|
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|
|
2011-12-06 14:46:21 +00:00
|
|
|
content_type = Locomotive::ContentType.where(:name => name).first
|
2011-06-30 10:41:20 +00:00
|
|
|
entries.hashes.each do |entry|
|
2011-12-22 23:45:32 +00:00
|
|
|
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|
|
2011-12-06 14:46:21 +00:00
|
|
|
content_type = Locomotive::ContentType.where(:name => name).first
|
2011-12-22 23:45:32 +00:00
|
|
|
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
|
2011-07-02 11:48:21 +00:00
|
|
|
end
|
|
|
|
|
2011-07-03 00:07:46 +00:00
|
|
|
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
|