odeon_uk 2.0.4 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -1
  3. data/CHANGELOG.md +6 -0
  4. data/Rakefile +29 -0
  5. data/lib/odeon_uk/api/cinema.rb +62 -0
  6. data/lib/odeon_uk/api/response.rb +55 -0
  7. data/lib/odeon_uk/api/screenings.rb +89 -0
  8. data/lib/odeon_uk/cinema.rb +53 -114
  9. data/lib/odeon_uk/configuration.rb +21 -0
  10. data/lib/odeon_uk/html/cinema.rb +101 -0
  11. data/lib/odeon_uk/html/parser/film_with_screenings.rb +160 -0
  12. data/lib/odeon_uk/html/screenings.rb +38 -0
  13. data/lib/odeon_uk/{internal → html}/website.rb +1 -1
  14. data/lib/odeon_uk/internal/title_sanitizer.rb +1 -0
  15. data/lib/odeon_uk/screening.rb +7 -15
  16. data/lib/odeon_uk/version.rb +2 -2
  17. data/lib/odeon_uk.rb +11 -4
  18. data/odeon_uk.gemspec +2 -0
  19. data/rake/fixture_creator.rb +98 -0
  20. data/test/fixtures/api/all_cinemas.plist +0 -0
  21. data/test/fixtures/api/app_init.plist +0 -0
  22. data/test/fixtures/api/film_times/71-100747.plist +0 -0
  23. data/test/fixtures/api/film_times/71-100750.plist +0 -0
  24. data/test/fixtures/api/film_times/71-100790.plist +0 -0
  25. data/test/fixtures/api/film_times/71-14646.plist +0 -0
  26. data/test/fixtures/api/film_times/71-14725.plist +0 -0
  27. data/test/fixtures/api/film_times/71-15086.plist +0 -0
  28. data/test/fixtures/api/film_times/71-15096.plist +0 -0
  29. data/test/fixtures/api/film_times/71-15122.plist +0 -0
  30. data/test/fixtures/api/film_times/71-15130.plist +0 -0
  31. data/test/fixtures/api/film_times/71-15141.plist +0 -0
  32. data/test/fixtures/api/film_times/71-15142.plist +0 -0
  33. data/test/fixtures/api/film_times/71-15143.plist +0 -0
  34. data/test/fixtures/api/film_times/71-15144.plist +0 -0
  35. data/test/fixtures/api/film_times/71-15145.plist +0 -0
  36. data/test/fixtures/api/film_times/71-15170.plist +0 -0
  37. data/test/fixtures/api/film_times/71-15172.plist +0 -0
  38. data/test/fixtures/api/film_times/71-15177.plist +0 -0
  39. data/test/fixtures/api/film_times/71-15179.plist +0 -0
  40. data/test/fixtures/api/film_times/71-15182.plist +0 -0
  41. data/test/fixtures/api/film_times/71-15286.plist +0 -0
  42. data/test/fixtures/api/film_times/71-15360.plist +0 -0
  43. data/test/fixtures/api/film_times/71-15586.plist +0 -0
  44. data/test/fixtures/api/film_times/71-15700.plist +0 -0
  45. data/test/fixtures/api/film_times/71-15718.plist +0 -0
  46. data/test/fixtures/api/film_times/71-15768.plist +0 -0
  47. data/test/fixtures/api/film_times/71-15788.plist +0 -0
  48. data/test/fixtures/api/film_times/71-15793.plist +0 -0
  49. data/test/fixtures/api/film_times/71-15794.plist +0 -0
  50. data/test/fixtures/api/film_times/71-15795.plist +0 -0
  51. data/test/fixtures/api/film_times/71-15796.plist +0 -0
  52. data/test/fixtures/api/film_times/71-15799.plist +0 -0
  53. data/test/fixtures/api/film_times/71-15802.plist +0 -0
  54. data/test/fixtures/api/film_times/71-15814.plist +0 -0
  55. data/test/fixtures/api/film_times/71-15817.plist +0 -0
  56. data/test/fixtures/api/film_times/71-15840.plist +0 -0
  57. data/test/fixtures/{cinema/leicester_square.html → html/cinema/105.html} +384 -313
  58. data/test/fixtures/{cinema/bfi_imax.html → html/cinema/211.html} +677 -355
  59. data/test/fixtures/{cinema/brighton.html → html/cinema/71.html} +899 -431
  60. data/test/fixtures/html/showtimes/11-imax.html +170 -0
  61. data/test/fixtures/html/showtimes/171-d-box.html +203 -0
  62. data/test/fixtures/html/showtimes/71-0.html +59 -0
  63. data/test/fixtures/html/showtimes/71.html +2395 -0
  64. data/test/fixtures/{sitemap.html → html/sitemap.html} +264 -352
  65. data/test/lib/odeon_uk/api/cinema_test.rb +149 -0
  66. data/test/lib/odeon_uk/api/response_test.rb +44 -0
  67. data/test/lib/odeon_uk/api/screenings_test.rb +43 -0
  68. data/test/lib/odeon_uk/cinema_test.rb +373 -148
  69. data/test/lib/odeon_uk/configuration_test.rb +29 -0
  70. data/test/lib/odeon_uk/html/cinema_test.rb +149 -0
  71. data/test/lib/odeon_uk/{internal/film_with_screenings_parser_test.rb → html/parser/film_with_screenings_test.rb} +12 -42
  72. data/test/lib/odeon_uk/html/screenings_test.rb +43 -0
  73. data/test/lib/odeon_uk/html/website_test.rb +37 -0
  74. data/test/lib/odeon_uk/screening_test.rb +17 -83
  75. data/test/support/api_fixtures_helper.rb +34 -0
  76. data/test/support/website_fixtures_helper.rb +25 -0
  77. data/test/test_helper.rb +7 -2
  78. metadata +149 -34
  79. data/lib/odeon_uk/film.rb +0 -65
  80. data/lib/odeon_uk/internal/film_with_screenings_parser.rb +0 -159
  81. data/lib/odeon_uk/internal/showtimes_page.rb +0 -36
  82. data/test/fixture_updater.rb +0 -72
  83. data/test/fixtures/showtimes/brighton/film_first.html +0 -92
  84. data/test/fixtures/showtimes/brighton/film_last.html +0 -100
  85. data/test/fixtures/showtimes/brighton.html +0 -2071
  86. data/test/fixtures/showtimes/liverpool_one/film_first_dbox.html +0 -188
  87. data/test/fixtures/showtimes/manchester/film_first_imax.html +0 -182
  88. data/test/lib/odeon_uk/film_test.rb +0 -142
  89. data/test/lib/odeon_uk/internal/showtimes_page_test.rb +0 -51
  90. data/test/lib/odeon_uk/internal/website_test.rb +0 -59
