datashift 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/README.markdown +13 -12
  2. data/Rakefile +8 -8
  3. data/VERSION +1 -5
  4. data/datashift.gemspec +12 -38
  5. data/lib/applications/jruby/jexcel_file.rb +23 -11
  6. data/lib/datashift/method_detail.rb +44 -5
  7. data/lib/datashift/method_dictionary.rb +210 -0
  8. data/lib/datashift/method_mapper.rb +25 -191
  9. data/lib/generators/excel_generator.rb +12 -11
  10. data/lib/helpers/spree_helper.rb +36 -12
  11. data/lib/loaders/excel_loader.rb +2 -1
  12. data/lib/loaders/loader_base.rb +37 -20
  13. data/lib/loaders/spree/image_loader.rb +35 -16
  14. data/lib/loaders/spree/product_loader.rb +27 -1
  15. data/spec/csv_loader_spec.rb +3 -3
  16. data/spec/excel_exporter_spec.rb +79 -0
  17. data/spec/excel_generator_spec.rb +3 -3
  18. data/spec/excel_loader_spec.rb +35 -16
  19. data/spec/fixtures/ProjectsMultiCategoriesHeaderLookup.xls +0 -0
  20. data/spec/fixtures/images/DEMO_001_ror_bag.jpeg +0 -0
  21. data/spec/fixtures/images/DEMO_002_Powerstation.jpg +0 -0
  22. data/spec/fixtures/images/DEMO_003_ror_mug.jpeg +0 -0
  23. data/spec/fixtures/images/DEMO_004_ror_ringer.jpeg +0 -0
  24. data/spec/fixtures/interact_models_db.sqlite +0 -0
  25. data/spec/fixtures/interact_spree_db.sqlite +0 -0
  26. data/spec/fixtures/spree/SpreeProductsWithImages.xls +0 -0
  27. data/spec/loader_spec.rb +4 -4
  28. data/spec/method_dictionary_spec.rb +243 -0
  29. data/spec/method_mapper_spec.rb +17 -213
  30. data/spec/spec_helper.rb +1 -0
  31. data/spec/spree_loader_spec.rb +18 -1
  32. data/spec/spree_method_mapping_spec.rb +4 -4
  33. metadata +14 -130
  34. data/Gemfile +0 -28
  35. data/spec/fixtures/.~lock.ProjectsSingleCategories.xls# +0 -1
@@ -8,231 +8,35 @@
8
8
  # and a classes different types of assignment operators
9
9
  #
10
10
  require File.dirname(__FILE__) + '/spec_helper'
11
-
11
+
12
12
  describe 'Method Mapping' do
13
13
 
14
14
  before(:all) do
15
15
  db_connect( 'test_file' ) # , test_memory, test_mysql
16
+
17
+ # load our test model definitions - Project etc
18
+ require ifixture_file('test_model_defs')
19
+
16
20
  migrate_up
17
- @klazz = Project
18
- @assoc_klazz = Milestone
19
21
  end
20
22
 
21
23
  before(:each) do
22
- MethodMapper.clear
23
- MethodMapper.find_operators( @klazz )
24
- MethodMapper.find_operators( @assoc_klazz )
25
- end
26
-
27
- it "should populate method map for a given AR model" do
28
-
29
- MethodMapper.has_many.should_not be_empty
30
- MethodMapper.has_many[Project].should include('milestones')
31
-
32
- MethodMapper.assignments.should_not be_empty
33
- MethodMapper.assignments[Project].should include('id')
34
- MethodMapper.assignments[Project].should include('value_as_string')
35
- MethodMapper.assignments[Project].should include('value_as_text')
36
-
37
- MethodMapper.belongs_to.should_not be_empty
38
- MethodMapper.belongs_to[Project].should be_empty
39
-
40
-
41
- MethodMapper.column_types.should be_is_a(Hash)
42
- MethodMapper.column_types.should_not be_empty
43
- MethodMapper.column_types[Project].size.should == Project.columns.size
44
-
45
-
24
+ MethodDictionary.clear
25
+
26
+ MethodDictionary.find_operators( Project )
27
+ MethodDictionary.find_operators( Milestone )
28
+
29
+
30
+ MethodDictionary.build_method_details( Project )
31
+ MethodDictionary.build_method_details( Milestone )
32
+
46
33
  end
