datashift 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/.document +5 -5
  2. data/Gemfile +28 -25
  3. data/LICENSE.txt +26 -26
  4. data/README.markdown +302 -285
  5. data/README.rdoc +19 -19
  6. data/Rakefile +93 -95
  7. data/VERSION +5 -5
  8. data/datashift.gemspec +162 -178
  9. data/lib/applications/jruby/jexcel_file.rb +396 -396
  10. data/lib/applications/jruby/word.rb +79 -79
  11. data/lib/datashift.rb +152 -113
  12. data/lib/datashift/exceptions.rb +11 -11
  13. data/lib/datashift/file_definitions.rb +353 -353
  14. data/lib/datashift/mapping_file_definitions.rb +87 -87
  15. data/lib/datashift/method_detail.rb +236 -236
  16. data/lib/datashift/method_mapper.rb +256 -256
  17. data/lib/generators/csv_generator.rb +36 -36
  18. data/lib/generators/excel_generator.rb +121 -121
  19. data/lib/generators/generator_base.rb +13 -13
  20. data/lib/helpers/core_ext/to_b.rb +24 -24
  21. data/lib/helpers/spree_helper.rb +131 -131
  22. data/lib/java/poi-3.7/LICENSE +507 -507
  23. data/lib/java/poi-3.7/NOTICE +21 -21
  24. data/lib/java/poi-3.7/RELEASE_NOTES.txt +115 -115
  25. data/lib/loaders/csv_loader.rb +98 -98
  26. data/lib/loaders/excel_loader.rb +154 -149
  27. data/lib/loaders/loader_base.rb +403 -331
  28. data/lib/loaders/spreadsheet_loader.rb +136 -136
  29. data/lib/loaders/spree/image_loader.rb +45 -45
  30. data/lib/loaders/spree/product_loader.rb +224 -224
  31. data/spec/csv_loader_spec.rb +30 -30
  32. data/spec/datashift_spec.rb +26 -26
  33. data/spec/db/migrate/20110803201325_create_test_bed.rb +85 -85
  34. data/spec/excel_generator_spec.rb +78 -78
  35. data/spec/excel_loader_spec.rb +204 -176
  36. data/spec/file_definitions.rb +141 -141
  37. data/spec/fixtures/.~lock.ProjectsSingleCategories.xls# +1 -0
  38. data/spec/fixtures/ProjectsDefaults.yml +29 -0
  39. data/spec/fixtures/config/database.yml +24 -24
  40. data/spec/fixtures/interact_models_db.sqlite +0 -0
  41. data/spec/fixtures/interact_spree_db.sqlite +0 -0
  42. data/spec/fixtures/negative/SpreeProdMiss1Mandatory.csv +4 -4
  43. data/spec/fixtures/negative/SpreeProdMissManyMandatory.csv +4 -4
  44. data/spec/fixtures/spree/SpreeProducts.csv +4 -4
  45. data/spec/fixtures/spree/SpreeProductsMultiColumn.csv +4 -4
  46. data/spec/fixtures/spree/SpreeProductsSimple.csv +4 -4
  47. data/spec/fixtures/spree/SpreeZoneExample.csv +5 -5
  48. data/spec/fixtures/test_model_defs.rb +57 -57
  49. data/spec/loader_spec.rb +120 -120
  50. data/spec/method_mapper_spec.rb +237 -237
  51. data/spec/spec_helper.rb +115 -115
  52. data/spec/spree_generator_spec.rb +64 -64
  53. data/spec/spree_loader_spec.rb +310 -310
  54. data/spec/spree_method_mapping_spec.rb +214 -214
  55. data/tasks/config/seed_fu_product_template.erb +15 -15
  56. data/tasks/config/tidy_config.txt +12 -12
  57. data/tasks/db_tasks.rake +65 -64
  58. data/tasks/excel_generator.rake +78 -78
  59. data/tasks/file_tasks.rake +36 -36
  60. data/tasks/import/csv.rake +49 -49
  61. data/tasks/import/excel.rake +71 -66
  62. data/tasks/spree/image_load.rake +108 -108
  63. data/tasks/spree/product_loader.rake +43 -43
  64. data/tasks/word_to_seedfu.rake +166 -166
  65. data/test/helper.rb +18 -18
  66. data/test/test_interact.rb +7 -7
  67. metadata +7 -38
  68. data/Gemfile.lock +0 -211
  69. data/bin/autospec +0 -16
  70. data/bin/convert_to_should_syntax +0 -16
  71. data/bin/erubis +0 -16
  72. data/bin/htmldiff +0 -16
  73. data/bin/jeweler +0 -16
  74. data/bin/ldiff +0 -16
  75. data/bin/nokogiri +0 -16
  76. data/bin/rackup +0 -16
  77. data/bin/rails +0 -16
  78. data/bin/rake +0 -16
  79. data/bin/rake2thor +0 -16
  80. data/bin/ri +0 -16
  81. data/bin/rspec +0 -16
  82. data/bin/spree +0 -16
  83. data/bin/thor +0 -16
  84. data/bin/tilt +0 -16
  85. data/bin/tt +0 -16