@@ -3,254 +3,479 @@ require_relative '../../test_helper'
3
3
  describe OdeonUk::Cinema do
4
4
  let(:described_class) { OdeonUk::Cinema }
5
5
 
6
- let(:website) { Minitest::Mock.new }
7
-
8
6
  before do
9
7
  WebMock.disable_net_connect!
10
8
  end
11
9
 
12
- describe '.all' do
13
- subject { described_class.all }
10
+ describe 'with HTML parsing' do
11
+ include WebsiteFixturesHelper
14
12
 
15
- before do
16
- website.expect(:sitemap, sitemap_html)
13
+ let(:website) { Minitest::Mock.new }
14
+
15
+ describe '.all' do
16
+ subject { described_class.all }
17
+
18
+ before do
19
+ website.expect(:sitemap, sitemap_html)
20
+ end
21
+
22
+ it 'returns an Array of OdeonUk::Cinemas' do
23
+ OdeonUk::Html::Website.stub :new, website do
24
+ subject.must_be_instance_of(Array)
25
+ subject.each do |value|
26
+ value.must_be_instance_of(described_class)
27
+ end
28
+ end
29
+ end
30
+
31
+ it 'returns the correctly sized array' do
32
+ OdeonUk::Html::Website.stub :new, website do
33
+ subject.size.must_equal 115
34
+ end
35
+ end
17
36
  end
18
37
 