47
-
48
- it "should populate assigment members without the equivalent association names" do
49
-
50
- # we should remove has-many & belongs_to from basic assignment set as they require a DB lookup
51
- # or a Model.create call, not a simple assignment
52
-
53
- MethodMapper.assignments_for(@klazz).should_not include( MethodMapper.belongs_to_for(@klazz) )
54
- MethodMapper.assignments_for(@klazz).should_not include( MethodMapper.has_many_for(@klazz) )
55
- end
56
-
57
-
58
- it "should populate assignment operators for method details for different forms of a column name" do
59
-
60
- [:value_as_string, 'value_as_string', "VALUE as_STRING", "value as string"].each do |format|
61
-
62
- method_details = MethodMapper.find_method_detail( @klazz, format )
63
-
64
- method_details.class.should == MethodDetail
65
-
66
- method_details.name.should eq( format.to_s )
67
-
68
- method_details.operator.should == 'value_as_string'
69
- method_details.operator_for(:assignment).should == 'value_as_string'
70
-
71
- method_details.operator?('value_as_string').should be_true
72
- method_details.operator?('blah_as_string').should be_false
73
-
74
- method_details.operator_for(:belongs_to).should be_nil
75
- method_details.operator_for(:has_many).should be_nil
76
- end
77
- end
78
-
79
-
80
- # Note : Not all assignments will currently have a column type, for example
81
- # those that are derived from a delegate_belongs_to
82
-
83
- it "should populate column types for assignment operators in method details" do
84
-
85
- [:value_as_string, 'value_as_string', "VALUE as_STRING", "value as string"].each do |format|
86
-
87
- method_details = MethodMapper.find_method_detail( @klazz, format )
88
-
89
- method_details.class.should == MethodDetail
90
-
91
- method_details.col_type.should_not be_nil
92
- method_details.col_type.name.should == 'value_as_string'
93
- method_details.col_type.default.should == nil
94
- method_details.col_type.sql_type.should include 'varchar(255)' # db specific, sqlite
95
- method_details.col_type.type.should == :string
96
- end
97
- end
98
-
99
- it "should populate required Class for assignment operators based on column type" do
100
-
101
- [:value_as_string, 'value_as_string', "VALUE as_STRING", "value as string"].each do |format|
102
-
103
- method_details = MethodMapper.find_method_detail( Project, format )
104
-
105
- method_details.operator_class_name.should == 'String'
106
- method_details.operator_class.should be_is_a(Class)
107
- method_details.operator_class.should == String
108
- end
109
-
110
- end
111
-
112
- it "should populate belongs_to operator for method details for different forms of a column name" do
113
-
114
- # milestone.project = project.id
115
- [:project, 'project', "PROJECT", "prOJECt"].each do |format|
116
-
117
- method_details = MethodMapper.find_method_detail( Milestone, format )
118
-
119
- method_details.should_not be_nil
120
-
121
- method_details.operator.should == 'project'
122
- method_details.operator_for(:belongs_to).should == 'project'
123
-
124
- method_details.operator_for(:assignment).should be_nil
125
- method_details.operator_for(:has_many).should be_nil
126
- end
127
-
128
- end
129
-
130
- it "should populate required Class for belongs_to operator method details" do
131
-
132
- MethodMapper.find_operators( LoaderRelease )
133
- MethodMapper.find_operators( LongAndComplexTableLinkedToVersion )
134
-
135
- # release.project = project.id
136
- [:project, 'project', "PROJECT", "prOJECt"].each do |format|
137
-
138
- method_details = MethodMapper.find_method_detail( LoaderRelease, format )
139
-
140
- method_details.operator_class_name.should == 'Project'
141
- method_details.operator_class.should == Project
142
- end
143
-
144
-
145
- #LongAndComplexTableLinkedToVersion.version = version.id
146
-
147
- [:version, "Version", "verSION"].each do |format|
148
- method_details = MethodMapper.find_method_detail( LongAndComplexTableLinkedToVersion, format )
149
-
150
- method_details.operator_type.should == :belongs_to
151
-
152
- method_details.operator_class_name.should == 'Version'
153
- method_details.operator_class.should == Version
154
- end
155
- end
156
-
157
- it "should populate required Class for has_one operator method details" do
158
-
159
- MethodMapper.find_operators( Version )
160
-
161
- # version.long_and_complex_table_linked_to_version = LongAndComplexTableLinkedToVersion.create()
162
-
163
- [:long_and_complex_table_linked_to_version, 'LongAndComplexTableLinkedToVersion', "Long And Complex_Table_Linked To Version", "Long_And_Complex_Table_Linked_To_Version"].each do |format|
164
- method_details = MethodMapper.find_method_detail( Version, format )
165
-
166
- method_details.should_not be_nil
167
-
168
- method_details.operator.should == 'long_and_complex_table_linked_to_version'
169
-
170
- method_details.operator_type.should == :has_one
171
-
172
- method_details.operator_class_name.should == 'LongAndComplexTableLinkedToVersion'
173
- method_details.operator_class.should == LongAndComplexTableLinkedToVersion
174
- end
175
- end
176
-
177
-
178
- it "should find has_many operator for method details" do
179
-
180
- [:milestones, "Mile Stones", 'mileSTONES', 'MileStones'].each do |format|
181
-
182
- method_details = MethodMapper.find_method_detail( Project, format )
183
-
184
- method_details.class.should == MethodDetail
185
-
186
- result = 'milestones'
187
- method_details.operator.should == result
188
- method_details.operator_for(:has_many).should == result
189
-
190
- method_details.operator_for(:belongs_to).should be_nil
191
- method_details.operator_for(:assignments).should be_nil
192
- end
193
-
194
- end
195
-
196
34
 
