datashift 0.1.0 → 0.2.1

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 (86) hide show
  1. data/.document +5 -5
  2. data/LICENSE.txt +26 -26
  3. data/README.markdown +305 -303
  4. data/README.rdoc +19 -19
  5. data/Rakefile +93 -93
  6. data/VERSION +1 -1
  7. data/datashift-0.1.0.gem +0 -0
  8. data/datashift.gemspec +152 -136
  9. data/lib/applications/jruby/jexcel_file.rb +408 -408
  10. data/lib/applications/jruby/word.rb +79 -79
  11. data/lib/datashift.rb +152 -152
  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 +275 -275
  16. data/lib/datashift/method_dictionary.rb +209 -209
  17. data/lib/datashift/method_mapper.rb +90 -90
  18. data/lib/generators/csv_generator.rb +36 -36
  19. data/lib/generators/excel_generator.rb +122 -122
  20. data/lib/generators/generator_base.rb +13 -13
  21. data/lib/helpers/core_ext/to_b.rb +24 -24
  22. data/lib/helpers/spree_helper.rb +153 -155
  23. data/lib/java/poi-3.7/LICENSE +507 -507
  24. data/lib/java/poi-3.7/NOTICE +21 -21
  25. data/lib/java/poi-3.7/RELEASE_NOTES.txt +115 -115
  26. data/lib/loaders/csv_loader.rb +98 -98
  27. data/lib/loaders/excel_loader.rb +155 -155
  28. data/lib/loaders/loader_base.rb +420 -420
  29. data/lib/loaders/spreadsheet_loader.rb +136 -136
  30. data/lib/loaders/spree/image_loader.rb +63 -64
  31. data/lib/loaders/spree/product_loader.rb +248 -250
  32. data/public/spree/products/large/DEMO_001_ror_bag.jpeg +0 -0
  33. data/public/spree/products/large/DEMO_002_Powerstation.jpg +0 -0
  34. data/public/spree/products/large/DEMO_003_ror_mug.jpeg +0 -0
  35. data/public/spree/products/mini/DEMO_001_ror_bag.jpeg +0 -0
  36. data/public/spree/products/mini/DEMO_002_Powerstation.jpg +0 -0
  37. data/public/spree/products/mini/DEMO_003_ror_mug.jpeg +0 -0
  38. data/public/spree/products/original/DEMO_001_ror_bag.jpeg +0 -0
  39. data/public/spree/products/original/DEMO_002_Powerstation.jpg +0 -0
  40. data/public/spree/products/original/DEMO_003_ror_mug.jpeg +0 -0
  41. data/public/spree/products/product/DEMO_001_ror_bag.jpeg +0 -0
  42. data/public/spree/products/product/DEMO_002_Powerstation.jpg +0 -0
  43. data/public/spree/products/product/DEMO_003_ror_mug.jpeg +0 -0
  44. data/public/spree/products/small/DEMO_001_ror_bag.jpeg +0 -0
  45. data/public/spree/products/small/DEMO_002_Powerstation.jpg +0 -0
  46. data/public/spree/products/small/DEMO_003_ror_mug.jpeg +0 -0
  47. data/spec/csv_loader_spec.rb +30 -30
  48. data/spec/datashift_spec.rb +26 -26
  49. data/spec/db/migrate/20110803201325_create_test_bed.rb +85 -85
  50. data/spec/excel_exporter_spec.rb +78 -78
  51. data/spec/excel_generator_spec.rb +78 -78
  52. data/spec/excel_loader_spec.rb +223 -223
  53. data/spec/file_definitions.rb +141 -141
  54. data/spec/fixtures/ProjectsDefaults.yml +29 -29
  55. data/spec/fixtures/config/database.yml +27 -24
  56. data/spec/fixtures/datashift_Spree_db.sqlite +0 -0
  57. data/spec/fixtures/interact_models_db.sqlite +0 -0
  58. data/spec/fixtures/negative/SpreeProdMiss1Mandatory.csv +4 -4
  59. data/spec/fixtures/negative/SpreeProdMissManyMandatory.csv +4 -4
  60. data/spec/fixtures/spree/SpreeProducts.csv +4 -4
  61. data/spec/fixtures/spree/SpreeProductsMultiColumn.csv +4 -4
  62. data/spec/fixtures/spree/SpreeProductsSimple.csv +4 -4
  63. data/spec/fixtures/spree/SpreeProductsWithImages.csv +4 -0
  64. data/spec/fixtures/spree/SpreeZoneExample.csv +5 -5
  65. data/spec/fixtures/test_model_defs.rb +57 -57
  66. data/spec/loader_spec.rb +120 -120
  67. data/spec/method_dictionary_spec.rb +242 -242
  68. data/spec/method_mapper_spec.rb +41 -41
  69. data/spec/spec_helper.rb +116 -116
  70. data/spec/spree_generator_spec.rb +64 -64
  71. data/spec/spree_loader_spec.rb +324 -327
  72. data/spec/spree_method_mapping_spec.rb +214 -214
  73. data/tasks/config/seed_fu_product_template.erb +15 -15
  74. data/tasks/config/tidy_config.txt +12 -12
  75. data/tasks/db_tasks.rake +65 -65
  76. data/tasks/excel_generator.rake +78 -78
  77. data/tasks/file_tasks.rake +36 -36
  78. data/tasks/import/csv.rake +49 -49
  79. data/tasks/import/excel.rake +71 -71
  80. data/tasks/spree/image_load.rake +108 -108
  81. data/tasks/spree/product_loader.rake +43 -43
  82. data/tasks/word_to_seedfu.rake +166 -166
  83. data/test/helper.rb +18 -18
  84. data/test/test_interact.rb +7 -7
  85. metadata +22 -3
  86. data/spec/fixtures/interact_spree_db.sqlite +0 -0
