datashift 0.2.1 → 0.2.2
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/.document +5 -5
- data/LICENSE.txt +26 -26
- data/README.markdown +326 -305
- data/README.rdoc +19 -19
- data/Rakefile +86 -93
- data/VERSION +1 -1
- data/datashift.gemspec +163 -152
- data/lib/applications/jruby/jexcel_file.rb +410 -408
- data/lib/applications/jruby/word.rb +79 -79
- data/lib/datashift.rb +183 -152
- data/lib/datashift/exceptions.rb +11 -11
- data/lib/datashift/file_definitions.rb +353 -353
- data/lib/datashift/mapping_file_definitions.rb +87 -87
- data/lib/datashift/method_detail.rb +293 -275
- data/lib/datashift/method_dictionary.rb +208 -209
- data/lib/datashift/method_mapper.rb +90 -90
- data/lib/datashift/model_mapper.rb +27 -0
- data/lib/exporters/csv_exporter.rb +36 -0
- data/lib/exporters/excel_exporter.rb +116 -0
- data/lib/exporters/exporter_base.rb +15 -0
- data/lib/generators/csv_generator.rb +36 -36
- data/lib/generators/excel_generator.rb +106 -122
- data/lib/generators/generator_base.rb +13 -13
- data/lib/helpers/core_ext/to_b.rb +24 -24
- data/lib/helpers/rake_utils.rb +42 -0
- data/lib/helpers/spree_helper.rb +194 -153
- data/lib/java/poi-3.7/LICENSE +507 -507
- data/lib/java/poi-3.7/NOTICE +21 -21
- data/lib/java/poi-3.7/RELEASE_NOTES.txt +115 -115
- data/lib/loaders/csv_loader.rb +98 -98
- data/lib/loaders/excel_loader.rb +155 -155
- data/lib/loaders/loader_base.rb +420 -420
- data/lib/loaders/spreadsheet_loader.rb +136 -136
- data/lib/loaders/spree/image_loader.rb +67 -63
- data/lib/loaders/spree/product_loader.rb +289 -248
- data/lib/thor/generate_excel.thor +54 -0
- data/sandbox/app/controllers/application_controller.rb +3 -0
- data/sandbox/config/application.rb +43 -0
- data/sandbox/config/database.yml +34 -0
- data/sandbox/config/environment.rb +7 -0
- data/sandbox/config/environments/development.rb +30 -0
- data/spec/csv_loader_spec.rb +30 -30
- data/spec/datashift_spec.rb +26 -26
- data/spec/db/migrate/20110803201325_create_test_bed.rb +85 -85
- data/spec/excel_exporter_spec.rb +78 -78
- data/spec/excel_generator_spec.rb +78 -78
- data/spec/excel_loader_spec.rb +223 -223
- data/spec/file_definitions.rb +141 -141
- data/spec/fixtures/ProjectsDefaults.yml +29 -29
- data/spec/fixtures/config/database.yml +27 -27
- 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 +4 -4
- data/spec/fixtures/negative/SpreeProdMissManyMandatory.csv +4 -4
- data/spec/fixtures/spree/SpreeProducts.csv +4 -4
- data/spec/fixtures/spree/SpreeProducts.xls +0 -0
- data/spec/fixtures/spree/SpreeProductsMultiColumn.csv +4 -4
- data/spec/fixtures/spree/SpreeProductsMultiColumn.xls +0 -0
- data/spec/fixtures/spree/SpreeProductsSimple.csv +4 -4
- data/spec/fixtures/spree/SpreeProductsWithImages.csv +4 -4
- data/spec/fixtures/spree/SpreeZoneExample.csv +5 -5
- data/spec/fixtures/test_model_defs.rb +57 -57
- data/spec/loader_spec.rb +120 -120
- data/spec/method_dictionary_spec.rb +242 -242
- data/spec/method_mapper_spec.rb +41 -41
- data/spec/spec_helper.rb +154 -116
- data/spec/spree_exporter_spec.rb +67 -0
- data/spec/spree_generator_spec.rb +77 -64
- data/spec/spree_loader_spec.rb +363 -324
- data/spec/spree_method_mapping_spec.rb +218 -214
- data/tasks/config/seed_fu_product_template.erb +15 -15
- data/tasks/config/tidy_config.txt +12 -12
- data/tasks/{excel_generator.rake → export/excel_generator.rake} +101 -78
- data/tasks/file_tasks.rake +36 -36
- data/tasks/import/csv.rake +50 -49
- data/tasks/import/excel.rake +74 -71
- data/tasks/spree/image_load.rake +108 -108
- data/tasks/spree/product_loader.rake +43 -43
- data/tasks/word_to_seedfu.rake +166 -166
- data/test/helper.rb +18 -18
- data/test/test_interact.rb +7 -7
- metadata +16 -8
- data/datashift-0.1.0.gem +0 -0
- data/tasks/db_tasks.rake +0 -66
data/spec/method_mapper_spec.rb
CHANGED
@@ -1,42 +1,42 @@
|
|
1
|
-
# Copyright:: (c) Autotelik Media Ltd 2011
|
2
|
-
# Author :: Tom Statter
|
3
|
-
# Date :: Aug 2011
|
4
|
-
# License:: MIT
|
5
|
-
#
|
6
|
-
# Details:: Specs for MethodMapper aspect of Active Record Loader
|
7
|
-
# MethodMapper provides the bridge between 'strings' e.g column headings
|
8
|
-
# and a classes different types of assignment operators
|
9
|
-
#
|
10
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
11
|
-
|
12
|
-
describe 'Method Mapping' do
|
13
|
-
|
14
|
-
before(:all) do
|
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
|
-
|
20
|
-
migrate_up
|
21
|
-
end
|
22
|
-
|
23
|
-
before(:each) do
|
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
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should find a set of methods based on a list of column names" do
|
36
|
-
pending("key API - map column headers to set of methods")
|
37
|
-
|
38
|
-
@method_mapper.map_inbound_to_methods( load_object_class, @headers )
|
39
|
-
end
|
40
|
-
|
41
|
-
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2011
|
2
|
+
# Author :: Tom Statter
|
3
|
+
# Date :: Aug 2011
|
4
|
+
# License:: MIT
|
5
|
+
#
|
6
|
+
# Details:: Specs for MethodMapper aspect of Active Record Loader
|
7
|
+
# MethodMapper provides the bridge between 'strings' e.g column headings
|
8
|
+
# and a classes different types of assignment operators
|
9
|
+
#
|
10
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
11
|
+
|
12
|
+
describe 'Method Mapping' do
|
13
|
+
|
14
|
+
before(:all) do
|
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
|
+
|
20
|
+
migrate_up
|
21
|
+
end
|
22
|
+
|
23
|
+
before(:each) do
|
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
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should find a set of methods based on a list of column names" do
|
36
|
+
pending("key API - map column headers to set of methods")
|
37
|
+
|
38
|
+
@method_mapper.map_inbound_to_methods( load_object_class, @headers )
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
42
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,117 +1,155 @@
|
|
1
|
-
require 'erb'
|
2
|
-
require 'yaml'
|
3
|
-
|
4
|
-
require File.dirname(__FILE__) + '/../lib/datashift'
|
5
|
-
|
6
|
-
include DataShift
|
7
|
-
|
8
|
-
#.# Copyright:: (c) Autotelik Media Ltd 2011
|
9
|
-
# Author :: Tom Statter
|
10
|
-
# Date :: Aug 2011
|
11
|
-
# License:: MIT
|
12
|
-
#
|
13
|
-
# Details:: Spec Helper for Active Record Loader
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# We are not setup as a Rails project so need to mimic an active record database setup so
|
17
|
-
# we have some AR models top test against. Create an in memory database from scratch.
|
18
|
-
#
|
19
|
-
$DataShiftFixturePath = File.join(File.dirname(__FILE__), 'fixtures')
|
20
|
-
$DataShiftDatabaseYml = File.join($DataShiftFixturePath, 'config/database.yml')
|
21
|
-
|
22
|
-
module DataShift
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
configuration[:database_configuration]
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
#
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
1
|
+
require 'erb'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
require File.dirname(__FILE__) + '/../lib/datashift'
|
5
|
+
|
6
|
+
include DataShift
|
7
|
+
|
8
|
+
#.# Copyright:: (c) Autotelik Media Ltd 2011
|
9
|
+
# Author :: Tom Statter
|
10
|
+
# Date :: Aug 2011
|
11
|
+
# License:: MIT
|
12
|
+
#
|
13
|
+
# Details:: Spec Helper for Active Record Loader
|
14
|
+
#
|
15
|
+
#
|
16
|
+
# We are not setup as a Rails project so need to mimic an active record database setup so
|
17
|
+
# we have some AR models top test against. Create an in memory database from scratch.
|
18
|
+
#
|
19
|
+
$DataShiftFixturePath = File.join(File.dirname(__FILE__), 'fixtures')
|
20
|
+
$DataShiftDatabaseYml = File.join($DataShiftFixturePath, 'config/database.yml')
|
21
|
+
|
22
|
+
module DataShift
|
23
|
+
|
24
|
+
def db_connect( env = 'test_file', version = nil)
|
25
|
+
|
26
|
+
version ? gem('activerecord', version) : gem('activerecord')
|
27
|
+
|
28
|
+
require 'active_record'
|
29
|
+
|
30
|
+
# Some active record stuff seems to rely on the RAILS_ENV being set ?
|
31
|
+
|
32
|
+
ENV['RAILS_ENV'] = env
|
33
|
+
|
34
|
+
configuration = {}
|
35
|
+
|
36
|
+
configuration[:database_configuration] = YAML::load( ERB.new(IO.read($DataShiftDatabaseYml)).result )
|
37
|
+
db = configuration[:database_configuration][ env ]
|
38
|
+
|
39
|
+
puts "Setting DB Config - #{db.inspect}"
|
40
|
+
ActiveRecord::Base.configurations = db
|
41
|
+
|
42
|
+
#dbtype = Rails.configuration.database_configuration[Rails.env]['adapter'].to_sym
|
43
|
+
|
44
|
+
#ActiveRecord::Base.logger = Logger.new(STDOUT)
|
45
|
+
|
46
|
+
require 'logger'
|
47
|
+
logdir = File.dirname(__FILE__) + '/logs'
|
48
|
+
FileUtils.mkdir_p(logdir) unless File.exists?(logdir)
|
49
|
+
ActiveRecord::Base.logger = Logger.new(logdir + '/datashift_spec.log')
|
50
|
+
|
51
|
+
@dslog = ActiveRecord::Base.logger
|
52
|
+
|
53
|
+
puts "Connecting to DB"
|
54
|
+
ActiveRecord::Base.establish_connection( db )
|
55
|
+
|
56
|
+
# See errors #<NameError: uninitialized constant RAILS_CACHE> when doing save (AR without Rails)
|
57
|
+
# so copied this from ... Rails::Initializer.initialize_cache
|
58
|
+
Object.const_set "RAILS_CACHE", ActiveSupport::Cache.lookup_store( :memory_store )
|
59
|
+
|
60
|
+
@dslog.info "Connected to DB - #{ActiveRecord::Base.connection.inspect}"
|
61
|
+
end
|
62
|
+
|
63
|
+
# These are our test models with associations
|
64
|
+
def db_clear
|
65
|
+
[Project, Milestone, Category, Version, LoaderRelease].each {|x| x.delete_all}
|
66
|
+
end
|
67
|
+
|
68
|
+
def load_in_memory
|
69
|
+
load "#{Rails.root}/db/schema.rb"
|
70
|
+
end
|
71
|
+
|
72
|
+
def migrate_up
|
73
|
+
ActiveRecord::Migrator.up( File.dirname(__FILE__) + '/db/migrate')
|
74
|
+
end
|
75
|
+
|
76
|
+
def results_path
|
77
|
+
File.join($DataShiftFixturePath, 'results')
|
78
|
+
end
|
79
|
+
|
80
|
+
def results_clear
|
81
|
+
begin FileUtils.rm_rf(results_path); rescue; end
|
82
|
+
|
83
|
+
FileUtils.mkdir(results_path) unless File.exists?(results_path);
|
84
|
+
end
|
85
|
+
|
86
|
+
# Return location of an expected results file and ensure tree clean before test
|
87
|
+
def result_file( name )
|
88
|
+
expect = File.join(results_path, name)
|
89
|
+
|
90
|
+
begin FileUtils.rm(expect); rescue; end
|
91
|
+
|
92
|
+
expect
|
93
|
+
end
|
94
|
+
|
95
|
+
def ifixture_file( name )
|
96
|
+
File.join($DataShiftFixturePath, name)
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
module SpecHelper
|
102
|
+
|
103
|
+
$SpreeFixturePath = File.join($DataShiftFixturePath, 'spree')
|
104
|
+
$SpreeNegativeFixturePath = File.join($DataShiftFixturePath, 'negative')
|
105
|
+
|
106
|
+
def self.spree_fixture( source)
|
107
|
+
File.join($SpreeFixturePath, source)
|
108
|
+
end
|
109
|
+
|
110
|
+
def self.before_all_spree
|
111
|
+
# we are not a Spree project, nor is it practical to externally generate
|
112
|
+
# a complete Spree application for testing so we implement a mini migrate/boot of our own
|
113
|
+
SpreeHelper.load() # require Spree gems
|
114
|
+
SpreeHelper.boot( 'test_spree_standalone' ) # key to YAML db e.g test_memory, test_mysql
|
115
|
+
|
116
|
+
SpreeHelper.migrate_up # create an sqlite Spree database on the fly
|
117
|
+
end
|
118
|
+
|
119
|
+
def before_each_spree
|
120
|
+
|
121
|
+
@klass = SpreeHelper::get_product_class
|
122
|
+
@Product_klass = @klass
|
123
|
+
@Taxon_klass = SpreeHelper::get_spree_class('Taxon')
|
124
|
+
@zone_klass = SpreeHelper::get_spree_class('Zone')
|
125
|
+
|
126
|
+
# Reset main tables - TODO should really purge properly, or roll back a transaction
|
127
|
+
@klass.delete_all
|
128
|
+
@Taxon_klass.delete_all
|
129
|
+
@zone_klass.delete_all
|
130
|
+
|
131
|
+
%w{OptionType OptionValue Property ProductProperty Variant Taxonomy}.each do |k|
|
132
|
+
instance_variable_set("@#{k}_klass", SpreeHelper::get_spree_class(k))
|
133
|
+
instance_variable_get("@#{k}_klass").delete_all
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
RSpec.configure do |config|
|
140
|
+
# config.use_transactional_fixtures = true
|
141
|
+
# config.use_instantiated_fixtures = false
|
142
|
+
# config.fixture_path = RAILS_ROOT + '/spec/fixtures'
|
143
|
+
|
144
|
+
# You can declare fixtures for each behaviour like this:
|
145
|
+
# describe "...." do
|
146
|
+
# fixtures :table_a, :table_b
|
147
|
+
#
|
148
|
+
# Alternatively, if you prefer to declare them only once, you can
|
149
|
+
# do so here, like so ...
|
150
|
+
#
|
151
|
+
# config.global_fixtures = :table_a, :table_b
|
152
|
+
#
|
153
|
+
# If you declare global fixtures, be aware that they will be declared
|
154
|
+
# for all of your examples, even those that don't use them.
|
117
155
|
end
|
@@ -0,0 +1,67 @@
|
|
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 generator aspect of datashift gem.
|
8
|
+
#
|
9
|
+
# Provides Loaders and rake tasks specifically tailored for uploading or exporting
|
10
|
+
# Spree Products, associations and Images
|
11
|
+
#
|
12
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
13
|
+
|
14
|
+
require 'spree_helper'
|
15
|
+
require 'excel_generator'
|
16
|
+
|
17
|
+
include DataShift
|
18
|
+
|
19
|
+
describe 'SpreeLoader' do
|
20
|
+
|
21
|
+
before(:all) do
|
22
|
+
SpecHelper::before_all_spree
|
23
|
+
end
|
24
|
+
|
25
|
+
before do
|
26
|
+
|
27
|
+
include SpecHelper
|
28
|
+
extend SpecHelper
|
29
|
+
|
30
|
+
before_each_spree # inits tests, cleans DB setups model types
|
31
|
+
|
32
|
+
# Create some test data
|
33
|
+
root = @Taxonomy_klass.create( :name => 'Paintings' )
|
34
|
+
|
35
|
+
@Taxon_klass.create( :name => 'Landscape', :taxonomy => root )
|
36
|
+
@Taxon_klass.create( :name => 'Sea', :taxonomy => root )
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should export any Spree model to .xls spreedsheet" do
|
41
|
+
|
42
|
+
expect = result_file('taxonomy_export_spec.xls')
|
43
|
+
|
44
|
+
gen = ExcelGenerator.new(expect)
|
45
|
+
|
46
|
+
items = @Taxonomy_klass.all
|
47
|
+
|
48
|
+
gen.export(items)
|
49
|
+
|
50
|
+
File.exists?(expect).should be_true
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should export a Spree model and associations to .xls spreedsheet" do
|
54
|
+
|
55
|
+
expect = result_file('taxonomy_and_assoc_export_spec.xls')
|
56
|
+
|
57
|
+
gen = ExcelGenerator.new(expect)
|
58
|
+
|
59
|
+
items = @Taxonomy_klass.all
|
60
|
+
|
61
|
+
gen.generate_with_associations(@Taxonomy_klass, items)
|
62
|
+
|
63
|
+
File.exists?(expect).should be_true
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -1,65 +1,78 @@
|
|
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 generator aspect of datashift gem.
|
8
|
-
#
|
9
|
-
# Provides Loaders and rake tasks specifically tailored for uploading or exporting
|
10
|
-
# Spree Products, associations and Images
|
11
|
-
#
|
12
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
13
|
-
|
14
|
-
require 'spree_helper'
|
15
|
-
require 'excel_generator'
|
16
|
-
|
17
|
-
include DataShift
|
18
|
-
|
19
|
-
describe 'SpreeLoader' do
|
20
|
-
|
21
|
-
before(:all) do
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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 generator aspect of datashift gem.
|
8
|
+
#
|
9
|
+
# Provides Loaders and rake tasks specifically tailored for uploading or exporting
|
10
|
+
# Spree Products, associations and Images
|
11
|
+
#
|
12
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
13
|
+
|
14
|
+
require 'spree_helper'
|
15
|
+
require 'excel_generator'
|
16
|
+
|
17
|
+
include DataShift
|
18
|
+
|
19
|
+
describe 'SpreeLoader' do
|
20
|
+
|
21
|
+
before(:all) do
|
22
|
+
SpecHelper::before_all_spree
|
23
|
+
end
|
24
|
+
|
25
|
+
before do
|
26
|
+
|
27
|
+
include SpecHelper
|
28
|
+
extend SpecHelper
|
29
|
+
|
30
|
+
before_each_spree # inits tests, cleans DB setups model types
|
31
|
+
|
32
|
+
# Create some test data
|
33
|
+
root = @Taxonomy_klass.create( :name => 'Paintings' )
|
34
|
+
|
35
|
+
@Taxon_klass.create( :name => 'Landscape', :taxonomy => root )
|
36
|
+
@Taxon_klass.create( :name => 'Sea', :taxonomy => root )
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should export any Spree model to .xls spreedsheet" do
|
41
|
+
|
42
|
+
expect = result_file('taxonomy_export_spec.xls')
|
43
|
+
|
44
|
+
excel = ExcelGenerator.new(expect)
|
45
|
+
|
46
|
+
excel.generate(@Taxonomy_klass)
|
47
|
+
|
48
|
+
File.exists?(expect).should be_true
|
49
|
+
|
50
|
+
puts "You can check results manually in file #{expect}"
|
51
|
+
|
52
|
+
expect = result_file('taxon_export_spec.xls')
|
53
|
+
|
54
|
+
excel.filename = expect
|
55
|
+
|
56
|
+
excel.generate(@Taxon_klass)
|
57
|
+
|
58
|
+
File.exists?(expect).should be_true
|
59
|
+
|
60
|
+
puts "You can check results manually in file #{expect}"
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should export Spree Product and all associations to .xls spreedsheet" do
|
65
|
+
|
66
|
+
expect = result_file('product_and_assoc_export_spec.xls')
|
67
|
+
|
68
|
+
excel = ExcelGenerator.new(expect)
|
69
|
+
|
70
|
+
excel.generate_with_associations(@klass)
|
71
|
+
|
72
|
+
File.exists?(expect).should be_true
|
73
|
+
|
74
|
+
puts "You can check results manually in file #{expect}"
|
75
|
+
|
76
|
+
end
|
77
|
+
|
65
78
|
end
|