ar_loader 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +9 -9
- data/README.markdown +268 -221
- data/Rakefile +76 -76
- data/lib/VERSION +1 -1
- data/lib/ar_loader.rb +87 -66
- data/lib/ar_loader/exceptions.rb +2 -0
- data/lib/{engine → ar_loader}/file_definitions.rb +353 -353
- data/lib/{engine → ar_loader}/mapping_file_definitions.rb +87 -87
- data/lib/ar_loader/method_detail.rb +257 -0
- data/lib/ar_loader/method_mapper.rb +213 -0
- data/lib/helpers/jruby/jexcel_file.rb +187 -0
- data/lib/{engine → helpers/jruby}/word.rb +79 -70
- data/lib/helpers/spree_helper.rb +85 -0
- data/lib/loaders/csv_loader.rb +87 -0
- data/lib/loaders/excel_loader.rb +132 -0
- data/lib/loaders/loader_base.rb +205 -73
- data/lib/loaders/spree/image_loader.rb +45 -41
- data/lib/loaders/spree/product_loader.rb +140 -91
- data/lib/to_b.rb +24 -24
- data/spec/csv_loader_spec.rb +27 -0
- data/spec/database.yml +19 -6
- data/spec/db/migrate/20110803201325_create_test_bed.rb +78 -0
- data/spec/excel_loader_spec.rb +113 -98
- data/spec/fixtures/BadAssociationName.xls +0 -0
- data/spec/fixtures/DemoNegativeTesting.xls +0 -0
- data/spec/fixtures/DemoTestModelAssoc.xls +0 -0
- data/spec/fixtures/ProjectsMultiCategories.xls +0 -0
- data/spec/fixtures/SimpleProjects.xls +0 -0
- data/spec/fixtures/SpreeProducts.xls +0 -0
- data/spec/fixtures/SpreeZoneExample.csv +5 -0
- data/spec/fixtures/SpreeZoneExample.xls +0 -0
- data/spec/loader_spec.rb +116 -0
- data/spec/logs/test.log +5000 -0
- data/spec/method_mapper_spec.rb +222 -0
- data/spec/models.rb +55 -0
- data/spec/spec_helper.rb +85 -18
- data/spec/spree_loader_spec.rb +223 -157
- data/tasks/config/seed_fu_product_template.erb +15 -15
- data/tasks/config/tidy_config.txt +12 -12
- data/tasks/db_tasks.rake +64 -64
- data/tasks/excel_loader.rake +63 -113
- data/tasks/file_tasks.rake +36 -37
- data/tasks/loader.rake +45 -0
- data/tasks/spree/image_load.rake +108 -107
- data/tasks/spree/product_loader.rake +49 -107
- data/tasks/word_to_seedfu.rake +166 -166
- metadata +66 -61
- data/lib/engine/jruby/jexcel_file.rb +0 -182
- data/lib/engine/jruby/method_mapper_excel.rb +0 -44
- data/lib/engine/method_detail.rb +0 -140
- data/lib/engine/method_mapper.rb +0 -157
- data/lib/engine/method_mapper_csv.rb +0 -28
- data/spec/db/migrate/20110803201325_create_testbed.rb +0 -25
@@ -1,92 +1,141 @@
|
|
1
|
-
# Copyright:: (c) Autotelik Media Ltd 2010
|
2
|
-
# Author :: Tom Statter
|
3
|
-
# Date :: Aug 2010
|
4
|
-
# License:: MIT ?
|
5
|
-
#
|
6
|
-
# Details:: Specific over-rides/additions to support Spree Products
|
7
|
-
#
|
8
|
-
require 'loader_base'
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
#
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
option_types
|
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
|
-
|
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
|
-
|
1
|
+
# Copyright:: (c) Autotelik Media Ltd 2010
|
2
|
+
# Author :: Tom Statter
|
3
|
+
# Date :: Aug 2010
|
4
|
+
# License:: MIT ?
|
5
|
+
#
|
6
|
+
# Details:: Specific over-rides/additions to support Spree Products
|
7
|
+
#
|
8
|
+
require 'loader_base'
|
9
|
+
require 'excel_loader'
|
10
|
+
|
11
|
+
|
12
|
+
module ARLoader
|
13
|
+
|
14
|
+
class ProductLoader < ExcelLoader
|
15
|
+
|
16
|
+
def initialize(product = nil)
|
17
|
+
super( Product, product )
|
18
|
+
raise "Failed to create Product for loading" unless @load_object
|
19
|
+
end
|
20
|
+
|
21
|
+
# What process a value string from a column, assigning value(s) to correct association on Product.
|
22
|
+
# Method map represents a column from a file and it's correlated Product association.
|
23
|
+
# Value string which may contain multiple values for a collection association.
|
24
|
+
# Product to assign that value to.
|
25
|
+
def process( method_detail, value)
|
26
|
+
|
27
|
+
@current_value = value
|
28
|
+
@current_method_detail = method_detail
|
29
|
+
|
30
|
+
#puts "DEBUG: process #{method_detail.inspect} : #{current_value.inspect}"
|
31
|
+
# Special case for OptionTypes as it's two stage process
|
32
|
+
# First add the possible option_types to Product, then we are able
|
33
|
+
# to define Variants on those options values.
|
34
|
+
|
35
|
+
if(method_detail.operator?('option_types') && current_value)
|
36
|
+
|
37
|
+
#puts "DEBUG: Special Case: VARIANTS: #{method_detail.inspect} : #{current_value.inspect}"
|
38
|
+
|
39
|
+
# TODO smart column ordering to ensure always valid by time we get to associations
|
40
|
+
save if(load_object.valid? && load_object.new_record?)
|
41
|
+
|
42
|
+
option_types = current_value.split(@@multi_assoc_delim)
|
43
|
+
|
44
|
+
option_types.each do |ostr|
|
45
|
+
oname, value_str = ostr.split(@@name_value_delim)
|
46
|
+
option_type = OptionType.find_or_create_by_name(oname)
|
47
|
+
unless option_type
|
48
|
+
puts "WARNING: OptionType #{oname} NOT found - Not set Product"
|
49
|
+
next
|
50
|
+
end
|
51
|
+
|
52
|
+
@load_object.option_types << option_type unless @load_object.option_types.include?(option_type)
|
53
|
+
|
54
|
+
# Now get the value(s) for the option e.g red,blue,green for OptType 'colour'
|
55
|
+
ovalues = value_str.split(',')
|
56
|
+
|
57
|
+
ovalues.each_with_index do |ovname, i|
|
58
|
+
ovname.strip!
|
59
|
+
ov = OptionValue.find_or_create_by_name(ovname)
|
60
|
+
if ov
|
61
|
+
object = Variant.new( :sku => "#{@load_object.sku}_#{i}", :price => @load_object.price, :available_on => @load_object.available_on)
|
62
|
+
#puts "DEBUG: Create New Variant: #{object.inspect}"
|
63
|
+
object.option_values << ov
|
64
|
+
@load_object.variants << object
|
65
|
+
else
|
66
|
+
puts "WARNING: Option #{ovname} NOT FOUND - No Variant created"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
elsif(method_detail.operator?('taxons') && current_value)
|
72
|
+
|
73
|
+
# TODO smart column ordering to ensure always valid by time we get to associations
|
74
|
+
save if(load_object.valid? && load_object.new_record?)
|
75
|
+
|
76
|
+
name_list = current_value.split(@@multi_assoc_delim)
|
77
|
+
|
78
|
+
taxons = name_list.collect do |t|
|
79
|
+
|
80
|
+
taxon = Taxon.find_by_name(t)
|
81
|
+
|
82
|
+
unless taxon
|
83
|
+
parent = Taxonomy.find_by_name(t)
|
84
|
+
|
85
|
+
#puts "DEBUG: Taxonomy #{parent} for #{t}"
|
86
|
+
begin
|
87
|
+
parent = Taxonomy.create!( :name => t ) unless parent
|
88
|
+
|
89
|
+
taxon = Taxon.create(:name => t, :taxonomy_id => parent.id)
|
90
|
+
rescue => e
|
91
|
+
e.backtrace
|
92
|
+
e.inspect
|
93
|
+
puts "ERROR : Cannot assign Taxon ['#{t}'] to Product ['#{load_object.name}']"
|
94
|
+
next
|
95
|
+
end
|
96
|
+
end
|
97
|
+
taxon
|
98
|
+
end
|
99
|
+
|
100
|
+
taxons.compact!
|
101
|
+
|
102
|
+
@load_object.taxons << taxons unless(taxons.empty?)
|
103
|
+
|
104
|
+
# Special case for ProductProperties since it can have additional value applied.
|
105
|
+
# A list of Properties with a optional Value - supplied in form :
|
106
|
+
# Property:value|Property2:value|Property3:value
|
107
|
+
#
|
108
|
+
elsif(method_detail.operator?('product_properties') && current_value)
|
109
|
+
|
110
|
+
# TODO smart column ordering to ensure always valid by time we get to associations
|
111
|
+
save if(load_object.valid? && load_object.new_record?)
|
112
|
+
|
113
|
+
property_list = current_value.split(@@multi_assoc_delim)
|
114
|
+
|
115
|
+
property_list.each do |pstr|
|
116
|
+
pname, pvalue = pstr.split(@@name_value_delim)
|
117
|
+
property = Property.find_by_name(pname)
|
118
|
+
unless property
|
119
|
+
puts "WARNING: Property #{pname} NOT found - Not set Product"
|
120
|
+
next
|
121
|
+
end
|
122
|
+
@load_object.product_properties << ProductProperty.create( :property => property, :value => pvalue)
|
123
|
+
end
|
124
|
+
|
125
|
+
elsif(method_detail.operator?('count_on_hand') && @load_object.variants.size > 0 && current_value.is_a?(String) && current_value.include?(@@multi_assoc_delim))
|
126
|
+
# Check if we processed Option Types and assign count per option
|
127
|
+
values = current_value.split(@@multi_assoc_delim)
|
128
|
+
if(@load_object.variants.size == values.size)
|
129
|
+
@load_object.variants.each_with_index {|v, i| v.count_on_hand == values[i] }
|
130
|
+
else
|
131
|
+
puts "WARNING: Count on hand entries does not match number of Variants"
|
132
|
+
end
|
133
|
+
|
134
|
+
else
|
135
|
+
super(method_detail, value)
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
92
141
|
end
|
data/lib/to_b.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
class Object
|
2
|
-
def to_b
|
3
|
-
case self
|
4
|
-
when true, false: self
|
5
|
-
when nil: false
|
6
|
-
else
|
7
|
-
to_i != 0
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
class String
|
13
|
-
TRUE_REGEXP = /^(yes|true|on|t|1|\-1)$/i.freeze
|
14
|
-
FALSE_REGEXP = /^(no|false|off|f|0)$/i.freeze
|
15
|
-
|
16
|
-
def to_b
|
17
|
-
case self
|
18
|
-
when TRUE_REGEXP: true
|
19
|
-
when FALSE_REGEXP: false
|
20
|
-
else
|
21
|
-
to_i != 0
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
1
|
+
class Object
|
2
|
+
def to_b
|
3
|
+
case self
|
4
|
+
when true, false: self
|
5
|
+
when nil: false
|
6
|
+
else
|
7
|
+
to_i != 0
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class String
|
13
|
+
TRUE_REGEXP = /^(yes|true|on|t|1|\-1)$/i.freeze
|
14
|
+
FALSE_REGEXP = /^(no|false|off|f|0)$/i.freeze
|
15
|
+
|
16
|
+
def to_b
|
17
|
+
case self
|
18
|
+
when TRUE_REGEXP: true
|
19
|
+
when FALSE_REGEXP: false
|
20
|
+
else
|
21
|
+
to_i != 0
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
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
|
+
require 'erb'
|
11
|
+
require 'excel_loader'
|
12
|
+
|
13
|
+
describe 'CSV Loader' do
|
14
|
+
|
15
|
+
before(:all) do
|
16
|
+
db_connect( 'test_file' ) # , test_memory, test_mysql
|
17
|
+
migrate_up
|
18
|
+
@klazz = Project
|
19
|
+
end
|
20
|
+
|
21
|
+
before(:each) do
|
22
|
+
MethodMapper.clear
|
23
|
+
MethodMapper.find_operators( @klazz )
|
24
|
+
MethodMapper.find_operators( @assoc_klazz )
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/spec/database.yml
CHANGED
@@ -1,6 +1,19 @@
|
|
1
|
-
<% adapter = '
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
database:
|
1
|
+
<% adapter = 'sqlite3' %>
|
2
|
+
<% adapter = 'jdbcsqlite3' if(Guards::jruby? ) %>
|
3
|
+
|
4
|
+
test_mysql:
|
5
|
+
adapter: jdbcmysql
|
6
|
+
database: ar_loader_test
|
7
|
+
username: test
|
8
|
+
password: test
|
9
|
+
host: localhost
|
10
|
+
|
11
|
+
test_memory:
|
12
|
+
adapter: <%= adapter %>
|
13
|
+
database: :memory
|
14
|
+
|
15
|
+
test_file:
|
16
|
+
adapter: <%= adapter %>
|
17
|
+
database: 'ar_loader_test'
|
18
|
+
encoding: utf8
|
19
|
+
host: localhost
|
@@ -0,0 +1,78 @@
|
|
1
|
+
class CreateTestBed < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
|
5
|
+
# has many :milestones
|
6
|
+
create_table :projects do |t|
|
7
|
+
t.string :title
|
8
|
+
t.string :value_as_string
|
9
|
+
t.text :value_as_text
|
10
|
+
t.boolean :value_as_boolean, :default => false
|
11
|
+
t.datetime :value_as_datetime, :default => nil
|
12
|
+
t.integer :value_as_integer, :default => 0
|
13
|
+
t.decimal :value_as_double, :precision => 8, :scale => 2, :default => 0.0
|
14
|
+
t.timestamps
|
15
|
+
end
|
16
|
+
|
17
|
+
# belongs_to :project, project => has_many
|
18
|
+
create_table :milestones do |t|
|
19
|
+
t.string :name
|
20
|
+
t.datetime :datetime, :default => nil
|
21
|
+
t.decimal :cost, :precision => 8, :scale => 2, :default => 0.0
|
22
|
+
t.references :project
|
23
|
+
t.timestamps
|
24
|
+
end
|
25
|
+
|
26
|
+
# belongs_to :project, project => has_one
|
27
|
+
create_table :owners do |t|
|
28
|
+
t.string :name
|
29
|
+
t.references :project
|
30
|
+
t.timestamps
|
31
|
+
end
|
32
|
+
|
33
|
+
# has_belongs_to_many :project
|
34
|
+
create_table :categories do |t|
|
35
|
+
t.string :reference
|
36
|
+
t.timestamps
|
37
|
+
end
|
38
|
+
|
39
|
+
# testing has_belongs_to_many (hence no id)
|
40
|
+
create_table :categories_projects, :id => false do |t|
|
41
|
+
t.references :category
|
42
|
+
t.references :project
|
43
|
+
end
|
44
|
+
|
45
|
+
create_table :versions do |t|
|
46
|
+
t.string :name
|
47
|
+
t.timestamps
|
48
|
+
end
|
49
|
+
|
50
|
+
# testing project has_many release + versions :through
|
51
|
+
create_table :loader_releases do |t|
|
52
|
+
t.string :name
|
53
|
+
t.references :project
|
54
|
+
t.references :version
|
55
|
+
t.timestamps
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
create_table :long_and_complex_table_linked_to_versions do |t|
|
60
|
+
t.references :version
|
61
|
+
end
|
62
|
+
|
63
|
+
create_table :empties do |t|
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.down
|
69
|
+
drop_table :projects
|
70
|
+
drop_table :categories
|
71
|
+
drop_table :loader_releases
|
72
|
+
drop_table :versions
|
73
|
+
drop_table :categories_projectss
|
74
|
+
drop_table :milestones
|
75
|
+
drop_table :long_and_complex_table_linked_to_versions
|
76
|
+
drop_table :empties
|
77
|
+
end
|
78
|
+
end
|
data/spec/excel_loader_spec.rb
CHANGED
@@ -1,99 +1,114 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
#
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
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
|
-
|
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
|
+
require 'erb'
|
11
|
+
require 'excel_loader'
|
12
|
+
|
13
|
+
include ARLoader
|
14
|
+
|
15
|
+
describe 'Excel Loader' do
|
16
|
+
|
17
|
+
before(:all) do
|
18
|
+
db_connect( 'test_file' ) # , test_memory, test_mysql
|
19
|
+
|
20
|
+
db_clear() # todo read up about proper transactional fixtures
|
21
|
+
|
22
|
+
|
23
|
+
@klazz = Project
|
24
|
+
@assoc_klazz = Category
|
25
|
+
end
|
26
|
+
|
27
|
+
before(:each) do
|
28
|
+
|
29
|
+
Project.delete_all
|
30
|
+
|
31
|
+
%w{category_001 category_002 category_003}.each do |cat|
|
32
|
+
@assoc_klazz.find_or_create_by_reference(cat)
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
MethodMapper.clear
|
37
|
+
MethodMapper.find_operators( @klazz )
|
38
|
+
MethodMapper.find_operators( @assoc_klazz )
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should be able to create a new excel loader and load object" do
|
42
|
+
loader = ExcelLoader.new( @klazz)
|
43
|
+
|
44
|
+
loader.load_object.should_not be_nil
|
45
|
+
loader.load_object.should be_is_a(@klazz)
|
46
|
+
loader.load_object.new_record?.should be_true
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should process a simple .xls spreedsheet" do
|
50
|
+
|
51
|
+
loader = ExcelLoader.new(@klazz)
|
52
|
+
|
53
|
+
count = @klazz.count
|
54
|
+
loader.load( $fixture_path + '/SimpleProjects.xls')
|
55
|
+
|
56
|
+
loader.loaded_count.should == (@klazz.count - count)
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should process associations in .xls spreedsheet" do
|
61
|
+
|
62
|
+
@klazz.find_by_title('001').should be_nil
|
63
|
+
count = @klazz.count
|
64
|
+
|
65
|
+
loader = ExcelLoader.new(@klazz)
|
66
|
+
|
67
|
+
loader.load( $fixture_path + '/DemoTestModelAssoc.xls')
|
68
|
+
|
69
|
+
loader.loaded_count.should be > 3
|
70
|
+
loader.loaded_count.should == (@klazz.count - count)
|
71
|
+
|
72
|
+
{'001' => 2, '002' => 1, '003' => 3, '004' => 0 }.each do|title, expected|
|
73
|
+
project = @klazz.find_by_title(title)
|
74
|
+
|
75
|
+
project.should_not be_nil
|
76
|
+
puts "#{project.inspect} [#{project.categories.size}]"
|
77
|
+
|
78
|
+
project.should have(expected).categories
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should process multiple associations in excel spreedsheet" do
|
83
|
+
|
84
|
+
loader = ExcelLoader.new(Project)
|
85
|
+
|
86
|
+
count = Project.count
|
87
|
+
loader.load( $fixture_path + '/ProjectsMultiCategories.xls')
|
88
|
+
|
89
|
+
loader.loaded_count.should == (Project.count - count)
|
90
|
+
|
91
|
+
{'004' => 3, '005' => 1, '006' => 0, '007' => 1 }.each do|title, expected|
|
92
|
+
project = @klazz.find_by_title(title)
|
93
|
+
|
94
|
+
project.should_not be_nil
|
95
|
+
puts "#{project.inspect} [#{project.categories.size}]"
|
96
|
+
|
97
|
+
project.should have(expected).categories
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should not process badly defined excel spreedsheet" do
|
103
|
+
loader = ExcelLoader.new(Project)
|
104
|
+
expect {loader.load( $fixture_path + '/BadAssociationName.xls')}.to raise_error(MappingDefinitionError)
|
105
|
+
end
|
106
|
+
|
107
|
+
#@pending
|
108
|
+
it "should raise an error when mandatory columns missing" do
|
109
|
+
#loader = ExcelLoader.new(Project)
|
110
|
+
#required = [:x, :. :z]
|
111
|
+
#expect {loader.load( $fixture_path + '/BadAssociationName.xls', { :mandatopry:=> required}) }.to raise_error(????????)
|
112
|
+
end
|
113
|
+
|
99
114
|
end
|