19
- it 'returns an Array of OdeonUk::Cinemas' do
20
- OdeonUk::Internal::Website.stub :new, website do
21
- subject.must_be_instance_of(Array)
22
- subject.each do |value|
23
- value.must_be_instance_of(described_class)
38
+ describe '.new(id)' do
39
+ subject { described_class.new(id) }
40
+
41
+ describe 'Brighton' do
42
+ let(:id) { 71 }
43
+
44
+ before do
45
+ website.expect(:sitemap, sitemap_html)
46
+ end
47
+
48
+ it 'returns a cinema' do
49
+ OdeonUk::Html::Website.stub :new, website do
50
+ subject.must_be_instance_of(described_class)
51
+
52
+ subject.id.must_equal 71
53
+ subject.brand.must_equal 'Odeon'
54
+ subject.name.must_equal 'Brighton'
55
+ subject.slug.must_equal 'odeon-brighton'
56
+ subject.url.must_equal 'http://www.odeon.co.uk/cinemas/brighton/71/'
57
+ end
24
58
  end
25
59
  end
26
60
  end
27
61
 
28
- it 'returns the correctly sized array' do
29
- OdeonUk::Internal::Website.stub :new, website do
30
- subject.size.must_equal 115
62
+ describe '#adr' do
63
+ subject { described_class.new(71).adr }
64
+
65
+ describe '(brighton)' do
66
+ before { website.expect(:cinema, cinema_html(71), [71]) }
67
+
68
+ it 'returns the address hash' do
69
+ OdeonUk::Html::Website.stub :new, website do
70
+ subject.must_equal(
71
+ street_address: 'Kingswest',
72
+ locality: 'Brighton',
73
+ postal_code: 'BN1 2RE',
74
+ country_name: 'United Kingdom'
75
+ )
76
+ end
77
+ end
31
78
  end
32
79
  end
33
- end
34
80
 
35
- describe '.find(id)' do
36
- subject { described_class.find(id) }
81
+ describe '#brand' do
82
+ subject { described_class.new(id).brand }
37
83
 
38
- describe 'Brighton' do
39
- let(:id) { 71 }
84
+ describe 'cinema name with London' do
85
+ let(:id) { 105 }
40
86
 
41
- before do
42
- website.expect(:sitemap, sitemap_html)
43
- # website.expect(:cinemas, cinema_html('brighton'), [71])
87
+ it 'removes "London" name prefix' do
88
+ subject.must_equal 'Odeon'
89
+ end
44
90
  end
91
+ end
45
92
 
46
- it 'returns a cinema' do
47
- OdeonUk::Internal::Website.stub :new, website do
48
- subject.must_be_instance_of(described_class)
93
+ describe '#full_name' do
94
+ subject { described_class.new(71).full_name }
49
95
 
50
- subject.id.must_equal 71
51
- subject.brand.must_equal 'Odeon'
52
- subject.name.must_equal 'Brighton'
53
- subject.slug.must_equal 'brighton'
54
- subject.url.must_equal 'http://www.odeon.co.uk/cinemas/brighton/71/'
96
+ describe 'simple name (brighton)' do
97
+ before { website.expect(:sitemap, sitemap_html) }
98
+
99
+ it 'returns the brand in the name' do
100
+ OdeonUk::Html::Website.stub :new, website do
101
+ subject.must_equal 'Odeon Brighton'
102
+ end
55
103
  end
56
104
  end
57
105
  end
58
- end
59
106
 
60
- describe '.new' do
61
- it 'removes "London" name prefix' do
62
- cinema = OdeonUk::Cinema.new 79, 'London - Leicester Square', '/cinemas/london_leicester_square/105/'
63
- cinema.id.must_equal 79
64
- cinema.name.must_equal 'Leicester Square'
65
- cinema.slug.must_equal 'leicester-square'
107
+ describe '#locality' do
108
+ subject { described_class.new(71).locality }
109
+
110
+ before { website.expect(:cinema, cinema_html(71), [71]) }
111
+
112
+ it 'returns town name' do
113
+ OdeonUk::Html::Website.stub :new, website do
114
+ subject.must_equal 'Brighton'
115
+ end
116
+ end
66
117
  end
67
118
 
