has_many target is not exported correctly (issue #165) + fix the import function as well
This commit is contained in:
parent
3ad8101ed6
commit
2d4f3df106
@ -6,3 +6,4 @@
|
|||||||
- Adding indexes for pages to avoid "Mongo::OperationFailure: too much data" errors (#159)
|
- Adding indexes for pages to avoid "Mongo::OperationFailure: too much data" errors (#159)
|
||||||
- better spanish translations (#161, #162)
|
- 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
|
@ -44,10 +44,3 @@ Scenario: I add a project to a client
|
|||||||
And I wait until the has many selector is visible
|
And I wait until the has many selector is visible
|
||||||
Then I should see "Fun project" within the list of added items
|
Then I should see "Fun project" within the list of added items
|
||||||
And "Fun project" should not be an option for "label"
|
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
|
|
||||||
|
@ -112,9 +112,19 @@ module Locomotive
|
|||||||
# custom_fields
|
# custom_fields
|
||||||
fields = []
|
fields = []
|
||||||
content_type.content_custom_fields.each do |field|
|
content_type.content_custom_fields.each do |field|
|
||||||
fields << {
|
field_attributes = self.extract_attributes(field, %w(label kind hint required))
|
||||||
field._alias => self.extract_attributes(field, %w(label kind hint target 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
|
end
|
||||||
|
|
||||||
attributes['fields'] = fields
|
attributes['fields'] = fields
|
||||||
@ -284,9 +294,11 @@ module Locomotive
|
|||||||
when 'text'
|
when 'text'
|
||||||
self.replace_asset_urls_in(content.send(field._name.to_sym) || '')
|
self.replace_asset_urls_in(content.send(field._name.to_sym) || '')
|
||||||
when 'has_one'
|
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'
|
when 'has_many'
|
||||||
|
unless field.reverse_has_many?
|
||||||
content.send(field.safe_alias.to_sym).collect(&:highlighted_field_value)
|
content.send(field.safe_alias.to_sym).collect(&:highlighted_field_value)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
content.send(field.safe_alias.to_sym)
|
content.send(field.safe_alias.to_sym)
|
||||||
end)
|
end)
|
||||||
|
@ -78,6 +78,8 @@ module Locomotive
|
|||||||
fields.each_with_index do |data, position|
|
fields.each_with_index do |data, position|
|
||||||
name, data = data.keys.first, data.values.first
|
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
|
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] }
|
field = content_type.content_custom_fields.detect { |f| f._alias == attributes[:_alias] }
|
||||||
@ -88,7 +90,9 @@ module Locomotive
|
|||||||
|
|
||||||
field.attributes = attributes
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -97,9 +101,16 @@ module Locomotive
|
|||||||
content_type.content_custom_fields.each do |field|
|
content_type.content_custom_fields.each do |field|
|
||||||
next unless ['has_many', 'has_one'].include?(field.kind)
|
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
|
end
|
||||||
|
|
||||||
content_type.save
|
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
|
content_type.content_custom_fields.size.should == 9
|
||||||
end
|
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
|
it 'correctly imports content type names' do
|
||||||
content_type = @site.content_types.where(:slug => 'projects').first
|
content_type = @site.content_types.where(:slug => 'projects').first
|
||||||
content_type.name.should == 'My projects'
|
content_type.name.should == 'My projects'
|
||||||
|
Loading…
Reference in New Issue
Block a user