Merge pull request #149 from corgibytes/content_type_names

Fixed issue with the way import was handling content_type name attributes
This commit is contained in:
Didier Lafforgue 2011-07-28 06:09:23 -07:00
commit 92ec012472
3 changed files with 65 additions and 3 deletions

View File

@ -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!(attributes)
end
def add_or_update_fields(content_type, fields)
fields.each_with_index do |data, position|

View File

@ -18,6 +18,18 @@ Factory.define "another site", :parent => "test site" do |s|
s.subdomain "test2"
end
Factory.define "existing site", :parent => "site" do |s|
s.name "Locomotive site with existing models"
s.subdomain "models"
s.after_build do |site_with_models|
site_with_models.content_types.build(
:slug => 'projects',
:name => 'Existing name',
:description => 'Existing description',
:order_by => 'created_at')
end
end
# Accounts ##
Factory.define :account do |a|

View File

@ -24,6 +24,11 @@ describe Locomotive::Import::Job do
content_type = @site.content_types.where(:slug => 'projects').first
content_type.content_custom_fields.size.should == 9
end
it 'correctly imports content type names' do
content_type = @site.content_types.where(:slug => 'projects').first
content_type.name.should == 'My projects'
end
it 'converts correctly the order_by option for content types' do
content_type = @site.content_types.where(:slug => 'messages').first
@ -90,5 +95,35 @@ describe Locomotive::Import::Job do
end
end
context 'with an existing site' do
before(:all) do
@site = Factory("existing site")
job = Locomotive::Import::Job.new(FixturedTheme.duplicate_and_open('default.zip'), @site, { :samples => true, :reset => false })
job.perform
job.success nil
end
context 'updates to content_type attributes' do
before(:all) do
@projects = content_type = @site.content_types.where(:slug => 'projects').first
end
it 'includes new name' do
@projects.name.should == 'My projects'
end
it 'includes new description' do
@projects.description.should == 'My portfolio'
end
it 'includes new order by' do
@projects.order_by.should == '_position_in_list'
end
end
end
end