@@ -1,79 +1,79 @@
1
- # Copyright:: (c) Autotelik Media Ltd 2011
2
- # Author :: Tom Statter
3
- # Date :: Aug 2011
4
- # License:: MIT
5
- #
6
- # Details:: Specs for Excel aspect of Active Record Loader
7
- #
8
- require File.dirname(__FILE__) + '/spec_helper'
9
-
10
- if(Guards::jruby?)
11
- require 'erb'
12
- require 'excel_generator'
13
-
14
- include DataShift
15
-
16
- describe 'Excel Generator' do
17
-
18
- before(:all) do
19
- db_connect( 'test_file' ) # , test_memory, test_mysql
20
-
21
- # load our test model definitions - Project etc
22
- require File.join($DataShiftFixturePath, 'test_model_defs')
23
-
24
- # handle migration changes or reset of test DB
25
- migrate_up
26
-
27
- db_clear() # todo read up about proper transactional fixtures
28
- results_clear()
29
-
30
- @klazz = Project
31
- @assoc_klazz = Category
32
- end
33
-
34
- before(:each) do
35
- MethodDictionary.clear
36
- MethodDictionary.find_operators( @klazz )
37
- MethodDictionary.find_operators( @assoc_klazz )
38
- end
39
-
40
- it "should be able to create a new excel generator" do
41
- generator = ExcelGenerator.new( 'dummy.xls' )
42
-
43
- generator.should_not be_nil
44
- end
45
-
46
- it "should generate template .xls file from model" do
47
-
48
- expect = result_file('project_template_spec.xls')
49
-
50
- gen = ExcelGenerator.new( expect )
51
-
52
- gen.generate(Project)
53
-
54
- File.exists?(expect).should be_true
55
-
56
- puts "Can manually check file @ #{expect}"
57
- end
58
-
59
- it "should export a simple model to .xls spreedsheet" do
60
-
61
- Project.create( :value_as_string => 'Value as Text', :value_as_boolean => true, :value_as_double => 75.672)
62
- #001 Demo string blah blah 2011-02-14 1.00 320.00
63
-
64
- expect= result_file('simple_export_spec.xls')
65
-
66
- gen = ExcelGenerator.new(expect)
67
-
68
- items = Project.all
69
-
70
- gen.export(items)
71
-
72
- File.exists?(expect).should be_true
73
-
74
- end
75
-
76
- end
77
- else
78
- puts "WARNING: skipped excel_generator_spec : Requires JRUBY - JExcelFile requires JAVA"
1
+ # Copyright:: (c) Autotelik Media Ltd 2011
2
+ # Author :: Tom Statter
3
+ # Date :: Aug 2011
4
+ # License:: MIT
5
+ #
6
+ # Details:: Specs for Excel aspect of Active Record Loader
7
+ #
8
+ require File.dirname(__FILE__) + '/spec_helper'
9
+
10
+ if(Guards::jruby?)
11
+ require 'erb'
12
+ require 'excel_generator'
13
+
14
+ include DataShift
15
+
16
+ describe 'Excel Generator' do
17
+
18
+ before(:all) do
19
+ db_connect( 'test_file' ) # , test_memory, test_mysql
20
+
21
+ # load our test model definitions - Project etc
22
+ require File.join($DataShiftFixturePath, 'test_model_defs')
23
+
24
+ # handle migration changes or reset of test DB
25
+ migrate_up
26
+
27
+ db_clear() # todo read up about proper transactional fixtures
28
+ results_clear()
29
+
30
+ @klazz = Project
31
+ @assoc_klazz = Category
32
+ end
33
+
34
+ before(:each) do
35
+ MethodDictionary.clear
36
+ MethodDictionary.find_operators( @klazz )
37
+ MethodDictionary.find_operators( @assoc_klazz )
38
+ end
39
+
40
+ it "should be able to create a new excel generator" do
41
+ generator = ExcelGenerator.new( 'dummy.xls' )
42
+
43
+ generator.should_not be_nil
44
+ end
45
+
46
+ it "should generate template .xls file from model" do
47
+
48
+ expect = result_file('project_template_spec.xls')
49
+
50
+ gen = ExcelGenerator.new( expect )
51
+
52
+ gen.generate(Project)
53
+
54
+ File.exists?(expect).should be_true
55
+
56
+ puts "Can manually check file @ #{expect}"
57
+ end
58
+
59
+ it "should export a simple model to .xls spreedsheet" do
60
+
61
+ Project.create( :value_as_string => 'Value as Text', :value_as_boolean => true, :value_as_double => 75.672)
62
+ #001 Demo string blah blah 2011-02-14 1.00 320.00
63
+
64
+ expect= result_file('simple_export_spec.xls')
65
+
66
+ gen = ExcelGenerator.new(expect)
67
+
68
+ items = Project.all
69
+
70
+ gen.export(items)
71
+
72
+ File.exists?(expect).should be_true
73
+
74
+ end
75
+
76
+ end
77
+ else
78
+ puts "WARNING: skipped excel_generator_spec : Requires JRUBY - JExcelFile requires JAVA"
79
79
  end # jruby
