datashift 0.5.0 → 0.6.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/Rakefile +3 -0
- data/VERSION +1 -1
- data/datashift.gemspec +6 -4
- data/lib/datashift/method_detail.rb +2 -2
- data/lib/datashift/method_dictionary.rb +15 -2
- data/lib/datashift/method_mapper.rb +18 -5
- data/lib/exporters/excel_exporter.rb +1 -2
- data/lib/helpers/spree_helper.rb +18 -12
- data/lib/loaders/csv_loader.rb +1 -8
- data/lib/loaders/excel_loader.rb +7 -7
- data/lib/loaders/loader_base.rb +34 -6
- data/lib/loaders/spreadsheet_loader.rb +86 -78
- data/lib/loaders/spree/image_loader.rb +72 -24
- data/lib/loaders/spree/product_loader.rb +3 -31
- data/lib/thor/import_excel.thor +15 -16
- data/lib/thor/spree/products_images.thor +5 -3
- data/sandbox/config/application.rb +21 -5
- data/sandbox/config/database.yml +18 -32
- data/sandbox/config/environment.rb +1 -3
- data/sandbox/config/environments/development.rb +9 -2
- data/spec/Gemfile +16 -5
- data/spec/fixtures/datashift_Spree_db.sqlite +0 -0
- data/spec/fixtures/datashift_test_models_db.sqlite +0 -0
- data/spec/fixtures/spree/{SpreeProductImages.xls → SpreeImages.xls} +0 -0
- data/spec/fixtures/spree/SpreeProductsWithImages.csv +3 -3
- data/spec/fixtures/spree/SpreeProductsWithImages.xls +0 -0
- data/spec/fixtures/test_model_defs.rb +1 -0
- data/spec/spec_helper.rb +13 -11
- data/spec/spree_exporter_spec.rb +6 -4
- data/spec/spree_generator_spec.rb +14 -10
- data/spec/spree_images_loader_spec.rb +59 -24
- data/spec/spree_loader_spec.rb +12 -10
- data/spec/spree_method_mapping_spec.rb +16 -9
- data/tasks/spree/image_load.rake +2 -8
- metadata +15 -6
Binary file
|
Binary file
|
Binary file
|
@@ -1,4 +1,4 @@
|
|
1
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,
|
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,
|
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,
|
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
|
data/spec/spec_helper.rb
CHANGED
@@ -115,7 +115,7 @@ module SpecHelper
|
|
115
115
|
File.join($SpreeFixturePath, source)
|
116
116
|
end
|
117
117
|
|
118
|
-
def
|
118
|
+
def before_all_spree
|
119
119
|
|
120
120
|
# we are not a Spree project, nor is it practical to externally generate
|
121
121
|
# a complete Spree application for testing so we implement a mini migrate/boot of our own
|
@@ -125,22 +125,24 @@ module SpecHelper
|
|
125
125
|
puts "Testing Spree standalone - version #{SpreeHelper::version}"
|
126
126
|
|
127
127
|
SpreeHelper.migrate_up # create an sqlite Spree database on the fly
|
128
|
+
|
129
|
+
@spree_klass_list = %w{Image OptionType OptionValue Property ProductProperty Variant Taxon Taxonomy Zone}
|
130
|
+
|
131
|
+
@klass = SpreeHelper::get_product_class
|
132
|
+
@Product_klass = @klass
|
133
|
+
|
134
|
+
@spree_klass_list.each do |k|
|
135
|
+
instance_variable_set("@#{k}_klass", SpreeHelper::get_spree_class(k))
|
136
|
+
end
|
137
|
+
|
128
138
|
end
|
129
139
|
|
130
140
|
def before_each_spree
|
131
141
|
|
132
|
-
@klass = SpreeHelper::get_product_class
|
133
|
-
@Product_klass = @klass
|
134
|
-
@Taxon_klass = SpreeHelper::get_spree_class('Taxon')
|
135
|
-
@zone_klass = SpreeHelper::get_spree_class('Zone')
|
136
|
-
|
137
142
|
# Reset main tables - TODO should really purge properly, or roll back a transaction
|
138
|
-
@
|
139
|
-
@Taxon_klass.delete_all
|
140
|
-
@zone_klass.delete_all
|
143
|
+
@Product_klass.delete_all
|
141
144
|
|
142
|
-
|
143
|
-
instance_variable_set("@#{k}_klass", SpreeHelper::get_spree_class(k))
|
145
|
+
@spree_klass_list.each do |k|
|
144
146
|
instance_variable_get("@#{k}_klass").delete_all
|
145
147
|
end
|
146
148
|
end
|
data/spec/spree_exporter_spec.rb
CHANGED
@@ -16,17 +16,19 @@ require 'excel_exporter'
|
|
16
16
|
|
17
17
|
include DataShift
|
18
18
|
|
19
|
-
describe '
|
19
|
+
describe 'SpreeExporter' do
|
20
20
|
|
21
|
+
include SpecHelper
|
22
|
+
extend SpecHelper
|
23
|
+
|
21
24
|
before(:all) do
|
22
|
-
|
25
|
+
before_all_spree
|
23
26
|
results_clear()
|
24
27
|
end
|
25
28
|
|
26
29
|
before do
|
27
30
|
|
28
|
-
|
29
|
-
extend SpecHelper
|
31
|
+
|
30
32
|
|
31
33
|
before_each_spree # inits tests, cleans DB setups model types
|
32
34
|
|
@@ -16,25 +16,29 @@ require 'excel_generator'
|
|
16
16
|
|
17
17
|
include DataShift
|
18
18
|
|
19
|
-
describe '
|
19
|
+
describe 'SpreeGenerator' do
|
20
20
|
|
21
|
+
include SpecHelper
|
22
|
+
extend SpecHelper
|
23
|
+
|
21
24
|
before(:all) do
|
22
|
-
|
25
|
+
before_all_spree
|
23
26
|
end
|
24
27
|
|
25
28
|
before do
|
26
|
-
|
27
|
-
#include SpecHelper
|
28
|
-
extend SpecHelper
|
29
|
-
|
29
|
+
|
30
30
|
before_each_spree # inits tests, cleans DB setups model types
|
31
31
|
|
32
32
|
# Create some test data
|
33
33
|
root = @Taxonomy_klass.create( :name => 'Paintings' )
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
38
42
|
end
|
39
43
|
|
40
44
|
it "should export any Spree model to .xls spreedsheet" do
|
@@ -75,7 +79,7 @@ describe 'SpreeLoader' do
|
|
75
79
|
|
76
80
|
end
|
77
81
|
|
78
|
-
|
82
|
+
it "should be able to exclude single associations from template" do
|
79
83
|
|
80
84
|
expect = result_file('product_and_assoc_export_spec.xls')
|
81
85
|
|
@@ -16,23 +16,23 @@ require 'product_loader'
|
|
16
16
|
|
17
17
|
include DataShift
|
18
18
|
|
19
|
-
describe '
|
19
|
+
describe 'SpreeImageLoading' do
|
20
20
|
|
21
|
+
include SpecHelper
|
22
|
+
extend SpecHelper
|
21
23
|
|
22
24
|
before(:all) do
|
23
|
-
|
25
|
+
before_all_spree
|
24
26
|
end
|
25
27
|
|
26
28
|
before(:each) do
|
27
29
|
|
28
30
|
begin
|
29
31
|
|
30
|
-
include SpecHelper
|
31
|
-
extend SpecHelper
|
32
|
-
|
33
32
|
before_each_spree
|
34
|
-
|
35
|
-
@
|
33
|
+
|
34
|
+
@Image_klass.count.should == 0
|
35
|
+
@Product_klass.count.should == 0
|
36
36
|
|
37
37
|
MethodDictionary.clear
|
38
38
|
MethodDictionary.find_operators( @klass )
|
@@ -48,42 +48,77 @@ describe 'SpreeLoader' do
|
|
48
48
|
it "should load Products with associated image from CSV" do
|
49
49
|
|
50
50
|
# In >= 1.1.0 Image moved to master Variant from Product
|
51
|
-
if(SpreeHelper::version.to_f < 1.1)
|
52
51
|
|
53
|
-
|
52
|
+
options = {:mandatory => ['sku', 'name', 'price']}
|
53
|
+
|
54
|
+
options[:force_inclusion] = ['sku', 'images'] if(SpreeHelper::version.to_f > 1 )
|
55
|
+
|
56
|
+
@product_loader.perform_load( SpecHelper::spree_fixture('SpreeProductsWithImages.csv'), options )
|
54
57
|
|
55
|
-
|
58
|
+
@Image_klass.all.each_with_index {|i, x| puts "RESULT IMAGE #{x}", i.inspect }
|
59
|
+
|
60
|
+
p = @Product_klass.find_by_name("Demo Product for AR Loader")
|
56
61
|
|
57
|
-
|
58
|
-
p.images.should have_exactly(1).items
|
62
|
+
p.name.should == "Demo Product for AR Loader"
|
59
63
|
|
60
|
-
|
61
|
-
|
64
|
+
p.images.should have_exactly(1).items
|
65
|
+
p.master.images.should have_exactly(1).items
|
66
|
+
|
67
|
+
@Product_klass.all.each {|p| p.images.should have_exactly(1).items }
|
68
|
+
|
69
|
+
@Image_klass.count.should == 3
|
62
70
|
end
|
63
71
|
|
64
72
|
|
65
|
-
it "should load Products with associated image"
|
73
|
+
it "should load Products with associated image" do
|
66
74
|
|
67
|
-
|
68
|
-
|
75
|
+
options = {:mandatory => ['sku', 'name', 'price']}
|
76
|
+
|
77
|
+
options[:force_inclusion] = ['sku', 'images'] if(SpreeHelper::version.to_f > 1 )
|
78
|
+
|
79
|
+
@product_loader.perform_load( SpecHelper::spree_fixture('SpreeProductsWithImages.xls'), options )
|
69
80
|
|
70
|
-
|
81
|
+
@Image_klass.all.each_with_index {|i, x| puts "RESULT IMAGE #{x}", i.inspect }
|
82
|
+
|
83
|
+
p = @klass.find_by_name("Demo Product for AR Loader")
|
71
84
|
|
72
|
-
|
73
|
-
|
85
|
+
p.name.should == "Demo Product for AR Loader"
|
86
|
+
p.images.should have_exactly(1).items
|
74
87
|
|
75
|
-
|
76
|
-
|
88
|
+
@Product_klass.all.each {|p| p.images.should have_exactly(1).items }
|
89
|
+
|
90
|
+
@Image_klass.count.should == 3
|
91
|
+
|
77
92
|
end
|
78
93
|
|
79
|
-
it "should be able to assign Images to preloaded Products" do
|
94
|
+
it "should be able to assign Images to preloaded Products", :fail => true do
|
95
|
+
|
96
|
+
MethodDictionary.find_operators( @Image_klass )
|
97
|
+
|
98
|
+
@Product_klass.count.should == 0
|
99
|
+
|
100
|
+
@product_loader.perform_load( SpecHelper::spree_fixture('SpreeProducts.xls'))
|
80
101
|
|
81
102
|
@Image_klass.all.size.should == 0
|
82
103
|
|
104
|
+
options = { :force_inclusion => ['sku', 'attachment'] } if(SpreeHelper::version.to_f > 1 )
|
105
|
+
|
83
106
|
loader = DataShift::SpreeHelper::ImageLoader.new
|
84
107
|
|
85
|
-
loader.perform_load( SpecHelper::spree_fixture('
|
108
|
+
loader.perform_load( SpecHelper::spree_fixture('SpreeImages.xls'), options )
|
86
109
|
|
110
|
+
@Image_klass.all.each_with_index {|i, x| puts "RESULT IMAGE #{x}", i.inspect }
|
111
|
+
|
112
|
+
@Image_klass.count.should == 3
|
113
|
+
|
114
|
+
p = @klass.find_by_name("Demo Product for AR Loader")
|
115
|
+
|
116
|
+
p.name.should == "Demo Product for AR Loader"
|
117
|
+
|
118
|
+
p.images.should have_exactly(1).items
|
119
|
+
|
120
|
+
@Product_klass.all.each {|p| p.images.should have_exactly(1).items }
|
121
|
+
|
87
122
|
end
|
88
123
|
|
89
124
|
end
|
data/spec/spree_loader_spec.rb
CHANGED
@@ -19,17 +19,19 @@ include DataShift
|
|
19
19
|
describe 'SpreeLoader' do
|
20
20
|
|
21
21
|
|
22
|
+
include SpecHelper
|
23
|
+
extend SpecHelper
|
24
|
+
|
25
|
+
|
22
26
|
before(:all) do
|
23
|
-
|
27
|
+
before_all_spree
|
24
28
|
end
|
25
29
|
|
26
30
|
before(:each) do
|
27
31
|
|
28
32
|
begin
|
29
33
|
|
30
|
-
|
31
|
-
extend SpecHelper
|
32
|
-
|
34
|
+
|
33
35
|
before_each_spree
|
34
36
|
|
35
37
|
@Product_klass.count.should == 0
|
@@ -58,24 +60,24 @@ describe 'SpreeLoader' do
|
|
58
60
|
|
59
61
|
it "should process a simple .xls spreadsheet" do
|
60
62
|
|
61
|
-
@
|
63
|
+
@Zone_klass.delete_all
|
62
64
|
|
63
|
-
loader = ExcelLoader.new(@
|
65
|
+
loader = ExcelLoader.new(@Zone_klass)
|
64
66
|
|
65
67
|
loader.perform_load( SpecHelper::spree_fixture('SpreeZoneExample.xls') )
|
66
68
|
|
67
|
-
loader.loaded_count.should == @
|
69
|
+
loader.loaded_count.should == @Zone_klass.count
|
68
70
|
end
|
69
71
|
|
70
72
|
it "should process a simple csv file" do
|
71
73
|
|
72
|
-
@
|
74
|
+
@Zone_klass.delete_all
|
73
75
|
|
74
|
-
loader = CsvLoader.new(@
|
76
|
+
loader = CsvLoader.new(@Zone_klass)
|
75
77
|
|
76
78
|
loader.perform_load( SpecHelper::spree_fixture('SpreeZoneExample.csv') )
|
77
79
|
|
78
|
-
loader.loaded_count.should == @
|
80
|
+
loader.loaded_count.should == @Zone_klass.count
|
79
81
|
end
|
80
82
|
|
81
83
|
|
@@ -16,17 +16,17 @@ require 'product_loader'
|
|
16
16
|
|
17
17
|
include DataShift
|
18
18
|
|
19
|
-
describe '
|
19
|
+
describe 'SpreeMethodMapping' do
|
20
20
|
|
21
|
+
include SpecHelper
|
22
|
+
extend SpecHelper
|
23
|
+
|
21
24
|
before(:all) do
|
22
|
-
|
25
|
+
before_all_spree
|
23
26
|
end
|
24
27
|
|
25
28
|
before(:each) do
|
26
|
-
|
27
|
-
include SpecHelper
|
28
|
-
extend SpecHelper
|
29
|
-
|
29
|
+
|
30
30
|
before_each_spree
|
31
31
|
|
32
32
|
MethodDictionary.clear
|
@@ -196,7 +196,9 @@ describe 'SpreeLoader' do
|
|
196
196
|
|
197
197
|
klazz_object = @Product_klass.new
|
198
198
|
|
199
|
-
@ProductProperty_klass.new
|
199
|
+
pp = @ProductProperty_klass.new
|
200
|
+
|
201
|
+
pp.property = @prop1
|
200
202
|
|
201
203
|
# NEW ASSOCIATION ASSIGNMENT
|
202
204
|
klazz_object.send( method_detail.operator ) << @ProductProperty_klass.new
|
@@ -207,10 +209,15 @@ describe 'SpreeLoader' do
|
|
207
209
|
klazz_object.product_properties.size.should == 3
|
208
210
|
|
209
211
|
# Use generic assignment on method detail - expect has_many to use << not =
|
210
|
-
|
212
|
+
pp2 = @ProductProperty_klass.new
|
213
|
+
pp2.property = @prop1
|
214
|
+
method_detail.assign( klazz_object, pp2)
|
211
215
|
klazz_object.product_properties.size.should == 4
|
212
216
|
|
213
|
-
|
217
|
+
pp3, pp4 = @ProductProperty_klass.new, @ProductProperty_klass.new
|
218
|
+
pp3.property = @prop2
|
219
|
+
pp4.property = @prop3
|
220
|
+
method_detail.assign( klazz_object, [pp3, pp4])
|
214
221
|
klazz_object.product_properties.size.should == 6
|
215
222
|
|
216
223
|
end
|
data/tasks/spree/image_load.rake
CHANGED
@@ -35,15 +35,9 @@ namespace :datashift do
|
|
35
35
|
attachment_klazz = SpreeHelper::get_spree_class('Product' )
|
36
36
|
sku_klazz = SpreeHelper::get_spree_class('Variant' )
|
37
37
|
|
38
|
-
# TODO generalise for any paperclip project, for now just Spree
|
39
|
-
#begin
|
40
|
-
# attachment_klazz = Kernel.const_get(args[:model]) if(args[:model])
|
41
|
-
# rescue NameError
|
42
|
-
# raise "Could not find contant for model #{args[:model]}"
|
43
|
-
#end
|
44
|
-
|
45
38
|
image_loader = ImageLoader.new
|
46
|
-
|
39
|
+
|
40
|
+
|
47
41
|
if(File.directory? @image_cache )
|
48
42
|
puts "Loading images from #{@image_cache}"
|
49
43
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: datashift
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.6.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Thomas Statter
|
@@ -10,9 +10,19 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-05-
|
14
|
-
dependencies:
|
15
|
-
|
13
|
+
date: 2012-05-18 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: spreadsheet
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
16
26
|
description: A suite of tools to move data between ActiveRecord models,databases,applications like Excel/Open Office, files and projects including Spree
|
17
27
|
email: rubygems@autotelik.co.uk
|
18
28
|
executables: []
|
@@ -30,7 +40,6 @@ files:
|
|
30
40
|
- README.rdoc
|
31
41
|
- Rakefile
|
32
42
|
- VERSION
|
33
|
-
- datashift-0.5.0.gem
|
34
43
|
- datashift.gemspec
|
35
44
|
- lib/applications/jruby/jexcel_file.rb
|
36
45
|
- lib/applications/jruby/word.rb
|
@@ -128,7 +137,7 @@ files:
|
|
128
137
|
- spec/fixtures/negative/SpreeProdMissManyMandatory.xls
|
129
138
|
- spec/fixtures/simple_export_spec.xls
|
130
139
|
- spec/fixtures/simple_template_spec.xls
|
131
|
-
- spec/fixtures/spree/
|
140
|
+
- spec/fixtures/spree/SpreeImages.xls
|
132
141
|
- spec/fixtures/spree/SpreeProducts.csv
|
133
142
|
- spec/fixtures/spree/SpreeProducts.xls
|
134
143
|
- spec/fixtures/spree/SpreeProductsDefaults.yml
|