Class: ODDB::Migel::TestProduct

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) setup



19
20
21
22
23
24
25
# File 'test/test_model/migel_product.rb', line 19

def setup
  @subgroup = FlexMock.new
  @subgroup.should_receive(:code).and_return { '04' }
  @subgroup.should_receive(:migel_code).and_return { '03.04' }
  @product = Product.new('01.00.2')
  @product.subgroup = @subgroup
end

- (Object) test_accessory_code



26
27
28
# File 'test/test_model/migel_product.rb', line 26

def test_accessory_code
  assert_equal '00.2', @product.accessory_code
end

- (Object) test_add_accessory



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'test/test_model/migel_product.rb', line 183

def test_add_accessory
  odba = ODBA.cache = FlexMock.new
  odba.should_receive(:store, 2).and_return { |arg|
    assert_equal(@product.accessories, arg)
  }
  acc = FlexMock.new
  res = @product.add_accessory(acc)
  assert_equal([acc], @product.accessories)
  assert_equal(acc, res)
  acc2 = FlexMock.new
  res = @product.add_accessory(acc2)
  assert_equal([acc, acc2], @product.accessories)
  assert_equal(acc2, res)
ensure
  ODBA.cache = nil
end

- (Object) test_adjust_types



29
30
31
32
33
34
35
36
37
38
39
40
# File 'test/test_model/migel_product.rb', line 29

def test_adjust_types
  ptr = Persistence::Pointer.new([:migel_product, :id])
  app = flexmock 'application'
  app.should_receive(:migel_product).with(:id).and_return 'resolved'
  data = {
    :something => ptr
  }
  expected = {
    :something => 'resolved'
  }
  assert_equal expected, @product.adjust_types(data, app)
end

- (Object) test_checkout



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
# File 'test/test_model/migel_product.rb', line 41

def test_checkout
  acc1 = flexmock 'accessory1'
  acc1.should_receive(:remove_product).times(1).and_return do
    @product.accessories.delete acc1
    assert true
  end
  acc2 = flexmock 'accessory2'
  acc2.should_receive(:remove_product).times(1).and_return do
    @product.accessories.delete acc2
    assert true
  end
  @product.accessories.push acc1, acc2
  prod1 = flexmock 'product1'
  prod1.should_receive(:remove_accessory).times(1).and_return do
    assert true
  end
  prod2 = flexmock 'product2'
  prod2.should_receive(:remove_accessory).times(1).and_return do
    assert true
  end
  @product.products.push prod1, prod2
  fb1 = flexmock :odba_store => true
  fb1.should_receive(:item=).with(nil).times(1).and_return do
    @product.feedbacks.delete fb1
    assert true
  end
  fb2 = flexmock :odba_store => true
  fb2.should_receive(:item=).with(nil).times(1).and_return do
    @product.feedbacks.delete fb2
    assert true
  end
  @product.feedbacks.push fb1, fb2
  @product.checkout
  assert_equal [], @product.accessories
  assert_equal [], @product.feedbacks
end

- (Object) test_create_limitation_text



77
78
79
80
81
82
# File 'test/test_model/migel_product.rb', line 77

def test_create_limitation_text
  assert_nil @product.limitation_text
  res = @product.create_limitation_text
  assert_instance_of LimitationText, res
  assert_equal res, @product.limitation_text
end

- (Object) test_create_product_text



83
84
85
86
87
88
# File 'test/test_model/migel_product.rb', line 83

def test_create_product_text
  assert_nil @product.product_text
  res = @product.create_product_text
  assert_instance_of Text::Document, res
  assert_equal res, @product.product_text
end

- (Object) test_create_unit



89
90
91
92
93
94
# File 'test/test_model/migel_product.rb', line 89

def test_create_unit
  assert_nil @product.unit
  res = @product.create_unit
  assert_instance_of Text::Document, res
  assert_equal res, @product.unit
end

- (Object) test_delete_limitation_text



95
96
97
98
99
100
# File 'test/test_model/migel_product.rb', line 95

def test_delete_limitation_text
  lt = flexmock :odba_delete => true
  @product.instance_variable_set '@limitation_text', lt
  @product.delete_limitation_text
  assert_nil @product.limitation_text
end

- (Object) test_delete_product_text



101
102
103
104
105
106
# File 'test/test_model/migel_product.rb', line 101

def test_delete_product_text
  lt = flexmock :odba_delete => true
  @product.instance_variable_set '@product_text', lt
  @product.delete_product_text
  assert_nil @product.product_text
end

- (Object) test_delete_unit



107
108
109
110
111
112
# File 'test/test_model/migel_product.rb', line 107