68
- it 'removes " - " and replaces it with a colon ": "' do
69
- cinema = OdeonUk::Cinema.new 208, 'Whiteleys - The Lounge', '/cinemas/whiteleys_the_lounge/208/'
70
- cinema.id.must_equal 208
71
- cinema.name.must_equal 'Whiteleys: The Lounge'
72
- cinema.slug.must_equal 'whiteleys-the-lounge'
119
+ describe '#name' do
120
+ subject { described_class.new(id).name }
121
+
122
+ before { website.expect(:sitemap, sitemap_html) }
123
+
124
+ describe 'cinema name with London' do
125
+ let(:id) { 105 }
126
+
127
+ it 'removes "London" name prefix' do
128
+ OdeonUk::Html::Website.stub :new, website do
129
+ subject.must_equal 'Leicester Square'
130
+ end
131
+ end
132
+ end
133
+
134
+ describe 'cinema name with dashes' do
135
+ let(:id) { 208 }
136
+
137
+ it 'removes " - " and replaces it with a colon ": "' do
138
+ OdeonUk::Html::Website.stub :new, website do
139
+ subject.must_equal 'Whiteleys: The Lounge'
140
+ end
141
+ end
142
+ end
73
143
  end
74
- end
75
144
 
76
- describe '#adr' do
77
- subject { cinema.adr }
145
+ describe '#postal_code' do
146
+ subject { described_class.new(id).postal_code }
147
+
148
+ describe 'short address' do
149
+ let(:id) { 71 }
78
150
 
79
- describe '(brighton)' do
80
- let(:cinema) do
81
- described_class.new(71, 'Brighton', '/cinemas/brighton/71/')
151
+ before { website.expect(:cinema, cinema_html(71), [71]) }
152
+
153
+ it 'returns the postcode' do
154
+ OdeonUk::Html::Website.stub :new, website do
155
+ subject.must_equal 'BN1 2RE'
156
+ end
157
+ end
82
158
  end
83
159
 
84
- before do
85
- website.expect(:cinema, cinema_html('brighton'), [71])
160
+ describe 'short address (London)' do
161
+ let(:id) { 211 }
162
+
163
+ before { website.expect(:cinema, cinema_html(211), [211]) }
164
+
165
+ it 'returns the postcode' do
166
+ OdeonUk::Html::Website.stub :new, website do
167
+ subject.must_equal 'SE1 8XR'
168
+ end
169
+ end
86
170
  end
87
171
 
88
- it 'returns the address hash' do
89
- OdeonUk::Internal::Website.stub :new, website do
90
- subject.must_equal(
91
- street_address: 'Kingswest',
92
- locality: 'Brighton',
93
- postal_code: 'BN1 2RE',
94
- country: 'United Kingdom'
95
- )
172
+ describe 'short address (extra London Postcode)' do
173
+ let(:id) { 105 }
174
+
175
+ before { website.expect(:cinema, cinema_html(105), [105]) }
176
+
177
+ it 'returns the postcode' do
178
+ OdeonUk::Html::Website.stub :new, website do
179
+ subject.must_equal 'WC2H 7LQ'
180
+ end
96
181
  end
97
182
  end
98
183
  end
99
- end
100
184
 
101
- describe '#films' do
102
- subject { cinema.films }
185
+ describe '#screenings' do
186
+ subject { described_class.new(71).screenings }
103
187
 
104
- let(:cinema) do
105
- described_class.new(71, 'Brighton', '/cinemas/brighton/71/')
188
+ it 'calls out to Screening object' do
189
+ OdeonUk::Screening.stub :at, [:screening] do
190
+ subject.must_equal([:screening])
191
+ end
192
+ end
106
193
  end
107
194
 
108
- it 'calls out to Screening object' do
109
- OdeonUk::Film.stub :at, [:film] do
110
- subject.must_equal([:film])
195
+ describe '#slug' do
196
+ subject { described_class.new(71).slug }
197
+
198
+ describe 'simple name (brighton)' do
199
+ before { website.expect(:sitemap, sitemap_html) }
200
+
201
+ it 'returns the brand in the name' do
202
+ OdeonUk::Html::Website.stub :new, website do
203
+ subject.must_equal 'odeon-brighton'
204
+ end
205
+ end
111
206
  end
112
207
  end
113
- end
114
208
 
115
- describe '#full_name' do
116
- subject { cinema.full_name }
209
+ describe '#street_address' do
210
+ subject { described_class.new(id).street_address }
117
211
 
118
- describe 'simple name (brighton)' do
119
- let(:cinema) do
120
- OdeonUk::Cinema.new('71', 'Brighton', '/cinemas/brighton/71/')
121
- end
212
+ describe 'short address' do
213
+ let(:id) { 71 }
122
214
 
