the position of a content type field was missing when fetched from the filesystem

did committed Sep 05, 2015
commit ad55e1d71c3c5516b07e7cca1be0006759f35983
Showing 2 changed files with 7 additions and 5 deletions
locomotive/steam/adapters/filesystem/yaml_loaders/content_type.rb b/lib/locomotive/steam/adapters/filesystem/yaml_loaders/content_type.rb +6 -5
@@ @@ -26,15 +26,16 @@ module Locomotive
end
def build_fields(list)
- list.map do |attributes|
- build_field(attributes.keys.first, attributes.values.first)
+ list.each_with_index.map do |attributes, index|
+ build_field(attributes.keys.first, attributes.values.first, index)
end
end
- def build_field(name, attributes)
+ def build_field(name, attributes, position)
attributes.tap do |attributes|
- attributes[:name] = name.to_s
- attributes[:type] = (attributes[:type] || 'string').to_s.downcase
+ attributes[:name] = name.to_s
+ attributes[:type] = (attributes[:type] || 'string').to_s.downcase
+ attributes[:position] ||= position
if attributes[:label].blank?
attributes[:label] = name.to_s.humanize
spec/unit/adapters/filesystem/yaml_loaders/content_type_spec.rb +1 -0
@@ @@ -18,6 +18,7 @@ describe Locomotive::Steam::Adapters::Filesystem::YAMLLoaders::ContentType do
expect(subject.size).to eq 5
expect(subject.first[:slug]).to eq('bands')
expect(subject.first[:entries_custom_fields].size).to eq 5
+ expect(subject.first[:entries_custom_fields].first[:position]).to eq 0
end
end