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.
Files changed (163) hide show
  1. data/README.markdown +63 -64
  2. data/Rakefile +4 -7
  3. data/VERSION +1 -1
  4. data/datashift.gemspec +92 -62
  5. data/lib/applications/apache_poi_extensions.rb +62 -0
  6. data/lib/applications/excel.rb +78 -0
  7. data/lib/applications/excel_base.rb +65 -0
  8. data/lib/applications/jexcel_file.rb +222 -0
  9. data/lib/applications/jexcel_file_extensions.rb +244 -0
  10. data/lib/applications/jruby/{jexcel_file.rb → old_pre_proxy_jexcel_file.rb} +0 -0
  11. data/lib/applications/ruby_poi_translations.rb +64 -0
  12. data/lib/applications/spreadsheet_extensions.rb +31 -0
  13. data/lib/datashift/method_details_manager.rb +4 -0
  14. data/lib/exporters/csv_exporter.rb +3 -1
  15. data/lib/exporters/excel_exporter.rb +59 -74
  16. data/lib/generators/excel_generator.rb +70 -74
  17. data/lib/guards.rb +57 -0
  18. data/lib/loaders/excel_loader.rb +105 -105
  19. data/lib/loaders/loader_base.rb +43 -21
  20. data/lib/loaders/paperclip/attachment_loader.rb +104 -0
  21. data/lib/loaders/paperclip/datashift_paperclip.rb +78 -0
  22. data/lib/loaders/paperclip/{image_loader.rb → image_loading.rb} +2 -18
  23. data/lib/thor/{generate_excel.thor → generate.thor} +48 -0
  24. data/lib/thor/paperclip.thor +85 -0
  25. data/lib/thor/tools.thor +23 -2
  26. data/spec/Gemfile +1 -7
  27. data/spec/csv_exporter_spec.rb +4 -4
  28. data/spec/csv_loader_spec.rb +1 -1
  29. data/spec/excel_exporter_spec.rb +43 -45
  30. data/spec/excel_generator_spec.rb +132 -60
  31. data/spec/excel_loader_spec.rb +134 -140
  32. data/spec/excel_spec.rb +179 -0
  33. data/spec/fixtures/ProjectsMultiCategoriesHeaderLookup.xls +0 -0
  34. data/spec/fixtures/config/database.yml +2 -2
  35. data/spec/fixtures/db/datashift_test_models_db.sqlite +0 -0
  36. data/spec/{db → fixtures/db}/migrate/20110803201325_create_test_bed.rb +0 -0
  37. data/spec/fixtures/load_datashift.thor +3 -0
  38. data/spec/fixtures/models/category.rb +7 -0
  39. data/spec/fixtures/models/empty.rb +2 -0
  40. data/spec/fixtures/models/loader_release.rb +10 -0
  41. data/spec/fixtures/models/long_and_complex_table_linked_to_version.rb +6 -0
  42. data/spec/fixtures/models/milestone.rb +8 -0
  43. data/spec/fixtures/models/owner.rb +5 -0
  44. data/spec/fixtures/models/project.rb +26 -0
  45. data/spec/fixtures/models/test_model_defs.rb +67 -0
  46. data/spec/fixtures/models/version.rb +7 -0
  47. data/spec/loader_spec.rb +4 -3
  48. data/spec/method_dictionary_spec.rb +7 -6
  49. data/spec/method_mapper_spec.rb +3 -2
  50. data/spec/rails_sandbox/.gitignore +15 -0
  51. data/spec/rails_sandbox/Gemfile +40 -0
  52. data/spec/rails_sandbox/README.rdoc +261 -0
  53. data/spec/rails_sandbox/Rakefile +7 -0
  54. data/spec/rails_sandbox/app/assets/images/rails.png +0 -0
  55. data/spec/rails_sandbox/app/assets/javascripts/application.js +15 -0
  56. data/spec/rails_sandbox/app/assets/stylesheets/application.css +13 -0
  57. data/spec/rails_sandbox/app/controllers/application_controller.rb +3 -0
  58. data/spec/rails_sandbox/app/helpers/application_helper.rb +2 -0
  59. data/spec/rails_sandbox/app/mailers/.gitkeep +0 -0
  60. data/spec/rails_sandbox/app/models/.gitkeep +0 -0
  61. data/spec/rails_sandbox/app/models/category.rb +7 -0
  62. data/spec/rails_sandbox/app/models/empty.rb +2 -0
  63. data/spec/rails_sandbox/app/models/loader_release.rb +10 -0
  64. data/spec/rails_sandbox/app/models/long_and_complex_table_linked_to_version.rb +6 -0
  65. data/spec/rails_sandbox/app/models/milestone.rb +8 -0
  66. data/spec/rails_sandbox/app/models/owner.rb +5 -0
  67. data/spec/rails_sandbox/app/models/project.rb +26 -0
  68. data/spec/rails_sandbox/app/models/test_model_defs.rb +67 -0
  69. data/spec/rails_sandbox/app/models/version.rb +7 -0
  70. data/spec/rails_sandbox/app/views/layouts/application.html.erb +14 -0
  71. data/spec/rails_sandbox/config.ru +4 -0
  72. data/spec/rails_sandbox/config/application.rb +62 -0
  73. data/spec/rails_sandbox/config/boot.rb +6 -0
  74. data/spec/rails_sandbox/config/database.yml +20 -0
  75. data/spec/rails_sandbox/config/environment.rb +5 -0
  76. data/spec/rails_sandbox/config/environments/development.rb +37 -0
  77. data/spec/rails_sandbox/config/environments/production.rb +67 -0
  78. data/spec/rails_sandbox/config/environments/test.rb +37 -0
  79. data/spec/rails_sandbox/config/initializers/backtrace_silencers.rb +7 -0
  80. data/spec/rails_sandbox/config/initializers/inflections.rb +15 -0
  81. data/spec/rails_sandbox/config/initializers/mime_types.rb +5 -0
  82. data/spec/rails_sandbox/config/initializers/secret_token.rb +7 -0
  83. data/spec/rails_sandbox/config/initializers/session_store.rb +8 -0
  84. data/spec/rails_sandbox/config/initializers/wrap_parameters.rb +14 -0
  85. data/spec/rails_sandbox/config/locales/en.yml +5 -0
  86. data/spec/rails_sandbox/config/routes.rb +58 -0
  87. data/spec/rails_sandbox/db/migrate/20110803201325_create_test_bed.rb +96 -0
  88. data/spec/rails_sandbox/db/schema.rb +81 -0
  89. data/spec/rails_sandbox/db/seeds.rb +7 -0
  90. data/spec/rails_sandbox/lib/assets/.gitkeep +0 -0
  91. data/spec/rails_sandbox/lib/tasks/.gitkeep +0 -0
  92. data/spec/rails_sandbox/log/.gitkeep +0 -0
  93. data/spec/rails_sandbox/public/404.html +26 -0
  94. data/spec/rails_sandbox/public/422.html +26 -0
  95. data/spec/rails_sandbox/public/500.html +25 -0
  96. data/spec/rails_sandbox/public/favicon.ico +0 -0
  97. data/spec/rails_sandbox/public/index.html +241 -0
  98. data/spec/rails_sandbox/public/robots.txt +5 -0
  99. data/spec/rails_sandbox/script/rails +6 -0
  100. data/spec/rails_sandbox/test/fixtures/.gitkeep +0 -0
  101. data/spec/rails_sandbox/test/functional/.gitkeep +0 -0
  102. data/spec/rails_sandbox/test/integration/.gitkeep +0 -0
  103. data/spec/rails_sandbox/test/performance/browsing_test.rb +12 -0
  104. data/spec/rails_sandbox/test/test_helper.rb +13 -0
  105. data/spec/rails_sandbox/test/unit/.gitkeep +0 -0
  106. data/spec/rails_sandbox/vendor/assets/javascripts/.gitkeep +0 -0
  107. data/spec/rails_sandbox/vendor/assets/stylesheets/.gitkeep +0 -0
  108. data/spec/rails_sandbox/vendor/plugins/.gitkeep +0 -0
  109. data/spec/spec_helper.rb +144 -121
  110. data/spec/thor_spec.rb +34 -14
  111. metadata +207 -194
  112. data/lib/helpers/spree_helper.rb +0 -213
  113. data/lib/loaders/spreadsheet_loader.rb +0 -144
  114. data/lib/loaders/spree/image_loader.rb +0 -90
  115. data/lib/loaders/spree/product_loader.rb +0 -354
  116. data/lib/thor/spree/bootstrap_cleanup.thor +0 -61
  117. data/lib/thor/spree/products_images.thor +0 -252
  118. data/lib/thor/spree/reports.thor +0 -56
  119. data/public/spree/products/large/DEMO_001_ror_bag.jpeg +0 -0
  120. data/public/spree/products/large/DEMO_002_Powerstation.jpg +0 -0
  121. data/public/spree/products/large/DEMO_003_ror_mug.jpeg +0 -0
  122. data/public/spree/products/mini/DEMO_001_ror_bag.jpeg +0 -0
  123. data/public/spree/products/mini/DEMO_002_Powerstation.jpg +0 -0
  124. data/public/spree/products/mini/DEMO_003_ror_mug.jpeg +0 -0
  125. data/public/spree/products/original/DEMO_001_ror_bag.jpeg +0 -0
  126. data/public/spree/products/original/DEMO_002_Powerstation.jpg +0 -0
  127. data/public/spree/products/original/DEMO_003_ror_mug.jpeg +0 -0
  128. data/public/spree/products/product/DEMO_001_ror_bag.jpeg +0 -0
  129. data/public/spree/products/product/DEMO_002_Powerstation.jpg +0 -0
  130. data/public/spree/products/product/DEMO_003_ror_mug.jpeg +0 -0
  131. data/public/spree/products/small/DEMO_001_ror_bag.jpeg +0 -0
  132. data/public/spree/products/small/DEMO_002_Powerstation.jpg +0 -0
  133. data/public/spree/products/small/DEMO_003_ror_mug.jpeg +0 -0
  134. data/spec/fixtures/datashift_Spree_db.sqlite +0 -0
  135. data/spec/fixtures/datashift_test_models_db.sqlite +0 -0
  136. data/spec/fixtures/negative/SpreeProdMiss1Mandatory.csv +0 -4
  137. data/spec/fixtures/negative/SpreeProdMiss1Mandatory.xls +0 -0
  138. data/spec/fixtures/negative/SpreeProdMissManyMandatory.csv +0 -4
  139. data/spec/fixtures/negative/SpreeProdMissManyMandatory.xls +0 -0
  140. data/spec/fixtures/spree/SpreeImages.xls +0 -0
  141. data/spec/fixtures/spree/SpreeMultiVariant.csv +0 -4
  142. data/spec/fixtures/spree/SpreeProducts.csv +0 -4
  143. data/spec/fixtures/spree/SpreeProducts.xls +0 -0
  144. data/spec/fixtures/spree/SpreeProductsDefaults.yml +0 -15
  145. data/spec/fixtures/spree/SpreeProductsMandatoryOnly.xls +0 -0
  146. data/spec/fixtures/spree/SpreeProductsMultiColumn.csv +0 -4
  147. data/spec/fixtures/spree/SpreeProductsMultiColumn.xls +0 -0
  148. data/spec/fixtures/spree/SpreeProductsSimple.csv +0 -4
  149. data/spec/fixtures/spree/SpreeProductsSimple.xls +0 -0
  150. data/spec/fixtures/spree/SpreeProductsWithImages.csv +0 -4
  151. data/spec/fixtures/spree/SpreeProductsWithImages.xls +0 -0
  152. data/spec/fixtures/spree/SpreeZoneExample.csv +0 -5
  153. data/spec/fixtures/spree/SpreeZoneExample.xls +0 -0
  154. data/spec/spree_exporter_spec.rb +0 -72
  155. data/spec/spree_generator_spec.rb +0 -96
  156. data/spec/spree_images_loader_spec.rb +0 -107
  157. data/spec/spree_loader_spec.rb +0 -375
  158. data/spec/spree_method_mapping_spec.rb +0 -226
  159. data/spec/spree_variants_loader_spec.rb +0 -189
  160. data/tasks/export/excel_generator.rake +0 -102
  161. data/tasks/import/excel.rake +0 -75
  162. data/test/helper.rb +0 -18
  163. data/test/test_interact.rb +0 -7
