Class: TestCompany

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
FlexMock::TestCase
Defined in:
test/test_model/company.rb

Defined Under Namespace

Classes: StubApp, StubRegistration, StubSession

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



40
41
42
43
# File 'test/test_model/company.rb', line 40

def setup
  @session = StubSession.new
  @company = @session.app.create_company
end

- (Object) test_active_package_count



44
45
46
47
48
49
# File 'test/test_model/company.rb', line 44

def test_active_package_count
  reg1 = flexmock :active_package_count => 2
  reg2 = flexmock :active_package_count => 1
  @company.registrations.push reg1, reg2
  assert_equal 3, @company.active_package_count
end

- (Object) test_add_registration



50
51
52
53
54
55
# File 'test/test_model/company.rb', line 50

def test_add_registration
  @company.registrations = []
  reg = StubRegistration.new
  @company.add_registration(reg)
  assert_equal([reg], @company.registrations)
end

- (Object) test_adjust_types



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'test/test_model/company.rb', line 258

def test_adjust_types
  values = {
    :name            =>  'ywesee.com',
    :cl_status     =>  true,
    :url           => 'www.ywesee.com',
    :business_area =>  'Intellectual Capital',
    :contact       => 'hwyss at ywesee.com',
    :address       => 'Winterthurerstrasse',
    :plz           => '8000',
    :powerlink      =>  '',
    :location        =>  'Zuerich',
    :generic_type   =>  'original',
    :complementary_type => 'homeopathy',
    :price_lookandfeel => '12',
  }
  expected = {
    :name            =>  'ywesee.com',
    :cl_status     =>  true,
    :url           => 'www.ywesee.com',
    :business_area =>  'Intellectual Capital',
    :contact       => 'hwyss at ywesee.com',
    :address       => 'Winterthurerstrasse',
    :plz           => '8000',
    :powerlink      =>  nil,
    :location        =>  'Zuerich',
    :generic_type   =>  :original,
    :complementary_type => :homeopathy,
    :price_lookandfeel => 1200,
  }
  assert_equal(expected, @company.adjust_types(values))
end

- (Object) test_atc_classes



56
57
58
59
60
61
# File 'test/test_model/company.rb', line 56

def test_atc_classes
  reg1 = flexmock :atc_classes => ['atc1', 'atc2', nil]
  reg2 = flexmock :atc_classes => ['atc1', 'atc3', 'atc4' ]
  @company.registrations.push reg1, reg2
  assert_equal ['atc1', 'atc2', 'atc3', 'atc4'], @company.atc_classes
end

- (Object) test_disable_invoice_fachinfo



62
63
64
65
66
67
68
# File 'test/test_model/company.rb', line 62

def test_disable_invoice_fachinfo
  assert_equal nil, @company.disable_invoice_fachinfo
  @company.disable_invoice_fachinfo = true
  assert_equal true, @company.disable_invoice_fachinfo
  @company.disable_invoice_fachinfo = false
  assert_equal false, @company.disable_invoice_fachinfo
end

- (Object) test_disable_invoice_patinfo



69
70
71
72
73
74
75
# File 'test/test_model/company.rb', line 69

def test_disable_invoice_patinfo
  assert_equal nil, @company.disable_invoice_patinfo
  @company.disable_invoice_patinfo = true
  assert_equal true, @company.disable_invoice_patinfo
  @company.disable_invoice_patinfo = false
  assert_equal false, @company.disable_invoice_patinfo
end

- (Object) test_inactive_packages



76
77
78
79
80
81
82
83
84
85
86
# File 'test/test_model/company.rb', line 76

def test_inactive_packages
  pac1 = flexmock :market_date => nil
  pac2 = flexmock :market_date => Date.today + 1
  pac3 = flexmock :market_date => Date.today
  pac4 = flexmock :market_date => Date.today + 2
  pac5 = flexmock :market_date => Date.today - 1
  reg1 = flexmock :packages => [pac1, pac2, pac3]
  reg2 = flexmock :packages => [pac4, pac5]
  @company.registrations.push reg1, reg2
  assert_equal [pac2, pac4], @company.inactive_packages
end

- (Object) test_inactive_registrations



87
88
89
90
91
92
# File 'test/test_model/company.rb', line 87

