From 881f74bb3201f096b93a5a6000fca5f627eccb39 Mon Sep 17 00:00:00 2001 From: Pietro Giorgianni Date: Thu, 16 Feb 2012 12:37:09 +0100 Subject: [PATCH 1/3] Spec: exporting a manually ordered content type. --- spec/lib/locomotive/export_spec.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/spec/lib/locomotive/export_spec.rb b/spec/lib/locomotive/export_spec.rb index da169829..36e849ef 100644 --- a/spec/lib/locomotive/export_spec.rb +++ b/spec/lib/locomotive/export_spec.rb @@ -60,6 +60,27 @@ describe Locomotive::Export do end + context 'manually ordered content_types' do + before(:each) do + site = FactoryGirl.build('another site') + Site.stubs(:find).returns(site) + @wish_type = build_wish_type(site) + @wish_type.contents.build(:what => 'nothing', :_position_in_list => 2) + @wish_type.contents.build(:what => 'everything', :_position_in_list => 1) + @wish_data = ::Locomotive::Export.new(site).send(:extract_contents, @wish_type) + end + + it 'should have the right order' do + @wish_data.should == [{'everything' => {}}, {'nothing' => {}}] + end + end + + def build_wish_type(site) + site.content_types.build(:slug => 'wishes', :name => 'Wishes', :site => site, :order_by => '_position_in_list', :order_direction => 'asc', :highlighted_field_name => 'custom_field_1').tap do |content_type| + content_type.content_custom_fields.build :label => 'What', :_alias => 'what', :kind => 'string' + end + end + context '#zipfile' do before(:all) do From ad3fefe304a27fcb0279f3c43d7cad2be70382c0 Mon Sep 17 00:00:00 2001 From: Pietro Giorgianni Date: Thu, 16 Feb 2012 12:37:52 +0100 Subject: [PATCH 2/3] Export contents preserving manual order. --- lib/locomotive/export.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/locomotive/export.rb b/lib/locomotive/export.rb index 78aab45f..40744004 100644 --- a/lib/locomotive/export.rb +++ b/lib/locomotive/export.rb @@ -277,7 +277,7 @@ module Locomotive highlighted_field_name = content_type.highlighted_field_name - content_type.contents.each do |content| + content_type.ordered_contents.each do |content| hash = {} content.custom_fields.each do |field| From de3d1b0a125ad2cd0ead8c4a3414854b42db1f27 Mon Sep 17 00:00:00 2001 From: Pietro Giorgianni Date: Thu, 16 Feb 2012 12:38:27 +0100 Subject: [PATCH 3/3] Ensure that fixtured content types always define order_by. --- spec/factories.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/factories.rb b/spec/factories.rb index 3968ccb9..8a60b85c 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -136,6 +136,7 @@ FactoryGirl.define do factory :content_type do name 'My project' site { Site.where(:subdomain => "acme").first || Factory(:site) } + order_by 'created_at' end factory :content_instance do