@@ -1,226 +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
- # Tests the method mapping aspect, such as that we correctly identify
10
- # Spree Product attributes and associations
11
- #
12
- require File.dirname(__FILE__) + '/spec_helper'
13
-
14
- require 'spree_helper'
15
- #require 'product_loader'
16
-
17
- include DataShift
18
-
19
- describe 'SpreeMethodMapping' 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
- before_each_spree
31
-
32
- MethodDictionary.clear
33
- MethodDictionary.find_operators( @Product_klass )
34
- #MethodDictionary.build_method_details( @Product_klass )
35
- end
36
-
37
-
38
- it "should populate operators for a Spree Product" do
39
-
40
- MethodDictionary.has_many.should_not be_empty
41
- MethodDictionary.belongs_to.should_not be_empty
42
- MethodDictionary.assignments.should_not be_empty
43
-
44
- assign = MethodDictionary.assignments_for(@Product_klass)
45
-
46
- assign.should include('available_on') # Example of a simple column
47
-
48
- MethodDictionary.assignments[@Product_klass].should include('available_on')
49
-
50
- has_many_ops = MethodDictionary.has_many_for(@Product_klass)
51
-
52
- has_many_ops.should include('properties') # Product can have many properties
53
-
54
- MethodDictionary.has_many[@Product_klass].should include('properties')
55
-
56
- btf = MethodDictionary.belongs_to_for(@Product_klass)
57
-
58
- btf.should include('tax_category') # Example of a belongs_to assignment
59
-
60
- MethodDictionary.belongs_to[@Product_klass].should include('tax_category')
61
-
62
- MethodDictionary.column_types[@Product_klass].size.should == @Product_klass.columns.size
63
- end
64
-
65
-
66
- it "should find method details correctly for different forms of a column name" do
67
-
68
- MethodDictionary.build_method_details( @Product_klass )
69
-
70
- ["available On", 'available_on', "Available On", "AVAILABLE_ON"].each do |format|
71
-
72
- method_details = MethodDictionary.find_method_detail( @Product_klass, format )
73
-
74
- method_details.operator.should == 'available_on'
75
- method_details.operator_for(:assignment).should == 'available_on'
76
-
77
- method_details.operator_for(:belongs_to).should be_nil
78
- method_details.operator_for(:has_many).should be_nil
79
-
80
- method_details.col_type.should_not be_nil
81
- method_details.col_type.name.should == 'available_on'
82
- method_details.col_type.default.should == nil
83
- method_details.col_type.sql_type.should include 'datetime' # works on mysql and sqlite
84
- method_details.col_type.type.should == :datetime
85
- end
86
- end
87
-
88
- it "should populate method details correctly for has_many forms of association name" do
89
-
90
- MethodDictionary.has_many[@Product_klass].should include('product_option_types')
91
-
92
- MethodDictionary.build_method_details( @Product_klass )
93
-
94
- ["product_option_types", "product option types", 'product Option_types', "ProductOptionTypes", "Product_Option_Types"].each do |format|
95
- method_detail = MethodDictionary.find_method_detail( @Product_klass, format )
96
-
97
- method_detail.should_not be_nil
98
-
99
- method_detail.operator_for(:has_many).should eq('product_option_types')
100
- method_detail.operator_for(:belongs_to).should be_nil
101
- method_detail.operator_for(:assignment).should be_nil
102
- end
103
- end
104
-
105
-
106
- it "should populate method details correctly for assignment operators (none columns on #{@Product_klass})" do
107
-
108
- MethodDictionary.find_operators( @Product_klass, :reload => true, :instance_methods => true )
109
-
110
- MethodDictionary.build_method_details( @Product_klass )
111
-
112
- # Example of delegates i.e. cost_price column on Variant, delegated to Variant by Product
113
-
114
- MethodDictionary.assignments[@Product_klass].should include('cost_price')
115
- MethodDictionary.assignments[@Product_klass].should include('sku')
116
-
117
-
118
- count_on_hand = MethodDictionary.find_method_detail( @Product_klass, 'count on hand' )
119
- count_on_hand.should_not be_nil
120
- count_on_hand.operator.should == 'count_on_hand'
121
-
122
- method = MethodDictionary.find_method_detail( @Product_klass, 'sku' )
123
- method.should_not be_nil
124
- method.operator.should == 'sku'
125
- end
126
-
127
- it "should enable assignment via operators for none columns on #{@Product_klass}" do
128
-
129
- MethodDictionary.find_operators( @Product_klass, :reload => true, :instance_methods => true )
130
-
131
- MethodDictionary.build_method_details( @Product_klass )
132
-
133
- klazz_object = @Product_klass.new
134
-
135
- klazz_object.should be_new_record
136
-
137
- # we can use method details to populate a new AR object, essentailly same as
138
- # klazz_object.send( count_on_hand.operator, 2)
139
- count_on_hand = MethodDictionary.find_method_detail( @Product_klass, 'count on hand' )
140
-
141
- count_on_hand.assign( klazz_object, 2 )
142
- klazz_object.count_on_hand.should == 2
143
-
144
- count_on_hand.assign( klazz_object, 5 )
145
- klazz_object.count_on_hand.should == 5
146
-
147
- method = MethodDictionary.find_method_detail( @Product_klass, 'sku' )
148
- method.should_not be_nil
149
-
150
- method.operator.should == 'sku'
151
-
152
- method.assign( klazz_object, 'TEST_SK 001')
153
- klazz_object.sku.should == 'TEST_SK 001'
154
-
155
- end
156
-
157
- it "should enable assignment to has_many association on new object" do
158
-
159
- MethodDictionary.build_method_details( @Product_klass )
160
-
161
- method_detail = MethodDictionary.find_method_detail( @Product_klass, 'taxons' )
162
-
163
- method_detail.operator.should == 'taxons'
164
-
165
- upload_object = @Product_klass.new
166
-
167
- upload_object.taxons.size.should == 0
168
-
169
- # NEW ASSOCIATION ASSIGNMENT
170
-
171
- # assign via the send operator directly on load object
172
- upload_object.send( method_detail.operator ) << @Taxon_klass.new
173
-
174
- upload_object.taxons.size.should == 1
175
-
176
- upload_object.send( method_detail.operator ) << [@Taxon_klass.new, @Taxon_klass.new]
177
- upload_object.taxons.size.should == 3
178
-
179
- # Use generic assignment on method detail - expect has_many to use << not =
180
- method_detail.assign( upload_object, @Taxon_klass.new )
181
- upload_object.taxons.size.should == 4
182
-
183
- method_detail.assign( upload_object, [@Taxon_klass.new, @Taxon_klass.new])
184
- upload_object.taxons.size.should == 6
185
- end
186
-
187
- it "should enable assignment to has_many association using existing objects" do
188
-
189
- MethodDictionary.find_operators( @Product_klass )
190
-
191
- MethodDictionary.build_method_details( @Product_klass )
192
-
193
- method_detail = MethodDictionary.find_method_detail( @Product_klass, 'product_properties' )
194
-
195
- method_detail.operator.should == 'product_properties'
196
-
197
- klazz_object = @Product_klass.new
198
-
199
- pp = @ProductProperty_klass.new
200
-
201
- pp.property = @prop1
202
-
203
- # NEW ASSOCIATION ASSIGNMENT
204
- klazz_object.send( method_detail.operator ) << @ProductProperty_klass.new
205
-
206
- klazz_object.product_properties.size.should == 1
207
-
208
- klazz_object.send( method_detail.operator ) << [@ProductProperty_klass.new, @ProductProperty_klass.new]
209
- klazz_object.product_properties.size.should == 3
210
-
211
- # Use generic assignment on method detail - expect has_many to use << not =
212
- pp2 = @ProductProperty_klass.new
213
- pp2.property = @prop1
214
- method_detail.assign( klazz_object, pp2)
215
- klazz_object.product_properties.size.should == 4
216
-
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])
221
- klazz_object.product_properties.size.should == 6
222
-
223
- end
224
-
225
-
226
- end
@@ -1,189 +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 'Spree Variants Loader' 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
- @Product_klass.count.should == 0
35
- @Taxon_klass.count.should == 0
36
- @Variant_klass.count.should == 0
37
-
38
- MethodDictionary.clear
39
-
40
- # For Spree important to get instance methods too as Product delegates
41
- # many important attributes to Variant (master)
42
- MethodDictionary.find_operators( @Product_klass, :instance_methods => true )
43
-
44
- # want to test both lookup and dynamic creation - this Taxonomy should be found, rest created
45
- root = @Taxonomy_klass.create( :name => 'Paintings' )
46
-
47
- t = @Taxon_klass.new( :name => 'Landscape' )
48
- t.taxonomy = root
49
- t.save
50
-
51
- @Taxon_klass.count.should == 2
52
-
53
- @product_loader = DataShift::SpreeHelper::ProductLoader.new
54
- rescue => e
55
- puts e.inspect
56
- puts e.backtrace
57
- end
58
- end
59
-
60
- # Operation and results should be identical when loading multiple associations
61
- # if using either single column embedded syntax, or one column per entry.
62
-
63
- it "should load Products and create Variants from single column" do
64
- test_variants_creation('SpreeProducts.xls')
65
- end
66
-
67
-
68
- it "should load Products and create Variants from multiple column #{SpecHelper::spree_fixture('SpreeProductsMultiColumn.xls')}" do
69
- test_variants_creation('SpreeProductsMultiColumn.xls')
70
- end
71
-
72
- def test_variants_creation( source )
73
- @Product_klass.count.should == 0
74
- @Variant_klass.count.should == 0
75
-
76
- @product_loader.perform_load( SpecHelper::spree_fixture(source), :mandatory => ['sku', 'name', 'price'] )
77
-
78
- expected_multi_column_variants
79
- end
80
-
81
-
82
- def expected_multi_column_variants
83
-
84
- # 3 MASTER products, 11 VARIANTS
85
- @Product_klass.count.should == 3
86
- @Variant_klass.count.should == 14
87
-
88
- p = @Product_klass.first
89
-
90
- p.sku.should == "DEMO_001"
91
-
92
- p.sku.should == "DEMO_001"
93
- p.price.should == 399.99
94
- p.description.should == "blah blah"
95
- p.cost_price.should == 320.00
96
-
97
- @Product_klass.all.select {|m| m.is_master.should == true }
98
-
99
-
100
- # mime_type:jpeg mime_type:PDF mime_type:PNG
101
-
102
- p.variants.should have_exactly(3).items
103
-
104
- p.option_types.should have_exactly(1).items # mime_type
105
-
106
- p.option_types[0].name.should == "mime_type"
107
- p.option_types[0].presentation.should == "Mime type"
108
-
109
- @Variant_klass.all[1].sku.should == "DEMO_001_1"
110
- @Variant_klass.all[1].price.should == 399.99
111
-
112
- # V1
113
- v1 = p.variants[0]
114
-
115
- v1.sku.should == "DEMO_001_1"
116
- v1.price.should == 399.99
117
- v1.count_on_hand.should == 12
118
-
119
-
120
- v1.option_values.should have_exactly(1).items # mime_type: jpeg
121
- v1.option_values[0].name.should == "jpeg"
122
-
123
-
124
- v2 = p.variants[1]
125
- v2.count_on_hand.should == 6
126
- v2.option_values.should have_exactly(1).items # mime_type: jpeg
127
- v2.option_values[0].name.should == "PDF"
128
-
129
- v2.option_values[0].option_type.should_not be_nil
130
- v2.option_values[0].option_type.position.should == 0
131
-
132
-
133
- v3 = p.variants[2]
134
- v3.count_on_hand.should == 7
135
- v3.option_values.should have_exactly(1).items # mime_type: jpeg
136
- v3.option_values[0].name.should == "PNG"
137
-
138
- @Variant_klass.last.price.should == 50.34
139
- @Variant_klass.last.count_on_hand.should == 18
140
-
141
- @product_loader.failed_objects.size.should == 0
142
- end
143
-
144
- # Composite Variant Syntax is option_type_A_name:value;option_type_B_name:value
145
- # which creates a SINGLE Variant with 2 option types
146
-
147
- it "should create Variants with MULTIPLE option types from single column", :new => true do
148
- @product_loader.perform_load( SpecHelper::spree_fixture('SpreeMultiVariant.csv'), :mandatory => ['sku', 'name', 'price'] )
149
-
150
- # Product 1)
151
- # 1 + 2) mime_type:jpeg,PDF;print_type:colour equivalent to (mime_type:jpeg;print_type:colour|mime_type:PDF;print_type:colour)
152
- # 3) mime_type:PNG
153
- #
154
- # Product 2
155
- # 4) mime_type:jpeg;print_type:black_white
156
- # 5) mime_type:PNG;print_type:black_white
157
- #
158
- # Product 3
159
- # 6 +7) mime_type:jpeg;print_type:colour,sepia;size:large
160
- # 8) mime_type:jpeg;print_type:colour
161
- # 9) mime_type:PNG
162
- # 9 + 10) mime_type:PDF|print_type:black_white
163
-
164
- prod_count = 3
165
- var_count = 10
166
-
167
- # plus 3 MASTER VARIANTS
168
- @Product_klass.count.should == prod_count
169
- @Variant_klass.count.should == prod_count + var_count
170
-
171
- p = @Product_klass.first
172
-
173
- p.variants_including_master.should have_exactly(4).items
174
- p.variants.should have_exactly(3).items
175
-
176
- p.variants.each { |v| v.option_values.each {|o| puts o.inspect } }
177
-
178
- p.option_types.each { |ot| puts ot.inspect }
179
- p.option_types.should have_exactly(2).items # mime_type, print_type
180
-
181
- v1 = p.variants[0]
182
- v1.option_values.should have_exactly(2).items
183
- v1.option_values.collect(&:name).sort.should == ['colour','jpeg']
184
-
185
- end
186
-
187
-
188
-
189
- end
@@ -1,102 +0,0 @@
1
- # Copyright:: (c) Autotelik Media Ltd 2011
2
- # Author :: Tom Statter
3
- # Date :: Aug 2011
4
- # License:: MIT.
5
- #
6
- # REQUIRES: JRuby
7
- #
8
- # Usage::
9
- #
10
- # In Rakefile:
11
- #
12
- # require 'datashift'
13
- #
14
- # DataShift::load_tasks
15
- #
16
- # Cmd Line:
17
- #
18
- # => jruby -S rake datashift:generate:excel model=<active record class> result=<output_template.xls>
19
- #
20
- namespace :datashift do
21
-
22
- namespace :generate do
23
-
24
- include RakeUtils
25
-
26
- desc "Generate a template .xls (Excel) file for a model"
27
-
28
- task :excel, [:model, :result] => :environment do |t, args|
29
-
30
-
31
- # in familiar ruby style args seems to have been become empty using this new style for rake 0.9.2
32
- # whatever format i try, on both Win and OSX .. so had to revert back to ENV
33
- model = args.model || ENV['model']
34
- result = args.result || ENV['result']
35
-
36
- RakeUtils::check_args(args, [:model, :result]) do
37
- x =<<-EOS
38
- USAGE::
39
-
40
- rake datashift:generate:excel model=<Class> result=<file.xls>
41
-
42
- Generate a template Excel file representing an Active Record mode.
43
- Once populated with data the template can be used to import the data,
44
- via the partner import tasks
45
- Parameters :
46
- [:model] - Mandatory - The database model to export.
47
- [:results] - Mandatory - Name of the output template file..
48
- EOS
49
- puts x
50
- end
51
-
52
-
53
- require 'excel_generator'
54
-
55
- raise "USAGE: jruby -S rake datashift:generate:excel model=<Class> result=<file.xls>" unless(result)
56
-
57
-
58
- begin
59
- # support modules e.g "Spree::Property")
60
- klass = ModelMapper::class_from_string(model) #Kernel.const_get(model)
61
- rescue NameError
62
- raise "ERROR: No such AR Model found - check valid model supplied via model=<Class>"
63
- end
64
-
65
- gen = DataShift::ExcelGenerator.new(result)
66
-
67
- gen.generate(klass)
68
- end
69
-
70
- end
71
-
72
- namespace :export do
73
-
74
- desc "Export active record data to .xls (Excel) file"
75
-
76
- task :excel, [:model, :result] => [:environment] do |t, args|
77
-
78
- require 'excel_generator'
79
-
80
- # in familiar ruby style args seems to have been become empty using this new style for rake 0.9.2
81
- # whatever format i try, on both Win and OSX .. so had to revert back to ENV
82
- model = ENV['model']
83
- result = ENV['result']
84
-
85
- raise "USAGE: jruby -S rake datashift:gen:excel model=<Class> result=<file.xls>" unless(result)
86
- raise "ERROR: Cannot process without AR Model - please supply model=<Class>" unless(model)
87
-
88
- begin
89
- # support modules e.g "Spree::Property")
90
- klass = ModelMapper::class_from_string(model) #Kernel.const_get(model)
91
- rescue NameError
92
- raise "ERROR: No such AR Model found - check valid model supplied via model=<Class>"
93
- end
94
-
95
- gen = DataShift::ExcelGenerator.new(result)
96
-
97
- gen.export(klass.all)
98
- end
99
-
100
- end
101
-
102
- end