def test_inactive_registrations
  reg1 = flexmock :public_package_count => 1
  reg2 = flexmock :public_package_count => 0
  @company.registrations.push reg1, reg2
  assert_equal [reg2], @company.inactive_registrations
end

- (Object) test_init



289
290
291
292
293
294
# File 'test/test_model/company.rb', line 289

def test_init
  @company.pointer = ODDB::Persistence::Pointer.new [:company]
  @company.init nil
  pointer = ODDB::Persistence::Pointer.new [:company, @company.oid]
  assert_equal pointer, @company.pointer
end

- (Object) test_invoice_date_fachinfo



126
127
128
129
130
131
132
133
134
# File 'test/test_model/company.rb', line 126

def test_invoice_date_fachinfo
  date = Date.today
  @company.invoice_date_fachinfo = date
  assert_equal(date, @company.invoice_date_fachinfo)
  @company.invoice_date_fachinfo = date >> 1
  assert_equal(date >> 1, @company.invoice_date_fachinfo)
  @company.invoice_date_fachinfo = date << 1
  assert_equal(date >> 11, @company.invoice_date_fachinfo)
end

- (Object) test_invoice_date_index



135
136
137
138
139
140
141
142
143
# File 'test/test_model/company.rb', line 135

def test_invoice_date_index
  date = Date.today
  @company.invoice_date_index = date
  assert_equal(date, @company.invoice_date_index)
  @company.invoice_date_index = date >> 1
  assert_equal(date >> 1, @company.invoice_date_index)
  @company.invoice_date_index = date << 1
  assert_equal(date >> 11, @company.invoice_date_index)
end

- (Object) test_invoice_date_lookandfeel



144
145
146
147
148
149
150
151
152
# File 'test/test_model/company.rb', line 144

def test_invoice_date_lookandfeel
  date = Date.today
  @company.invoice_date_lookandfeel = date
  assert_equal(date, @company.invoice_date_lookandfeel)
  @company.invoice_date_lookandfeel = date >> 1
  assert_equal(date >> 1, @company.invoice_date_lookandfeel)
  @company.invoice_date_lookandfeel = date << 1
  assert_equal(date >> 11, @company.invoice_date_lookandfeel)
end

- (Object) test_invoice_date_patinfo



117
118
119
120
121
122
123
124
125
# File 'test/test_model/company.rb', line 117

def test_invoice_date_patinfo
  date = Date.today
  @company.invoice_date_patinfo = date
  assert_equal(date, @company.invoice_date_patinfo)
  @company.invoice_date_patinfo = date >> 1
  assert_equal(date >> 1, @company.invoice_date_patinfo)
  @company.invoice_date_patinfo = date << 1
  assert_equal(date >> 11, @company.invoice_date_patinfo)
end

- (Object) test_invoiceable



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'test/test_model/company.rb', line 93

def test_invoiceable
  assert_equal false, @company.invoiceable?
  @company.name = 'Name'
  @company.contact = 'Contact'
  @company.invoice_email = 'Invoice Email'
  addr = @company.address(0)
  addr.address = 'Street, Number'
  addr.location = '1234 City'
  addr.fon = 'Phone Number'
  assert_equal true, @company.invoiceable?
  [:address, :location, :fon].each do |key|
    old = addr.send(key)
    addr.send("#{key}=", nil)
    assert_equal false, @company.invoiceable?
    addr.send("#{key}=", old)
  end
  [:name, :contact, :invoice_email].each do |key|
    old = @company.send(key)
    @company.send("#{key}=", nil)
    assert_equal false, @company.invoiceable?
    @company.send("#{key}=", old)
  end
  assert_equal true, @company.invoiceable?
end

- (Object) test_listed



153
154
155
156
157
158
159
# File 'test/test_model/company.rb', line 153

def test_listed
  assert_equal false, @company.listed?
  @company.cl_status = true
  assert_equal true, @company.listed?
  @company.cl_status = false
  assert_equal false, @company.listed?
end

- (Object) test_merge



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'test/test_model/company.rb', line 160