@@ -1,215 +1,215 @@
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 'SpreeLoader' do
20
-
21
- before(:all) do
22
-
23
- # we are not a Spree project, nor is it practical to externally generate
24
- # a complete Spree application for testing so we implement a mini migrate/boot of our own
25
- Spree.load() # require Spree gems
26
-
27
- # key to YAML db e.g test_memory, test_mysql
28
- db_connect( 'test_spree_standalone' )
29
-
30
- Spree.boot # create a sort-of Spree app
31
-
32
- Spree.migrate_up # create an sqlite Spree database on the fly
33
-
34
- @klazz = Product
35
-
36
- # Reset main tables - TODO should really purge properly, or roll back a transaction
37
- [OptionType, OptionValue, Product, Property, Variant, Taxonomy, Taxon, Zone].each { |x| x.delete_all }
38
- end
39
-
40
- before(:each) do
41
- MethodMapper.clear
42
- MethodMapper.find_operators( @klazz )
43
- end
44
-
45
-
46
- it "should populate operators for a Spree Product" do
47
-
48
- MethodMapper.has_many.should_not be_empty
49
- MethodMapper.belongs_to.should_not be_empty
50
- MethodMapper.assignments.should_not be_empty
51
-
52
- assign = MethodMapper.assignments_for(@klazz)
53
-
54
- assign.should include('available_on') # Example of a simple column
55
-
56
- MethodMapper.assignments[@klazz].should include('available_on')
57
-
58
- has_many_ops = MethodMapper.has_many_for(@klazz)
59
-
60
- has_many_ops.should include('properties') # Product can have many properties
61
-
62
- MethodMapper.has_many[@klazz].should include('properties')
63
-
64
- btf = MethodMapper.belongs_to_for(@klazz)
65
-
66
- btf.should include('tax_category') # Example of a belongs_to assignment
67
-
68
- MethodMapper.belongs_to[@klazz].should include('tax_category')
69
-
70
- MethodMapper.column_types[@klazz].size.should == @klazz.columns.size
71
- end
72
-
73
-
74
- it "should find method details correctly for different forms of a column name" do
75
-
76
- ["available On", 'available_on', "Available On", "AVAILABLE_ON"].each do |format|
77
-
78
- method_details = MethodMapper.find_method_detail( @klazz, format )
79
-
80
- method_details.operator.should == 'available_on'
81
- method_details.operator_for(:assignment).should == 'available_on'
82
-
83
- method_details.operator_for(:belongs_to).should be_nil
84
- method_details.operator_for(:has_many).should be_nil
85
-
86
- method_details.col_type.should_not be_nil
87
- method_details.col_type.name.should == 'available_on'
88
- method_details.col_type.default.should == nil
89
- method_details.col_type.sql_type.should include 'datetime' # works on mysql and sqlite
90
- method_details.col_type.type.should == :datetime
91
- end
92
- end
93
-
94
- it "should populate method details correctly for has_many forms of association name" do
95
-
96
- MethodMapper.has_many[@klazz].should include('product_option_types')
97
-
98
- ["product_option_types", "product option types", 'product Option_types', "ProductOptionTypes", "Product_Option_Types"].each do |format|
99
- method_detail = MethodMapper.find_method_detail( @klazz, format )
100
-
101
- method_detail.should_not be_nil
102
-
103
- method_detail.operator_for(:has_many).should eq('product_option_types')
104
- method_detail.operator_for(:belongs_to).should be_nil
105
- method_detail.operator_for(:assignment).should be_nil
106
- end
107
- end
108
-
109
-
110
- it "should populate method details correctly for assignment operators (none columns on #{@klazz})" do
111
-
112
- MethodMapper.find_operators( @klazz, :reload => true, :instance_methods => true )
113
-
114
- # Example of delegates i.e. cost_price column on Variant, delegated to Variant by Product
115
-
116
- MethodMapper.assignments[@klazz].should include('cost_price')
117
- MethodMapper.assignments[@klazz].should include('sku')
118
-
119
-
120
- count_on_hand = MethodMapper.find_method_detail( @klazz, 'count on hand' )
121
- count_on_hand.should_not be_nil
122
- count_on_hand.operator.should == 'count_on_hand'
123
-
124
- method = MethodMapper.find_method_detail( @klazz, 'sku' )
125
- method.should_not be_nil
126
- method.operator.should == 'sku'
127
- end
128
-
129
- it "should enable assignment via operators for none columns on #{@klazz}" do
130
-
131
- MethodMapper.find_operators( @klazz, :reload => true, :instance_methods => true )
132
-
133
- klazz_object = @klazz.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 = MethodMapper.find_method_detail( @klazz, '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 = MethodMapper.find_method_detail( @klazz, '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
- method_detail = MethodMapper.find_method_detail( @klazz, 'taxons' )
160
-
161
- method_detail.operator.should == 'taxons'
162
-
163
- klazz_object = @klazz.new
164
-
165
- klazz_object.taxons.size.should == 0
166
-
167
- # NEW ASSOCIATION ASSIGNMENT
168
-
169
- # assign via the send operator directly on load object
170
- klazz_object.send( method_detail.operator ) << Taxon.new
171
-
172
- klazz_object.taxons.size.should == 1
173
-
174
- klazz_object.send( method_detail.operator ) << [Taxon.new, Taxon.new]
175
- klazz_object.taxons.size.should == 3
176
-
177
- # Use generic assignment on method detail - expect has_many to use << not =
178
- method_detail.assign( klazz_object, Taxon.new )
179
- klazz_object.taxons.size.should == 4
180
-
181
- method_detail.assign( klazz_object, [Taxon.new, Taxon.new])
182
- klazz_object.taxons.size.should == 6
183
- end
184
-
185
- it "should enable assignment to has_many association using existing objects" do
186
-
187
- MethodMapper.find_operators( @klazz )
188
-
189
- method_detail = MethodMapper.find_method_detail( @klazz, 'product_properties' )
190
-
191
- method_detail.operator.should == 'product_properties'
192
-
193
- klazz_object = @klazz.new
194
-
195
- ProductProperty.new(:property => @prop1)
196
-
197
- # NEW ASSOCIATION ASSIGNMENT
198
- klazz_object.send( method_detail.operator ) << ProductProperty.new
199
-
200
- klazz_object.product_properties.size.should == 1
201
-
202
- klazz_object.send( method_detail.operator ) << [ProductProperty.new, ProductProperty.new]
203
- klazz_object.product_properties.size.should == 3
204
-
205
- # Use generic assignment on method detail - expect has_many to use << not =
206
- method_detail.assign( klazz_object, ProductProperty.new(:property => @prop1) )
207
- klazz_object.product_properties.size.should == 4
208
-
209
- method_detail.assign( klazz_object, [ProductProperty.new(:property => @prop2), ProductProperty.new(:property => @prop3)])
210
- klazz_object.product_properties.size.should == 6
211
-
212
- end
213
-
214
-
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 'SpreeLoader' do
20
+
21
+ before(:all) do
22
+
23
+ # we are not a Spree project, nor is it practical to externally generate
24
+ # a complete Spree application for testing so we implement a mini migrate/boot of our own
25
+ Spree.load() # require Spree gems
26
+
27
+ # key to YAML db e.g test_memory, test_mysql
28
+ db_connect( 'test_spree_standalone' )
29
+
30
+ Spree.boot # create a sort-of Spree app
31
+
32
+ Spree.migrate_up # create an sqlite Spree database on the fly
33
+
34
+ @klazz = Product
35
+
36
+ # Reset main tables - TODO should really purge properly, or roll back a transaction
37
+ [OptionType, OptionValue, Product, Property, Variant, Taxonomy, Taxon, Zone].each { |x| x.delete_all }
38
+ end
39
+
40
+ before(:each) do
41
+ MethodMapper.clear
42
+ MethodMapper.find_operators( @klazz )
43
+ end
44
+
45
+
46
+ it "should populate operators for a Spree Product" do
47
+
48
+ MethodMapper.has_many.should_not be_empty
49
+ MethodMapper.belongs_to.should_not be_empty
50
+ MethodMapper.assignments.should_not be_empty
51
+
52
+ assign = MethodMapper.assignments_for(@klazz)
53
+
54
+ assign.should include('available_on') # Example of a simple column
55
+
56
+ MethodMapper.assignments[@klazz].should include('available_on')
57
+
58
+ has_many_ops = MethodMapper.has_many_for(@klazz)
59
+
60
+ has_many_ops.should include('properties') # Product can have many properties
61
+
62
+ MethodMapper.has_many[@klazz].should include('properties')
63
+
64
+ btf = MethodMapper.belongs_to_for(@klazz)
65
+
66
+ btf.should include('tax_category') # Example of a belongs_to assignment
67
+
68
+ MethodMapper.belongs_to[@klazz].should include('tax_category')
69
+
70
+ MethodMapper.column_types[@klazz].size.should == @klazz.columns.size
71
+ end
72
+
73
+
74
+ it "should find method details correctly for different forms of a column name" do
75
+
76
+ ["available On", 'available_on', "Available On", "AVAILABLE_ON"].each do |format|
77
+
78
+ method_details = MethodMapper.find_method_detail( @klazz, format )
79
+
80
+ method_details.operator.should == 'available_on'
81
+ method_details.operator_for(:assignment).should == 'available_on'
82
+
83
+ method_details.operator_for(:belongs_to).should be_nil
84
+ method_details.operator_for(:has_many).should be_nil
85
+
86
+ method_details.col_type.should_not be_nil
87
+ method_details.col_type.name.should == 'available_on'
88
+ method_details.col_type.default.should == nil
89
+ method_details.col_type.sql_type.should include 'datetime' # works on mysql and sqlite
90
+ method_details.col_type.type.should == :datetime
91
+ end
92
+ end
93
+
94
+ it "should populate method details correctly for has_many forms of association name" do
95
+
96
+ MethodMapper.has_many[@klazz].should include('product_option_types')
97
+
98
+ ["product_option_types", "product option types", 'product Option_types', "ProductOptionTypes", "Product_Option_Types"].each do |format|
99
+ method_detail = MethodMapper.find_method_detail( @klazz, format )
100
+
101
+ method_detail.should_not be_nil
102
+
103
+ method_detail.operator_for(:has_many).should eq('product_option_types')
104
+ method_detail.operator_for(:belongs_to).should be_nil
105
+ method_detail.operator_for(:assignment).should be_nil
106
+ end
107
+ end
108
+
109
+
110
+ it "should populate method details correctly for assignment operators (none columns on #{@klazz})" do
111
+
112
+ MethodMapper.find_operators( @klazz, :reload => true, :instance_methods => true )
113
+
114
+ # Example of delegates i.e. cost_price column on Variant, delegated to Variant by Product
115
+
116
+ MethodMapper.assignments[@klazz].should include('cost_price')
117
+ MethodMapper.assignments[@klazz].should include('sku')
118
+
119
+
120
+ count_on_hand = MethodMapper.find_method_detail( @klazz, 'count on hand' )
121
+ count_on_hand.should_not be_nil
122
+ count_on_hand.operator.should == 'count_on_hand'
123
+
124
+ method = MethodMapper.find_method_detail( @klazz, 'sku' )
125
+ method.should_not be_nil
126
+ method.operator.should == 'sku'
127
+ end
128
+
129
+ it "should enable assignment via operators for none columns on #{@klazz}" do
130
+
131
+ MethodMapper.find_operators( @klazz, :reload => true, :instance_methods => true )
132
+
133
+ klazz_object = @klazz.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 = MethodMapper.find_method_detail( @klazz, '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 = MethodMapper.find_method_detail( @klazz, '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
+ method_detail = MethodMapper.find_method_detail( @klazz, 'taxons' )
160
+
161
+ method_detail.operator.should == 'taxons'
162
+
163
+ klazz_object = @klazz.new
164
+
165
+ klazz_object.taxons.size.should == 0
166
+
167
+ # NEW ASSOCIATION ASSIGNMENT
168
+
169
+ # assign via the send operator directly on load object
170
+ klazz_object.send( method_detail.operator ) << Taxon.new
171
+
172
+ klazz_object.taxons.size.should == 1
173
+
174
+ klazz_object.send( method_detail.operator ) << [Taxon.new, Taxon.new]
175
+ klazz_object.taxons.size.should == 3
176
+
177
+ # Use generic assignment on method detail - expect has_many to use << not =
178
+ method_detail.assign( klazz_object, Taxon.new )
179
+ klazz_object.taxons.size.should == 4
180
+
181
+ method_detail.assign( klazz_object, [Taxon.new, Taxon.new])
182
+ klazz_object.taxons.size.should == 6
183
+ end
184
+
185
+ it "should enable assignment to has_many association using existing objects" do
186
+
187
+ MethodMapper.find_operators( @klazz )
188
+
189
+ method_detail = MethodMapper.find_method_detail( @klazz, 'product_properties' )
190
+
191
+ method_detail.operator.should == 'product_properties'
192
+
193
+ klazz_object = @klazz.new
194
+
195
+ ProductProperty.new(:property => @prop1)
196
+
197
+ # NEW ASSOCIATION ASSIGNMENT
198
+ klazz_object.send( method_detail.operator ) << ProductProperty.new
199
+
200
+ klazz_object.product_properties.size.should == 1
201
+
202
+ klazz_object.send( method_detail.operator ) << [ProductProperty.new, ProductProperty.new]
203
+ klazz_object.product_properties.size.should == 3
204
+
205
+ # Use generic assignment on method detail - expect has_many to use << not =
206
+ method_detail.assign( klazz_object, ProductProperty.new(:property => @prop1) )
207
+ klazz_object.product_properties.size.should == 4
208
+
209
+ method_detail.assign( klazz_object, [ProductProperty.new(:property => @prop2), ProductProperty.new(:property => @prop3)])
210
+ klazz_object.product_properties.size.should == 6
211
+
212
+ end
213
+
214
+
215
215
  end
@@ -1,15 +1,15 @@
1
- p = Product.seed( :name ) do |s|
2
- s.name = <%= @name %>
3
- s.available_on = '2009-09-01 09:00:00.0'
4
- s.meta_keywords = ['training', 'training']
5
- s.meta_description = ""
6
- s.description = '<%= @description %>'
7
- s.price = 0.00
8
- s.sku = '<%= @sku %>'
9
-
10
- s.is_physical = false
11
- s.is_private = false
12
-
13
- s.append_association :taxons, Taxon.find_by_name( 'Training' )
14
-
15
- end
1
+ p = Product.seed( :name ) do |s|
2
+ s.name = <%= @name %>
3
+ s.available_on = '2009-09-01 09:00:00.0'
4
+ s.meta_keywords = ['training', 'training']
5
+ s.meta_description = ""
6
+ s.description = '<%= @description %>'
7
+ s.price = 0.00
8
+ s.sku = '<%= @sku %>'
9
+
10
+ s.is_physical = false
11
+ s.is_private = false
12
+
13
+ s.append_association :taxons, Taxon.find_by_name( 'Training' )
14
+
15
+ end