From a532bb4c60fddbe841867947fedc52d8da46e170 Mon Sep 17 00:00:00 2001 From: "M. Scott Ford" Date: Thu, 28 Jul 2011 00:38:18 -0400 Subject: [PATCH] Fixed issues with the way import handled the content_type.name attribute. --- lib/locomotive/import/content_types.rb | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/locomotive/import/content_types.rb b/lib/locomotive/import/content_types.rb index b656ca60..bcda7768 100644 --- a/lib/locomotive/import/content_types.rb +++ b/lib/locomotive/import/content_types.rb @@ -14,7 +14,13 @@ module Locomotive content_type = site.content_types.where(:slug => attributes['slug']).first - content_type ||= self.build_content_type(attributes.merge(:name => name)) + content_type_name = attributes['name'] || name + + if content_type.nil? + content_type = self.build_content_type(attributes.merge(:name => content_type_name)) + else + self.update_attributes(content_type, attributes.merge(:name => content_type_name)) + end self.add_or_update_fields(content_type, attributes['fields']) @@ -50,14 +56,23 @@ module Locomotive def content_types database['site']['content_types'] end - - def build_content_type(data) + + def cleanse_attributes(data) attributes = { :group_by_field_name => data.delete('group_by') }.merge(data) attributes.delete_if { |name, value| %w{fields contents}.include?(name) } + attributes + end + def build_content_type(data) + attributes = cleanse_attributes(data) site.content_types.build(attributes) end + + def update_attributes(content_type, data) + attributes = cleanse_attributes(data) + content_type.update(attributes) + end def add_or_update_fields(content_type, fields) fields.each_with_index do |data, position|