beerdb 0.9.13 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_values.rb DELETED
@@ -1,240 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ###
4
- # to run use
5
- # ruby -I ./lib -I ./test test/test_helper.rb
6
- # or better
7
- # rake test
8
-
9
- require 'helper'
10
-
11
-
12
- class TestValues < MiniTest::Unit::TestCase
13
-
14
- def setup
15
- # delete all beers, brands, breweries in in-memory only db
16
- BeerDb.delete!
17
- end
18
-
19
- def test_load_beer_values
20
-
21
- key = 'ottakringerpur'
22
-
23
- values = [
24
- 'Ottakringer (Gold Fassl) Pur {Bio}',
25
- '5.2 %',
26
- '11.8°',
27
- 'bio'
28
- ]
29
-
30
- more_attribs = {
31
- country_id: AT.id
32
- }
33
-
34
- beer = Beer.create_or_update_from_values( values, more_attribs )
35
-
36
- beer2 = Beer.find_by_key!( key )
37
- assert_equal beer.id, beer2.id
38
-
39
- assert_equal beer.title, values[0]
40
- assert_equal beer.country_id, AT.id
41
- assert_equal beer.country.title, AT.title
42
- assert_equal beer.abv, 5.2
43
- assert_equal beer.og, 11.8
44
- assert_equal beer.srm, nil
45
- end
46
-
47
- def test_load_brewery_values
48
-
49
- # ottakringer, Ottakringer Brauerei, 1838, www.ottakringer.at, WI, city:wien, 1160 Wien // Ottakringer Platz 1
50
- # brands: Ottakringer
51
-
52
- key = 'ottakringer'
53
-
54
- values = [
55
- key,
56
- 'Ottakringer Brauerei',
57
- '1838',
58
- 'www.ottakringer.at',
59
- '1160 Wien // Ottakringer Platz 1',
60
- 'brands: Ottakringer'
61
- ]
62
-
63
- more_attribs = {
64
- country_id: AT.id
65
- }
66
-
67
-
68
- by = Brewery.create_or_update_from_values( values, more_attribs )
69
-
70
- by2 = Brewery.find_by_key!( key )
71
- assert_equal by.id, by2.id
72
-
73
- assert_equal by.title, values[1]
74
- assert_equal by.country_id, AT.id
75
- assert_equal by.country.title, AT.title
76
- assert_equal by.since, 1838
77
- assert_equal by.web, 'www.ottakringer.at'
78
- assert_equal by.address, '1160 Wien // Ottakringer Platz 1'
79
- assert_equal by.grade, 4
80
-
81
- # check auto-created brand
82
-
83
- br = Brand.find_by_key!( 'ottakringer')
84
-
85
- assert_equal br.title, 'Ottakringer'
86
- assert_equal br.brewery_id, by.id
87
- assert_equal br.brewery.title, by.title
88
- assert_equal br.country_id, by.country_id
89
- end
90
-
91
-
92
- def test_load_brewery_values_w_grade
93
-
94
- # ottakringer, Ottakringer Brauerei, 1838, www.ottakringer.at, WI, city:wien, 1160 Wien // Ottakringer Platz 1
95
- # brands: Ottakringer
96
-
97
- key = 'ottakringer'
98
-
99
- values = [
100
- key,
101
- 'Ottakringer Brauerei **',
102
- '1838',
103
- 'www.ottakringer.at',
104
- '1160 Wien // Ottakringer Platz 1',
105
- 'brands: Ottakringer'
106
- ]
107
-
108
- more_attribs = {
109
- country_id: AT.id
110
- }
111
-
112
- by = Brewery.create_or_update_from_values( values, more_attribs )
113
-
114
- by2 = Brewery.find_by_key!( key )
115
- assert_equal by.id, by2.id
116
-
117
- assert_equal by.title, 'Ottakringer Brauerei'
118
- assert_equal by.grade, 2
119
- end
120
-
121
- def test_load_brewery_values_w_grade_in_synonyms
122
-
123
- ## fix!!!!!!!!: use different brewery! use one w/ synonyms
124
- ###
125
-
126
- # ottakringer, Ottakringer Brauerei, 1838, www.ottakringer.at, WI, city:wien, 1160 Wien // Ottakringer Platz 1
127
- # brands: Ottakringer
128
-
129
- key = 'ottakringer'
130
-
131
- values = [
132
- key,
133
- 'Ottakringer Brauerei|Otta **', # NB: title will auto-gen grade n synonyms
134
- '1838',
135
- 'www.ottakringer.at',
136
- '1160 Wien // Ottakringer Platz 1',
137
- 'brands: Ottakringer'
138
- ]
139
-
140
- more_attribs = {
141
- country_id: AT.id
142
- }
143
-
144
- by = Brewery.create_or_update_from_values( values, more_attribs )
145
-
146
- by2 = Brewery.find_by_key!( key )
147
- assert_equal by.id, by2.id
148
-
149
- assert_equal by.title, 'Ottakringer Brauerei'
150
- assert_equal by.synonyms, 'Otta'
151
- assert_equal by.grade, 2
152
- end
153
-
154
-
155
- def test_load_brewery_values_w_city_at
156
-
157
- # ottakringer, Ottakringer Brauerei, 1838, www.ottakringer.at, WI, city:wien, 1160 Wien // Ottakringer Platz 1
158
- # brands: Ottakringer
159
-
160
- key = 'ottakringer'
161
-
162
- values = [
163
- key,
164
- 'Ottakringer Brauerei',
165
- '1838',
166
- 'www.ottakringer.at',
167
- '1160 Wien // Ottakringer Platz 1',
168
- 'brands: Ottakringer'
169
- ]
170
-
171
- more_attribs = {
172
- country_id: AT.id,
173
- region_id: W.id
174
- }
175
-
176
- by = Brewery.create_or_update_from_values( values, more_attribs )
177
-
178
- by2 = Brewery.find_by_key!( key )
179
- assert( by.id == by2.id )
180
-
181
- assert( by.title == values[1] )
182
- assert( by.country_id == AT.id )
183
- assert( by.country.title == AT.title )
184
- assert( by.since == 1838 )
185
- assert( by.web == 'www.ottakringer.at' )
186
- assert( by.address == '1160 Wien // Ottakringer Platz 1' )
187
-
188
- # check auto-created brand
189
-
190
- br = Brand.find_by_key!( 'ottakringer')
191
-
192
- assert( br.title == 'Ottakringer' )
193
- assert( br.brewery_id == by.id )
194
- assert( br.brewery.title == by.title )
195
- assert( br.country_id == by.country_id )
196
-
197
- # todo: check for auto-created city
198
- assert( by.city.title == 'Wien' )
199
- end
200
-
201
-
202
- def test_load_brewery_values_w_city_de
203
-
204
- # hofbraeu, Hofbräu München, 1589, www.hofbraeu-muenchen.de, 81829 München // Hofbräuallee 1
205
-
206
- key = 'hofbraeu'
207
-
208
- values = [
209
- key,
210
- 'Hofbräu München',
211
- '1589',
212
- 'www.hofbraeu-muenchen.de',
213
- '81829 München // Hofbräuallee 1',
214
- 'brands: Hofbräu'
215
- ]
216
-
217
- more_attribs = {
218
- country_id: DE.id,
219
- region_id: BY.id
220
- }
221
-
222
- by = Brewery.create_or_update_from_values( values, more_attribs )
223
-
224
- by2 = Brewery.find_by_key!( key )
225
- assert( by.id == by2.id )
226
-
227
- assert( by.title == values[1] )
228
- assert( by.country_id == DE.id )
229
- assert( by.country.title == DE.title )
230
- assert( by.since == 1589 )
231
- assert( by.web == 'www.hofbraeu-muenchen.de' )
232
- assert( by.address == '81829 München // Hofbräuallee 1' )
233
-
234
- # tood: check auto-created brand
235
- # todo: check for auto-created city
236
- assert( by.city.title == 'München' )
237
-
238
- end
239
-
240
- end # class TestValues