123
- before do
124
- website.expect(:cinema, cinema_html('brighton'), [71])
215
+ before { website.expect(:cinema, cinema_html(71), [71]) }
216
+
217
+ it 'returns first line of address' do
218
+ OdeonUk::Html::Website.stub :new, website do
219
+ subject.must_equal 'Kingswest'
220
+ end
221
+ end
125
222
  end
223
+ end
126
224
 
127
- it 'returns the brand in the name' do
128
- OdeonUk::Internal::Website.stub :new, website do
129
- subject.must_equal 'Odeon Brighton'
225
+ describe '#url' do
226
+ subject { described_class.new(71).url }
227
+
228
+ describe 'brighton' do
229
+ before { website.expect(:sitemap, sitemap_html) }
230
+
231
+ it 'returns the brand in the name' do
232
+ OdeonUk::Html::Website.stub :new, website do
233
+ subject.must_equal 'http://www.odeon.co.uk/cinemas/brighton/71/'
234
+ end
130
235
  end
131
236
  end
132
237
  end
133
238
  end
134
239
 
135
- describe '#locality' do
136
- subject { cinema.locality }
240
+ describe 'with API parsing' do
241
+ include ApiFixturesHelper
242
+
243
+ before do
244
+ OdeonUk.configure do |config|
245
+ config.method = :api
246
+ end
247
+ end
137
248
 
138
- describe 'short address' do
139
- let(:cinema) do
140
- OdeonUk::Cinema.new('71', 'Brighton', '/cinemas/brighton/71/')
249
+ after do
250
+ OdeonUk.configure do |config|
251
+ config.method = :html
141
252
  end
253
+ end
254
+
255
+ let(:response) { Minitest::Mock.new }
256
+
257
+ describe '.all' do
258
+ subject { described_class.all }
142
259
 
143
260
  before do
144
- website.expect(:cinema, cinema_html('brighton'), [71])
261
+ response.expect(:all_cinemas, parse(all_cinemas_plist))
145
262
  end
146
263
 
147
- it 'returns town name' do
148
- OdeonUk::Internal::Website.stub :new, website do
149
- subject.must_equal 'Brighton'
264
+ it 'returns an Array of OdeonUk::Cinemas' do
265
+ OdeonUk::Api::Response.stub :new, response do
266
+ subject.must_be_instance_of(Array)
267
+ subject.each do |value|
268
+ value.must_be_instance_of(described_class)
269
+ end
270
+ end
271
+ end
272
+
273
+ it 'returns the correctly sized array' do
274
+ OdeonUk::Api::Response.stub :new, response do
275
+ subject.size.must_equal 115
150
276
  end
151
277
  end
152
278
  end
153
- end
154
279
 
155
- describe '#postal_code' do
156
- subject { cinema.postal_code }
280
+ describe '.new(id)' do
281
+ subject { described_class.new(id) }
282
+
283
+ describe 'Brighton' do
284
+ let(:id) { 71 }
285
+
286
+ before do
287
+ response.expect(:all_cinemas, parse(all_cinemas_plist))
288
+ end
289
+
290
+ it 'returns a cinema' do
291
+ OdeonUk::Api::Response.stub :new, response do
292
+ subject.must_be_instance_of(described_class)
157
293
 
158
- describe 'short address' do
159
- let(:cinema) do
160
- OdeonUk::Cinema.new('71', 'Brighton', '/cinemas/brighton/71/')
294
+ subject.id.must_equal 71
295
+ subject.brand.must_equal 'Odeon'
296
+ subject.name.must_equal 'Brighton'
297
+ subject.slug.must_equal 'odeon-brighton'
298
+ subject.url.must_be_nil
299
+ end
300
+ end
161
301
  end
302
+ end
162
303
 
163
- before do
164
- website.expect(:cinema, cinema_html('brighton'), [71])
304
+ describe '#adr' do
305
+ subject { described_class.new(71).adr }
306
+
307
+ describe '(brighton)' do
308
+ before { response.expect(:all_cinemas, parse(all_cinemas_plist)) }
309
+
310
+ it 'returns the address hash' do
311
+ OdeonUk::Api::Response.stub :new, response do
312
+ subject.must_equal(
313
+ street_address: 'Kingswest',
314
+ locality: 'Brighton',
315
+ postal_code: 'BN1 2RE',
316
+ country_name: 'United Kingdom'
317
+ )
318
+ end
319
+ end
165
320
  end