def test_merge
  reg1 = flexmock :odba_isolated_store => :ignore
  reg2 = flexmock :odba_isolated_store => :ignore
  other = ODDB::Company.new 
  other.registrations.push reg1, reg2
  reg1.should_receive(:company=).with(@company).times(1).and_return do
    other.registrations.delete reg1
    @company.registrations.push reg1
    assert true
  end
  reg2.should_receive(:company=).with(@company).times(1).and_return do
    other.registrations.delete reg2
    @company.registrations.push reg2
    assert true
  end
  @company.merge other
  assert_equal [reg1, reg2], @company.registrations
end

- (Object) test_packages



178
179
180
181
182
183
184
# File 'test/test_model/company.rb', line 178

def test_packages
  reg1 = flexmock :packages => ['package1', 'package2']
  reg2 = flexmock :packages => ['package3', 'package4', 'package5']
  @company.registrations.push reg1, reg2
  assert_equal ['package1', 'package2', 'package3', 'package4', 'package5'],
               @company.packages
end

- (Object) test_pointer_descr



185
186
187
188
# File 'test/test_model/company.rb', line 185

def test_pointer_descr
  @company.name = 'Company-Name'
  assert_equal 'Company-Name', @company.pointer_descr
end

- (Object) test_prices



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'test/test_model/company.rb', line 189

def test_prices
  assert_nil @company.price_fachinfo
  assert_nil @company.price(:fachinfo)
  @company.price_fachinfo = 100
  assert_equal 100, @company.price_fachinfo
  assert_equal 100, @company.price(:fachinfo)
  assert_nil @company.price_index
  assert_nil @company.price(:index)
  @company.price_index = 100
  assert_equal 100, @company.price_index
  assert_equal 100, @company.price(:index)
  assert_nil @company.price_index_package
  assert_nil @company.price(:index_package)
  @company.price_index_package = 100
  assert_equal 100, @company.price_index_package
  assert_equal 100, @company.price(:index_package)
  assert_nil @company.price_lookandfeel
  assert_nil @company.price(:lookandfeel)
  @company.price_lookandfeel = 100
  assert_equal 100, @company.price_lookandfeel
  assert_equal 100, @company.price(:lookandfeel)
  assert_nil @company.price_lookandfeel_member
  assert_nil @company.price(:lookandfeel_member)
  @company.price_lookandfeel_member = 100
  assert_equal 100, @company.price_lookandfeel_member
  assert_equal 100, @company.price(:lookandfeel_member)
  assert_nil @company.price_patinfo
  assert_nil @company.price(:patinfo)
  @company.price_patinfo = 100
  assert_equal 100, @company.price_patinfo
  assert_equal 100, @company.price(:patinfo)
end

- (Object) test_remove_registration



221
222
223
224
225
226
# File 'test/test_model/company.rb', line 221

def test_remove_registration
  reg = StubRegistration.new
  @company.registrations = [reg]
  @company.remove_registration(reg)
  assert_equal([], @company.registrations)
end

- (Object) test_search_terms



227
228
229
230
231
232
233
234
235
236
237
238
# File 'test/test_model/company.rb', line 227

def test_search_terms
  @company.name = 'Company-Name'
  @company.ean13 = '7681123456789'
  addr = @company.address(0)
  addr.address = 'Street, Number'
  addr.location = '1234 City'
  expected = [
    'Company', 'Name', 'Company', 'CompanyName', 'Company Name', 
     "7681123456789", "Street Number", "1234 City", "City", "1234"
  ]
  assert_equal expected, @company.search_terms
end

- (Object) test_update_values



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'test/test_model/company.rb', line 239

def test_update_values
  values = {
    :name            =>  'ywesee.com',
    :cl_status     =>  true,
    :url           => 'www.ywesee.com',
    :business_area =>  'Intellectual Capital',
    :contact       => 'hwyss at ywesee.com',
  }
  reg = StubRegistration.new
  @company.add_registration(reg)
  assert_equal(nil, @company.name)
  @company.update_values(values)
  assert_equal('ywesee.com', @company.name)
  assert_equal(true, @company.cl_status)
  assert_equal('www.ywesee.com', @company.url)
  assert_equal('Intellectual Capital', @company.business_area)
  assert_equal('hwyss at ywesee.com', @company.contact)
  assert_equal([reg], @company.registrations)
end