197
- it "should return nil when non existent column name" do
198
- ["On sale", 'on_sale'].each do |format|
199
- detail = MethodMapper.find_method_detail( @klazz, format )
200
-
201
- detail.should be_nil
202
- end
203
- end
204
-
205
-
206
35
  it "should find a set of methods based on a list of column names" do
207
-
208
- mapper = MethodMapper.new
209
-
210
- [:value_as_string, 'value_as_string', "VALUE as_STRING", "value as string"].each do |column_name_format|
211
-
212
- method_details = MethodMapper.find_method_detail( @klazz, column_name_format )
213
-
214
- method_details.class.should == MethodDetail
215
-
216
- method_details.col_type.should_not be_nil
217
- method_details.col_type.name.should == 'value_as_string'
218
- method_details.col_type.default.should == nil
219
- method_details.col_type.sql_type.should include 'varchar(255)' # db specific, sqlite
220
- method_details.col_type.type.should == :string
221
- end
222
- end
223
-
224
- it "should not by default map setter methods", :fail => true do
225
- MethodMapper.assignments[Milestone].should_not include('title')
226
- end
227
-
228
- it "should support reload and inclusion of setter methods", :fail => true do
229
-
230
- MethodMapper.assignments[Milestone].should_not include('title')
231
-
232
- MethodMapper.find_operators( Milestone, :reload => true, :instance_methods => true )
36
+ pending("key API - map column headers to set of methods")
233
37
 
234
- # Milestone delegates :title to Project
235
- MethodMapper.assignments[Milestone].should include('title')
38
+ @method_mapper.map_inbound_to_methods( load_object_class, @headers )
236
39
  end
237
40
 
41
+
238
42
  end
data/spec/spec_helper.rb CHANGED
@@ -21,6 +21,7 @@ $DataShiftDatabaseYml = File.join($DataShiftFixturePath, 'config/database.yml')
21
21
 
22
22
  module DataShift
23
23
 
24
+
24
25
  def db_connect( env = 'test_file', version = nil)
25
26
 
26
27
  version ? gem('activerecord', version) : gem('activerecord')
@@ -51,7 +51,7 @@ describe 'SpreeLoader' do
51
51
  before(:each) do
52
52
 
53
53
  MethodMapper.clear
54
- MethodMapper.find_operators( @klazz )
54
+ MethodDictionary.find_operators( @klazz )
55
55
 
56
56
  # Reset main tables - TODO should really purge properly, or roll back a transaction
57
57
  [OptionType, OptionValue, Product, Property, Variant, Taxonomy, Taxon, Zone].each { |x| x.delete_all }
@@ -269,6 +269,15 @@ describe 'SpreeLoader' do
269
269
 
270
270
  end
271
271
 
272
+ it "should load Products with assoicated image", :img => true do
273
+
274
+ @product_loader.perform_load( spree_fix('SpreeProductsWithImages.csv'), :mandatory => ['sku', 'name', 'price'] )
275
+
276
+ p = Product.find_by_sku( "DEMO_001")
277
+
278
+ p.images.should have_exactly(1).items
279
+ end
280
+
272
281
 
273
282
  # REPEAT THE WHOLE TEST SUITE VIA CSV
274
283
 
@@ -288,6 +297,14 @@ describe 'SpreeLoader' do
288
297
 
289
298
  expected_multi_column_taxons
290
299
  end
300
+
301
+ it "should load Products with assoicated image" do
302
+ test_variants_creation('SpreeProductsMultiColumn.csv')
303
+
304
+ expected_multi_column_properties
305
+
306
+ expected_multi_column_taxons
307
+ end
291
308
 
292
309
 
293
310
  it "should raise exception when mandatory columns missing from .xls", :ex => true do
@@ -39,7 +39,7 @@ describe 'SpreeLoader' do
39
39
 