def test_delete_unit
  lt = flexmock :odba_delete => true
  @product.instance_variable_set '@unit', lt
  @product.delete_unit
  assert_nil @product.unit
end

- (Object) test_localized_name



113
114
115
116
117
118
119
120
121
# File 'test/test_model/migel_product.rb', line 113

def test_localized_name
  @product.descriptions.update 'fr' => 'Description', 'de' => 'Beschreibung'
  assert_equal 'Beschreibung', @product.localized_name(:de)
  assert_equal 'Description', @product.localized_name(:fr)
  pt = @product.create_product_text
  pt.descriptions.store 'de', 'ProductText'
  assert_equal 'ProductText: Beschreibung', @product.localized_name(:de)
  assert_equal 'ProductText: Description', @product.localized_name(:fr)
end

- (Object) test_migel_code



122
123
124
# File 'test/test_model/migel_product.rb', line 122

def test_migel_code
  assert_equal('03.04.01.00.2', @product.migel_code)
end

- (Object) test_product_code



125
126
127
# File 'test/test_model/migel_product.rb', line 125

def test_product_code
  assert_equal('01', @product.product_code)
end

- (Object) test_product_writer



153
154
155
156
157
158
159
160
161
162
163
164
# File 'test/test_model/migel_product.rb', line 153

def test_product_writer
  product = FlexMock.new
  product.should_receive(:add_accessory, 1).and_return { |acc| 
    assert_equal(@product, acc)
  }
  res = @product.add_product(product)
  assert_equal(product, res)
  assert_equal([product], @product.products)
  @product.add_product(product)
  assert_equal([product], @product.products)
  product.flexmock_verify
end

- (Object) test_product_writer__nil



165
166
167
168
# File 'test/test_model/migel_product.rb', line 165

def test_product_writer__nil
  assert_nothing_raised { @product.add_product(nil) }
  assert_equal([], @product.products)
end

- (Object) test_product_writer__remove



169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'test/test_model/migel_product.rb', line 169

def test_product_writer__remove
  product = FlexMock.new
  product.should_receive(:add_accessory).and_return { |acc| 
    assert_equal(@product, acc)
  }
  @product.add_product(product)
  assert_equal([product], @product.products)
  product.should_receive(:remove_accessory, 1).and_return { |acc| 
    assert_equal(@product, acc)
  }
  @product.remove_product(product)
  assert_equal([product], @product.products)
  product.flexmock_verify
end

- (Object) test_remove_accessory



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'test/test_model/migel_product.rb', line 199

def test_remove_accessory
  odba = ODBA.cache = FlexMock.new
  odba.should_receive(:store, 2).and_return { |arg|
    assert_equal(@product.accessories, arg)
  }
  acc = FlexMock.new
  acc2 = FlexMock.new
  @product.accessories.push(acc)
  @product.accessories.push(acc2)
  res = @product.remove_accessory(acc)
  assert_equal([acc2], @product.accessories)
  assert_equal(acc, res)
  res = @product.remove_accessory(acc)
  assert_equal([acc2], @product.accessories)
  assert_equal(nil, res)
  res = @product.remove_accessory(acc2)
  assert_equal([], @product.accessories)
  assert_equal(acc2, res)
ensure
  ODBA.cache = nil
end

- (Object) test_search_terms



128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'test/test_model/migel_product.rb', line 128

def test_search_terms
  @group = FlexMock.new 'group'
  @group.should_receive(:de).and_return { 'group' }
  lt = LimitationText.new
  lt.descriptions.store 'de', 'Limitation-Text'
  @group.should_receive(:limitation_text).and_return lt
  @subgroup.should_receive(:group).and_return { @group }
  @subgroup.should_receive(:de).and_return { 'subgroup' }
  @subgroup.should_receive(:limitation_text).and_return nil
  expected = [ '030401002', 'group', 'Limitation',
               'LimitationText', 'Limitation Text', 'subgroup' ]
  assert_equal(expected, @product.search_terms)
end

- (Object) test_search_text



141
142
143
144
145
146
147
148
149
150
151
152
# File 'test/test_model/migel_product.rb', line 141

def test_search_text
  @group = FlexMock.new 'group'
  @group.should_receive(:de).and_return { 'group' }
  lt = LimitationText.new
  lt.descriptions.store 'de', 'Limitation-Text'
  @group.should_receive(:limitation_text).and_return lt
  @subgroup.should_receive(:group).and_return { @group }
  @subgroup.should_receive(:de).and_return { 'subgroup' }
  @subgroup.should_receive(:limitation_text).and_return nil
  expected = '030401002 group limitation limitationtext limitation text subgroup'
  assert_equal(expected, @product.search_text)
end