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.
- data/README.markdown +63 -64
- data/Rakefile +4 -7
- data/VERSION +1 -1
- data/datashift.gemspec +92 -62
- data/lib/applications/apache_poi_extensions.rb +62 -0
- data/lib/applications/excel.rb +78 -0
- data/lib/applications/excel_base.rb +65 -0
- data/lib/applications/jexcel_file.rb +222 -0
- data/lib/applications/jexcel_file_extensions.rb +244 -0
- data/lib/applications/jruby/{jexcel_file.rb → old_pre_proxy_jexcel_file.rb} +0 -0
- data/lib/applications/ruby_poi_translations.rb +64 -0
- data/lib/applications/spreadsheet_extensions.rb +31 -0
- data/lib/datashift/method_details_manager.rb +4 -0
- data/lib/exporters/csv_exporter.rb +3 -1
- data/lib/exporters/excel_exporter.rb +59 -74
- data/lib/generators/excel_generator.rb +70 -74
- data/lib/guards.rb +57 -0
- data/lib/loaders/excel_loader.rb +105 -105
- data/lib/loaders/loader_base.rb +43 -21
- data/lib/loaders/paperclip/attachment_loader.rb +104 -0
- data/lib/loaders/paperclip/datashift_paperclip.rb +78 -0
- data/lib/loaders/paperclip/{image_loader.rb → image_loading.rb} +2 -18
- data/lib/thor/{generate_excel.thor → generate.thor} +48 -0
- data/lib/thor/paperclip.thor +85 -0
- data/lib/thor/tools.thor +23 -2
- data/spec/Gemfile +1 -7
- data/spec/csv_exporter_spec.rb +4 -4
- data/spec/csv_loader_spec.rb +1 -1
- data/spec/excel_exporter_spec.rb +43 -45
- data/spec/excel_generator_spec.rb +132 -60
- data/spec/excel_loader_spec.rb +134 -140
- data/spec/excel_spec.rb +179 -0
- data/spec/fixtures/ProjectsMultiCategoriesHeaderLookup.xls +0 -0
- data/spec/fixtures/config/database.yml +2 -2
- data/spec/fixtures/db/datashift_test_models_db.sqlite +0 -0
- data/spec/{db → fixtures/db}/migrate/20110803201325_create_test_bed.rb +0 -0
- data/spec/fixtures/load_datashift.thor +3 -0
- data/spec/fixtures/models/category.rb +7 -0
- data/spec/fixtures/models/empty.rb +2 -0
- data/spec/fixtures/models/loader_release.rb +10 -0
- data/spec/fixtures/models/long_and_complex_table_linked_to_version.rb +6 -0
- data/spec/fixtures/models/milestone.rb +8 -0
- data/spec/fixtures/models/owner.rb +5 -0
- data/spec/fixtures/models/project.rb +26 -0
- data/spec/fixtures/models/test_model_defs.rb +67 -0
- data/spec/fixtures/models/version.rb +7 -0
- data/spec/loader_spec.rb +4 -3
- data/spec/method_dictionary_spec.rb +7 -6
- data/spec/method_mapper_spec.rb +3 -2
- data/spec/rails_sandbox/.gitignore +15 -0
- data/spec/rails_sandbox/Gemfile +40 -0
- data/spec/rails_sandbox/README.rdoc +261 -0
- data/spec/rails_sandbox/Rakefile +7 -0
- data/spec/rails_sandbox/app/assets/images/rails.png +0 -0
- data/spec/rails_sandbox/app/assets/javascripts/application.js +15 -0
- data/spec/rails_sandbox/app/assets/stylesheets/application.css +13 -0
- data/spec/rails_sandbox/app/controllers/application_controller.rb +3 -0
- data/spec/rails_sandbox/app/helpers/application_helper.rb +2 -0
- data/spec/rails_sandbox/app/mailers/.gitkeep +0 -0
- data/spec/rails_sandbox/app/models/.gitkeep +0 -0
- data/spec/rails_sandbox/app/models/category.rb +7 -0
- data/spec/rails_sandbox/app/models/empty.rb +2 -0
- data/spec/rails_sandbox/app/models/loader_release.rb +10 -0
- data/spec/rails_sandbox/app/models/long_and_complex_table_linked_to_version.rb +6 -0
- data/spec/rails_sandbox/app/models/milestone.rb +8 -0
- data/spec/rails_sandbox/app/models/owner.rb +5 -0
- data/spec/rails_sandbox/app/models/project.rb +26 -0
- data/spec/rails_sandbox/app/models/test_model_defs.rb +67 -0
- data/spec/rails_sandbox/app/models/version.rb +7 -0
- data/spec/rails_sandbox/app/views/layouts/application.html.erb +14 -0
- data/spec/rails_sandbox/config.ru +4 -0
- data/spec/rails_sandbox/config/application.rb +62 -0
- data/spec/rails_sandbox/config/boot.rb +6 -0
- data/spec/rails_sandbox/config/database.yml +20 -0
- data/spec/rails_sandbox/config/environment.rb +5 -0
- data/spec/rails_sandbox/config/environments/development.rb +37 -0
- data/spec/rails_sandbox/config/environments/production.rb +67 -0
- data/spec/rails_sandbox/config/environments/test.rb +37 -0
- data/spec/rails_sandbox/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails_sandbox/config/initializers/inflections.rb +15 -0
- data/spec/rails_sandbox/config/initializers/mime_types.rb +5 -0
- data/spec/rails_sandbox/config/initializers/secret_token.rb +7 -0
- data/spec/rails_sandbox/config/initializers/session_store.rb +8 -0
- data/spec/rails_sandbox/config/initializers/wrap_parameters.rb +14 -0
- data/spec/rails_sandbox/config/locales/en.yml +5 -0
- data/spec/rails_sandbox/config/routes.rb +58 -0
- data/spec/rails_sandbox/db/migrate/20110803201325_create_test_bed.rb +96 -0
- data/spec/rails_sandbox/db/schema.rb +81 -0
- data/spec/rails_sandbox/db/seeds.rb +7 -0
- data/spec/rails_sandbox/lib/assets/.gitkeep +0 -0
- data/spec/rails_sandbox/lib/tasks/.gitkeep +0 -0
- data/spec/rails_sandbox/log/.gitkeep +0 -0
- data/spec/rails_sandbox/public/404.html +26 -0
- data/spec/rails_sandbox/public/422.html +26 -0
- data/spec/rails_sandbox/public/500.html +25 -0
- data/spec/rails_sandbox/public/favicon.ico +0 -0
- data/spec/rails_sandbox/public/index.html +241 -0
- data/spec/rails_sandbox/public/robots.txt +5 -0
- data/spec/rails_sandbox/script/rails +6 -0
- data/spec/rails_sandbox/test/fixtures/.gitkeep +0 -0
- data/spec/rails_sandbox/test/functional/.gitkeep +0 -0
- data/spec/rails_sandbox/test/integration/.gitkeep +0 -0
- data/spec/rails_sandbox/test/performance/browsing_test.rb +12 -0
- data/spec/rails_sandbox/test/test_helper.rb +13 -0
- data/spec/rails_sandbox/test/unit/.gitkeep +0 -0
- data/spec/rails_sandbox/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/rails_sandbox/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/rails_sandbox/vendor/plugins/.gitkeep +0 -0
- data/spec/spec_helper.rb +144 -121
- data/spec/thor_spec.rb +34 -14
- metadata +207 -194
- data/lib/helpers/spree_helper.rb +0 -213
- data/lib/loaders/spreadsheet_loader.rb +0 -144
- data/lib/loaders/spree/image_loader.rb +0 -90
- data/lib/loaders/spree/product_loader.rb +0 -354
- data/lib/thor/spree/bootstrap_cleanup.thor +0 -61
- data/lib/thor/spree/products_images.thor +0 -252
- data/lib/thor/spree/reports.thor +0 -56
- data/public/spree/products/large/DEMO_001_ror_bag.jpeg +0 -0
- data/public/spree/products/large/DEMO_002_Powerstation.jpg +0 -0
- data/public/spree/products/large/DEMO_003_ror_mug.jpeg +0 -0
- data/public/spree/products/mini/DEMO_001_ror_bag.jpeg +0 -0
- data/public/spree/products/mini/DEMO_002_Powerstation.jpg +0 -0
- data/public/spree/products/mini/DEMO_003_ror_mug.jpeg +0 -0
- data/public/spree/products/original/DEMO_001_ror_bag.jpeg +0 -0
- data/public/spree/products/original/DEMO_002_Powerstation.jpg +0 -0
- data/public/spree/products/original/DEMO_003_ror_mug.jpeg +0 -0
- data/public/spree/products/product/DEMO_001_ror_bag.jpeg +0 -0
- data/public/spree/products/product/DEMO_002_Powerstation.jpg +0 -0
- data/public/spree/products/product/DEMO_003_ror_mug.jpeg +0 -0
- data/public/spree/products/small/DEMO_001_ror_bag.jpeg +0 -0
- data/public/spree/products/small/DEMO_002_Powerstation.jpg +0 -0
- data/public/spree/products/small/DEMO_003_ror_mug.jpeg +0 -0
- data/spec/fixtures/datashift_Spree_db.sqlite +0 -0
- data/spec/fixtures/datashift_test_models_db.sqlite +0 -0
- data/spec/fixtures/negative/SpreeProdMiss1Mandatory.csv +0 -4
- data/spec/fixtures/negative/SpreeProdMiss1Mandatory.xls +0 -0
- data/spec/fixtures/negative/SpreeProdMissManyMandatory.csv +0 -4
- data/spec/fixtures/negative/SpreeProdMissManyMandatory.xls +0 -0
- data/spec/fixtures/spree/SpreeImages.xls +0 -0
- data/spec/fixtures/spree/SpreeMultiVariant.csv +0 -4
- data/spec/fixtures/spree/SpreeProducts.csv +0 -4
- data/spec/fixtures/spree/SpreeProducts.xls +0 -0
- data/spec/fixtures/spree/SpreeProductsDefaults.yml +0 -15
- data/spec/fixtures/spree/SpreeProductsMandatoryOnly.xls +0 -0
- data/spec/fixtures/spree/SpreeProductsMultiColumn.csv +0 -4
- data/spec/fixtures/spree/SpreeProductsMultiColumn.xls +0 -0
- data/spec/fixtures/spree/SpreeProductsSimple.csv +0 -4
- data/spec/fixtures/spree/SpreeProductsSimple.xls +0 -0
- data/spec/fixtures/spree/SpreeProductsWithImages.csv +0 -4
- data/spec/fixtures/spree/SpreeProductsWithImages.xls +0 -0
- data/spec/fixtures/spree/SpreeZoneExample.csv +0 -5
- data/spec/fixtures/spree/SpreeZoneExample.xls +0 -0
- data/spec/spree_exporter_spec.rb +0 -72
- data/spec/spree_generator_spec.rb +0 -96
- data/spec/spree_images_loader_spec.rb +0 -107
- data/spec/spree_loader_spec.rb +0 -375
- data/spec/spree_method_mapping_spec.rb +0 -226
- data/spec/spree_variants_loader_spec.rb +0 -189
- data/tasks/export/excel_generator.rake +0 -102
- data/tasks/import/excel.rake +0 -75
- data/test/helper.rb +0 -18
- data/test/test_interact.rb +0 -7
data/spec/excel_exporter_spec.rb
CHANGED
|
@@ -7,72 +7,70 @@
|
|
|
7
7
|
#
|
|
8
8
|
require File.dirname(__FILE__) + '/spec_helper'
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
include DataShift
|
|
10
|
+
|
|
11
|
+
require 'erb'
|
|
12
|
+
require 'excel_exporter'
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
include DataShift
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
db_connect( 'test_file' ) # , test_memory, test_mysql
|
|
16
|
+
describe 'Excel Exporter' do
|
|
20
17
|
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
before(:all) do
|
|
19
|
+
|
|
20
|
+
# load our test model definitions - Project etc
|
|
21
|
+
require ifixture_file('test_model_defs')
|
|
22
|
+
|
|
23
|
+
db_connect( 'test_file' ) # , test_memory, test_mysql
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
# handle migration changes or reset of test DB
|
|
26
|
+
migrate_up
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
db_clear() # todo read up about proper transactional fixtures
|
|
29
|
+
results_clear()
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
@klazz = Project
|
|
32
|
+
@assoc_klazz = Category
|
|
33
|
+
end
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
before(:each) do
|
|
36
|
+
MethodDictionary.clear
|
|
37
|
+
MethodDictionary.find_operators( @klazz )
|
|
38
|
+
MethodDictionary.find_operators( @assoc_klazz )
|
|
39
|
+
end
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
it "should be able to create a new excel exporter" do
|
|
42
|
+
generator = ExcelExporter.new( 'dummy.xls' )
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
generator.should_not be_nil
|
|
45
|
+
end
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
it "should export a model to .xls file" do
|
|
47
48
|
|
|
48
|
-
|
|
49
|
+
expect = result_file('project_export_spec.xls')
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
gen = ExcelExporter.new( expect )
|
|
51
52
|
|
|
52
|
-
|
|
53
|
+
gen.export(Project.all)
|
|
53
54
|
|
|
54
|
-
|
|
55
|
+
File.exists?(expect).should be_true
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
it "should export a model and associations to .xls file" do
|
|
57
|
+
puts "Can manually check file @ #{expect}"
|
|
58
|
+
end
|
|
60
59
|
|
|
61
|
-
|
|
60
|
+
it "should export a model and associations to .xls file" do
|
|
62
61
|
|
|
63
|
-
|
|
62
|
+
Project.create( :value_as_string => 'Value as Text', :value_as_boolean => true, :value_as_double => 75.672)
|
|
64
63
|
|
|
65
|
-
|
|
64
|
+
expect= result_file('project_plus_assoc_export_spec.xls')
|
|
66
65
|
|
|
67
|
-
|
|
66
|
+
gen = ExcelExporter.new(expect)
|
|
68
67
|
|
|
69
|
-
|
|
68
|
+
items = Project.all
|
|
70
69
|
|
|
71
|
-
|
|
70
|
+
gen.export_with_associations(Project, items)
|
|
72
71
|
|
|
73
|
-
|
|
72
|
+
File.exists?(expect).should be_true
|
|
74
73
|
|
|
75
74
|
end
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
end # jruby
|
|
75
|
+
|
|
76
|
+
end
|
|
@@ -7,106 +7,178 @@
|
|
|
7
7
|
#
|
|
8
8
|
require File.dirname(__FILE__) + '/spec_helper'
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
require 'excel_generator'
|
|
10
|
+
require 'erb'
|
|
11
|
+
require 'excel_generator'
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
include DataShift
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
describe 'Excel Generator' do
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
before(:all) do
|
|
18
|
+
|
|
19
|
+
# load our test model definitions - Project etc
|
|
20
|
+
require ifixture_file('test_model_defs')
|
|
21
|
+
|
|
22
|
+
db_connect( 'test_file' ) # , test_memory, test_mysql
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
# handle migration changes or reset of test DB
|
|
25
|
+
migrate_up
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
db_clear() # todo read up about proper transactional fixtures
|
|
28
|
+
results_clear()
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
@klazz = Project
|
|
31
|
+
@assoc_klazz = Category
|
|
32
|
+
end
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
before(:each) do
|
|
35
|
+
MethodDictionary.clear
|
|
36
|
+
MethodDictionary.find_operators( @klazz )
|
|
37
|
+
MethodDictionary.find_operators( @assoc_klazz )
|
|
38
|
+
end
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
it "should be able to create a new excel generator" do
|
|
41
|
+
generator = ExcelGenerator.new( 'dummy.xls' )
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
generator.should_not be_nil
|
|
44
|
+
end
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
it "should generate template .xls file from model" do
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
expect = result_file('project_template_spec.xls')
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
gen = ExcelGenerator.new( expect )
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
gen.generate(Project)
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
File.exists?(expect).should be_true
|
|
55
|
+
|
|
56
|
+
puts "Can manually check file @ #{expect}"
|
|
57
|
+
|
|
58
|
+
excel = Excel.new
|
|
59
|
+
excel.open(expect)
|
|
60
|
+
|
|
61
|
+
excel.worksheets.should have(1).items
|
|
62
|
+
|
|
63
|
+
excel.worksheet(0).name.should == 'Project'
|
|
55
64
|
|
|
56
|
-
|
|
65
|
+
headers = excel.worksheets[0].row(0)
|
|
66
|
+
|
|
67
|
+
[ "title", "value_as_string", "value_as_text", "value_as_boolean", "value_as_datetime", "value_as_integer", "value_as_double"].each do |check|
|
|
68
|
+
headers.include?(check).should == true
|
|
57
69
|
end
|
|
70
|
+
end
|
|
58
71
|
|
|
59
|
-
|
|
72
|
+
# has_one :owner
|
|
73
|
+
# has_many :milestones
|
|
74
|
+
# has_many :loader_releases
|
|
75
|
+
# has_many :versions, :through => :loader_releases
|
|
76
|
+
# has_and_belongs_to_many :categories
|
|
77
|
+
|
|
78
|
+
it "should include all associations in template .xls file from model" do
|
|
60
79
|
|
|
61
|
-
|
|
80
|
+
expect= result_file('project_plus_assoc_template_spec.xls')
|
|
62
81
|
|
|
63
|
-
|
|
82
|
+
gen = ExcelGenerator.new(expect)
|
|
64
83
|
|
|
65
|
-
|
|
84
|
+
gen.generate_with_associations(Project)
|
|
66
85
|
|
|
67
|
-
|
|
86
|
+
File.exists?(expect).should be_true
|
|
68
87
|
|
|
69
|
-
|
|
88
|
+
excel = Excel.new
|
|
89
|
+
excel.open(expect)
|
|
90
|
+
|
|
91
|
+
excel.worksheets.should have(1).items
|
|
70
92
|
|
|
93
|
+
excel.worksheet(0).name.should == 'Project'
|
|
94
|
+
|
|
95
|
+
headers = excel.worksheets[0].row(0)
|
|
71
96
|
|
|
72
|
-
|
|
97
|
+
["owner", "milestones", "loader_releases", "versions", "categories"].each do |check|
|
|
98
|
+
headers.include?(check).should == true
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
it "should enable us to exclude associations by type in template .xls file", :fail => true do
|
|
73
104
|
|
|
74
|
-
|
|
105
|
+
expect= result_file('project_plus_some_assoc_template_spec.xls')
|
|
75
106
|
|
|
76
|
-
|
|
107
|
+
gen = ExcelGenerator.new(expect)
|
|
77
108
|
|
|
78
|
-
|
|
109
|
+
options = {:exclude => :has_many }
|
|
79
110
|
|
|
80
|
-
|
|
111
|
+
gen.generate_with_associations(Project, options)
|
|
81
112
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
excel = JExcelFile.new(expect)
|
|
113
|
+
File.exists?(expect).should be_true, "Failed to find expected result file #{expect}"
|
|
85
114
|
|
|
86
|
-
|
|
115
|
+
excel = Excel.new
|
|
116
|
+
excel.open(expect)
|
|
117
|
+
|
|
118
|
+
excel.worksheets.should have(1).items
|
|
119
|
+
|
|
120
|
+
excel.worksheet(0).name.should == 'Project'
|
|
87
121
|
|
|
88
|
-
|
|
122
|
+
headers = excel.worksheets[0].row(0)
|
|
89
123
|
|
|
124
|
+
headers.include?('title').should == true
|
|
125
|
+
headers.include?('owner').should == true
|
|
126
|
+
|
|
127
|
+
["milestones", "loader_releases", "versions", "categories"].each do |check|
|
|
128
|
+
headers.should_not include check
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
end
|
|
132
|
+
|
|
90
133
|
|
|
91
|
-
|
|
134
|
+
it "should enable us to exclude certain associations in template .xls file ", :fail => true do
|
|
92
135
|
|
|
93
|
-
|
|
136
|
+
expect= result_file('project_plus_some_assoc_template_spec.xls')
|
|
94
137
|
|
|
95
|
-
|
|
138
|
+
gen = ExcelGenerator.new(expect)
|
|
96
139
|
|
|
97
|
-
|
|
140
|
+
options = {:remove => [:milestones, :versions] }
|
|
98
141
|
|
|
99
|
-
|
|
142
|
+
gen.generate_with_associations(Project, options)
|
|
100
143
|
|
|
101
|
-
|
|
144
|
+
File.exists?(expect).should be_true, "Failed to find expected result file #{expect}"
|
|
102
145
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
146
|
+
excel = Excel.new
|
|
147
|
+
excel.open(expect)
|
|
148
|
+
|
|
149
|
+
excel.worksheets.should have(1).items
|
|
150
|
+
|
|
151
|
+
excel.worksheet(0).name.should == 'Project'
|
|
106
152
|
|
|
153
|
+
headers = excel.worksheets[0].row(0)
|
|
154
|
+
|
|
155
|
+
["title", "loader_releases", "owner", "categories"].each do |check|
|
|
156
|
+
headers.should include check
|
|
107
157
|
end
|
|
108
158
|
|
|
159
|
+
|
|
160
|
+
["milestones", "versions", ].each do |check|
|
|
161
|
+
headers.should_not include check
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
it "should enable us to autosize columns in the .xls file" do
|
|
168
|
+
|
|
169
|
+
expect= result_file('project_autosized_template_spec.xls')
|
|
170
|
+
|
|
171
|
+
gen = ExcelGenerator.new(expect)
|
|
172
|
+
|
|
173
|
+
options = {:autosize => true, :exclude => :milestones }
|
|
174
|
+
|
|
175
|
+
gen.generate_with_associations(Project, options)
|
|
176
|
+
|
|
177
|
+
File.exists?(expect).should be_true
|
|
178
|
+
|
|
179
|
+
excel = Excel.new
|
|
180
|
+
excel.open(expect)
|
|
181
|
+
|
|
109
182
|
end
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
end # jruby
|
|
183
|
+
|
|
184
|
+
end
|
data/spec/excel_loader_spec.rb
CHANGED
|
@@ -7,219 +7,213 @@
|
|
|
7
7
|
#
|
|
8
8
|
require File.dirname(__FILE__) + '/spec_helper'
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
require 'erb'
|
|
11
|
+
require 'excel_loader'
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
require 'excel_loader'
|
|
13
|
+
include DataShift
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
describe 'Excel Loader' do
|
|
16
16
|
|
|
17
|
-
|
|
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
|
|
17
|
+
before(:all) do
|
|
34
18
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
19
|
+
# load our test model definitions - Project etc
|
|
20
|
+
require ifixture_file('test_model_defs')
|
|
21
|
+
|
|
22
|
+
db_connect( 'test_file' ) # , test_memory, test_mysql
|
|
38
23
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
24
|
+
# handle migration changes or reset of test DB
|
|
25
|
+
migrate_up
|
|
26
|
+
|
|
27
|
+
db_clear() # todo read up about proper transactional fixtures
|
|
42
28
|
|
|
29
|
+
@assoc_klazz = Category
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
before(:each) do
|
|
43
33
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
34
|
+
Project.delete_all
|
|
35
|
+
|
|
36
|
+
%w{category_001 category_002 category_003 category_004 category_005}.each do |cat|
|
|
37
|
+
@assoc_klazz.find_or_create_by_reference(cat)
|
|
47
38
|
end
|
|
39
|
+
|
|
40
|
+
MethodDictionary.clear
|
|
41
|
+
MethodDictionary.find_operators( Project )
|
|
42
|
+
MethodDictionary.find_operators( @assoc_klazz )
|
|
43
|
+
end
|
|
48
44
|
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
it "should be able to create a new excel loader and load object" do
|
|
46
|
+
loader = ExcelLoader.new( Project)
|
|
51
47
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
loader.load_object.should_not be_nil
|
|
49
|
+
loader.load_object.should be_is_a(Project)
|
|
50
|
+
loader.load_object.new_record?.should be_true
|
|
51
|
+
end
|
|
56
52
|
|
|
57
|
-
|
|
53
|
+
it "should process a simple .xls spreedsheet" do
|
|
58
54
|
|
|
59
|
-
|
|
55
|
+
loader = ExcelLoader.new(Project)
|
|
60
56
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
loader.loaded_count.should == (Project.count - count)
|
|
57
|
+
count = Project.count
|
|
58
|
+
loader.perform_load ifixture_file('SimpleProjects.xls')
|
|
65
59
|
|
|
66
|
-
|
|
60
|
+
loader.loaded_count.should == (Project.count - count)
|
|
61
|
+
end
|
|
67
62
|
|
|
68
|
-
|
|
63
|
+
it "should process multiple associationss from single column" do
|
|
69
64
|
|
|
70
|
-
|
|
71
|
-
|
|
65
|
+
Project.find_by_title('001').should be_nil
|
|
66
|
+
count = Project.count
|
|
72
67
|
|
|
73
|
-
|
|
68
|
+
loader = ExcelLoader.new(Project)
|
|
74
69
|
|
|
75
|
-
|
|
70
|
+
loader.perform_load( ifixture_file('ProjectsSingleCategories.xls') )
|
|
76
71
|
|
|
77
|
-
|
|
78
|
-
|
|
72
|
+
loader.loaded_count.should be > 3
|
|
73
|
+
loader.loaded_count.should == (Project.count - count)
|
|
79
74
|
|
|
80
|
-
|
|
81
|
-
|
|
75
|
+
{'001' => 2, '002' => 1, '003' => 3, '099' => 0 }.each do|title, expected|
|
|
76
|
+
project = Project.find_by_title(title)
|
|
82
77
|
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
project.should_not be_nil
|
|
79
|
+
#puts "#{project.inspect} [#{project.categories.size}]"
|
|
85
80
|
|
|
86
|
-
|
|
87
|
-
end
|
|
81
|
+
project.should have(expected).categories
|
|
88
82
|
end
|
|
83
|
+
end
|
|
89
84
|
|
|
90
|
-
|
|
85
|
+
it "should process multiple associations in excel spreedsheet" do
|
|
91
86
|
|
|
92
|
-
|
|
87
|
+
loader = ExcelLoader.new(Project)
|
|
93
88
|
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
count = Project.count
|
|
90
|
+
loader.perform_load( ifixture_file('ProjectsMultiCategories.xls' ))
|
|
96
91
|
|
|
97
|
-
|
|
92
|
+
loader.loaded_count.should == (Project.count - count)
|
|
98
93
|
|
|
99
|
-
|
|
100
|
-
|
|
94
|
+
{'004' => 3, '005' => 1, '006' => 0, '007' => 1 }.each do|title, expected|
|
|
95
|
+
project = Project.find_by_title(title)
|
|
101
96
|
|
|
102
|
-
|
|
97
|
+
project.should_not be_nil
|
|
103
98
|
|
|
104
|
-
|
|
105
|
-
end
|
|
106
|
-
|
|
99
|
+
project.should have(expected).categories
|
|
107
100
|
end
|
|
108
101
|
|
|
109
|
-
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it "should process multiple associations with lookup specified in column from excel spreedsheet" do
|
|
110
105
|
|
|
111
|
-
|
|
106
|
+
loader = ExcelLoader.new(Project)
|
|
112
107
|
|
|
113
|
-
|
|
114
|
-
|
|
108
|
+
count = Project.count
|
|
109
|
+
loader.perform_load( ifixture_file('ProjectsMultiCategoriesHeaderLookup.xls'))
|
|
115
110
|
|
|
116
|
-
|
|
117
|
-
|
|
111
|
+
loader.loaded_count.should == (Project.count - count)
|
|
112
|
+
loader.loaded_count.should > 3
|
|
118
113
|
|
|
119
|
-
|
|
120
|
-
|
|
114
|
+
{'004' => 4, '005' => 1, '006' => 0, '007' => 1 }.each do|title, expected|
|
|
115
|
+
project = Project.find_by_title(title)
|
|
121
116
|
|
|
122
|
-
|
|
117
|
+
project.should_not be_nil
|
|
123
118
|
|
|
124
|
-
|
|
125
|
-
end
|
|
126
|
-
|
|
119
|
+
project.should have(expected).categories
|
|
127
120
|
end
|
|
121
|
+
|
|
122
|
+
end
|
|
128
123
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
124
|
+
it "should process excel spreedsheet with extra undefined columns" do
|
|
125
|
+
loader = ExcelLoader.new(Project)
|
|
126
|
+
lambda {loader.perform_load( ifixture_file('BadAssociationName.xls') ) }.should_not raise_error
|
|
127
|
+
end
|
|
133
128
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
129
|
+
it "should NOT process excel spreedsheet with extra undefined columns when strict mode" do
|
|
130
|
+
loader = ExcelLoader.new(Project)
|
|
131
|
+
expect {loader.perform_load( ifixture_file('BadAssociationName.xls'), :strict => true)}.to raise_error(MappingDefinitionError)
|
|
132
|
+
end
|
|
138
133
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
134
|
+
it "should raise an error when mandatory columns missing" do
|
|
135
|
+
loader = ExcelLoader.new(Project)
|
|
136
|
+
expect {loader.perform_load(ifixture_file('ProjectsMultiCategories.xls'), :mandatory => ['not_an_option', 'must_be_there'])}.to raise_error(DataShift::MissingMandatoryError)
|
|
137
|
+
end
|
|
143
138
|
|
|
144
|
-
|
|
145
|
-
|
|
139
|
+
it "should provide facility to set default values", :focus => true do
|
|
140
|
+
loader = ExcelLoader.new(Project)
|
|
146
141
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
142
|
+
loader.set_default_value('value_as_string', 'some default text' )
|
|
143
|
+
loader.set_default_value('value_as_double', 45.467 )
|
|
144
|
+
loader.set_default_value('value_as_boolean', true )
|
|
150
145
|
|
|
151
|
-
|
|
146
|
+
texpected = Time.now.to_s(:db)
|
|
152
147
|
|
|
153
|
-
|
|
148
|
+
loader.set_default_value('value_as_datetime', texpected )
|
|
154
149
|
|
|
155
|
-
|
|
150
|
+
#value_as_string Value as Text value as datetime value_as_boolean value_as_double category
|
|
156
151
|
|
|
157
|
-
|
|
152
|
+
loader.perform_load(ifixture_file('ProjectsSingleCategories.xls'))
|
|
158
153
|
|
|
159
|
-
|
|
154
|
+
p = Project.find_by_title( '099' )
|
|
160
155
|
|
|
161
|
-
|
|
156
|
+
p.should_not be_nil
|
|
162
157
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
158
|
+
p.value_as_string.should == 'some default text'
|
|
159
|
+
p.value_as_double.should == 45.467
|
|
160
|
+
p.value_as_boolean.should == true
|
|
161
|
+
p.value_as_datetime.to_s(:db).should == texpected
|
|
162
|
+
|
|
163
|
+
# expected: "2012-09-17 10:00:52"
|
|
164
|
+
# got: Mon Sep 17 10:00:52 +0100 2012 (using ==)
|
|
167
165
|
|
|
168
|
-
|
|
166
|
+
p_no_defs = Project.first
|
|
169
167
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
168
|
+
p_no_defs.value_as_string.should_not == 'some default text'
|
|
169
|
+
p_no_defs.value_as_double.should_not == 45.467
|
|
170
|
+
p_no_defs.value_as_datetime.should_not == texpected
|
|
173
171
|
|
|
174
|
-
|
|
172
|
+
end
|
|
175
173
|
|
|
176
|
-
|
|
177
|
-
|
|
174
|
+
it "should provide facility to set pre and post fix values" do
|
|
175
|
+
loader = ExcelLoader.new(Project)
|
|
178
176
|
|
|
179
|
-
|
|
180
|
-
|
|
177
|
+
loader.set_prefix('value_as_string', 'myprefix' )
|
|
178
|
+
loader.set_postfix('value_as_string', 'my post fix' )
|
|
181
179
|
|
|
182
|
-
|
|
180
|
+
#value_as_string Value as Text value as datetime value_as_boolean value_as_double category
|
|
183
181
|
|
|
184
|
-
|
|
182
|
+
loader.perform_load( ifixture_file('ProjectsSingleCategories.xls'))
|
|
185
183
|
|
|
186
|
-
|
|
184
|
+
p = Project.find_by_title( '001' )
|
|
187
185
|
|
|
188
|
-
|
|
186
|
+
p.should_not be_nil
|
|
189
187
|
|
|
190
|
-
|
|
191
|
-
|
|
188
|
+
p.value_as_string.should == 'myprefixDemo stringmy post fix'
|
|
189
|
+
end
|
|
192
190
|
|
|
193
|
-
|
|
194
|
-
|
|
191
|
+
it "should provide facility to set default values via YAML configuration", :excel => true do
|
|
192
|
+
loader = ExcelLoader.new(Project)
|
|
195
193
|
|
|
196
|
-
|
|
194
|
+
loader.configure_from( ifixture_file('ProjectsDefaults.yml') )
|
|
197
195
|
|
|
198
196
|
|
|
199
|
-
|
|
197
|
+
loader.perform_load( ifixture_file('ProjectsSingleCategories.xls') )
|
|
200
198
|
|
|
201
|
-
|
|
199
|
+
p = Project.find_by_title( '099' )
|
|
202
200
|
|
|
203
|
-
|
|
201
|
+
p.should_not be_nil
|
|
204
202
|
|
|
205
|
-
|
|
206
|
-
|
|
203
|
+
p.value_as_string.should == "Default Project Value"
|
|
204
|
+
end
|
|
207
205
|
|
|
208
206
|
|
|
209
|
-
|
|
210
|
-
|
|
207
|
+
it "should provide facility to over ride values via YAML configuration", :excel => true do
|
|
208
|
+
loader = ExcelLoader.new(Project)
|
|
211
209
|
|
|
212
|
-
|
|
210
|
+
loader.configure_from( ifixture_file('ProjectsDefaults.yml') )
|
|
213
211
|
|
|
214
212
|
|
|
215
|
-
|
|
213
|
+
loader.perform_load( ifixture_file('ProjectsSingleCategories.xls') )
|
|
216
214
|
|
|
217
|
-
|
|
218
|
-
|
|
215
|
+
Project.all.each {|p| p.value_as_double.should == 99.23546 }
|
|
216
|
+
end
|
|
219
217
|
|
|
220
218
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
else
|
|
224
|
-
puts "WARNING: skipped excel_loader_spec : Requires JRUBY - JExcelFile requires JAVA"
|
|
225
|
-
end # jruby
|
|
219
|
+
end
|