has_many target is not exported correctly (issue #165) + fix the import function as well
This commit is contained in:
parent
3ad8101ed6
commit
2d4f3df106
@ -5,4 +5,5 @@
|
||||
- rake task to create an admin account for the first site (#158)
|
||||
- Adding indexes for pages to avoid "Mongo::OperationFailure: too much data" errors (#159)
|
||||
- better spanish translations (#161, #162)
|
||||
- fix carrierwave version to 0.5.6 (#163)
|
||||
- fix carrierwave version to 0.5.6 (#163)
|
||||
- has_many target is not exported correctly (issue #165) + fix the import module as well
|
@ -43,11 +43,4 @@ Scenario: I add a project to a client
|
||||
When I press "Save"
|
||||
And I wait until the has many selector is visible
|
||||
Then I should see "Fun project" within the list of added items
|
||||
And "Fun project" should not be an option for "label"
|
||||
#
|
||||
# And I should not see "Empty" within the list of items
|
||||
# When I go to the "Clients" model list page
|
||||
# And I follow "Beta, Inc"
|
||||
# And I wait until the has many selector is visible
|
||||
# Then I should see "Fun project" within the list of added items
|
||||
# And I should not see "Empty" within the list of items
|
||||
And "Fun project" should not be an option for "label"
|
@ -112,9 +112,19 @@ module Locomotive
|
||||
# custom_fields
|
||||
fields = []
|
||||
content_type.content_custom_fields.each do |field|
|
||||
fields << {
|
||||
field._alias => self.extract_attributes(field, %w(label kind hint target required))
|
||||
}
|
||||
field_attributes = self.extract_attributes(field, %w(label kind hint required))
|
||||
|
||||
if field.target.present?
|
||||
target_klass = field['target'].constantize
|
||||
|
||||
field_attributes['target'] = target_klass._parent.slug
|
||||
|
||||
if field['reverse_lookup'].present?
|
||||
field_attributes['reverse'] = target_klass.custom_field_name_to_alias(field['reverse_lookup'])
|
||||
end
|
||||
end
|
||||
|
||||
fields << { field._alias => field_attributes }
|
||||
end
|
||||
|
||||
attributes['fields'] = fields
|
||||
@ -284,9 +294,11 @@ module Locomotive
|
||||
when 'text'
|
||||
self.replace_asset_urls_in(content.send(field._name.to_sym) || '')
|
||||
when 'has_one'
|
||||
content.send(field.safe_alias.to_sym).highlighted_field_value
|
||||
content.send(field.safe_alias.to_sym).highlighted_field_value rescue nil # no bound object
|
||||
when 'has_many'
|
||||
content.send(field.safe_alias.to_sym).collect(&:highlighted_field_value)
|
||||
unless field.reverse_has_many?
|
||||
content.send(field.safe_alias.to_sym).collect(&:highlighted_field_value)
|
||||
end
|
||||
else
|
||||
content.send(field.safe_alias.to_sym)
|
||||
end)
|
||||
|
@ -56,7 +56,7 @@ module Locomotive
|
||||
def content_types
|
||||
database['site']['content_types']
|
||||
end
|
||||
|
||||
|
||||
def cleanse_attributes(data)
|
||||
attributes = { :group_by_field_name => data.delete('group_by') }.merge(data)
|
||||
|
||||
@ -68,7 +68,7 @@ module Locomotive
|
||||
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)
|
||||
@ -78,6 +78,8 @@ module Locomotive
|
||||
fields.each_with_index do |data, position|
|
||||
name, data = data.keys.first, data.values.first
|
||||
|
||||
reverse_lookup = data.delete('reverse')
|
||||
|
||||
attributes = { :_alias => name, :label => name.humanize, :kind => 'string', :position => position }.merge(data).symbolize_keys
|
||||
|
||||
field = content_type.content_custom_fields.detect { |f| f._alias == attributes[:_alias] }
|
||||
@ -88,7 +90,9 @@ module Locomotive
|
||||
|
||||
field.attributes = attributes
|
||||
|
||||
field[:kind] = field[:kind].downcase # old versions of the kind are capitalized
|
||||
field[:kind] = field[:kind].downcase # old versions of the kind field are capitalized
|
||||
|
||||
field[:tmp_reverse_lookup] = reverse_lookup # use the ability in mongoid to set free attributes on the fly
|
||||
end
|
||||
end
|
||||
|
||||
@ -97,9 +101,16 @@ module Locomotive
|
||||
content_type.content_custom_fields.each do |field|
|
||||
next unless ['has_many', 'has_one'].include?(field.kind)
|
||||
|
||||
target_content_type = site.content_types.where(:name => field.target).first
|
||||
target_content_type = site.content_types.where(:slug => field.target).first
|
||||
|
||||
field.target = target_content_type.content_klass.to_s if target_content_type
|
||||
if target_content_type
|
||||
field.target = target_content_type.content_klass.to_s
|
||||
|
||||
if field[:tmp_reverse_lookup]
|
||||
field.reverse_lookup = field[:tmp_reverse_lookup]
|
||||
field.reverse_lookup = field.safe_reverse_lookup # make sure we store the true value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
content_type.save
|
||||
|
BIN
spec/fixtures/themes/default.zip
vendored
BIN
spec/fixtures/themes/default.zip
vendored
Binary file not shown.
@ -30,6 +30,13 @@ describe Locomotive::Import::Job do
|
||||
content_type.content_custom_fields.size.should == 9
|
||||
end
|
||||
|
||||
it 'replaces the target and the reverse_lookup values by the correct ones in a has_many relationship' do
|
||||
content_type = @site.content_types.where(:slug => 'clients').first
|
||||
field = content_type.content_custom_fields.last
|
||||
field.target.should match /^ContentContentType/
|
||||
field.reverse_lookup.should == 'custom_field_8'
|
||||
end
|
||||
|
||||
it 'correctly imports content type names' do
|
||||
content_type = @site.content_types.where(:slug => 'projects').first
|
||||
content_type.name.should == 'My projects'
|
||||
|
Loading…
Reference in New Issue
Block a user