321
+ end
322
+
323
+ describe '#brand' do
324
+ subject { described_class.new(id).brand }
325
+
326
+ describe 'cinema name with London' do
327
+ let(:id) { 105 }
166
328
 
167
- it 'returns the postcode' do
168
- OdeonUk::Internal::Website.stub :new, website do
169
- subject.must_equal 'BN1 2RE'
329
+ it 'removes "London" name prefix' do
330
+ subject.must_equal 'Odeon'
170
331
  end
171
332
  end
172
333
  end
173
334
 
174
- describe 'short address (London)' do
175
- let(:cinema) do
176
- OdeonUk::Cinema.new('211', 'BFI Imax', '/cinemas/bfi_imax/211/')
335
+ describe '#full_name' do
336
+ subject { described_class.new(71).full_name }
337
+
338
+ describe 'simple name (brighton)' do
339
+ before { response.expect(:all_cinemas, parse(all_cinemas_plist)) }
340
+
341
+ it 'returns the brand in the name' do
342
+ OdeonUk::Api::Response.stub :new, response do
343
+ subject.must_equal 'Odeon Brighton'
344
+ end
345
+ end
177
346
  end
347
+ end
178
348
 
179
- before do
180
- website.expect(:cinema, cinema_html('bfi_imax'), [211])
349
+ describe '#locality' do
350
+ subject { described_class.new(71).locality }
351
+
352
+ before { response.expect(:all_cinemas, parse(all_cinemas_plist)) }
353
+
354
+ it 'returns town name' do
355
+ OdeonUk::Api::Response.stub :new, response do
356
+ subject.must_equal 'Brighton'
357
+ end
181
358
  end
359
+ end
360
+
361
+ describe '#name' do
362
+ subject { described_class.new(id).name }
182
363
 
183
- it 'returns the postcode' do
184
- OdeonUk::Internal::Website.stub :new, website do
185
- subject.must_equal 'SE1 8XR'
364
+ before { response.expect(:all_cinemas, parse(all_cinemas_plist)) }
365
+
366
+ describe 'cinema name with London' do
367
+ let(:id) { 105 }
368
+
369
+ it 'removes "London" name prefix' do
370
+ OdeonUk::Api::Response.stub :new, response do
371
+ subject.must_equal 'Leicester Square'
372
+ end
373
+ end
374
+ end
375
+
376
+ describe 'cinema name with dashes' do
377
+ let(:id) { 208 }
378
+
379
+ it 'removes " - " and replaces it with a colon ": "' do
380
+ OdeonUk::Api::Response.stub :new, response do
381
+ subject.must_equal 'Whiteleys: The Lounge'
382
+ end
186
383
  end
187
384
  end
188
385
  end
189
386
 
190
- describe 'short address (extra London Postcode)' do
191
- let(:cinema) do
192
- OdeonUk::Cinema.new('105',
193
- 'Leicester Square',
194
- '/cinemas/london_leicester_square/105/')
387
+ describe '#postal_code' do
388
+ subject { described_class.new(id).postal_code }
389
+
390
+ describe 'short address' do
391
+ let(:id) { 71 }
392
+
393
+ before { response.expect(:all_cinemas, parse(all_cinemas_plist)) }
394
+
395
+ it 'returns the postcode' do
396
+ OdeonUk::Api::Response.stub :new, response do
397
+ subject.must_equal 'BN1 2RE'
398
+ end
399
+ end
195
400
  end
196
401
 
197
- before do
198
- website.expect(:cinema, cinema_html('leicester_square'), [105])
402
+ describe 'short address (London)' do
403
+ let(:id) { 211 }
404
+
405
+ before { response.expect(:all_cinemas, parse(all_cinemas_plist)) }
406
+
407
+ it 'returns the postcode' do
408
+ OdeonUk::Api::Response.stub :new, response do
409
+ subject.must_equal 'SE1 8XR'
410
+ end
411
+ end
199
412
  end
200
413
 
