datashift 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -5
- data/LICENSE.txt +26 -26
- data/README.markdown +305 -303
- data/README.rdoc +19 -19
- data/Rakefile +93 -93
- data/VERSION +1 -1
- data/datashift-0.1.0.gem +0 -0
- data/datashift.gemspec +152 -136
- data/lib/applications/jruby/jexcel_file.rb +408 -408
- data/lib/applications/jruby/word.rb +79 -79
- data/lib/datashift.rb +152 -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 +275 -275
- data/lib/datashift/method_dictionary.rb +209 -209
- data/lib/datashift/method_mapper.rb +90 -90
- data/lib/generators/csv_generator.rb +36 -36
- data/lib/generators/excel_generator.rb +122 -122
- data/lib/generators/generator_base.rb +13 -13
- data/lib/helpers/core_ext/to_b.rb +24 -24
- data/lib/helpers/spree_helper.rb +153 -155
- 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 +63 -64
- data/lib/loaders/spree/product_loader.rb +248 -250
- 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/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 -24
- data/spec/fixtures/datashift_Spree_db.sqlite +0 -0
- data/spec/fixtures/interact_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/SpreeProductsMultiColumn.csv +4 -4
- data/spec/fixtures/spree/SpreeProductsSimple.csv +4 -4
- data/spec/fixtures/spree/SpreeProductsWithImages.csv +4 -0
- 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 +116 -116
- data/spec/spree_generator_spec.rb +64 -64
- data/spec/spree_loader_spec.rb +324 -327
- data/spec/spree_method_mapping_spec.rb +214 -214
- data/tasks/config/seed_fu_product_template.erb +15 -15
- data/tasks/config/tidy_config.txt +12 -12
- data/tasks/db_tasks.rake +65 -65
- data/tasks/excel_generator.rake +78 -78
- data/tasks/file_tasks.rake +36 -36
- data/tasks/import/csv.rake +49 -49
- data/tasks/import/excel.rake +71 -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 +22 -3
- data/spec/fixtures/interact_spree_db.sqlite +0 -0
@@ -1,215 +1,215 @@
|
|
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 aspect of datashift gem.
|
8
|
-
#
|
9
|
-
# Tests the method mapping aspect, such as that we correctly identify
|
10
|
-
# Spree Product attributes and associations
|
11
|
-
#
|
12
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
13
|
-
|
14
|
-
require 'spree_helper'
|
15
|
-
require 'product_loader'
|
16
|
-
|
17
|
-
include DataShift
|
18
|
-
|
19
|
-
describe 'SpreeLoader' do
|
20
|
-
|
21
|
-
before(:all) do
|
22
|
-
|
23
|
-
# we are not a Spree project, nor is it practical to externally generate
|
24
|
-
# a complete Spree application for testing so we implement a mini migrate/boot of our own
|
25
|
-
Spree.load() # require Spree gems
|
26
|
-
|
27
|
-
# key to YAML db e.g test_memory, test_mysql
|
28
|
-
db_connect( 'test_spree_standalone' )
|
29
|
-
|
30
|
-
Spree.boot # create a sort-of Spree app
|
31
|
-
|
32
|
-
Spree.migrate_up # create an sqlite Spree database on the fly
|
33
|
-
|
34
|
-
@klazz = Product
|
35
|
-
|
36
|
-
# Reset main tables - TODO should really purge properly, or roll back a transaction
|
37
|
-
[OptionType, OptionValue, Product, Property, Variant, Taxonomy, Taxon, Zone].each { |x| x.delete_all }
|
38
|
-
end
|
39
|
-
|
40
|
-
before(:each) do
|
41
|
-
MethodMapper.clear
|
42
|
-
MethodDictionary.find_operators( @klazz )
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
it "should populate operators for a Spree Product" do
|
47
|
-
|
48
|
-
MethodMapper.has_many.should_not be_empty
|
49
|
-
MethodMapper.belongs_to.should_not be_empty
|
50
|
-
MethodMapper.assignments.should_not be_empty
|
51
|
-
|
52
|
-
assign = MethodMapper.assignments_for(@klazz)
|
53
|
-
|
54
|
-
assign.should include('available_on') # Example of a simple column
|
55
|
-
|
56
|
-
MethodMapper.assignments[@klazz].should include('available_on')
|
57
|
-
|
58
|
-
has_many_ops = MethodMapper.has_many_for(@klazz)
|
59
|
-
|
60
|
-
has_many_ops.should include('properties') # Product can have many properties
|
61
|
-
|
62
|
-
MethodMapper.has_many[@klazz].should include('properties')
|
63
|
-
|
64
|
-
btf = MethodMapper.belongs_to_for(@klazz)
|
65
|
-
|
66
|
-
btf.should include('tax_category') # Example of a belongs_to assignment
|
67
|
-
|
68
|
-
MethodMapper.belongs_to[@klazz].should include('tax_category')
|
69
|
-
|
70
|
-
MethodMapper.column_types[@klazz].size.should == @klazz.columns.size
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
it "should find method details correctly for different forms of a column name" do
|
75
|
-
|
76
|
-
["available On", 'available_on', "Available On", "AVAILABLE_ON"].each do |format|
|
77
|
-
|
78
|
-
method_details = MethodMapper.find_method_detail( @klazz, format )
|
79
|
-
|
80
|
-
method_details.operator.should == 'available_on'
|
81
|
-
method_details.operator_for(:assignment).should == 'available_on'
|
82
|
-
|
83
|
-
method_details.operator_for(:belongs_to).should be_nil
|
84
|
-
method_details.operator_for(:has_many).should be_nil
|
85
|
-
|
86
|
-
method_details.col_type.should_not be_nil
|
87
|
-
method_details.col_type.name.should == 'available_on'
|
88
|
-
method_details.col_type.default.should == nil
|
89
|
-
method_details.col_type.sql_type.should include 'datetime' # works on mysql and sqlite
|
90
|
-
method_details.col_type.type.should == :datetime
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should populate method details correctly for has_many forms of association name" do
|
95
|
-
|
96
|
-
MethodMapper.has_many[@klazz].should include('product_option_types')
|
97
|
-
|
98
|
-
["product_option_types", "product option types", 'product Option_types', "ProductOptionTypes", "Product_Option_Types"].each do |format|
|
99
|
-
method_detail = MethodMapper.find_method_detail( @klazz, format )
|
100
|
-
|
101
|
-
method_detail.should_not be_nil
|
102
|
-
|
103
|
-
method_detail.operator_for(:has_many).should eq('product_option_types')
|
104
|
-
method_detail.operator_for(:belongs_to).should be_nil
|
105
|
-
method_detail.operator_for(:assignment).should be_nil
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
|
110
|
-
it "should populate method details correctly for assignment operators (none columns on #{@klazz})" do
|
111
|
-
|
112
|
-
MethodDictionary.find_operators( @klazz, :reload => true, :instance_methods => true )
|
113
|
-
|
114
|
-
# Example of delegates i.e. cost_price column on Variant, delegated to Variant by Product
|
115
|
-
|
116
|
-
MethodMapper.assignments[@klazz].should include('cost_price')
|
117
|
-
MethodMapper.assignments[@klazz].should include('sku')
|
118
|
-
|
119
|
-
|
120
|
-
count_on_hand = MethodMapper.find_method_detail( @klazz, 'count on hand' )
|
121
|
-
count_on_hand.should_not be_nil
|
122
|
-
count_on_hand.operator.should == 'count_on_hand'
|
123
|
-
|
124
|
-
method = MethodMapper.find_method_detail( @klazz, 'sku' )
|
125
|
-
method.should_not be_nil
|
126
|
-
method.operator.should == 'sku'
|
127
|
-
end
|
128
|
-
|
129
|
-
it "should enable assignment via operators for none columns on #{@klazz}" do
|
130
|
-
|
131
|
-
MethodDictionary.find_operators( @klazz, :reload => true, :instance_methods => true )
|
132
|
-
|
133
|
-
klazz_object = @klazz.new
|
134
|
-
|
135
|
-
klazz_object.should be_new_record
|
136
|
-
|
137
|
-
# we can use method details to populate a new AR object, essentailly same as
|
138
|
-
# klazz_object.send( count_on_hand.operator, 2)
|
139
|
-
count_on_hand = MethodMapper.find_method_detail( @klazz, 'count on hand' )
|
140
|
-
|
141
|
-
count_on_hand.assign( klazz_object, 2 )
|
142
|
-
klazz_object.count_on_hand.should == 2
|
143
|
-
|
144
|
-
count_on_hand.assign( klazz_object, 5 )
|
145
|
-
klazz_object.count_on_hand.should == 5
|
146
|
-
|
147
|
-
method = MethodMapper.find_method_detail( @klazz, 'sku' )
|
148
|
-
method.should_not be_nil
|
149
|
-
|
150
|
-
method.operator.should == 'sku'
|
151
|
-
|
152
|
-
method.assign( klazz_object, 'TEST_SK 001')
|
153
|
-
klazz_object.sku.should == 'TEST_SK 001'
|
154
|
-
|
155
|
-
end
|
156
|
-
|
157
|
-
it "should enable assignment to has_many association on new object" do
|
158
|
-
|
159
|
-
method_detail = MethodMapper.find_method_detail( @klazz, 'taxons' )
|
160
|
-
|
161
|
-
method_detail.operator.should == 'taxons'
|
162
|
-
|
163
|
-
klazz_object = @klazz.new
|
164
|
-
|
165
|
-
klazz_object.taxons.size.should == 0
|
166
|
-
|
167
|
-
# NEW ASSOCIATION ASSIGNMENT
|
168
|
-
|
169
|
-
# assign via the send operator directly on load object
|
170
|
-
klazz_object.send( method_detail.operator ) << Taxon.new
|
171
|
-
|
172
|
-
klazz_object.taxons.size.should == 1
|
173
|
-
|
174
|
-
klazz_object.send( method_detail.operator ) << [Taxon.new, Taxon.new]
|
175
|
-
klazz_object.taxons.size.should == 3
|
176
|
-
|
177
|
-
# Use generic assignment on method detail - expect has_many to use << not =
|
178
|
-
method_detail.assign( klazz_object, Taxon.new )
|
179
|
-
klazz_object.taxons.size.should == 4
|
180
|
-
|
181
|
-
method_detail.assign( klazz_object, [Taxon.new, Taxon.new])
|
182
|
-
klazz_object.taxons.size.should == 6
|
183
|
-
end
|
184
|
-
|
185
|
-
it "should enable assignment to has_many association using existing objects" do
|
186
|
-
|
187
|
-
MethodDictionary.find_operators( @klazz )
|
188
|
-
|
189
|
-
method_detail = MethodMapper.find_method_detail( @klazz, 'product_properties' )
|
190
|
-
|
191
|
-
method_detail.operator.should == 'product_properties'
|
192
|
-
|
193
|
-
klazz_object = @klazz.new
|
194
|
-
|
195
|
-
ProductProperty.new(:property => @prop1)
|
196
|
-
|
197
|
-
# NEW ASSOCIATION ASSIGNMENT
|
198
|
-
klazz_object.send( method_detail.operator ) << ProductProperty.new
|
199
|
-
|
200
|
-
klazz_object.product_properties.size.should == 1
|
201
|
-
|
202
|
-
klazz_object.send( method_detail.operator ) << [ProductProperty.new, ProductProperty.new]
|
203
|
-
klazz_object.product_properties.size.should == 3
|
204
|
-
|
205
|
-
# Use generic assignment on method detail - expect has_many to use << not =
|
206
|
-
method_detail.assign( klazz_object, ProductProperty.new(:property => @prop1) )
|
207
|
-
klazz_object.product_properties.size.should == 4
|
208
|
-
|
209
|
-
method_detail.assign( klazz_object, [ProductProperty.new(:property => @prop2), ProductProperty.new(:property => @prop3)])
|
210
|
-
klazz_object.product_properties.size.should == 6
|
211
|
-
|
212
|
-
end
|
213
|
-
|
214
|
-
|
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 aspect of datashift gem.
|
8
|
+
#
|
9
|
+
# Tests the method mapping aspect, such as that we correctly identify
|
10
|
+
# Spree Product attributes and associations
|
11
|
+
#
|
12
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
13
|
+
|
14
|
+
require 'spree_helper'
|
15
|
+
require 'product_loader'
|
16
|
+
|
17
|
+
include DataShift
|
18
|
+
|
19
|
+
describe 'SpreeLoader' do
|
20
|
+
|
21
|
+
before(:all) do
|
22
|
+
|
23
|
+
# we are not a Spree project, nor is it practical to externally generate
|
24
|
+
# a complete Spree application for testing so we implement a mini migrate/boot of our own
|
25
|
+
Spree.load() # require Spree gems
|
26
|
+
|
27
|
+
# key to YAML db e.g test_memory, test_mysql
|
28
|
+
db_connect( 'test_spree_standalone' )
|
29
|
+
|
30
|
+
Spree.boot # create a sort-of Spree app
|
31
|
+
|
32
|
+
Spree.migrate_up # create an sqlite Spree database on the fly
|
33
|
+
|
34
|
+
@klazz = Product
|
35
|
+
|
36
|
+
# Reset main tables - TODO should really purge properly, or roll back a transaction
|
37
|
+
[OptionType, OptionValue, Product, Property, Variant, Taxonomy, Taxon, Zone].each { |x| x.delete_all }
|
38
|
+
end
|
39
|
+
|
40
|
+
before(:each) do
|
41
|
+
MethodMapper.clear
|
42
|
+
MethodDictionary.find_operators( @klazz )
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
it "should populate operators for a Spree Product" do
|
47
|
+
|
48
|
+
MethodMapper.has_many.should_not be_empty
|
49
|
+
MethodMapper.belongs_to.should_not be_empty
|
50
|
+
MethodMapper.assignments.should_not be_empty
|
51
|
+
|
52
|
+
assign = MethodMapper.assignments_for(@klazz)
|
53
|
+
|
54
|
+
assign.should include('available_on') # Example of a simple column
|
55
|
+
|
56
|
+
MethodMapper.assignments[@klazz].should include('available_on')
|
57
|
+
|
58
|
+
has_many_ops = MethodMapper.has_many_for(@klazz)
|
59
|
+
|
60
|
+
has_many_ops.should include('properties') # Product can have many properties
|
61
|
+
|
62
|
+
MethodMapper.has_many[@klazz].should include('properties')
|
63
|
+
|
64
|
+
btf = MethodMapper.belongs_to_for(@klazz)
|
65
|
+
|
66
|
+
btf.should include('tax_category') # Example of a belongs_to assignment
|
67
|
+
|
68
|
+
MethodMapper.belongs_to[@klazz].should include('tax_category')
|
69
|
+
|
70
|
+
MethodMapper.column_types[@klazz].size.should == @klazz.columns.size
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
it "should find method details correctly for different forms of a column name" do
|
75
|
+
|
76
|
+
["available On", 'available_on', "Available On", "AVAILABLE_ON"].each do |format|
|
77
|
+
|
78
|
+
method_details = MethodMapper.find_method_detail( @klazz, format )
|
79
|
+
|
80
|
+
method_details.operator.should == 'available_on'
|
81
|
+
method_details.operator_for(:assignment).should == 'available_on'
|
82
|
+
|
83
|
+
method_details.operator_for(:belongs_to).should be_nil
|
84
|
+
method_details.operator_for(:has_many).should be_nil
|
85
|
+
|
86
|
+
method_details.col_type.should_not be_nil
|
87
|
+
method_details.col_type.name.should == 'available_on'
|
88
|
+
method_details.col_type.default.should == nil
|
89
|
+
method_details.col_type.sql_type.should include 'datetime' # works on mysql and sqlite
|
90
|
+
method_details.col_type.type.should == :datetime
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should populate method details correctly for has_many forms of association name" do
|
95
|
+
|
96
|
+
MethodMapper.has_many[@klazz].should include('product_option_types')
|
97
|
+
|
98
|
+
["product_option_types", "product option types", 'product Option_types', "ProductOptionTypes", "Product_Option_Types"].each do |format|
|
99
|
+
method_detail = MethodMapper.find_method_detail( @klazz, format )
|
100
|
+
|
101
|
+
method_detail.should_not be_nil
|
102
|
+
|
103
|
+
method_detail.operator_for(:has_many).should eq('product_option_types')
|
104
|
+
method_detail.operator_for(:belongs_to).should be_nil
|
105
|
+
method_detail.operator_for(:assignment).should be_nil
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
it "should populate method details correctly for assignment operators (none columns on #{@klazz})" do
|
111
|
+
|
112
|
+
MethodDictionary.find_operators( @klazz, :reload => true, :instance_methods => true )
|
113
|
+
|
114
|
+
# Example of delegates i.e. cost_price column on Variant, delegated to Variant by Product
|
115
|
+
|
116
|
+
MethodMapper.assignments[@klazz].should include('cost_price')
|
117
|
+
MethodMapper.assignments[@klazz].should include('sku')
|
118
|
+
|
119
|
+
|
120
|
+
count_on_hand = MethodMapper.find_method_detail( @klazz, 'count on hand' )
|
121
|
+
count_on_hand.should_not be_nil
|
122
|
+
count_on_hand.operator.should == 'count_on_hand'
|
123
|
+
|
124
|
+
method = MethodMapper.find_method_detail( @klazz, 'sku' )
|
125
|
+
method.should_not be_nil
|
126
|
+
method.operator.should == 'sku'
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should enable assignment via operators for none columns on #{@klazz}" do
|
130
|
+
|
131
|
+
MethodDictionary.find_operators( @klazz, :reload => true, :instance_methods => true )
|
132
|
+
|
133
|
+
klazz_object = @klazz.new
|
134
|
+
|
135
|
+
klazz_object.should be_new_record
|
136
|
+
|
137
|
+
# we can use method details to populate a new AR object, essentailly same as
|
138
|
+
# klazz_object.send( count_on_hand.operator, 2)
|
139
|
+
count_on_hand = MethodMapper.find_method_detail( @klazz, 'count on hand' )
|
140
|
+
|
141
|
+
count_on_hand.assign( klazz_object, 2 )
|
142
|
+
klazz_object.count_on_hand.should == 2
|
143
|
+
|
144
|
+
count_on_hand.assign( klazz_object, 5 )
|
145
|
+
klazz_object.count_on_hand.should == 5
|
146
|
+
|
147
|
+
method = MethodMapper.find_method_detail( @klazz, 'sku' )
|
148
|
+
method.should_not be_nil
|
149
|
+
|
150
|
+
method.operator.should == 'sku'
|
151
|
+
|
152
|
+
method.assign( klazz_object, 'TEST_SK 001')
|
153
|
+
klazz_object.sku.should == 'TEST_SK 001'
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should enable assignment to has_many association on new object" do
|
158
|
+
|
159
|
+
method_detail = MethodMapper.find_method_detail( @klazz, 'taxons' )
|
160
|
+
|
161
|
+
method_detail.operator.should == 'taxons'
|
162
|
+
|
163
|
+
klazz_object = @klazz.new
|
164
|
+
|
165
|
+
klazz_object.taxons.size.should == 0
|
166
|
+
|
167
|
+
# NEW ASSOCIATION ASSIGNMENT
|
168
|
+
|
169
|
+
# assign via the send operator directly on load object
|
170
|
+
klazz_object.send( method_detail.operator ) << Taxon.new
|
171
|
+
|
172
|
+
klazz_object.taxons.size.should == 1
|
173
|
+
|
174
|
+
klazz_object.send( method_detail.operator ) << [Taxon.new, Taxon.new]
|
175
|
+
klazz_object.taxons.size.should == 3
|
176
|
+
|
177
|
+
# Use generic assignment on method detail - expect has_many to use << not =
|
178
|
+
method_detail.assign( klazz_object, Taxon.new )
|
179
|
+
klazz_object.taxons.size.should == 4
|
180
|
+
|
181
|
+
method_detail.assign( klazz_object, [Taxon.new, Taxon.new])
|
182
|
+
klazz_object.taxons.size.should == 6
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should enable assignment to has_many association using existing objects" do
|
186
|
+
|
187
|
+
MethodDictionary.find_operators( @klazz )
|
188
|
+
|
189
|
+
method_detail = MethodMapper.find_method_detail( @klazz, 'product_properties' )
|
190
|
+
|
191
|
+
method_detail.operator.should == 'product_properties'
|
192
|
+
|
193
|
+
klazz_object = @klazz.new
|
194
|
+
|
195
|
+
ProductProperty.new(:property => @prop1)
|
196
|
+
|
197
|
+
# NEW ASSOCIATION ASSIGNMENT
|
198
|
+
klazz_object.send( method_detail.operator ) << ProductProperty.new
|
199
|
+
|
200
|
+
klazz_object.product_properties.size.should == 1
|
201
|
+
|
202
|
+
klazz_object.send( method_detail.operator ) << [ProductProperty.new, ProductProperty.new]
|
203
|
+
klazz_object.product_properties.size.should == 3
|
204
|
+
|
205
|
+
# Use generic assignment on method detail - expect has_many to use << not =
|
206
|
+
method_detail.assign( klazz_object, ProductProperty.new(:property => @prop1) )
|
207
|
+
klazz_object.product_properties.size.should == 4
|
208
|
+
|
209
|
+
method_detail.assign( klazz_object, [ProductProperty.new(:property => @prop2), ProductProperty.new(:property => @prop3)])
|
210
|
+
klazz_object.product_properties.size.should == 6
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
|
215
215
|
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
p = Product.seed( :name ) do |s|
|
2
|
-
s.name = <%= @name %>
|
3
|
-
s.available_on = '2009-09-01 09:00:00.0'
|
4
|
-
s.meta_keywords = ['training', 'training']
|
5
|
-
s.meta_description = ""
|
6
|
-
s.description = '<%= @description %>'
|
7
|
-
s.price = 0.00
|
8
|
-
s.sku = '<%= @sku %>'
|
9
|
-
|
10
|
-
s.is_physical = false
|
11
|
-
s.is_private = false
|
12
|
-
|
13
|
-
s.append_association :taxons, Taxon.find_by_name( 'Training' )
|
14
|
-
|
15
|
-
end
|
1
|
+
p = Product.seed( :name ) do |s|
|
2
|
+
s.name = <%= @name %>
|
3
|
+
s.available_on = '2009-09-01 09:00:00.0'
|
4
|
+
s.meta_keywords = ['training', 'training']
|
5
|
+
s.meta_description = ""
|
6
|
+
s.description = '<%= @description %>'
|
7
|
+
s.price = 0.00
|
8
|
+
s.sku = '<%= @sku %>'
|
9
|
+
|
10
|
+
s.is_physical = false
|
11
|
+
s.is_private = false
|
12
|
+
|
13
|
+
s.append_association :taxons, Taxon.find_by_name( 'Training' )
|
14
|
+
|
15
|
+
end
|