40
40
  before(:each) do
41
41
  MethodMapper.clear
42
- MethodMapper.find_operators( @klazz )
42
+ MethodDictionary.find_operators( @klazz )
43
43
  end
44
44
 
45
45
 
@@ -109,7 +109,7 @@ describe 'SpreeLoader' do
109
109
 
110
110
  it "should populate method details correctly for assignment operators (none columns on #{@klazz})" do
111
111
 
112
- MethodMapper.find_operators( @klazz, :reload => true, :instance_methods => true )
112
+ MethodDictionary.find_operators( @klazz, :reload => true, :instance_methods => true )
113
113
 
114
114
  # Example of delegates i.e. cost_price column on Variant, delegated to Variant by Product
115
115
 
@@ -128,7 +128,7 @@ describe 'SpreeLoader' do
128
128
 
129
129
  it "should enable assignment via operators for none columns on #{@klazz}" do
130
130
 
131
- MethodMapper.find_operators( @klazz, :reload => true, :instance_methods => true )
131
+ MethodDictionary.find_operators( @klazz, :reload => true, :instance_methods => true )
132
132
 
133
133
  klazz_object = @klazz.new
134
134
 
@@ -184,7 +184,7 @@ describe 'SpreeLoader' do
184
184
 
185
185
  it "should enable assignment to has_many association using existing objects" do
186
186
 
187
- MethodMapper.find_operators( @klazz )
187
+ MethodDictionary.find_operators( @klazz )
188
188
 
189
189
  method_detail = MethodMapper.find_method_detail( @klazz, 'product_properties' )
190
190
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: datashift
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Thomas Statter
@@ -10,129 +10,9 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-02-12 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: rails
17
- version_requirements: &id001 !ruby/object:Gem::Requirement
18
- none: false
19
- requirements:
20
- - - "="
21
- - !ruby/object:Gem::Version
22
- version: 3.1.3
23
- requirement: *id001
24
- prerelease: false
25
- type: :development
26
- - !ruby/object:Gem::Dependency
27
- name: activerecord
28
- version_requirements: &id002 !ruby/object:Gem::Requirement
29
- none: false
30
- requirements:
31
- - - "="
32
- - !ruby/object:Gem::Version
33
- version: 3.1.3
34
- requirement: *id002
35
- prerelease: false
36
- type: :development
37
- - !ruby/object:Gem::Dependency
38
- name: activesupport
39
- version_requirements: &id003 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - "="
43
- - !ruby/object:Gem::Version
44
- version: 3.1.3
45
- requirement: *id003
46
- prerelease: false
47
- type: :development
48
- - !ruby/object:Gem::Dependency
49
- name: jruby-openssl
50
- version_requirements: &id004 !ruby/object:Gem::Requirement
51
- none: false
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: "0"
56
- requirement: *id004
57
- prerelease: false
58
- type: :development
59
- - !ruby/object:Gem::Dependency
60
- name: activerecord-jdbcsqlite3-adapter
61
- version_requirements: &id005 !ruby/object:Gem::Requirement
62
- none: false
63
- requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- version: "0"
67
- requirement: *id005
68
- prerelease: false
69
- type: :development
70
- - !ruby/object:Gem::Dependency
71
- name: spree
72
- version_requirements: &id006 !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - "="
76
- - !ruby/object:Gem::Version
77
- version: 0.70.3
78
- requirement: *id006
79
- prerelease: false
80
- type: :development
81
- - !ruby/object:Gem::Dependency
82
- name: rspec
83
- version_requirements: &id007 !ruby/object:Gem::Requirement
84
- none: false
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- version: "0"
89
- requirement: *id007
90
- prerelease: false
91
- type: :development
92
- - !ruby/object:Gem::Dependency
93
- name: shoulda
94
- version_requirements: &id008 !ruby/object:Gem::Requirement
95
- none: false
96
- requirements:
97
- - - ">="
98
- - !ruby/object:Gem::Version
99
- version: "0"
100
- requirement: *id008
101
- prerelease: false
102
- type: :development
103
- - !ruby/object:Gem::Dependency
104
- name: rdoc
105
- version_requirements: &id009 !ruby/object:Gem::Requirement
106
- none: false
107
- requirements:
108
- - - ~>
109
- - !ruby/object:Gem::Version
110
- version: "3.12"
111
- requirement: *id009
112
- prerelease: false
113
- type: :development
114
- - !ruby/object:Gem::Dependency
115
- name: bundler
116
- version_requirements: &id010 !ruby/object:Gem::Requirement
117
- none: false
118
- requirements:
119
- - - ~>
120
- - !ruby/object:Gem::Version
121
- version: 1.0.0
122
- requirement: *id010
123
- prerelease: false
124
- type: :development
125
- - !ruby/object:Gem::Dependency
126
- name: jeweler
127
- version_requirements: &id011 !ruby/object:Gem::Requirement
128
- none: false
129
- requirements:
130
- - - ~>
131
- - !ruby/object:Gem::Version
132
- version: 1.8.3
133
- requirement: *id011
134
- prerelease: false
135
- type: :development
13
+ date: 2012-02-27 00:00:00 Z
14
+ dependencies: []
15
+
136
16
  description: A suite of tools to move data between ActiveRecord models,databases,applications like Excel/Open Office, files and projects including Spree