201
- it 'returns the postcode' do
202
- OdeonUk::Internal::Website.stub :new, website do
203
- subject.must_equal 'WC2H 7LQ'
414
+ describe 'short address (extra London Postcode)' do
415
+ let(:id) { 105 }
416
+
417
+ before { response.expect(:all_cinemas, parse(all_cinemas_plist)) }
418
+
419
+ it 'returns the postcode' do
420
+ OdeonUk::Api::Response.stub :new, response do
421
+ subject.must_equal 'WC2H 7LQ'
422
+ end
204
423
  end
205
424
  end
206
425
  end
207
- end
208
426
 
209
- describe '#screenings' do
210
- subject { cinema.screenings }
427
+ describe '#screenings' do
428
+ subject { described_class.new(71).screenings }
211
429
 
212
- let(:cinema) do
213
- described_class.new(71, 'Brighton', '/cinemas/brighton/71/')
430
+ it 'calls out to Screening object' do
431
+ OdeonUk::Screening.stub :at, [:screening] do
432
+ subject.must_equal([:screening])
433
+ end
434
+ end
214
435
  end
215
436
 
216
- it 'calls out to Screening object' do
217
- OdeonUk::Screening.stub :at, [:screening] do
218
- subject.must_equal([:screening])
437
+ describe '#slug' do
438
+ subject { described_class.new(71).slug }
439
+
440
+ describe 'simple name (brighton)' do
441
+ before { response.expect(:all_cinemas, parse(all_cinemas_plist)) }
442
+
443
+ it 'returns the brand in the name' do
444
+ OdeonUk::Api::Response.stub :new, response do
445
+ subject.must_equal 'odeon-brighton'
446
+ end
447
+ end
219
448
  end
220
449
  end
221
- end
222
450
 
223
- describe '#street_address' do
224
- subject { cinema.street_address }
451
+ describe '#street_address' do
452
+ subject { described_class.new(id).street_address }
225
453
 
226
- describe 'short address' do
227
- let(:cinema) do
228
- OdeonUk::Cinema.new('71', 'Brighton', '/cinemas/brighton/71/')
229
- end
454
+ describe 'short address' do
455
+ let(:id) { 71 }
230
456
 
231
- before do
232
- website.expect(:cinema, cinema_html('brighton'), [71])
233
- end
457
+ before { response.expect(:all_cinemas, parse(all_cinemas_plist)) }
234
458
 
235
- it 'returns first line of address' do
236
- OdeonUk::Internal::Website.stub :new, website do
237
- subject.must_equal 'Kingswest'
459
+ it 'returns first line of address' do
460
+ OdeonUk::Api::Response.stub :new, response do
461
+ subject.must_equal 'Kingswest'
462
+ end
238
463
  end
239
464
  end
240
465
  end
241
- end
242
466
 
243
- private
244
-
245
- def read_file(filepath)
246
- File.read(File.expand_path(filepath, __FILE__))
247
- end
467
+ describe '#url' do
468
+ subject { described_class.new(71).url }
248
469
 
249
- def sitemap_html
250
- read_file('../../../fixtures/sitemap.html')
251
- end
470
+ describe 'brighton' do
471
+ before { response.expect(:all_cinemas, parse(all_cinemas_plist)) }
252
472
 
253
- def cinema_html(filename)
254
- read_file("../../../fixtures/cinema/#{filename}.html")
473
+ it 'returns the brand in the name' do
474
+ OdeonUk::Api::Response.stub :new, response do
475
+ subject.must_be_nil
476
+ end
477
+ end
478
+ end
479
+ end
255
480
  end
256
481
  end
@@ -0,0 +1,29 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe OdeonUk do
4
+ describe '.configuration' do
5
+ describe '.method' do
6
+ it 'sets default value' do
7
+ OdeonUk.configuration.method.must_equal(:html)
8
+ end
9
+ end
10
+ end
11
+
12
+ describe '.configure' do
13
+ before do
14
+ OdeonUk.configure do |config|
15
+ config.method = :api
16
+ end
17
+ end
18
+
19
+ after do
20
+ OdeonUk.configure do |config|
21
+ config.method = :html
22
+ end
23
+ end
24
+
25
+ it 'sets the small words for the gem to downcase' do
26
+ OdeonUk.configuration.method.must_equal(:api)
27
+ end
28
+ end
29
+ end