datashift 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +63 -64
- data/Rakefile +4 -7
- data/VERSION +1 -1
- data/datashift.gemspec +92 -62
- data/lib/applications/apache_poi_extensions.rb +62 -0
- data/lib/applications/excel.rb +78 -0
- data/lib/applications/excel_base.rb +65 -0
- data/lib/applications/jexcel_file.rb +222 -0
- data/lib/applications/jexcel_file_extensions.rb +244 -0
- data/lib/applications/jruby/{jexcel_file.rb → old_pre_proxy_jexcel_file.rb} +0 -0
- data/lib/applications/ruby_poi_translations.rb +64 -0
- data/lib/applications/spreadsheet_extensions.rb +31 -0
- data/lib/datashift/method_details_manager.rb +4 -0
- data/lib/exporters/csv_exporter.rb +3 -1
- data/lib/exporters/excel_exporter.rb +59 -74
- data/lib/generators/excel_generator.rb +70 -74
- data/lib/guards.rb +57 -0
- data/lib/loaders/excel_loader.rb +105 -105
- data/lib/loaders/loader_base.rb +43 -21
- data/lib/loaders/paperclip/attachment_loader.rb +104 -0
- data/lib/loaders/paperclip/datashift_paperclip.rb +78 -0
- data/lib/loaders/paperclip/{image_loader.rb → image_loading.rb} +2 -18
- data/lib/thor/{generate_excel.thor → generate.thor} +48 -0
- data/lib/thor/paperclip.thor +85 -0
- data/lib/thor/tools.thor +23 -2
- data/spec/Gemfile +1 -7
- data/spec/csv_exporter_spec.rb +4 -4
- data/spec/csv_loader_spec.rb +1 -1
- data/spec/excel_exporter_spec.rb +43 -45
- data/spec/excel_generator_spec.rb +132 -60
- data/spec/excel_loader_spec.rb +134 -140
- data/spec/excel_spec.rb +179 -0
- data/spec/fixtures/ProjectsMultiCategoriesHeaderLookup.xls +0 -0
- data/spec/fixtures/config/database.yml +2 -2
- data/spec/fixtures/db/datashift_test_models_db.sqlite +0 -0
- data/spec/{db → fixtures/db}/migrate/20110803201325_create_test_bed.rb +0 -0
- data/spec/fixtures/load_datashift.thor +3 -0
- data/spec/fixtures/models/category.rb +7 -0
- data/spec/fixtures/models/empty.rb +2 -0
- data/spec/fixtures/models/loader_release.rb +10 -0
- data/spec/fixtures/models/long_and_complex_table_linked_to_version.rb +6 -0
- data/spec/fixtures/models/milestone.rb +8 -0
- data/spec/fixtures/models/owner.rb +5 -0
- data/spec/fixtures/models/project.rb +26 -0
- data/spec/fixtures/models/test_model_defs.rb +67 -0
- data/spec/fixtures/models/version.rb +7 -0
- data/spec/loader_spec.rb +4 -3
- data/spec/method_dictionary_spec.rb +7 -6
- data/spec/method_mapper_spec.rb +3 -2
- data/spec/rails_sandbox/.gitignore +15 -0
- data/spec/rails_sandbox/Gemfile +40 -0
- data/spec/rails_sandbox/README.rdoc +261 -0
- data/spec/rails_sandbox/Rakefile +7 -0
- data/spec/rails_sandbox/app/assets/images/rails.png +0 -0
- data/spec/rails_sandbox/app/assets/javascripts/application.js +15 -0
- data/spec/rails_sandbox/app/assets/stylesheets/application.css +13 -0
- data/spec/rails_sandbox/app/controllers/application_controller.rb +3 -0
- data/spec/rails_sandbox/app/helpers/application_helper.rb +2 -0
- data/spec/rails_sandbox/app/mailers/.gitkeep +0 -0
- data/spec/rails_sandbox/app/models/.gitkeep +0 -0
- data/spec/rails_sandbox/app/models/category.rb +7 -0
- data/spec/rails_sandbox/app/models/empty.rb +2 -0
- data/spec/rails_sandbox/app/models/loader_release.rb +10 -0
- data/spec/rails_sandbox/app/models/long_and_complex_table_linked_to_version.rb +6 -0
- data/spec/rails_sandbox/app/models/milestone.rb +8 -0
- data/spec/rails_sandbox/app/models/owner.rb +5 -0
- data/spec/rails_sandbox/app/models/project.rb +26 -0
- data/spec/rails_sandbox/app/models/test_model_defs.rb +67 -0
- data/spec/rails_sandbox/app/models/version.rb +7 -0
- data/spec/rails_sandbox/app/views/layouts/application.html.erb +14 -0
- data/spec/rails_sandbox/config.ru +4 -0
- data/spec/rails_sandbox/config/application.rb +62 -0
- data/spec/rails_sandbox/config/boot.rb +6 -0
- data/spec/rails_sandbox/config/database.yml +20 -0
- data/spec/rails_sandbox/config/environment.rb +5 -0
- data/spec/rails_sandbox/config/environments/development.rb +37 -0
- data/spec/rails_sandbox/config/environments/production.rb +67 -0
- data/spec/rails_sandbox/config/environments/test.rb +37 -0
- data/spec/rails_sandbox/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails_sandbox/config/initializers/inflections.rb +15 -0
- data/spec/rails_sandbox/config/initializers/mime_types.rb +5 -0
- data/spec/rails_sandbox/config/initializers/secret_token.rb +7 -0
- data/spec/rails_sandbox/config/initializers/session_store.rb +8 -0
- data/spec/rails_sandbox/config/initializers/wrap_parameters.rb +14 -0
- data/spec/rails_sandbox/config/locales/en.yml +5 -0
- data/spec/rails_sandbox/config/routes.rb +58 -0
- data/spec/rails_sandbox/db/migrate/20110803201325_create_test_bed.rb +96 -0
- data/spec/rails_sandbox/db/schema.rb +81 -0
- data/spec/rails_sandbox/db/seeds.rb +7 -0
- data/spec/rails_sandbox/lib/assets/.gitkeep +0 -0
- data/spec/rails_sandbox/lib/tasks/.gitkeep +0 -0
- data/spec/rails_sandbox/log/.gitkeep +0 -0
- data/spec/rails_sandbox/public/404.html +26 -0
- data/spec/rails_sandbox/public/422.html +26 -0
- data/spec/rails_sandbox/public/500.html +25 -0
- data/spec/rails_sandbox/public/favicon.ico +0 -0
- data/spec/rails_sandbox/public/index.html +241 -0
- data/spec/rails_sandbox/public/robots.txt +5 -0
- data/spec/rails_sandbox/script/rails +6 -0
- data/spec/rails_sandbox/test/fixtures/.gitkeep +0 -0
- data/spec/rails_sandbox/test/functional/.gitkeep +0 -0
- data/spec/rails_sandbox/test/integration/.gitkeep +0 -0
- data/spec/rails_sandbox/test/performance/browsing_test.rb +12 -0
- data/spec/rails_sandbox/test/test_helper.rb +13 -0
- data/spec/rails_sandbox/test/unit/.gitkeep +0 -0
- data/spec/rails_sandbox/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/rails_sandbox/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/rails_sandbox/vendor/plugins/.gitkeep +0 -0
- data/spec/spec_helper.rb +144 -121
- data/spec/thor_spec.rb +34 -14
- metadata +207 -194
- data/lib/helpers/spree_helper.rb +0 -213
- data/lib/loaders/spreadsheet_loader.rb +0 -144
- data/lib/loaders/spree/image_loader.rb +0 -90
- data/lib/loaders/spree/product_loader.rb +0 -354
- data/lib/thor/spree/bootstrap_cleanup.thor +0 -61
- data/lib/thor/spree/products_images.thor +0 -252
- data/lib/thor/spree/reports.thor +0 -56
- data/public/spree/products/large/DEMO_001_ror_bag.jpeg +0 -0
- data/public/spree/products/large/DEMO_002_Powerstation.jpg +0 -0
- data/public/spree/products/large/DEMO_003_ror_mug.jpeg +0 -0
- data/public/spree/products/mini/DEMO_001_ror_bag.jpeg +0 -0
- data/public/spree/products/mini/DEMO_002_Powerstation.jpg +0 -0
- data/public/spree/products/mini/DEMO_003_ror_mug.jpeg +0 -0
- data/public/spree/products/original/DEMO_001_ror_bag.jpeg +0 -0
- data/public/spree/products/original/DEMO_002_Powerstation.jpg +0 -0
- data/public/spree/products/original/DEMO_003_ror_mug.jpeg +0 -0
- data/public/spree/products/product/DEMO_001_ror_bag.jpeg +0 -0
- data/public/spree/products/product/DEMO_002_Powerstation.jpg +0 -0
- data/public/spree/products/product/DEMO_003_ror_mug.jpeg +0 -0
- data/public/spree/products/small/DEMO_001_ror_bag.jpeg +0 -0
- data/public/spree/products/small/DEMO_002_Powerstation.jpg +0 -0
- data/public/spree/products/small/DEMO_003_ror_mug.jpeg +0 -0
- data/spec/fixtures/datashift_Spree_db.sqlite +0 -0
- data/spec/fixtures/datashift_test_models_db.sqlite +0 -0
- data/spec/fixtures/negative/SpreeProdMiss1Mandatory.csv +0 -4
- data/spec/fixtures/negative/SpreeProdMiss1Mandatory.xls +0 -0
- data/spec/fixtures/negative/SpreeProdMissManyMandatory.csv +0 -4
- data/spec/fixtures/negative/SpreeProdMissManyMandatory.xls +0 -0
- data/spec/fixtures/spree/SpreeImages.xls +0 -0
- data/spec/fixtures/spree/SpreeMultiVariant.csv +0 -4
- data/spec/fixtures/spree/SpreeProducts.csv +0 -4
- data/spec/fixtures/spree/SpreeProducts.xls +0 -0
- data/spec/fixtures/spree/SpreeProductsDefaults.yml +0 -15
- data/spec/fixtures/spree/SpreeProductsMandatoryOnly.xls +0 -0
- data/spec/fixtures/spree/SpreeProductsMultiColumn.csv +0 -4
- data/spec/fixtures/spree/SpreeProductsMultiColumn.xls +0 -0
- data/spec/fixtures/spree/SpreeProductsSimple.csv +0 -4
- data/spec/fixtures/spree/SpreeProductsSimple.xls +0 -0
- data/spec/fixtures/spree/SpreeProductsWithImages.csv +0 -4
- data/spec/fixtures/spree/SpreeProductsWithImages.xls +0 -0
- data/spec/fixtures/spree/SpreeZoneExample.csv +0 -5
- data/spec/fixtures/spree/SpreeZoneExample.xls +0 -0
- data/spec/spree_exporter_spec.rb +0 -72
- data/spec/spree_generator_spec.rb +0 -96
- data/spec/spree_images_loader_spec.rb +0 -107
- data/spec/spree_loader_spec.rb +0 -375
- data/spec/spree_method_mapping_spec.rb +0 -226
- data/spec/spree_variants_loader_spec.rb +0 -189
- data/tasks/export/excel_generator.rake +0 -102
- data/tasks/import/excel.rake +0 -75
- data/test/helper.rb +0 -18
- data/test/test_interact.rb +0 -7
|
Binary file
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
"SKU","Name","Description","Available On"," Price","CostPrice","product_properties","product_properties","product_properties","Taxons","Taxons","Taxons","Option Types","Option Types","Variants","Variants","Variants","count_on_hand"
|
|
2
|
-
"DEMO_001","Demo Product for AR Loader","blah blah","2011-02-14",399.99,320.00,"test_pp_001",,,"Paintings","WaterColour",,"mime_type:jpeg","mime_type:PDF","mime_type:PNG",,,"12|6|7"
|
|
3
|
-
"DEMO_002","Demo Excel Load via Jruby","less blah","2011-05-14",100.00,30.00,"test_pp_003",,,"Paintings","Oils","Paintings>Nature>Seascape","mime_type:jpeg","mime_type:PDF","mime_type:PNG",,,"5|4|2"
|
|
4
|
-
"DEMO_003","Demo third row in future","more blah blah","2012-07-01",50.34,23.34,"test_pp_002","test_pp_003:Example free value","yet_another_property","Drawings","Landscape",,"mime_type:jpeg","mime_type:PDF","mime_type:PNG","print_type:black_white","print_type:colour","12|4|7|12|18"
|
|
Binary file
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
"SKU","Name","Description","Available On"," Price","CostPrice","count_on_hand","Option Types"
|
|
2
|
-
"SIMPLE_001","Simple Product for AR Loader","blah blah","2011-02-14",345.78,320.00,12,"mime_type"
|
|
3
|
-
"SIMPLE_002","Simple Excel Load via Jruby","less blah","2011-05-14",100.00,30.00,5,"mime_type"
|
|
4
|
-
"SIMPLE_003","Simple third row avail in future","more blah blah","2112-07-01",50.34,23.34,23,"mime_type|print_type"
|
|
Binary file
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
SKU,Name,Description,Available On, Price,CostPrice,product_properties,Taxons,Variants,count_on_hand,Images
|
|
2
|
-
DEMO_001,Demo Product for AR Loader,blah blah,14/02/2011,399.99,320,test_pp_001,Paintings|WaterColour,"mime_type:jpeg,PDF,PNG",12|6|7,fixtures/images/DEMO_001_ror_bag.jpeg
|
|
3
|
-
DEMO_002,Demo Excel Load via Jruby,less blah,14/05/2011,100,30,test_pp_003,Paintings|Landscape|Oils,"mime_type:jpeg, PDF,PNG",5|4|2,fixtures/images/DEMO_002_Powerstation.jpg
|
|
4
|
-
DEMO_003,Demo third row in future,more blah blah,01/07/2012,50.34,23.34,test_pp_002|test_pp_003:Example free value|yet_another_property,Drawings,"mime_type:jpeg,PDF,PNG|print_type:black_white,colour",12|4|7|12|18,fixtures/images/DEMO_003_ror_mug.jpeg
|
|
Binary file
|
|
Binary file
|
data/spec/spree_exporter_spec.rb
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
# Copyright:: (c) Autotelik Media Ltd 2011
|
|
2
|
-
# Author :: Tom Statter
|
|
3
|
-
# Date :: Summer 2011
|
|
4
|
-
#
|
|
5
|
-
# License:: MIT - Free, OpenSource
|
|
6
|
-
#
|
|
7
|
-
# Details:: Specification for Spree generator aspect of datashift gem.
|
|
8
|
-
#
|
|
9
|
-
# Provides Loaders and rake tasks specifically tailored for uploading or exporting
|
|
10
|
-
# Spree Products, associations and Images
|
|
11
|
-
#
|
|
12
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
|
13
|
-
|
|
14
|
-
require 'spree_helper'
|
|
15
|
-
require 'excel_exporter'
|
|
16
|
-
|
|
17
|
-
include DataShift
|
|
18
|
-
|
|
19
|
-
describe 'SpreeExporter' do
|
|
20
|
-
|
|
21
|
-
include SpecHelper
|
|
22
|
-
extend SpecHelper
|
|
23
|
-
|
|
24
|
-
before(:all) do
|
|
25
|
-
before_all_spree
|
|
26
|
-
results_clear()
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
before do
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
before_each_spree # inits tests, cleans DB setups model types
|
|
34
|
-
|
|
35
|
-
@Taxon_klass.delete_all
|
|
36
|
-
|
|
37
|
-
# Create some test data
|
|
38
|
-
root = @Taxonomy_klass.create( :name => 'Paintings' )
|
|
39
|
-
|
|
40
|
-
@Taxon_klass.create( :name => 'Landscape', :description => "Nice paintings", :taxonomy_id => root.id )
|
|
41
|
-
@Taxon_klass.create( :name => 'Sea', :description => "Waves and sand", :taxonomy_id => root.id )
|
|
42
|
-
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it "should export any Spree model to .xls spreedsheet" do
|
|
46
|
-
|
|
47
|
-
expect = result_file('taxon_export_spec.xls')
|
|
48
|
-
|
|
49
|
-
exporter = ExcelExporter.new(expect)
|
|
50
|
-
|
|
51
|
-
items = @Taxon_klass.all
|
|
52
|
-
|
|
53
|
-
exporter.export(items)
|
|
54
|
-
|
|
55
|
-
File.exists?(expect).should be_true
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it "should export a Spree model and associations to .xls spreedsheet" do
|
|
59
|
-
|
|
60
|
-
expect = result_file('taxon_and_assoc_export_spec.xls')
|
|
61
|
-
|
|
62
|
-
exporter = ExcelExporter.new(expect)
|
|
63
|
-
|
|
64
|
-
items = @Taxon_klass.all
|
|
65
|
-
|
|
66
|
-
exporter.export_with_associations(@Taxon_klass, items)
|
|
67
|
-
|
|
68
|
-
File.exists?(expect).should be_true
|
|
69
|
-
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
end
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
# Copyright:: (c) Autotelik Media Ltd 2011
|
|
2
|
-
# Author :: Tom Statter
|
|
3
|
-
# Date :: Summer 2011
|
|
4
|
-
#
|
|
5
|
-
# License:: MIT - Free, OpenSource
|
|
6
|
-
#
|
|
7
|
-
# Details:: Specification for Spree generator aspect of datashift gem.
|
|
8
|
-
#
|
|
9
|
-
# Provides Loaders and rake tasks specifically tailored for uploading or exporting
|
|
10
|
-
# Spree Products, associations and Images
|
|
11
|
-
#
|
|
12
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
|
13
|
-
|
|
14
|
-
require 'spree_helper'
|
|
15
|
-
require 'excel_generator'
|
|
16
|
-
|
|
17
|
-
include DataShift
|
|
18
|
-
|
|
19
|
-
describe 'SpreeGenerator' do
|
|
20
|
-
|
|
21
|
-
include SpecHelper
|
|
22
|
-
extend SpecHelper
|
|
23
|
-
|
|
24
|
-
before(:all) do
|
|
25
|
-
before_all_spree
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
before do
|
|
29
|
-
|
|
30
|
-
before_each_spree # inits tests, cleans DB setups model types
|
|
31
|
-
|
|
32
|
-
# Create some test data
|
|
33
|
-
root = @Taxonomy_klass.create( :name => 'Paintings' )
|
|
34
|
-
|
|
35
|
-
if(SpreeHelper::version.to_f > 1 )
|
|
36
|
-
root.taxons.create( :name => 'Landscape' )
|
|
37
|
-
root.taxons.create( :name => 'Sea' )
|
|
38
|
-
else
|
|
39
|
-
@Taxon_klass.create( :name => 'Landscape', :taxonomy => root )
|
|
40
|
-
@Taxon_klass.create( :name => 'Sea', :taxonomy => root )
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it "should export any Spree model to .xls spreedsheet" do
|
|
45
|
-
|
|
46
|
-
expect = result_file('taxonomy_export_spec.xls')
|
|
47
|
-
|
|
48
|
-
excel = ExcelGenerator.new(expect)
|
|
49
|
-
|
|
50
|
-
excel.generate(@Taxonomy_klass)
|
|
51
|
-
|
|
52
|
-
File.exists?(expect).should be_true
|
|
53
|
-
|
|
54
|
-
puts "You can check results manually in file #{expect}"
|
|
55
|
-
|
|
56
|
-
expect = result_file('taxon_export_spec.xls')
|
|
57
|
-
|
|
58
|
-
excel.filename = expect
|
|
59
|
-
|
|
60
|
-
excel.generate(@Taxon_klass)
|
|
61
|
-
|
|
62
|
-
File.exists?(expect).should be_true
|
|
63
|
-
|
|
64
|
-
puts "You can check results manually in file #{expect}"
|
|
65
|
-
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it "should export Spree Product and all associations to .xls spreedsheet" do
|
|
69
|
-
|
|
70
|
-
expect = result_file('product_and_assoc_export_spec.xls')
|
|
71
|
-
|
|
72
|
-
excel = ExcelGenerator.new(expect)
|
|
73
|
-
|
|
74
|
-
excel.generate_with_associations(@klass)
|
|
75
|
-
|
|
76
|
-
File.exists?(expect).should be_true
|
|
77
|
-
|
|
78
|
-
puts "You can check results manually in file #{expect}"
|
|
79
|
-
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
it "should be able to exclude single associations from template" do
|
|
83
|
-
|
|
84
|
-
expect = result_file('product_and_assoc_export_spec.xls')
|
|
85
|
-
|
|
86
|
-
excel = ExcelGenerator.new(expect)
|
|
87
|
-
|
|
88
|
-
excel.generate_with_associations(@klass, :exclude => :has_many)
|
|
89
|
-
|
|
90
|
-
File.exists?(expect).should be_true
|
|
91
|
-
|
|
92
|
-
puts "You can check results manually in file #{expect}"
|
|
93
|
-
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
end
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
# Copyright:: (c) Autotelik Media Ltd 2011
|
|
2
|
-
# Author :: Tom Statter
|
|
3
|
-
# Date :: Summer 2011
|
|
4
|
-
#
|
|
5
|
-
# License:: MIT - Free, OpenSource
|
|
6
|
-
#
|
|
7
|
-
# Details:: Specification for Spree aspect of datashift gem.
|
|
8
|
-
#
|
|
9
|
-
# Provides Loaders and rake tasks specifically tailored for uploading or exporting
|
|
10
|
-
# Spree Products, associations and Images
|
|
11
|
-
#
|
|
12
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
|
13
|
-
|
|
14
|
-
require 'spree_helper'
|
|
15
|
-
require 'product_loader'
|
|
16
|
-
|
|
17
|
-
include DataShift
|
|
18
|
-
|
|
19
|
-
describe 'SpreeImageLoading' do
|
|
20
|
-
|
|
21
|
-
include SpecHelper
|
|
22
|
-
extend SpecHelper
|
|
23
|
-
|
|
24
|
-
before(:all) do
|
|
25
|
-
before_all_spree
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
before(:each) do
|
|
29
|
-
|
|
30
|
-
begin
|
|
31
|
-
|
|
32
|
-
before_each_spree
|
|
33
|
-
|
|
34
|
-
@Image_klass.count.should == 0
|
|
35
|
-
@Product_klass.count.should == 0
|
|
36
|
-
|
|
37
|
-
MethodDictionary.clear
|
|
38
|
-
|
|
39
|
-
# For Spree important to get instance methods too as Product delegates
|
|
40
|
-
# many important attributes to Variant (master)
|
|
41
|
-
MethodDictionary.find_operators( @Product_klass, :instance_methods => true )
|
|
42
|
-
|
|
43
|
-
@product_loader = DataShift::SpreeHelper::ProductLoader.new
|
|
44
|
-
rescue => e
|
|
45
|
-
puts e.inspect
|
|
46
|
-
puts e.backtrace
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
it "should create Image from path in Product loading column from CSV", :fail => true do
|
|
52
|
-
|
|
53
|
-
options = {:mandatory => ['sku', 'name', 'price']}
|
|
54
|
-
|
|
55
|
-
@product_loader.perform_load( SpecHelper::spree_fixture('SpreeProductsWithImages.csv'), options )
|
|
56
|
-
|
|
57
|
-
@Image_klass.all.each_with_index {|i, x| puts "SPEC CHECK IMAGE #{x}", i.inspect }
|
|
58
|
-
|
|
59
|
-
p = @Product_klass.find_by_name("Demo Product for AR Loader")
|
|
60
|
-
|
|
61
|
-
p.name.should == "Demo Product for AR Loader"
|
|
62
|
-
|
|
63
|
-
p.images.should have_exactly(1).items
|
|
64
|
-
p.master.images.should have_exactly(1).items
|
|
65
|
-
|
|
66
|
-
@Product_klass.all.each {|p| p.images.should have_exactly(1).items }
|
|
67
|
-
|
|
68
|
-
@Image_klass.count.should == 3
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
it "should create Image from path in Product loading column from Excel", :fail => true do
|
|
73
|
-
|
|
74
|
-
options = {:mandatory => ['sku', 'name', 'price']}
|
|
75
|
-
|
|
76
|
-
@product_loader.perform_load( SpecHelper::spree_fixture('SpreeProductsWithImages.xls'), options )
|
|
77
|
-
|
|
78
|
-
p = @klass.find_by_name("Demo Product for AR Loader")
|
|
79
|
-
|
|
80
|
-
p.name.should == "Demo Product for AR Loader"
|
|
81
|
-
p.images.should have_exactly(1).items
|
|
82
|
-
|
|
83
|
-
@Product_klass.all.each {|p| p.images.should have_exactly(1).items }
|
|
84
|
-
|
|
85
|
-
@Image_klass.count.should == 3
|
|
86
|
-
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
it "should be able to assign Images to preloaded Products" do
|
|
90
|
-
|
|
91
|
-
pending "Currently functionality supplied by a thor task images()"
|
|
92
|
-
|
|
93
|
-
MethodDictionary.find_operators( @Image_klass )
|
|
94
|
-
|
|
95
|
-
@Product_klass.count.should == 0
|
|
96
|
-
|
|
97
|
-
@product_loader.perform_load( SpecHelper::spree_fixture('SpreeProducts.xls'))
|
|
98
|
-
|
|
99
|
-
@Image_klass.all.size.should == 0
|
|
100
|
-
|
|
101
|
-
loader = DataShift::SpreeHelper::ImageLoader.new(nil, options)
|
|
102
|
-
|
|
103
|
-
loader.perform_load( SpecHelper::spree_fixture('SpreeImages.xls'), options )
|
|
104
|
-
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
end
|
data/spec/spree_loader_spec.rb
DELETED
|
@@ -1,375 +0,0 @@
|
|
|
1
|
-
# Copyright:: (c) Autotelik Media Ltd 2011
|
|
2
|
-
# Author :: Tom Statter
|
|
3
|
-
# Date :: Summer 2011
|
|
4
|
-
#
|
|
5
|
-
# License:: MIT - Free, OpenSource
|
|
6
|
-
#
|
|
7
|
-
# Details:: Specification for Spree aspect of datashift gem.
|
|
8
|
-
#
|
|
9
|
-
# Provides Loaders and rake tasks specifically tailored for uploading or exporting
|
|
10
|
-
# Spree Products, associations and Images
|
|
11
|
-
#
|
|
12
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
|
13
|
-
|
|
14
|
-
require 'spree_helper'
|
|
15
|
-
require 'product_loader'
|
|
16
|
-
|
|
17
|
-
include DataShift
|
|
18
|
-
|
|
19
|
-
describe 'SpreeLoader' do
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
include SpecHelper
|
|
23
|
-
extend SpecHelper
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
before(:all) do
|
|
27
|
-
before_all_spree
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
before(:each) do
|
|
31
|
-
|
|
32
|
-
begin
|
|
33
|
-
|
|
34
|
-
before_each_spree
|
|
35
|
-
|
|
36
|
-
@Product_klass.count.should == 0
|
|
37
|
-
@Taxon_klass.count.should == 0
|
|
38
|
-
@Variant_klass.count.should == 0
|
|
39
|
-
|
|
40
|
-
MethodDictionary.clear
|
|
41
|
-
|
|
42
|
-
# For Spree important to get instance methods too as Product delegates
|
|
43
|
-
# many important attributes to Variant (master)
|
|
44
|
-
MethodDictionary.find_operators( @Product_klass, :instance_methods => true )
|
|
45
|
-
|
|
46
|
-
# want to test both lookup and dynamic creation - this Taxonomy should be found, rest created
|
|
47
|
-
root = @Taxonomy_klass.create( :name => 'Paintings' )
|
|
48
|
-
|
|
49
|
-
t = @Taxon_klass.new( :name => 'Landscape' )
|
|
50
|
-
t.taxonomy = root
|
|
51
|
-
t.save
|
|
52
|
-
|
|
53
|
-
@Taxon_klass.count.should == 2
|
|
54
|
-
|
|
55
|
-
@product_loader = DataShift::SpreeHelper::ProductLoader.new
|
|
56
|
-
rescue => e
|
|
57
|
-
puts e.inspect
|
|
58
|
-
puts e.backtrace
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
it "should process a simple .xls spreadsheet" do
|
|
64
|
-
|
|
65
|
-
@Zone_klass.delete_all
|
|
66
|
-
|
|
67
|
-
loader = ExcelLoader.new(@Zone_klass)
|
|
68
|
-
|
|
69
|
-
loader.perform_load( SpecHelper::spree_fixture('SpreeZoneExample.xls') )
|
|
70
|
-
|
|
71
|
-
loader.loaded_count.should == @Zone_klass.count
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
it "should process a simple csv file" do
|
|
75
|
-
|
|
76
|
-
@Zone_klass.delete_all
|
|
77
|
-
|
|
78
|
-
loader = CsvLoader.new(@Zone_klass)
|
|
79
|
-
|
|
80
|
-
loader.perform_load( SpecHelper::spree_fixture('SpreeZoneExample.csv') )
|
|
81
|
-
|
|
82
|
-
loader.loaded_count.should == @Zone_klass.count
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "should raise an error for missing file" do
|
|
86
|
-
lambda { test_basic_product('SpreeProductsSimple.txt') }.should raise_error BadFile
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
it "should raise an error for unsupported file types" do
|
|
90
|
-
lambda { test_basic_product('SpreeProductsDefaults.yml') }.should raise_error UnsupportedFileType
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
# Loader should perform identically regardless of source, whether csv, .xls etc
|
|
94
|
-
|
|
95
|
-
it "should load basic Products .xls via Spree loader", :fail => true do
|
|
96
|
-
test_basic_product('SpreeProductsSimple.xls')
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it "should load basic Products from .csv via Spree loader", :fail => true do
|
|
100
|
-
test_basic_product('SpreeProductsSimple.csv')
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def test_basic_product( source )
|
|
104
|
-
|
|
105
|
-
@product_loader.perform_load( SpecHelper::spree_fixture(source), :mandatory => ['sku', 'name', 'price'] )
|
|
106
|
-
|
|
107
|
-
@Product_klass.count.should == 3
|
|
108
|
-
|
|
109
|
-
# 2 products available_on set in past, 1 in future
|
|
110
|
-
@Product_klass.active.size.should == 2
|
|
111
|
-
@Product_klass.available.size.should == 2
|
|
112
|
-
|
|
113
|
-
@product_loader.failed_objects.size.should == 0
|
|
114
|
-
@product_loader.loaded_objects.size.should == 3
|
|
115
|
-
|
|
116
|
-
@product_loader.loaded_count.should == @Product_klass.count
|
|
117
|
-
|
|
118
|
-
p = @Product_klass.first
|
|
119
|
-
|
|
120
|
-
puts p.inspect
|
|
121
|
-
puts p.master.inspect
|
|
122
|
-
|
|
123
|
-
p.sku.should == "SIMPLE_001"
|
|
124
|
-
p.price.should == 345.78
|
|
125
|
-
p.name.should == "Simple Product for AR Loader"
|
|
126
|
-
p.description.should == "blah blah"
|
|
127
|
-
p.cost_price.should == 320.00
|
|
128
|
-
p.option_types.should have_exactly(1).items
|
|
129
|
-
p.option_types.should have_exactly(1).items
|
|
130
|
-
|
|
131
|
-
p.has_variants?.should be false
|
|
132
|
-
p.master.count_on_hand.should == 12
|
|
133
|
-
|
|
134
|
-
puts SpreeHelper::version
|
|
135
|
-
puts SpreeHelper::version.to_f
|
|
136
|
-
puts SpreeHelper::version > "1.1.2"
|
|
137
|
-
|
|
138
|
-
SpreeHelper::version < "1.1.3" ? p.count_on_hand.should == 12 : p.count_on_hand.should == 0
|
|
139
|
-
|
|
140
|
-
@Product_klass.last.master.count_on_hand.should == 23
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
it "should support default values for Spree Products loader" do
|
|
145
|
-
|
|
146
|
-
@expected_time = Time.now.to_s(:db)
|
|
147
|
-
|
|
148
|
-
@product_loader.set_default_value('available_on', @expected_time)
|
|
149
|
-
@product_loader.set_default_value('cost_price', 1.0 )
|
|
150
|
-
@product_loader.set_default_value('meta_description', 'super duper meta desc.' )
|
|
151
|
-
@product_loader.set_default_value('meta_keywords', 'techno dubstep d&b' )
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
@product_loader.set_prefix('sku', 'SPEC_')
|
|
155
|
-
|
|
156
|
-
test_default_values
|
|
157
|
-
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
it "should support default values from config for Spree Products loader" do
|
|
161
|
-
|
|
162
|
-
@product_loader.configure_from( SpecHelper::spree_fixture('SpreeProductsDefaults.yml') )
|
|
163
|
-
|
|
164
|
-
@product_loader.set_prefix('sku', 'SPEC_')
|
|
165
|
-
|
|
166
|
-
test_default_values
|
|
167
|
-
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
def test_default_values
|
|
171
|
-
@product_loader.perform_load( SpecHelper::spree_fixture('SpreeProductsMandatoryOnly.xls'), :mandatory => ['sku', 'name', 'price'] )
|
|
172
|
-
|
|
173
|
-
@Product_klass.count.should == 3
|
|
174
|
-
|
|
175
|
-
@product_loader.failed_objects.size.should == 0
|
|
176
|
-
@product_loader.loaded_objects.size.should == 3
|
|
177
|
-
|
|
178
|
-
p = @Product_klass.first
|
|
179
|
-
|
|
180
|
-
p.sku.should == "SPEC_SIMPLE_001"
|
|
181
|
-
|
|
182
|
-
@Product_klass.all { |p|
|
|
183
|
-
p.sku.should.include "SPEC_"
|
|
184
|
-
p.cost_price = 1.0
|
|
185
|
-
p.available_on.should == @expected_time
|
|
186
|
-
p.meta_description.should == 'super duper meta desc.'
|
|
187
|
-
p.meta_keywords.should == 'techno dubstep d&b'
|
|
188
|
-
}
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
##################
|
|
192
|
-
### PROPERTIES ###
|
|
193
|
-
##################
|
|
194
|
-
|
|
195
|
-
# Operation and results should be identical when loading multiple associations
|
|
196
|
-
# if using either single column embedded syntax, or one column per entry.
|
|
197
|
-
|
|
198
|
-
it "should load Products and multiple Properties from single column", :props => true do
|
|
199
|
-
test_properties_creation( 'SpreeProducts.xls' )
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
it "should load Products and multiple Properties from multiple column", :props => true do
|
|
203
|
-
test_properties_creation( 'SpreeProductsMultiColumn.xls' )
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
def test_properties_creation( source )
|
|
207
|
-
|
|
208
|
-
# want to test both lookup and dynamic creation - this Prop should be found, rest created
|
|
209
|
-
@Property_klass.create( :name => 'test_pp_001', :presentation => 'Test PP 001' )
|
|
210
|
-
|
|
211
|
-
@Property_klass.count.should == 1
|
|
212
|
-
|
|
213
|
-
@product_loader.perform_load( SpecHelper::spree_fixture(source), :mandatory => ['sku', 'name', 'price'] )
|
|
214
|
-
|
|
215
|
-
expected_multi_column_properties
|
|
216
|
-
|
|
217
|
-
end
|
|
218
|
-
|
|
219
|
-
def expected_multi_column_properties
|
|
220
|
-
# 3 MASTER products, 11 VARIANTS
|
|
221
|
-
@Product_klass.count.should == 3
|
|
222
|
-
@Variant_klass.count.should == 14
|
|
223
|
-
|
|
224
|
-
@Product_klass.first.properties.should have_exactly(1).items
|
|
225
|
-
|
|
226
|
-
p3 = @Product_klass.all.last
|
|
227
|
-
|
|
228
|
-
p3.properties.should have_exactly(3).items
|
|
229
|
-
|
|
230
|
-
p3.properties.should include @Property_klass.find_by_name('test_pp_002')
|
|
231
|
-
|
|
232
|
-
# Test the optional text value got set on assigned product property
|
|
233
|
-
p3.product_properties.select {|p| p.value == 'Example free value' }.should have_exactly(1).items
|
|
234
|
-
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
##############
|
|
238
|
-
### TAXONS ###
|
|
239
|
-
##############
|
|
240
|
-
|
|
241
|
-
# Operation and results should be identical when loading multiple associations
|
|
242
|
-
# if using either single column embedded syntax, or one column per entry.
|
|
243
|
-
|
|
244
|
-
it "should load Products and multiple Taxons from single column", :taxons => true do
|
|
245
|
-
test_taxon_creation( 'SpreeProducts.xls' )
|
|
246
|
-
end
|
|
247
|
-
|
|
248
|
-
it "should load Products and multiple Taxons from multiple columns", :taxons => true do
|
|
249
|
-
test_taxon_creation( 'SpreeProductsMultiColumn.xls' )
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
def test_taxon_creation( source )
|
|
253
|
-
|
|
254
|
-
# we want to test both find and find_or_create so should already have an object
|
|
255
|
-
# for find
|
|
256
|
-
@Taxonomy_klass.count.should == 1
|
|
257
|
-
@Taxon_klass.count.should == 2
|
|
258
|
-
|
|
259
|
-
@product_loader.perform_load( SpecHelper::spree_fixture(source), :mandatory => ['sku', 'name', 'price'] )
|
|
260
|
-
|
|
261
|
-
expected_multi_column_taxons
|
|
262
|
-
end
|
|
263
|
-
|
|
264
|
-
def expected_multi_column_taxons
|
|
265
|
-
|
|
266
|
-
#puts @Taxonomy_klass.all.collect( &:name).inspect
|
|
267
|
-
#puts @Taxon_klass.all.collect( &:name).inspect
|
|
268
|
-
|
|
269
|
-
# Paintings already existed and had 1 child Taxon (Landscape)
|
|
270
|
-
# 2 nested Taxon (Paintings>Nature>Seascape) created under it so expect Taxonomy :
|
|
271
|
-
|
|
272
|
-
# WaterColour
|
|
273
|
-
# Oils
|
|
274
|
-
# Paintings >Nature>Seascape + >Landscape
|
|
275
|
-
# Drawings
|
|
276
|
-
|
|
277
|
-
@Taxonomy_klass.count.should == 4
|
|
278
|
-
@Taxon_klass.count.should == 7
|
|
279
|
-
|
|
280
|
-
@Product_klass.first.taxons.should have_exactly(2).items
|
|
281
|
-
@Product_klass.last.taxons.should have_exactly(2).items
|
|
282
|
-
|
|
283
|
-
p2 = @Variant_klass.find_by_sku("DEMO_002").product
|
|
284
|
-
|
|
285
|
-
# Paintings Oils Paintings>Nature>Seascape
|
|
286
|
-
|
|
287
|
-
# ["Nature", "Paintings", "Seascape"]
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
#puts p2.taxons.collect(&:name).inspect
|
|
291
|
-
|
|
292
|
-
p2.taxons.should have_exactly(4).items
|
|
293
|
-
|
|
294
|
-
p2.taxons.collect(&:name).sort.should == ['Nature','Oils','Paintings','Seascape']
|
|
295
|
-
|
|
296
|
-
paint_parent = @Taxonomy_klass.find_by_name('Paintings')
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
puts paint_parent.taxons.collect(&:name).sort.inspect
|
|
300
|
-
|
|
301
|
-
paint_parent.taxons.should have_exactly(4).items # 3 children + all Taxonomies have a root Taxon
|
|
302
|
-
|
|
303
|
-
paint_parent.taxons.collect(&:name).sort.should == ['Landscape','Nature','Paintings','Seascape']
|
|
304
|
-
|
|
305
|
-
tn = @Taxon_klass.find_by_name('Nature') # child with children
|
|
306
|
-
ts = @Taxon_klass.find_by_name('Seascape') # last child
|
|
307
|
-
|
|
308
|
-
ts.should_not be_nil
|
|
309
|
-
tn.should_not be_nil
|
|
310
|
-
|
|
311
|
-
p2.taxons.collect( &:id ).should include(ts.id)
|
|
312
|
-
p2.taxons.collect( &:id ).should include(tn.id)
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
tn.parent.id.should == paint_parent.root.id
|
|
316
|
-
ts.parent.id.should == tn.id
|
|
317
|
-
|
|
318
|
-
tn.children.should have_exactly(1).items
|
|
319
|
-
ts.children.should have_exactly(0).items
|
|
320
|
-
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
it "should correctly identify and create nested Taxons ", :taxons => true do#
|
|
324
|
-
x=<<-EOS
|
|
325
|
-
lucky_product : A>mysubcat
|
|
326
|
-
bad_luck : B>mysubcat
|
|
327
|
-
|
|
328
|
-
The bad_luck product is created with in B and somehow pushed into A>mysubcat.
|
|
329
|
-
The category B>mysubcat is not created at all...
|
|
330
|
-
EOS
|
|
331
|
-
pending(x)
|
|
332
|
-
|
|
333
|
-
end
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
# REPEAT THE WHOLE TEST SUITE VIA CSV
|
|
337
|
-
|
|
338
|
-
it "should load Products from single column csv as per .xls" do
|
|
339
|
-
test_variants_creation('SpreeProducts.csv')
|
|
340
|
-
|
|
341
|
-
expected_multi_column_properties
|
|
342
|
-
|
|
343
|
-
expected_multi_column_taxons
|
|
344
|
-
end
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
it "should load Products from multiple column csv as per .xls", :blah => true do
|
|
348
|
-
test_variants_creation('SpreeProductsMultiColumn.csv')
|
|
349
|
-
|
|
350
|
-
expected_multi_column_properties
|
|
351
|
-
|
|
352
|
-
expected_multi_column_taxons
|
|
353
|
-
end
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
it "should raise exception when mandatory columns missing from .xls", :ex => true do
|
|
357
|
-
expect {@product_loader.perform_load($SpreeNegativeFixturePath + '/SpreeProdMissManyMandatory.xls', :mandatory => ['sku', 'name', 'price'] )}.to raise_error(DataShift::MissingMandatoryError)
|
|
358
|
-
end
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
it "should raise exception when single mandatory column missing from .xls", :ex => true do
|
|
362
|
-
expect {@product_loader.perform_load($SpreeNegativeFixturePath + '/SpreeProdMiss1Mandatory.xls', :mandatory => 'sku' )}.to raise_error(DataShift::MissingMandatoryError)
|
|
363
|
-
end
|
|
364
|
-
|
|
365
|
-
it "should raise exception when mandatory columns missing from .csv", :ex => true do
|
|
366
|
-
expect {@product_loader.perform_load($SpreeNegativeFixturePath + '/SpreeProdMissManyMandatory.csv', :mandatory => ['sku', 'name', 'price'] )}.to raise_error(DataShift::MissingMandatoryError)
|
|
367
|
-
end
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
it "should raise exception when single mandatory column missing from .csv", :ex => true do
|
|
371
|
-
expect {@product_loader.perform_load($SpreeNegativeFixturePath + '/SpreeProdMiss1Mandatory.csv', :mandatory => 'sku' )}.to raise_error(DataShift::MissingMandatoryError)
|
|
372
|
-
end
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
end
|