137
17
  email: rubygems@autotelik.co.uk
138
18
  executables: []
@@ -145,13 +25,12 @@ extra_rdoc_files:
145
25
  - README.rdoc
146
26
  files:
147
27
  - .document
148
- - Gemfile
149
28
  - LICENSE.txt
150
29
  - README.markdown
151
30
  - README.rdoc
152
31
  - Rakefile
153
32
  - VERSION
154
- - datashift-0.0.2.gem
33
+ - datashift-0.1.0.gem
155
34
  - datashift.gemspec
156
35
  - lib/applications/jruby/jexcel_file.rb
157
36
  - lib/applications/jruby/word.rb
@@ -160,6 +39,7 @@ files:
160
39
  - lib/datashift/file_definitions.rb
161
40
  - lib/datashift/mapping_file_definitions.rb
162
41
  - lib/datashift/method_detail.rb
42
+ - lib/datashift/method_dictionary.rb
163
43
  - lib/datashift/method_mapper.rb
164
44
  - lib/generators/csv_generator.rb
165
45
  - lib/generators/excel_generator.rb
@@ -190,17 +70,22 @@ files:
190
70
  - spec/csv_loader_spec.rb
191
71
  - spec/datashift_spec.rb
192
72
  - spec/db/migrate/20110803201325_create_test_bed.rb
73
+ - spec/excel_exporter_spec.rb
193
74
  - spec/excel_generator_spec.rb
194
75
  - spec/excel_loader_spec.rb
195
76
  - spec/file_definitions.rb
196
- - spec/fixtures/.~lock.ProjectsSingleCategories.xls#
197
77
  - spec/fixtures/BadAssociationName.xls
198
78
  - spec/fixtures/DemoNegativeTesting.xls
199
79
  - spec/fixtures/ProjectsDefaults.yml
200
80
  - spec/fixtures/ProjectsMultiCategories.xls
81
+ - spec/fixtures/ProjectsMultiCategoriesHeaderLookup.xls
201
82
  - spec/fixtures/ProjectsSingleCategories.xls
202
83
  - spec/fixtures/SimpleProjects.xls
203
84
  - spec/fixtures/config/database.yml
85
+ - spec/fixtures/images/DEMO_001_ror_bag.jpeg
86
+ - spec/fixtures/images/DEMO_002_Powerstation.jpg
87
+ - spec/fixtures/images/DEMO_003_ror_mug.jpeg
88
+ - spec/fixtures/images/DEMO_004_ror_ringer.jpeg
204
89
  - spec/fixtures/interact_models_db.sqlite
205
90
  - spec/fixtures/interact_spree_db.sqlite
206
91
  - spec/fixtures/negative/SpreeProdMiss1Mandatory.csv
@@ -215,10 +100,12 @@ files:
215
100
  - spec/fixtures/spree/SpreeProductsMultiColumn.xls
216
101
  - spec/fixtures/spree/SpreeProductsSimple.csv
217
102
  - spec/fixtures/spree/SpreeProductsSimple.xls
103
+ - spec/fixtures/spree/SpreeProductsWithImages.xls
218
104
  - spec/fixtures/spree/SpreeZoneExample.csv
219
105
  - spec/fixtures/spree/SpreeZoneExample.xls
220
106
  - spec/fixtures/test_model_defs.rb
221
107
  - spec/loader_spec.rb
108
+ - spec/method_dictionary_spec.rb
222
109
  - spec/method_mapper_spec.rb
223
110
  - spec/spec_helper.rb
224
111
  - spec/spree_generator_spec.rb
@@ -249,9 +136,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
249
136
  requirements:
250
137
  - - ">="
251
138
  - !ruby/object:Gem::Version
252
- hash: 2
253
- segments:
254
- - 0
255
139
  version: "0"
256
140
  required_rubygems_version: !ruby/object:Gem::Requirement
257
141
  none: false