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,238 @@
1
+ #!/usr/bin/env ruby
2
+ # Model::TestProduct -- bbmb.ch -- 14.09.2006 -- hwyss@ywesee.com
3
+
4
+ $: << File.expand_path('../../lib', File.dirname(__FILE__))
5
+
6
+ require 'test/unit'
7
+ require 'bbmb/model/product'
8
+ require 'bbmb/model/promotion'
9
+
10
+ module BBMB
11
+ module Model
12
+ class TestProduct < Test::Unit::TestCase
13
+ def setup
14
+ @product = Product.new("article_number")
15
+ end
16
+ def test_int_accessors
17
+ [:l1_qty, :l2_qty, :l3_qty, :l4_qty, :l5_qty, :l6_qty ].each { |key|
18
+ assert_nil(@product.send(key))
19
+ @product.send("#{key}=", "2")
20
+ int = @product.send(key)
21
+ assert_instance_of(Fixnum, int)
22
+ assert_equal(2, int)
23
+ @product.send("#{key}=", nil)
24
+ assert_nil(@product.send(key))
25
+ }
26
+ end
27
+ def test_money_accessors
28
+ [:price, :l1_price, :l2_price, :l3_price, :l4_price, :l5_price,
29
+ :l6_price, :vat ].each { |key|
30
+ assert_nil(@product.send(key))
31
+ @product.send("#{key}=", "1.23")
32
+ price = @product.send(key)
33
+ assert_instance_of(Util::Money, price)
34
+ assert_equal(1.23, price)
35
+ @product.send("#{key}=", nil)
36
+ assert_nil(@product.send(key))
37
+ }
38
+ end
39
+ def test_backorder_accessor
40
+ assert_equal(false, @product.backorder)
41
+ @product.backorder = "yes"
42
+ assert_equal(true, @product.backorder)
43
+ @product.backorder = "no"
44
+ assert_equal(false, @product.backorder)
45
+ @product.backorder = 1
46
+ assert_equal(true, @product.backorder)
47
+ @product.backorder = "1"
48
+ assert_equal(true, @product.backorder)
49
+ @product.backorder = nil
50
+ assert_equal(false, @product.backorder)
51
+ end
52
+ def test_equals
53
+ assert_not_equal(@product, 'article_number')
54
+ other = Product.new("article_number")
55
+ assert_equal(@product, other)
56
+ other = Product.new("foobar")
57
+ assert_not_equal(@product, other)
58
+ end
59
+ def test_price
60
+ assert_equal(nil, @product.price)
61
+ assert_equal(0, @product.price_effective)
62
+ assert_equal(nil, @product.price(1))
63
+ assert_equal(0, @product.price_effective(1))
64
+ @product.l1_price = 11.50
65
+ assert_equal(11.50, @product.price)
66
+ assert_equal(11.50, @product.price(1))
67
+ @product.price = 12.50
68
+ assert_equal(12.50, @product.price)
69
+ @product.l1_qty = 1
70
+ assert_equal(11.50, @product.price(1))
71
+ @product.l1_qty = 2
72
+ assert_equal(12.50, @product.price(1))
73
+ @product.l2_qty = 3
74
+ assert_equal(11.50, @product.price(3))
75
+ @product.l2_price = 13.50
76
+ assert_equal(13.50, @product.price(3))
77
+ @product.l3_qty = 4
78
+ @product.l3_price = 14.50
79
+ assert_equal(13.50, @product.price(3))
80
+ assert_equal(14.50, @product.price(4))
81
+ assert_equal(14.50, @product.price(5))
82
+ assert_equal(14.50, @product.price(6))
83
+ @product.l6_qty = 6
84
+ @product.l6_price = 16.50
85
+ assert_equal(16.50, @product.price(6))
86
+ end
87
+ def test_info
88
+ info = @product.to_info
89
+ assert_instance_of(ProductInfo, info)
90
+ assert_equal('article_number', info.article_number)
91
+ info1 = info.to_info
92
+ assert_equal(info, info1)
93
+ end
94
+ def test_price_levels__no_promo
95
+ @product.l1_qty = 1
96
+ @product.l1_price = 10
97
+ assert_equal(10, @product.price_qty(1))
98
+ assert_equal(10, @product.price_qty(6))
99
+ @product.l2_qty = 6
100
+ @product.l2_price = 8
101
+ assert_equal(10, @product.price_qty(1))
102
+ assert_equal(8, @product.price_qty(6))
103
+ assert_equal(8, @product.price_qty(12))
104
+ @product.l3_qty = 12
105
+ @product.l3_price = 6
106
+ assert_equal(10, @product.price_qty(1))
107
+ assert_equal(8, @product.price_qty(6))
108
+ assert_equal(6, @product.price_qty(12))
109
+ end
110
+ def test_price_levels__with_old_promo
111
+ @product.promotion = promo = Promotion.new
112
+ promo.start_date = Date.today - 2
113
+ promo.end_date = Date.today - 1
114
+ promo.l1_qty = 1
115
+ promo.l1_price = 8
116
+ promo.l2_qty = 12
117
+ promo.l2_price = 6
118
+ @product.l1_qty = 1
119
+ @product.l1_price = 10
120
+ assert_equal(10, @product.price_qty(1))
121
+ assert_equal(10, @product.price_qty(6))
122
+ @product.l2_qty = 6
123
+ @product.l2_price = 8
124
+ assert_equal(10, @product.price_qty(1))
125
+ assert_equal(8, @product.price_qty(6))
126
+ assert_equal(8, @product.price_qty(12))
127
+ @product.l3_qty = 12
128
+ @product.l3_price = 6
129
+ assert_equal(10, @product.price_qty(1))
130
+ assert_equal(8, @product.price_qty(6))
131
+ assert_equal(6, @product.price_qty(12))
132
+ end
133
+ def test_price_levels__with_current_promo
134
+ @product.promotion = promo = Promotion.new
135
+ promo.start_date = Date.today - 1
136
+ promo.end_date = Date.today + 1
137
+ promo.l1_qty = 1
138
+ promo.l1_price = 8
139
+ promo.l2_qty = 12
140
+ promo.l2_price = 5
141
+ @product.l1_qty = 1
142
+ @product.l1_price = 10
143
+ @product.l2_qty = 6
144
+ @product.l2_price = 8
145
+ @product.l3_qty = 12
146
+ @product.l3_price = 6
147
+ assert_equal(8, @product.price_qty(1))
148
+ assert_equal(8, @product.price_qty(6))
149
+ assert_equal(5, @product.price_qty(12))
150
+ end
151
+ def test_price_levels__with_promo_override
152
+ @product.promotion = promo = Promotion.new
153
+ promo.start_date = Date.today - 1
154
+ promo.end_date = Date.today + 1
155
+ promo.l1_qty = 6
156
+ promo.l1_price = 10
157
+ promo.l2_qty = 12
158
+ promo.l2_price = 5
159
+ @product.l1_qty = 1
160
+ @product.l1_price = 9
161
+ @product.l2_qty = 6
162
+ @product.l2_price = 8
163
+ @product.l3_qty = 12
164
+ @product.l3_price = 6
165
+ assert_equal(10, @product.price_qty(1))
166
+ assert_equal(10, @product.price_qty(6))
167
+ assert_equal(5, @product.price_qty(12))
168
+ end
169
+ def test_freebies__no_promo
170
+ assert_equal(nil, @product.freebies(1))
171
+ end
172
+ def test_freebies__with_old_promo
173
+ @product.promotion = promo = Promotion.new
174
+ promo.start_date = Date.today - 2
175
+ promo.end_date = Date.today - 1
176
+ promo.l1_qty = 6
177
+ promo.l1_price = 8
178
+ promo.l1_free = 1
179
+ promo.l2_qty = 12
180
+ promo.l2_price = 7
181
+ promo.l2_free = 3
182
+ assert_equal(nil, @product.freebies(5))
183
+ assert_equal(nil, @product.freebies(6))
184
+ end
185
+ def test_freebies__with_current_promo
186
+ @product.promotion = promo = Promotion.new
187
+ promo.start_date = Date.today - 1
188
+ promo.end_date = Date.today + 1
189
+ promo.l1_qty = 6
190
+ promo.l1_price = 8
191
+ promo.l1_free = 1
192
+ promo.l2_qty = 12
193
+ promo.l2_price = 7
194
+ promo.l2_free = 3
195
+ assert_equal(nil, @product.freebies(5))
196
+ assert_equal(1, @product.freebies(6))
197
+ assert_equal(1, @product.freebies(11))
198
+ assert_equal(3, @product.freebies(12))
199
+ end
200
+ def test_discount__use_normal_price_levels
201
+ @product.l1_qty = 1
202
+ @product.l1_price = 99.50
203
+ @product.l2_qty = 3
204
+ @product.l2_price = 94.50
205
+ @product.l3_qty = 6
206
+ @product.l3_price = 88.50
207
+ @product.sale = promo = Promotion.new
208
+ promo.start_date = Date.today - 1
209
+ promo.end_date = Date.today + 1
210
+ promo.l1_qty = 1
211
+ promo.l1_discount = 50
212
+ promo.l1_price = 0
213
+ promo.l1_free = 0
214
+ assert_equal(99.50, @product.price_qty(1))
215
+ assert_equal(99.50, @product.price_qty(2))
216
+ assert_equal(94.50, @product.price_qty(3))
217
+ assert_equal(94.50, @product.price_qty(5))
218
+ assert_equal(88.50, @product.price_qty(6))
219
+ assert_equal(49.75, @product.price_effective(1))
220
+ end
221
+ def test_qty_level__promo
222
+ @product.l1_qty = 1
223
+ @product.l2_qty = 10
224
+ @product.promotion = promo = Promotion.new
225
+ promo.start_date = Date.today - 1
226
+ promo.end_date = Date.today + 1
227
+ assert_equal(1, @product.qty_level(1))
228
+ assert_equal(10, @product.qty_level(2))
229
+ promo.l1_qty = 5
230
+ assert_equal(1, @product.qty_level(1))
231
+ assert_equal(10, @product.qty_level(2))
232
+ promo.l1_price = 2
233
+ assert_equal(5, @product.qty_level(1))
234
+ assert_equal(nil, @product.qty_level(2))
235
+ end
236
+ end
237
+ end
238
+ end
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+ # Model::TestPromotion -- bbmb -- 14.08.2007 -- hwyss@ywesee.com
3
+
4
+ $: << File.expand_path('../../lib', File.dirname(__FILE__))
5
+
6
+ require 'test/unit'
7
+ require 'bbmb/model/promotion'
8
+
9
+ module BBMB
10
+ module Model
11
+ class TestPromotion < Test::Unit::TestCase
12
+ def setup
13
+ @promo = Promotion.new
14
+ end
15
+ def test_current
16
+ assert_equal(false, @promo.current?)
17
+ @promo.start_date = Date.today + 1
18
+ assert_equal(false, @promo.current?)
19
+ @promo.start_date = Date.today
20
+ assert_equal(true, @promo.current?)
21
+ @promo.end_date = Date.today
22
+ assert_equal(true, @promo.current?)
23
+ @promo.start_date = nil
24
+ assert_equal(true, @promo.current?)
25
+ @promo.end_date = Date.today - 1
26
+ assert_equal(false, @promo.current?)
27
+ end
28
+ def test_price_qty
29
+ assert_equal(nil, @promo.price_qty(1))
30
+ @promo.l1_qty = 6
31
+ @promo.l1_price = 10
32
+ assert_equal(nil, @promo.price_qty(5))
33
+ assert_equal(10, @promo.price_qty(6))
34
+ @promo.l1_discount = 10
35
+ assert_equal(nil, @promo.price_qty(5))
36
+ assert_equal(10, @promo.price_qty(6))
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env ruby
2
+ # Persistence::Test -- bbmb.ch -- 14.09.2006 -- hwyss@ywesee.com
3
+
4
+ require 'bbmb/model/customer'
5
+ require 'bbmb/model/product'
6
+
7
+ class Object
8
+ def meta_class; class << self; self; end; end
9
+ def meta_eval &blk; meta_class.instance_eval &blk; end
10
+ end
11
+ module BBMB
12
+ module Persistable
13
+ def Persistable.append_features(mod)
14
+ super
15
+ mod.module_eval {
16
+ alias :__test_initialize__ :initialize
17
+ @instances = []
18
+ def initialize(*args)
19
+ __test_initialize__(*args)
20
+ self.class.instances.push(self)
21
+ end
22
+ class << self
23
+ attr_reader :instances
24
+ def clear_instances
25
+ @instances.clear
26
+ end
27
+ def index(*keys)
28
+ index_suffix = keys.join('_and_')
29
+ method_name = sprintf("find_by_%s", index_suffix)
30
+ meta_eval {
31
+ define_method(method_name) { |*vals|
32
+ @instances.find { |instance|
33
+ vals == keys.collect { |key| instance.send(key) }
34
+ }
35
+ }
36
+ }
37
+ end
38
+ end
39
+ }
40
+ end
41
+ end
42
+ module Model
43
+ class Product
44
+ include Persistable
45
+ index :article_number
46
+ index :ean13
47
+ index :description
48
+ index :pcode
49
+ end
50
+ class Customer
51
+ include Persistable
52
+ index :customer_id
53
+ index :email
54
+ index :ean13
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # suite.rb -- oddb -- 08.09.2006 -- hwyss@ywesee.com
3
+
4
+ here = File.dirname(__FILE__)
5
+ $: << here
6
+
7
+ require 'find'
8
+ Find.find(here) { |file|
9
+ if /test_.*\.rb$/o.match(file)
10
+ require file
11
+ end
12
+ }
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # TestBbmb -- bbmb.ch -- 15.09.2006 -- hwyss@ywesee.com
3
+
4
+ $: << File.expand_path('../lib', File.dirname(__FILE__))
5
+
6
+ require 'test/unit'
7
+ require 'bbmb'
8
+
9
+ module BBMB
10
+ class TestBbmb < Test::Unit::TestCase
11
+ def test_global_readers
12
+ assert_respond_to(BBMB, :config)
13
+ assert_respond_to(BBMB, :persistence)
14
+ assert_respond_to(BBMB, :logger)
15
+ assert_respond_to(BBMB, :server)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,189 @@
1
+ #!/usr/bin/env ruby
2
+ # Util::TestInvoicer -- bbmb.ch -- 05.10.2006 -- hwyss@ywesee.com
3
+
4
+
5
+ $: << File.expand_path('..', File.dirname(__FILE__))
6
+ $: << File.expand_path('../lib', File.dirname(__FILE__))
7
+
8
+ require 'bbmb/config'
9
+ require 'bbmb/util/invoicer'
10
+ require 'bbmb/util/numbers'
11
+ require 'flexmock'
12
+ require 'ostruct'
13
+ require 'stub/persistence'
14
+ require 'test/unit'
15
+
16
+ module BBMB
17
+ module Util
18
+ class TestInvoicer < Test::Unit::TestCase
19
+ include FlexMock::TestCase
20
+ def setup
21
+ key = OpenSSL::PKey::DSA.new(512)
22
+ keypath = File.expand_path('../data/private_key',
23
+ File.dirname(__FILE__))
24
+ File.open(keypath, 'w') { |fh| fh.puts(key) }
25
+ YDIM::Client::CONFIG.private_key = keypath
26
+ BBMB.config = flexmock('config')
27
+ @ydim_server = flexmock('ydim')
28
+ @ydim_url = 'druby://localhost:10082'
29
+ @ydim_config = flexstub(YDIM::Client::CONFIG)
30
+ @ydim_config.should_receive(:server_url).and_return(@ydim_url)
31
+ @drb_server = DRb.start_service(@ydim_url, @ydim_server)
32
+ end
33
+ def teardown
34
+ @drb_server.stop_service
35
+ super
36
+ end
37
+ def test_create_invoice
38
+ datadir = File.expand_path('data', File.dirname(__FILE__))
39
+ order1 = flexmock('order1')
40
+ order2 = flexmock('order2')
41
+ order1.should_receive(:total).and_return(Util::Money.new(11.00))
42
+ order2.should_receive(:total).and_return(Util::Money.new(13.00))
43
+ path = File.join(datadir, "ydim.yml")
44
+ FileUtils.mkdir_p(datadir)
45
+ File.open(path, 'w') { |fh|
46
+ fh.puts({'server_url' => @ydim_url}.to_yaml) }
47
+ @ydim_config.should_receive(:load).and_return { |ydim_path|
48
+ assert_equal(path, ydim_path)
49
+ }
50
+ BBMB.config.should_receive(:ydim_config).and_return(path)
51
+ BBMB.config.should_receive(:ydim_id).and_return(7)
52
+ BBMB.config.should_receive(:invoice_percentage).and_return(1)
53
+ BBMB.config.should_receive(:invoice_format).and_return("%s - %s")
54
+ BBMB.config.should_receive(:invoice_item_format).and_return("%.2f -> %i")
55
+ BBMB.config.should_receive(:invoice_monthly_baseline)
56
+ BBMB.config.should_receive(:invoice_monthly_baseamount)
57
+ session = flexmock('session')
58
+ @ydim_server.should_receive(:login).and_return(session)
59
+ invoice = OpenStruct.new
60
+ invoice.unique_id = 2
61
+ session.should_receive(:create_invoice).and_return { |id|
62
+ assert_equal(7, id)
63
+ invoice
64
+ }
65
+ today = Date.new(2006,10)
66
+ data = {
67
+ :price => 0.24,
68
+ :quantity => 1,
69
+ :text => "24.00 -> 2",
70
+ :time => Time.local(2006,10),
71
+ :unit => "1.0%",
72
+ }
73
+ session.should_receive(:add_items).and_return { |id, items|
74
+ assert_equal(2, id)
75
+ assert_equal([data], items)
76
+ }
77
+ @ydim_server.should_receive(:logout).and_return { |client|
78
+ assert_equal(session, client)
79
+ }
80
+ range = Time.local(2006,9)...Time.local(2006,10)
81
+ result = Invoicer.create_invoice(range, Util::Money.new(24), [order1, order2], today)
82
+ assert_equal(invoice, result)
83
+ assert_equal("01.09.2006 - 30.09.2006", invoice.description)
84
+ assert_equal(today, invoice.date)
85
+ assert_equal('CHF', invoice.currency)
86
+ assert_equal(30, invoice.payment_period)
87
+ ensure
88
+ FileUtils.rm_r(datadir) if(File.exist?(datadir))
89
+ end
90
+ def test_send_invoice
91
+ BBMB.config.should_ignore_missing
92
+ session = flexmock('session')
93
+ @ydim_server.should_receive(:login).and_return(session)
94
+ session.should_receive(:send_invoice).and_return { |id|
95
+ assert_equal(123, id)
96
+ }
97
+ @ydim_server.should_receive(:logout).and_return { |client|
98
+ assert_equal(session, client)
99
+ }
100
+ Invoicer.send_invoice(123)
101
+ end
102
+ def test_run
103
+ order1 = flexmock('order1')
104
+ order1.should_receive(:total).and_return(Util::Money.new(11.00))
105
+ order1.should_receive(:commit_time).and_return(Time.local(2006,8,31,23,59,59))
106
+ order2 = flexmock('order2')
107
+ order2.should_receive(:total).and_return(Util::Money.new(13.00))
108
+ order2.should_receive(:commit_time).and_return(Time.local(2006,9))
109
+ order3 = flexmock('order1')
110
+ order3.should_receive(:total).and_return(Util::Money.new(17.00))
111
+ order3.should_receive(:commit_time).and_return(Time.local(2006,9,30,23,59,59))
112
+ order4 = flexmock('order1')
113
+ order4.should_receive(:total).and_return(Util::Money.new(19.00))
114
+ order4.should_receive(:commit_time).and_return(Time.local(2006,10))
115
+ BBMB.persistence = flexmock('persistence')
116
+ BBMB.persistence.should_receive(:all).and_return { |klass|
117
+ assert_equal(Model::Order, klass)
118
+ [order1, order2, order3, order4]
119
+ }
120
+ BBMB.config.should_receive(:ydim_config)
121
+ BBMB.config.should_receive(:ydim_id).and_return(7)
122
+ BBMB.config.should_receive(:invoice_percentage).and_return(1)
123
+ BBMB.config.should_receive(:invoice_format).and_return("%s - %s")
124
+ BBMB.config.should_receive(:invoice_item_format).and_return("%.2f -> %i")
125
+ BBMB.config.should_receive(:invoice_baseline).and_return(20)
126
+ BBMB.config.should_receive(:invoice_newyear).and_return('1.1.')
127
+ BBMB.config.should_receive(:invoice_monthly_baseline)
128
+ BBMB.config.should_receive(:invoice_monthly_baseamount)
129
+ session = flexmock('session')
130
+ @ydim_server.should_receive(:login).and_return(session)
131
+ invoice = OpenStruct.new
132
+ invoice.unique_id = 39
133
+ session.should_receive(:create_invoice).and_return { |id|
134
+ assert_equal(7, id)
135
+ invoice
136
+ }
137
+ today = Date.new(2006,10)
138
+ data = {
139
+ :price => 0.21,
140
+ :quantity => 1,
141
+ :text => "21.00 -> 2",
142
+ :time => Time.local(2006,10),
143
+ :unit => "1.0%",
144
+ }
145
+ session.should_receive(:add_items).and_return { |id, items|
146
+ assert_equal(39, id)
147
+ assert_equal([data], items)
148
+ }
149
+ @ydim_server.should_receive(:logout).and_return { |client|
150
+ assert_equal(session, client)
151
+ }
152
+ range = Time.local(2006,9)...Time.local(2006,10)
153
+ session.should_receive(:send_invoice).with(39)
154
+ Invoicer.run(range, today)
155
+ assert_equal("01.09.2006 - 30.09.2006", invoice.description)
156
+ assert_equal(today, invoice.date)
157
+ assert_equal('CHF', invoice.currency)
158
+ assert_equal(30, invoice.payment_period)
159
+ end
160
+ def test_number_format
161
+ assert_equal "155", Invoicer.number_format('155')
162
+ assert_equal "15.5", Invoicer.number_format('15.5')
163
+ assert_equal '1.55', Invoicer.number_format('1.55')
164
+ assert_equal "1'555", Invoicer.number_format('1555')
165
+ assert_equal "155.5", Invoicer.number_format('155.5')
166
+ assert_equal '15.55', Invoicer.number_format('15.55')
167
+ assert_equal '1.555', Invoicer.number_format('1.555')
168
+ assert_equal "15'555", Invoicer.number_format('15555')
169
+ assert_equal "1'555.5", Invoicer.number_format('1555.5')
170
+ assert_equal '155.55', Invoicer.number_format('155.55')
171
+ assert_equal '15.555', Invoicer.number_format('15.555')
172
+ assert_equal '1.5555', Invoicer.number_format('1.5555')
173
+ assert_equal "155'555", Invoicer.number_format('155555')
174
+ assert_equal "15'555.5", Invoicer.number_format('15555.5')
175
+ assert_equal "1'555.55", Invoicer.number_format('1555.55')
176
+ assert_equal "155.555", Invoicer.number_format('155.555')
177
+ assert_equal "15.5555", Invoicer.number_format('15.5555')
178
+ assert_equal "1.55555", Invoicer.number_format('1.55555')
179
+ assert_equal "1'555'555", Invoicer.number_format('1555555')
180
+ assert_equal "155'555.5", Invoicer.number_format('155555.5')
181
+ assert_equal "15'555.55", Invoicer.number_format('15555.55')
182
+ assert_equal "1'555.555", Invoicer.number_format('1555.555')
183
+ assert_equal "155.5555", Invoicer.number_format('155.5555')
184
+ assert_equal "15.55555", Invoicer.number_format('15.55555')
185
+ assert_equal "1.555555", Invoicer.number_format('1.555555')
186
+ end
187
+ end
188
+ end
189
+ end