@@ -1,224 +1,224 @@
1
- # Copyright:: (c) Autotelik Media Ltd 2011
2
- # Author :: Tom Statter
3
- # Date :: Aug 2011
4
- # License:: MIT
5
- #
6
- # Details:: Specs for Excel aspect of Active Record Loader
7
- #
8
- require File.dirname(__FILE__) + '/spec_helper'
9
-
10
- if(Guards::jruby?)
11
-
12
- require 'erb'
13
- require 'excel_loader'
14
-
15
- include DataShift
16
-
17
- describe 'Excel Loader' do
18
-
19
- before(:all) do
20
- db_connect( 'test_file' ) # , test_memory, test_mysql
21
-
22
- # load our test model definitions - Project etc
23
- require File.join($DataShiftFixturePath, 'test_model_defs')
24
-
25
- # handle migration changes or reset of test DB
26
- migrate_up
27
-
28
- db_clear() # todo read up about proper transactional fixtures
29
-
30
-
31
- Project = Project
32
- @assoc_klazz = Category
33
- end
34
-
35
- before(:each) do
36
-
37
- Project.delete_all
38
-
39
- %w{category_001 category_002 category_003 category_004 category_005}.each do |cat|
40
- @assoc_klazz.find_or_create_by_reference(cat)
41
- end
42
-
43
-
44
- MethodDictionary.clear
45
- MethodDictionary.find_operators( Project )
46
- MethodDictionary.find_operators( @assoc_klazz )
47
- end
48
-
49
- it "should be able to create a new excel loader and load object" do
50
- loader = ExcelLoader.new( Project)
51
-
52
- loader.load_object.should_not be_nil
53
- loader.load_object.should be_is_a(Project)
54
- loader.load_object.new_record?.should be_true
55
- end
56
-
57
- it "should process a simple .xls spreedsheet" do
58
-
59
- loader = ExcelLoader.new(Project)
60
-
61
- count = Project.count
62
- loader.perform_load( $DataShiftFixturePath + '/SimpleProjects.xls')
63
-
64
- loader.loaded_count.should == (Project.count - count)
65
-
66
- end
67
-
68
- it "should process multiple associationss from single column" do
69
-
70
- Project.find_by_title('001').should be_nil
71
- count = Project.count
72
-
73
- loader = ExcelLoader.new(Project)
74
-
75
- loader.perform_load( $DataShiftFixturePath + '/ProjectsSingleCategories.xls')
76
-
77
- loader.loaded_count.should be > 3
78
- loader.loaded_count.should == (Project.count - count)
79
-
80
- {'001' => 2, '002' => 1, '003' => 3, '099' => 0 }.each do|title, expected|
81
- project = Project.find_by_title(title)
82
-
83
- project.should_not be_nil
84
- puts "#{project.inspect} [#{project.categories.size}]"
85
-
86
- project.should have(expected).categories
87
- end
88
- end
89
-
90
- it "should process multiple associations in excel spreedsheet" do
91
-
92
- loader = ExcelLoader.new(Project)
93
-
94
- count = Project.count
95
- loader.perform_load( $DataShiftFixturePath + '/ProjectsMultiCategories.xls')
96
-
97
- loader.loaded_count.should == (Project.count - count)
98
-
99
- {'004' => 3, '005' => 1, '006' => 0, '007' => 1 }.each do|title, expected|
100
- project = Project.find_by_title(title)
101
-
102
- project.should_not be_nil
103
-
104
- project.should have(expected).categories
105
- end
106
-
107
- end
108
-
109
- it "should process multiple associations with lookup specified in column from excel spreedsheet", :fail => true do
110
-
111
- loader = ExcelLoader.new(Project)
112
-
113
- count = Project.count
114
- loader.perform_load( $DataShiftFixturePath + '/ProjectsMultiCategoriesHeaderLookup.xls')
115
-
116
- loader.loaded_count.should == (Project.count - count)
117
-
118
- {'004' => 4, '005' => 1, '006' => 0, '007' => 1 }.each do|title, expected|
119
- project = Project.find_by_title(title)
120
-
121
- project.should_not be_nil
122
-
123
- project.should have(expected).categories
124
- end
125
-
126
- end
127
-
128
- it "should process excel spreedsheet with extra undefined columns" do
129
- loader = ExcelLoader.new(Project)
130
- lambda {loader.perform_load( ifixture_file('BadAssociationName.xls') ) }.should_not raise_error
131
- end
132
-
133
- it "should NOT process excel spreedsheet with extra undefined columns when strict mode" do
134
- loader = ExcelLoader.new(Project)
135
- expect {loader.perform_load( ifixture_file('BadAssociationName.xls'), :strict => true)}.to raise_error(MappingDefinitionError)
136
- end
137
-
138
- it "should raise an error when mandatory columns missing" do
139
- loader = ExcelLoader.new(Project)
140
- expect {loader.perform_load($DataShiftFixturePath + '/ProjectsMultiCategories.xls', :mandatory => ['not_an_option', 'must_be_there'] )}.to raise_error(DataShift::MissingMandatoryError)
141
- end
142
-
143
- it "should provide facility to set default values", :focus => true do
144
- loader = ExcelLoader.new(Project)
145
-
146
- loader.set_default_value('value_as_string', 'some default text' )
147
- loader.set_default_value('value_as_double', 45.467 )
148
- loader.set_default_value('value_as_boolean', true )
149
-
150
- texpected = Time.now.to_s(:db)
151
-
152
- loader.set_default_value('value_as_datetime', texpected )
153
-
154
- #value_as_string Value as Text value as datetime value_as_boolean value_as_double category
155
-
156
- loader.perform_load($DataShiftFixturePath + '/ProjectsSingleCategories.xls')
157
-
158
- p = Project.find_by_title( '099' )
159
-
160
- p.should_not be_nil
161
-
162
- p.value_as_string.should == 'some default text'
163
- p.value_as_double.should == 45.467
164
- p.value_as_boolean.should == true
165
- p.value_as_datetime.should == texpected
166
-
167
- p_no_defs = Project.first
168
-
169
- p_no_defs.value_as_string.should_not == 'some default text'
170
- p_no_defs.value_as_double.should_not == 45.467
171
- p_no_defs.value_as_datetime.should_not == texpected
172
-
173
- end
174
-
175
- it "should provide facility to set pre and post fix values" do
176
- loader = ExcelLoader.new(Project)
177
-
178
- loader.set_prefix('value_as_string', 'myprefix' )
179
- loader.set_postfix('value_as_string', 'my post fix' )
180
-
181
- #value_as_string Value as Text value as datetime value_as_boolean value_as_double category
182
-
183
- loader.perform_load($DataShiftFixturePath + '/ProjectsSingleCategories.xls')
184
-
185
- p = Project.find_by_title( '001' )
186
-
187
- p.should_not be_nil
188
-
189
- p.value_as_string.should == 'myprefixDemo stringmy post fix'
190
- end
191
-
192
- it "should provide facility to set default values via YAML configuration", :excel => true do
193
- loader = ExcelLoader.new(Project)
194
-
195
- loader.configure_from( File.join($DataShiftFixturePath, 'ProjectsDefaults.yml') )
196
-
197
-
198
- loader.perform_load( File.join($DataShiftFixturePath, 'ProjectsSingleCategories.xls') )
199
-
200
- p = Project.find_by_title( '099' )
201
-
202
- p.should_not be_nil
203
-
204
- p.value_as_string.should == "Default Project Value"
205
- end
206
-
207
-
208
- it "should provide facility to over ride values via YAML configuration", :excel => true do
209
- loader = ExcelLoader.new(Project)
210
-
211
- loader.configure_from( File.join($DataShiftFixturePath, 'ProjectsDefaults.yml') )
212
-
213
-
214
- loader.perform_load( File.join($DataShiftFixturePath, 'ProjectsSingleCategories.xls') )
215
-
216
- Project.all.each {|p| p.value_as_double.should == 99.23546 }
217
- end
218
-
219
-
220
- end
221
-
222
- else
223
- puts "WARNING: skipped excel_loader_spec : Requires JRUBY - JExcelFile requires JAVA"
1
+ # Copyright:: (c) Autotelik Media Ltd 2011
2
+ # Author :: Tom Statter
3
+ # Date :: Aug 2011
4
+ # License:: MIT
5
+ #
6
+ # Details:: Specs for Excel aspect of Active Record Loader
7
+ #
8
+ require File.dirname(__FILE__) + '/spec_helper'
9
+
10
+ if(Guards::jruby?)
11
+
12
+ require 'erb'
13
+ require 'excel_loader'
14
+
15
+ include DataShift
16
+
17
+ describe 'Excel Loader' do
18
+
19
+ before(:all) do
20
+ db_connect( 'test_file' ) # , test_memory, test_mysql
21
+
22
+ # load our test model definitions - Project etc
23
+ require File.join($DataShiftFixturePath, 'test_model_defs')
24
+
25
+ # handle migration changes or reset of test DB
26
+ migrate_up
27
+
28
+ db_clear() # todo read up about proper transactional fixtures
29
+
30
+
31
+ Project = Project
32
+ @assoc_klazz = Category
33
+ end
34
+
35
+ before(:each) do
36
+
37
+ Project.delete_all
38
+
39
+ %w{category_001 category_002 category_003 category_004 category_005}.each do |cat|
40
+ @assoc_klazz.find_or_create_by_reference(cat)
41
+ end
42
+
43
+
44
+ MethodDictionary.clear
45
+ MethodDictionary.find_operators( Project )
46
+ MethodDictionary.find_operators( @assoc_klazz )
47
+ end
48
+
49
+ it "should be able to create a new excel loader and load object" do
50
+ loader = ExcelLoader.new( Project)
51
+
52
+ loader.load_object.should_not be_nil
53
+ loader.load_object.should be_is_a(Project)
54
+ loader.load_object.new_record?.should be_true
55
+ end
56
+
57
+ it "should process a simple .xls spreedsheet" do
58
+
59
+ loader = ExcelLoader.new(Project)
60
+
61
+ count = Project.count
62
+ loader.perform_load( $DataShiftFixturePath + '/SimpleProjects.xls')
63
+
64
+ loader.loaded_count.should == (Project.count - count)
65
+
66
+ end
67
+
68
+ it "should process multiple associationss from single column" do
69
+
70
+ Project.find_by_title('001').should be_nil
71
+ count = Project.count
72
+
73
+ loader = ExcelLoader.new(Project)
74
+
75
+ loader.perform_load( $DataShiftFixturePath + '/ProjectsSingleCategories.xls')
76
+
77
+ loader.loaded_count.should be > 3
78
+ loader.loaded_count.should == (Project.count - count)
79
+
80
+ {'001' => 2, '002' => 1, '003' => 3, '099' => 0 }.each do|title, expected|
81
+ project = Project.find_by_title(title)
82
+
83
+ project.should_not be_nil
84
+ puts "#{project.inspect} [#{project.categories.size}]"
85
+
86
+ project.should have(expected).categories
87
+ end
88
+ end
89
+
90
+ it "should process multiple associations in excel spreedsheet" do
91
+
92
+ loader = ExcelLoader.new(Project)
93
+
94
+ count = Project.count
95
+ loader.perform_load( $DataShiftFixturePath + '/ProjectsMultiCategories.xls')
96
+
97
+ loader.loaded_count.should == (Project.count - count)
98
+
99
+ {'004' => 3, '005' => 1, '006' => 0, '007' => 1 }.each do|title, expected|
100
+ project = Project.find_by_title(title)
101
+
102
+ project.should_not be_nil
103
+
104
+ project.should have(expected).categories
105
+ end
106
+
107
+ end
108
+
109
+ it "should process multiple associations with lookup specified in column from excel spreedsheet", :fail => true do
110
+
111
+ loader = ExcelLoader.new(Project)
112
+
113
+ count = Project.count
114
+ loader.perform_load( $DataShiftFixturePath + '/ProjectsMultiCategoriesHeaderLookup.xls')
115
+
116
+ loader.loaded_count.should == (Project.count - count)
117
+
118
+ {'004' => 4, '005' => 1, '006' => 0, '007' => 1 }.each do|title, expected|
119
+ project = Project.find_by_title(title)
120
+
121
+ project.should_not be_nil
122
+
123
+ project.should have(expected).categories
124
+ end
125
+
126
+ end
127
+
128
+ it "should process excel spreedsheet with extra undefined columns" do
129
+ loader = ExcelLoader.new(Project)
130
+ lambda {loader.perform_load( ifixture_file('BadAssociationName.xls') ) }.should_not raise_error
131
+ end
132
+
133
+ it "should NOT process excel spreedsheet with extra undefined columns when strict mode" do
134
+ loader = ExcelLoader.new(Project)
135
+ expect {loader.perform_load( ifixture_file('BadAssociationName.xls'), :strict => true)}.to raise_error(MappingDefinitionError)
136
+ end
137
+
138
+ it "should raise an error when mandatory columns missing" do
139
+ loader = ExcelLoader.new(Project)
140
+ expect {loader.perform_load($DataShiftFixturePath + '/ProjectsMultiCategories.xls', :mandatory => ['not_an_option', 'must_be_there'] )}.to raise_error(DataShift::MissingMandatoryError)
141
+ end
142
+
143
+ it "should provide facility to set default values", :focus => true do
144
+ loader = ExcelLoader.new(Project)
145
+
146
+ loader.set_default_value('value_as_string', 'some default text' )
147
+ loader.set_default_value('value_as_double', 45.467 )
148
+ loader.set_default_value('value_as_boolean', true )
149
+
150
+ texpected = Time.now.to_s(:db)
151
+
152
+ loader.set_default_value('value_as_datetime', texpected )
153
+
154
+ #value_as_string Value as Text value as datetime value_as_boolean value_as_double category
155
+
156
+ loader.perform_load($DataShiftFixturePath + '/ProjectsSingleCategories.xls')
157
+
158
+ p = Project.find_by_title( '099' )
159
+
160
+ p.should_not be_nil
161
+
162
+ p.value_as_string.should == 'some default text'
163
+ p.value_as_double.should == 45.467
164
+ p.value_as_boolean.should == true
165
+ p.value_as_datetime.should == texpected
166
+
167
+ p_no_defs = Project.first
168
+
169
+ p_no_defs.value_as_string.should_not == 'some default text'
170
+ p_no_defs.value_as_double.should_not == 45.467
171
+ p_no_defs.value_as_datetime.should_not == texpected
172
+
173
+ end
174
+
175
+ it "should provide facility to set pre and post fix values" do
176
+ loader = ExcelLoader.new(Project)
177
+
178
+ loader.set_prefix('value_as_string', 'myprefix' )
179
+ loader.set_postfix('value_as_string', 'my post fix' )
180
+
181
+ #value_as_string Value as Text value as datetime value_as_boolean value_as_double category
182
+
183
+ loader.perform_load($DataShiftFixturePath + '/ProjectsSingleCategories.xls')
184
+
185
+ p = Project.find_by_title( '001' )
186
+
187
+ p.should_not be_nil
188
+
189
+ p.value_as_string.should == 'myprefixDemo stringmy post fix'
190
+ end
191
+
192
+ it "should provide facility to set default values via YAML configuration", :excel => true do
193
+ loader = ExcelLoader.new(Project)
194
+
195
+ loader.configure_from( File.join($DataShiftFixturePath, 'ProjectsDefaults.yml') )
196
+
197
+
198
+ loader.perform_load( File.join($DataShiftFixturePath, 'ProjectsSingleCategories.xls') )
199
+
200
+ p = Project.find_by_title( '099' )
201
+
202
+ p.should_not be_nil
203
+
204
+ p.value_as_string.should == "Default Project Value"
205
+ end
206
+
207
+
208
+ it "should provide facility to over ride values via YAML configuration", :excel => true do
209
+ loader = ExcelLoader.new(Project)
210
+
211
+ loader.configure_from( File.join($DataShiftFixturePath, 'ProjectsDefaults.yml') )
212
+
213
+
214
+ loader.perform_load( File.join($DataShiftFixturePath, 'ProjectsSingleCategories.xls') )
215
+
216
+ Project.all.each {|p| p.value_as_double.should == 99.23546 }
217
+ end
218
+
219
+
220
+ end
221
+
222
+ else
223
+ puts "WARNING: skipped excel_loader_spec : Requires JRUBY - JExcelFile requires JAVA"
224
224
  end # jruby