bbmb 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. data/History.txt +5 -0
  2. data/LICENSE.txt +339 -0
  3. data/Manifest.txt +91 -0
  4. data/README.txt +25 -0
  5. data/Rakefile +28 -0
  6. data/bin/admin +71 -0
  7. data/bin/bbmbd +61 -0
  8. data/lib/bbmb.rb +9 -0
  9. data/lib/bbmb/config.rb +106 -0
  10. data/lib/bbmb/html/state/change_password.rb +50 -0
  11. data/lib/bbmb/html/state/current_order.rb +81 -0
  12. data/lib/bbmb/html/state/customer.rb +109 -0
  13. data/lib/bbmb/html/state/customers.rb +52 -0
  14. data/lib/bbmb/html/state/favorites.rb +19 -0
  15. data/lib/bbmb/html/state/favorites_result.rb +21 -0
  16. data/lib/bbmb/html/state/global.rb +62 -0
  17. data/lib/bbmb/html/state/history.rb +95 -0
  18. data/lib/bbmb/html/state/info.rb +23 -0
  19. data/lib/bbmb/html/state/json.rb +16 -0
  20. data/lib/bbmb/html/state/login.rb +76 -0
  21. data/lib/bbmb/html/state/order.rb +21 -0
  22. data/lib/bbmb/html/state/orders.rb +19 -0
  23. data/lib/bbmb/html/state/result.rb +64 -0
  24. data/lib/bbmb/html/state/show_pass.rb +16 -0
  25. data/lib/bbmb/html/state/viral/admin.rb +41 -0
  26. data/lib/bbmb/html/state/viral/customer.rb +143 -0
  27. data/lib/bbmb/html/util/known_user.rb +51 -0
  28. data/lib/bbmb/html/util/multilingual.rb +18 -0
  29. data/lib/bbmb/html/util/session.rb +52 -0
  30. data/lib/bbmb/html/util/validator.rb +55 -0
  31. data/lib/bbmb/html/view/backorder.rb +24 -0
  32. data/lib/bbmb/html/view/change_password.rb +42 -0
  33. data/lib/bbmb/html/view/copyleft.rb +41 -0
  34. data/lib/bbmb/html/view/current_order.rb +482 -0
  35. data/lib/bbmb/html/view/customer.rb +152 -0
  36. data/lib/bbmb/html/view/customers.rb +145 -0
  37. data/lib/bbmb/html/view/favorites.rb +162 -0
  38. data/lib/bbmb/html/view/favorites_result.rb +26 -0
  39. data/lib/bbmb/html/view/foot.rb +21 -0
  40. data/lib/bbmb/html/view/head.rb +32 -0
  41. data/lib/bbmb/html/view/history.rb +60 -0
  42. data/lib/bbmb/html/view/info.rb +33 -0
  43. data/lib/bbmb/html/view/json.rb +20 -0
  44. data/lib/bbmb/html/view/list_prices.rb +51 -0
  45. data/lib/bbmb/html/view/login.rb +46 -0
  46. data/lib/bbmb/html/view/multilingual.rb +17 -0
  47. data/lib/bbmb/html/view/navigation.rb +30 -0
  48. data/lib/bbmb/html/view/order.rb +123 -0
  49. data/lib/bbmb/html/view/orders.rb +50 -0
  50. data/lib/bbmb/html/view/result.rb +107 -0
  51. data/lib/bbmb/html/view/search.rb +28 -0
  52. data/lib/bbmb/html/view/show_pass.rb +60 -0
  53. data/lib/bbmb/html/view/template.rb +61 -0
  54. data/lib/bbmb/model/customer.rb +96 -0
  55. data/lib/bbmb/model/order.rb +255 -0
  56. data/lib/bbmb/model/product.rb +99 -0
  57. data/lib/bbmb/model/promotion.rb +52 -0
  58. data/lib/bbmb/model/quota.rb +27 -0
  59. data/lib/bbmb/model/subject.rb +46 -0
  60. data/lib/bbmb/persistence/none.rb +6 -0
  61. data/lib/bbmb/persistence/odba.rb +42 -0
  62. data/lib/bbmb/persistence/odba/model/customer.rb +47 -0
  63. data/lib/bbmb/persistence/odba/model/order.rb +50 -0
  64. data/lib/bbmb/persistence/odba/model/product.rb +26 -0
  65. data/lib/bbmb/persistence/odba/model/quota.rb +12 -0
  66. data/lib/bbmb/util/invoicer.rb +126 -0
  67. data/lib/bbmb/util/mail.rb +140 -0
  68. data/lib/bbmb/util/multilingual.rb +57 -0
  69. data/lib/bbmb/util/numbers.rb +67 -0
  70. data/lib/bbmb/util/password_generator.rb +44 -0
  71. data/lib/bbmb/util/polling_manager.rb +135 -0
  72. data/lib/bbmb/util/server.rb +159 -0
  73. data/lib/bbmb/util/target_dir.rb +36 -0
  74. data/lib/bbmb/util/transfer_dat.rb +34 -0
  75. data/lib/bbmb/util/updater.rb +27 -0
  76. data/test/data/ydim.yml +2 -0
  77. data/test/model/test_customer.rb +75 -0
  78. data/test/model/test_order.rb +426 -0
  79. data/test/model/test_product.rb +238 -0
  80. data/test/model/test_promotion.rb +40 -0
  81. data/test/stub/persistence.rb +57 -0
  82. data/test/suite.rb +12 -0
  83. data/test/test_bbmb.rb +18 -0
  84. data/test/util/test_invoicer.rb +189 -0
  85. data/test/util/test_mail.rb +359 -0
  86. data/test/util/test_money.rb +71 -0
  87. data/test/util/test_password_generator.rb +27 -0
  88. data/test/util/test_polling_manager.rb +312 -0
  89. data/test/util/test_server.rb +189 -0
  90. data/test/util/test_target_dir.rb +82 -0
  91. data/test/util/test_transfer_dat.rb +45 -0
  92. metadata +190 -0
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+ # Util::TargetDir -- bbmb -- 17.04.2007 -- hwyss@ywesee.com
3
+
4
+ require 'bbmb/config'
5
+ require 'net/ftp'
6
+ require 'tempfile'
7
+ require 'uri'
8
+
9
+ module BBMB
10
+ module Util
11
+ module TargetDir
12
+ def TargetDir.send_order(order)
13
+ content = order.to_target_format
14
+ basename = BBMB.config.tmpfile_basename
15
+ BBMB.config.order_destinations.each { |destination|
16
+ uri = URI.parse(File.join(destination, order.filename))
17
+ case uri.scheme
18
+ when "ftp"
19
+ Tempfile.open(basename) { |tmp|
20
+ tmp.puts(content)
21
+ tmp.flush
22
+ Net::FTP.open(uri.host, uri.user, uri.password) { |ftp|
23
+ ftp.put(tmp.path, uri.path)
24
+ }
25
+ }
26
+ else
27
+ path = File.expand_path(uri.path, BBMB.config.bbmb_dir)
28
+ File.open(path, 'w') { |fh|
29
+ fh.puts content
30
+ }
31
+ end
32
+ }
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+ # TransferDat -- bbmb -- 31.10.2002 -- hwyss@ywesee.com
3
+
4
+ require 'bbmb/model/order'
5
+
6
+ module BBMB
7
+ module Util
8
+ module TransferDat
9
+ def TransferDat.parse(io)
10
+ io.rewind
11
+ data = io.read
12
+ data.split(/[\r\n]+/).collect { |line|
13
+ if(parsed = parse_line(line))
14
+ yield parsed
15
+ end
16
+ }
17
+ end
18
+ def TransferDat.parse_line(line)
19
+ begin
20
+ result = Model::Order::Info.new
21
+ result.pcode = u(line[13,7].to_i.to_s)
22
+ result.description = u(line[20,50].strip)
23
+ result.ean13 = u(line[74,13])
24
+ result.quantity = line[70,4].to_i
25
+ result
26
+ rescue Exception => e
27
+ BBMB.logger.error('transfer') {
28
+ [e.class, e.message, e.backtrace].pretty_inspect
29
+ }
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # Util::Updater -- bbmb.ch -- 14.09.2006 -- hwyss@ywesee.com
3
+
4
+ require 'bbmb'
5
+ require 'bbmb/util/polling_manager'
6
+
7
+ module BBMB
8
+ module Util
9
+ module Updater
10
+ def Updater.run
11
+ require 'pp'
12
+ PollingManager.new.poll_sources { |filename, io|
13
+ importer, *args = BBMB.config.importers[filename]
14
+ if(importer)
15
+ import(importer, args, io)
16
+ end
17
+ }
18
+ end
19
+ def Updater.import(importer, args, io)
20
+ klass = Util.const_get(importer)
21
+ count = klass.new(*args).import(io)
22
+ BBMB.logger.debug('updater') {
23
+ sprintf("%s imported %i entities", importer, count) }
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,2 @@
1
+ ---
2
+ server_url: druby://localhost:10082
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+ # Model::TestCustomer -- bbmb.ch -- 22.09.2006 -- hwyss@ywesee.com
3
+
4
+ $: << File.expand_path('..', File.dirname(__FILE__))
5
+ $: << File.expand_path('../../lib', File.dirname(__FILE__))
6
+
7
+ require 'test/unit'
8
+ require 'bbmb'
9
+ require 'bbmb/model/customer'
10
+ require 'bbmb/model/order'
11
+ require 'stub/persistence'
12
+ require 'flexmock'
13
+
14
+ module BBMB
15
+ module Model
16
+ class TestCustomer < Test::Unit::TestCase
17
+ include FlexMock::TestCase
18
+ def setup
19
+ Customer.clear_instances
20
+ @customer = Customer.new('007')
21
+ end
22
+ def test_email_writer
23
+ BBMB.server = flexmock('server')
24
+ @customer.instance_variable_set('@email', 'old@bbmb.ch')
25
+ BBMB.server.should_receive(:rename_user).and_return { |old, new|
26
+ assert_equal('old@bbmb.ch', old)
27
+ assert_equal('test@bbmb.ch', new)
28
+ }
29
+ @customer.email = 'test@bbmb.ch'
30
+ assert_equal('test@bbmb.ch', @customer.email)
31
+ end
32
+ def test_email_writer__nil
33
+ BBMB.server = flexmock('server')
34
+ @customer.instance_variable_set('@email', 'old@bbmb.ch')
35
+ assert_raises(RuntimeError) {
36
+ @customer.email = nil
37
+ }
38
+ assert_equal('old@bbmb.ch', @customer.email)
39
+ end
40
+ def test_email_writer__both_nil
41
+ BBMB.server = flexmock('server')
42
+ assert_nothing_raised {
43
+ @customer.email = nil
44
+ }
45
+ assert_equal(nil, @customer.email)
46
+ end
47
+ def test_protect
48
+ assert_equal false, @customer.protects?(:email)
49
+ @customer.protect!(:email)
50
+ assert_equal true, @customer.protects?(:email)
51
+ end
52
+ def test_current_order
53
+ assert_instance_of(Model::Order, @customer.current_order)
54
+ end
55
+ def test_commit_order
56
+ assert_equal(true, @customer.current_order.empty?)
57
+ end
58
+ def test_inject_order__empty
59
+ assert_raises(RuntimeError) {
60
+ @customer.inject_order(Model::Order.new(@customer))
61
+ }
62
+ assert_equal({}, @customer.archive)
63
+ end
64
+ def test_inject_order
65
+ order = flexmock(Model::Order.new(@customer))
66
+ time = Time.now
67
+ order.should_receive(:commit!).with(1, time).times(1)
68
+ assert_nothing_raised {
69
+ @customer.inject_order(order, time)
70
+ }
71
+ assert_equal({1 => order}, @customer.archive)
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,426 @@
1
+ #!/usr/bin/env ruby
2
+ # Model::TestOrder -- bbmb.ch -- 22.09.2006 -- hwyss@ywesee.com
3
+
4
+ $: << File.expand_path('../../lib', File.dirname(__FILE__))
5
+
6
+ require 'bbmb/model/order'
7
+ require 'date'
8
+ require 'flexmock'
9
+ require 'test/unit'
10
+
11
+ module BBMB
12
+ module Model
13
+ class TestOrder < Test::Unit::TestCase
14
+ include FlexMock::TestCase
15
+ def setup
16
+ @customer = flexmock("customer")
17
+ @customer.should_receive(:quota)
18
+ @order = Order.new(@customer)
19
+ end
20
+ def test_add
21
+ assert_equal(true, @order.empty?)
22
+ product = flexmock('product')
23
+ product.should_receive(:article_number).and_return('12345')
24
+ product.should_receive(:price_effective)
25
+ pos = @order.add(3, product)
26
+ assert_equal(false, @order.empty?)
27
+ assert_equal(1, @order.positions.size)
28
+ position = @order.positions.first
29
+ assert_equal(pos, position)
30
+ assert_instance_of(Order::Position, position)
31
+ assert_equal(product, position.product)
32
+ assert_equal(3, position.quantity)
33
+ end
34
+ def test_add__0
35
+ assert_equal(true, @order.empty?)
36
+ product = flexmock('product')
37
+ product.should_receive(:article_number).and_return('12345')
38
+ pos = @order.add(0, product)
39
+ assert_equal(true, @order.empty?)
40
+ end
41
+ def test_add__0__remove
42
+ assert_equal(true, @order.empty?)
43
+ product = flexmock('product')
44
+ product.should_receive(:article_number).and_return('12345')
45
+ product.should_receive(:price_effective)
46
+ pos = @order.add(3, product)
47
+ assert_equal(false, @order.empty?)
48
+ assert_equal(1, @order.positions.size)
49
+ pos = @order.add(0, product)
50
+ assert_equal([], @order.positions)
51
+ end
52
+ def test_additional_info
53
+ assert_equal({}, @order.additional_info)
54
+ @order.comment = 'Comment'
55
+ assert_equal({:comment => 'Comment'}, @order.additional_info)
56
+ @order.reference = '12345'
57
+ assert_equal({:comment => 'Comment', :reference => '12345'},
58
+ @order.additional_info)
59
+ @order.comment = nil
60
+ assert_equal({:reference => '12345'}, @order.additional_info)
61
+ end
62
+ def test_clear
63
+ position = flexmock('position')
64
+ @order.positions.push(position)
65
+ @order.clear
66
+ assert_equal([], @order.positions)
67
+ end
68
+ def test_commit
69
+ assert_equal(nil, @order.commit_time)
70
+ assert_raises(RuntimeError) { @order.commit!('commit_id', Time.now) }
71
+ assert_equal(nil, @order.commit_time)
72
+ position = flexmock('position')
73
+ @order.positions.push(position)
74
+ position.should_receive(:article_number).and_return('12345')
75
+ position.should_receive(:quota)
76
+ position.should_receive(:price_effective).and_return(12)
77
+ position.should_receive(:price_effective=).with(12)
78
+ position.should_receive(:commit!).times(1)
79
+ time = Time.now
80
+ @order.commit!('commit_id', time)
81
+ assert_equal(time, @order.commit_time)
82
+ assert_equal('commit_id', @order.commit_id)
83
+ end
84
+ def test_empty
85
+ assert_equal(true, @order.empty?)
86
+ position = flexmock('position')
87
+ @order.positions.push(position)
88
+ assert_equal(false, @order.empty?)
89
+ end
90
+ def test_enumerable
91
+ assert @order.is_a?(Enumerable)
92
+ assert @order.respond_to?(:empty?)
93
+ assert @order.respond_to?(:each)
94
+ end
95
+ def test_position
96
+ product = flexmock('product')
97
+ assert_nil(@order.position(product))
98
+ position = flexmock('position')
99
+ position.should_receive(:product).and_return(product)
100
+ @order.positions.push(position)
101
+ pos = @order.position(product)
102
+ assert_equal(position, pos)
103
+ end
104
+ def test_quantity
105
+ product = flexmock('product')
106
+ assert_equal(0, @order.quantity(product))
107
+ product.should_receive(:article_number).and_return('12345')
108
+ product.should_receive(:price_effective)
109
+ @order.add(17, product)
110
+ assert_equal(17, @order.quantity(product))
111
+ end
112
+ def test_size
113
+ assert_equal(0, @order.size)
114
+ position = flexmock('position')
115
+ @order.positions.push(position)
116
+ assert_equal(1, @order.size)
117
+ end
118
+ def test_total
119
+ pos1 = flexmock('position')
120
+ pos2 = flexmock('position')
121
+ @order.positions.push(pos1, pos2)
122
+ pos1.should_receive(:total).and_return(Util::Money.new(12.80))
123
+ pos2.should_receive(:total).and_return(Util::Money.new(17.20))
124
+ assert_equal(30, @order.total)
125
+ @order.shipping = 10
126
+ assert_equal(40, @order.total)
127
+ end
128
+ def test_to_i2
129
+ @customer.should_receive(:customer_id).and_return(7)
130
+ @customer.should_receive(:organisation).and_return('Organisation')
131
+ position = flexmock('position')
132
+ position.should_receive(:ean13).and_return("EAN13")
133
+ position.should_receive(:article_number).and_return("ArticleNumber")
134
+ position.should_receive(:quantity).and_return(17)
135
+ position.should_ignore_missing
136
+ @order.positions.push(position)
137
+ @order.reference = "Reference"
138
+ @order.comment = "Comment"
139
+ @order.commit!('8', Time.local(2006,9,27,9,50,12))
140
+ @order.priority = 41
141
+ expected = <<-EOS
142
+ 001:7601001000681
143
+ 002:ORDERX
144
+ 003:220
145
+ 010:7-8-20060927095012.txt
146
+ 100:YWESEE
147
+ 101:Reference
148
+ 201:CU
149
+ 202:7
150
+ 201:BY
151
+ 202:1075
152
+ 231:Organisation
153
+ 236:Comment
154
+ 237:61
155
+ 238:41
156
+ 250:ADE
157
+ 251:700008
158
+ 300:4
159
+ 301:20060927
160
+ 500:1
161
+ 501:EAN13
162
+ 502:ArticleNumber
163
+ 520:17
164
+ 521:PCE
165
+ 540:2
166
+ 541:20060927
167
+ EOS
168
+ assert_equal(expected, @order.to_i2)
169
+ end
170
+ def test_to_i2__no_comment
171
+ @customer.should_receive(:customer_id).and_return(7)
172
+ @customer.should_receive(:organisation).and_return('Organisation')
173
+ position = flexmock('position')
174
+ position.should_receive(:ean13).and_return("EAN13")
175
+ position.should_receive(:article_number).and_return("ArticleNumber")
176
+ position.should_receive(:quantity).and_return(17)
177
+ position.should_ignore_missing
178
+ @order.positions.push(position)
179
+ @order.reference = "Reference"
180
+ @order.commit!('8', Time.local(2006,9,27,9,50,12))
181
+ @order.priority = 41
182
+ expected = <<-EOS
183
+ 001:7601001000681
184
+ 002:ORDERX
185
+ 003:220
186
+ 010:7-8-20060927095012.txt
187
+ 100:YWESEE
188
+ 101:Reference
189
+ 201:CU
190
+ 202:7
191
+ 201:BY
192
+ 202:1075
193
+ 231:Organisation
194
+ 237:61
195
+ 238:41
196
+ 250:ADE
197
+ 251:700008
198
+ 300:4
199
+ 301:20060927
200
+ 500:1
201
+ 501:EAN13
202
+ 502:ArticleNumber
203
+ 520:17
204
+ 521:PCE
205
+ 540:2
206
+ 541:20060927
207
+ EOS
208
+ assert_equal(expected, @order.to_i2)
209
+ end
210
+ def test_to_i2__configurable_origin
211
+ @customer.should_receive(:customer_id).and_return(7)
212
+ @customer.should_receive(:organisation).and_return('Organisation')
213
+ position = flexmock('position')
214
+ position.should_receive(:ean13).and_return("EAN13")
215
+ position.should_receive(:article_number).and_return("ArticleNumber")
216
+ position.should_receive(:quantity).and_return(17)
217
+ position.should_ignore_missing
218
+ @order.positions.push(position)
219
+ @order.reference = "Reference"
220
+ @order.comment = "Comment"
221
+ @order.commit!('8', Time.local(2006,9,27,9,50,12))
222
+ @order.priority = 41
223
+ BBMB.config.i2_100 = 'YWESEE_VES'
224
+ expected = <<-EOS
225
+ 001:7601001000681
226
+ 002:ORDERX
227
+ 003:220
228
+ 010:7-8-20060927095012.txt
229
+ 100:YWESEE_VES
230
+ 101:Reference
231
+ 201:CU
232
+ 202:7
233
+ 201:BY
234
+ 202:1075
235
+ 231:Organisation
236
+ 236:Comment
237
+ 237:61
238
+ 238:41
239
+ 250:ADE
240
+ 251:700008
241
+ 300:4
242
+ 301:20060927
243
+ 500:1
244
+ 501:EAN13
245
+ 502:ArticleNumber
246
+ 520:17
247
+ 521:PCE
248
+ 540:2
249
+ 541:20060927
250
+ EOS
251
+ assert_equal(expected, @order.to_i2)
252
+ end
253
+ def test_to_i2__freebies
254
+ @customer.should_receive(:customer_id).and_return(7)
255
+ @customer.should_receive(:organisation).and_return('Organisation')
256
+ position = flexmock('position')
257
+ position.should_receive(:ean13).and_return("EAN13")
258
+ position.should_receive(:article_number).and_return("ArticleNumber")
259
+ position.should_receive(:quantity).and_return(17)
260
+ position.should_receive(:freebies).and_return(3)
261
+ position.should_ignore_missing
262
+ @order.positions.push(position, position)
263
+ @order.reference = "Reference"
264
+ @order.comment = "Comment"
265
+ @order.commit!('8', Time.local(2006,9,27,9,50,12))
266
+ @order.priority = 41
267
+ BBMB.config.i2_100 = 'YWESEE'
268
+ expected = <<-EOS
269
+ 001:7601001000681
270
+ 002:ORDERX
271
+ 003:220
272
+ 010:7-8-20060927095012.txt
273
+ 100:YWESEE
274
+ 101:Reference
275
+ 201:CU
276
+ 202:7
277
+ 201:BY
278
+ 202:1075
279
+ 231:Organisation
280
+ 236:Comment
281
+ 237:61
282
+ 238:41
283
+ 250:ADE
284
+ 251:700008
285
+ 300:4
286
+ 301:20060927
287
+ 500:1
288
+ 501:EAN13
289
+ 502:ArticleNumber
290
+ 520:17
291
+ 521:PCE
292
+ 540:2
293
+ 541:20060927
294
+ 500:2
295
+ 501:EAN13
296
+ 502:ArticleNumber
297
+ 520:3
298
+ 521:PCE
299
+ 540:2
300
+ 541:20060927
301
+ 603:21
302
+ 500:3
303
+ 501:EAN13
304
+ 502:ArticleNumber
305
+ 520:17
306
+ 521:PCE
307
+ 540:2
308
+ 541:20060927
309
+ 500:4
310
+ 501:EAN13
311
+ 502:ArticleNumber
312
+ 520:3
313
+ 521:PCE
314
+ 540:2
315
+ 541:20060927
316
+ 603:21
317
+ EOS
318
+ assert_equal(expected, @order.to_i2)
319
+ end
320
+ def test_to_csv
321
+ @customer.should_receive(:customer_id).and_return(7)
322
+ @customer.should_receive(:ean13).and_return(1234567890123)
323
+ @customer.should_receive(:organisation).and_return('Organisation')
324
+ position = flexmock('position')
325
+ position.should_receive(:ean13).and_return("EAN13")
326
+ position.should_receive(:article_number).and_return("ArticleNumber")
327
+ position.should_receive(:quantity).and_return(17)
328
+ position.should_ignore_missing
329
+ @order.positions.push(position, position)
330
+ @order.reference = "Reference"
331
+ @order.comment = "Comment"
332
+ @order.commit!('8', Time.local(2006,9,27,9,50,12))
333
+ @order.priority = 41
334
+ expected = <<-EOS
335
+ 7,1234567890123,27092006,8,,EAN13,ArticleNumber,17,,Reference,Comment
336
+ 7,1234567890123,27092006,8,,EAN13,ArticleNumber,17,,Reference,Comment
337
+ EOS
338
+ assert_equal(expected, @order.to_csv)
339
+ end
340
+ def test_to_csv__no_comment
341
+ @customer.should_receive(:customer_id).and_return(7)
342
+ @customer.should_receive(:ean13).and_return(1234567890123)
343
+ @customer.should_receive(:organisation).and_return('Organisation')
344
+ position = flexmock('position')
345
+ position.should_receive(:ean13).and_return("EAN13")
346
+ position.should_receive(:article_number).and_return("ArticleNumber")
347
+ position.should_receive(:quantity).and_return(17)
348
+ position.should_ignore_missing
349
+ @order.positions.push(position, position)
350
+ @order.reference = "Reference"
351
+ @order.commit!('8', Time.local(2006,9,27,9,50,12))
352
+ @order.priority = 41
353
+ expected = <<-EOS
354
+ 7,1234567890123,27092006,8,,EAN13,ArticleNumber,17,,Reference,
355
+ 7,1234567890123,27092006,8,,EAN13,ArticleNumber,17,,Reference,
356
+ EOS
357
+ assert_equal(expected, @order.to_csv)
358
+ end
359
+ def test_to_target_format
360
+ @customer.should_receive(:customer_id).and_return(7)
361
+ @customer.should_receive(:ean13).and_return(1234567890123)
362
+ @customer.should_receive(:organisation).and_return('Organisation')
363
+ position = flexmock('position')
364
+ position.should_receive(:ean13).and_return("EAN13")
365
+ position.should_receive(:article_number).and_return("ArticleNumber")
366
+ position.should_receive(:quantity).and_return(17)
367
+ position.should_ignore_missing
368
+ @order.positions.push(position)
369
+ @order.reference = "Reference"
370
+ @order.comment = "Comment"
371
+ @order.commit!('8', Time.local(2006,9,27,9,50,12))
372
+ @order.priority = 41
373
+ expected = <<-EOS
374
+ 001:7601001000681
375
+ 002:ORDERX
376
+ 003:220
377
+ 010:7-8-20060927095012.txt
378
+ 100:YWESEE
379
+ 101:Reference
380
+ 201:CU
381
+ 202:7
382
+ 201:BY
383
+ 202:1075
384
+ 231:Organisation
385
+ 236:Comment
386
+ 237:61
387
+ 238:41
388
+ 250:ADE
389
+ 251:700008
390
+ 300:4
391
+ 301:20060927
392
+ 500:1
393
+ 501:EAN13
394
+ 502:ArticleNumber
395
+ 520:17
396
+ 521:PCE
397
+ 540:2
398
+ 541:20060927
399
+ EOS
400
+ assert_equal(expected, @order.to_target_format)
401
+ BBMB.config.target_format = 'csv'
402
+ expected = <<-EOS
403
+ 7,1234567890123,27092006,8,,EAN13,ArticleNumber,17,,Reference,Comment
404
+ EOS
405
+ assert_equal(expected, @order.to_target_format)
406
+ end
407
+ end
408
+ class TestOrderPosition < Test::Unit::TestCase
409
+ include FlexMock::TestCase
410
+ def setup
411
+ @product = flexmock('product')
412
+ @position = Order::Position.new(3, @product)
413
+ end
414
+ def test_commit
415
+ info = flexmock('info')
416
+ @product.should_receive(:to_info).and_return(info)
417
+ @position.commit!
418
+ assert_equal(info, @position.product)
419
+ end
420
+ def test_total
421
+ @product.should_receive(:price_effective).with(3).and_return(12)
422
+ assert_equal(36, @position.total)
423
+ end
424
+ end
425
+ end
426
+ end