picturehouse_uk 1.0.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -1
  3. data/CHANGELOG.md +18 -0
  4. data/README.md +7 -10
  5. data/Rakefile +20 -7
  6. data/lib/picturehouse_uk.rb +4 -1
  7. data/lib/picturehouse_uk/cinema.rb +51 -100
  8. data/lib/picturehouse_uk/film.rb +22 -8
  9. data/lib/picturehouse_uk/internal/address_parser.rb +72 -0
  10. data/lib/picturehouse_uk/internal/cinema_page.rb +35 -0
  11. data/lib/picturehouse_uk/internal/film_with_screenings_parser.rb +87 -37
  12. data/lib/picturehouse_uk/internal/title_sanitizer.rb +49 -0
  13. data/lib/picturehouse_uk/internal/website.rb +39 -0
  14. data/lib/picturehouse_uk/screening.rb +63 -19
  15. data/lib/picturehouse_uk/version.rb +2 -2
  16. data/picturehouse_uk.gemspec +11 -11
  17. data/test/fixture_updater.rb +43 -0
  18. data/test/fixtures/address-fragments/duke-of-yorks.html +39 -0
  19. data/test/fixtures/address-fragments/hackney-picturehouse.html +12 -0
  20. data/test/fixtures/cinema/Duke_Of_Yorks.html +4370 -0
  21. data/test/fixtures/cinema/Duke_Of_Yorks/film_last.html +45 -0
  22. data/test/fixtures/cinema/Duke_Of_Yorks/film_second.html +37 -0
  23. data/test/fixtures/{abbeygate-contact-us.html → contact_us/Duke_Of_Yorks.html} +635 -156
  24. data/test/fixtures/{dukes-at-komedia-contact-us.html → contact_us/Dukes_At_Komedia.html} +582 -98
  25. data/test/fixtures/{picturehouses-homepage.html → home.html} +642 -146
  26. data/test/lib/picturehouse_uk/cinema_test.rb +127 -307
  27. data/test/lib/picturehouse_uk/film_test.rb +65 -16
  28. data/test/lib/picturehouse_uk/internal/address_parser_test.rb +55 -0
  29. data/test/lib/picturehouse_uk/internal/cinema_page_test.rb +51 -0
  30. data/test/lib/picturehouse_uk/internal/film_with_screenings_parser_test.rb +44 -151
  31. data/test/lib/picturehouse_uk/internal/title_sanitizer_test.rb +131 -0
  32. data/test/lib/picturehouse_uk/internal/website_test.rb +64 -0
  33. data/test/lib/picturehouse_uk/screening_test.rb +149 -21
  34. data/test/live/integration_test.rb +68 -0
  35. data/test/test_helper.rb +3 -1
  36. metadata +40 -43
  37. data/test/fixtures/dukes-at-komedia-cinema.html +0 -7148
  38. data/test/fixtures/film_node/blue-jasmine-done.html +0 -53
  39. data/test/fixtures/film_node/blue-jasmine-future.html +0 -55
  40. data/test/fixtures/film_node/bolshoi-spartacus.html +0 -26
  41. data/test/fixtures/film_node/captain-phillips-with-silver-screen-and-subtitles.html +0 -103
  42. data/test/fixtures/film_node/fifth-estate-with-big-scream.html +0 -73
  43. data/test/fixtures/film_node/london-film-festival-with-toddler-time.html +0 -46
  44. data/test/fixtures/film_node/met-encore-rusalka-as-live.html +0 -26
  45. data/test/fixtures/film_node/nt-encore-hamlet.html +0 -26
  46. data/test/fixtures/film_node/planes-with-kids-club.html +0 -77
  47. data/test/fixtures/film_node/royal-opera-house-don-quixote.html +0 -26
  48. data/test/fixtures/film_node/rsc-encore-richard-ii.html +0 -28
  49. data/test/fixtures/film_node/rsc-live-richard-ii.html +0 -41
  50. data/test/fixtures/film_node/rsc-live-the-two-gentlemen-of-verona-zero-cert.html +0 -19
  51. data/test/fixtures/hackney-contact-us.html +0 -998
@@ -0,0 +1,131 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ describe PicturehouseUk::Internal::TitleSanitizer do
4
+ let(:described_class) { PicturehouseUk::Internal::TitleSanitizer }
5
+
6
+ describe '#sanitized' do
7
+ subject { described_class.new(title).sanitized }
8
+
9
+ describe 'with 2d in title' do
10
+ let(:title) { 'Iron Man 3 2D' }
11
+
12
+ it 'removes dimension' do
13
+ subject.must_equal('Iron Man 3')
14
+ end
15
+ end
16
+
17
+ describe 'with 3d in title' do
18
+ let(:title) { 'Iron Man 3 3d' }
19
+
20
+ it 'removes dimension' do
21
+ subject.must_equal('Iron Man 3')
22
+ end
23
+ end
24
+
25
+ describe 'with NO CERT in title' do
26
+ let(:title) { 'Iron Man 3 [NO CERT]' }
27
+
28
+ it 'removes dimension' do
29
+ subject.must_equal('Iron Man 3')
30
+ end
31
+ end
32
+
33
+ describe 'with blank cert in title' do
34
+ let(:title) { 'Iron Man 3 []' }
35
+
36
+ it 'removes dimension' do
37
+ subject.must_equal('Iron Man 3')
38
+ end
39
+ end
40
+
41
+ describe 'with cert in title' do
42
+ let(:title) { 'Beauty and the Beast 2D [U]' }
43
+
44
+ it 'removes dimension' do
45
+ subject.must_equal('Beauty and the Beast')
46
+ end
47
+ end
48
+
49
+ describe 'with (Re) in title' do
50
+ let(:title) { 'Beauty and the Beast 2D (Re) [U]' }
51
+
52
+ it 'removes dimension' do
53
+ subject.must_equal('Beauty and the Beast')
54
+ end
55
+ end
56
+
57
+ describe 'Bolshoi screening' do
58
+ let(:title) { 'Bolshoi: Spartacus [NO CERT]' }
59
+
60
+ it 'removes prefix' do
61
+ subject.must_equal('Bolshoi: Spartacus')
62
+ end
63
+ end
64
+
65
+ describe 'Glyndebourne' do
66
+ let(:title) do
67
+ 'Glyndebourne Tour 2014: The Cunning Little Vixen [CERT TBC]'
68
+ end
69
+
70
+ it 'removes certificate TBC' do
71
+ subject.must_equal 'Glyndebourne Tour 2014: The Cunning Little Vixen'
72
+ end
73
+ end
74
+
75
+ describe 'Met Opera screening' do
76
+ let(:title) { 'Met. Opera: Macbeth [NO CERT]' }
77
+
78
+ it 'removes prefix' do
79
+ subject.must_equal('Met Opera: Macbeth')
80
+ end
81
+ end
82
+
83
+ describe 'Met Opera screening v2' do
84
+ let(:title) { 'Met Opera: Rusalka [AS LIVE: 12A]' }
85
+
86
+ it 'removes prefix' do
87
+ subject.must_equal('Met Opera: Rusalka')
88
+ end
89
+ end
90
+
91
+ describe 'NT Live screening' do
92
+ let(:title) { 'National Theatre: Hamlet [PG]' }
93
+
94
+ it 'removes prefix' do
95
+ subject.must_equal('National Theatre: Hamlet')
96
+ end
97
+ end
98
+
99
+ describe 'ourscreen' do
100
+ let(:title) { 'ourscreen: Northern Soul [15]' }
101
+
102
+ it 'removes prefix' do
103
+ subject.must_equal('Northern Soul')
104
+ end
105
+ end
106
+
107
+ describe 're release' do
108
+ let(:title) { 'To Kill A Mockingbird (Re) [PG]' }
109
+
110
+ it 'removes rerelease notice' do
111
+ subject.must_equal('To Kill A Mockingbird')
112
+ end
113
+ end
114
+
115
+ describe 're release with year' do
116
+ let(:title) { 'Withnail & I (re: 2014) [15]' }
117
+
118
+ it 'removes rerelease notice' do
119
+ subject.must_equal('Withnail & I')
120
+ end
121
+ end
122
+
123
+ describe 'Royal Opera House screening' do
124
+ let(:title) { 'Royal Shakespeare Company: Richard II [NO CERT]' }
125
+
126
+ it 'removes prefix' do
127
+ subject.must_equal('Royal Shakespeare Company: Richard II')
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,64 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ describe PicturehouseUk::Internal::Website do
4
+ let(:described_class) { PicturehouseUk::Internal::Website }
5
+
6
+ describe '#cinema(id)' do
7
+ subject { described_class.new.cinema('Duke_Of_Yorks') }
8
+
9
+ before { stub_get('cinema/Duke_Of_Yorks/', duke_of_yorks_html) }
10
+
11
+ it 'returns a string' do
12
+ subject.class.must_equal String
13
+ end
14
+ end
15
+
16
+ describe '#contact_us(id)' do
17
+ subject { described_class.new.contact_us('Duke_Of_Yorks') }
18
+
19
+ before do
20
+ stub_get(
21
+ 'cinema/Duke_Of_Yorks/Hires_Info/Contact_Us/',
22
+ duke_of_yorks_contact_us_html
23
+ )
24
+ end
25
+
26
+ it 'returns a string' do
27
+ subject.class.must_equal String
28
+ end
29
+ end
30
+
31
+ describe '#home' do
32
+ subject { described_class.new.home }
33
+
34
+ before { stub_get('', home_html) }
35
+
36
+ it 'returns a string' do
37
+ subject.class.must_equal String
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def duke_of_yorks_html
44
+ read_file('../../../../fixtures/cinema/Duke_Of_Yorks.html')
45
+ end
46
+
47
+ def duke_of_yorks_contact_us_html
48
+ read_file('../../../../fixtures/contact_us/Duke_Of_Yorks.html')
49
+ end
50
+
51
+ def home_html
52
+ read_file('../../../../fixtures/home.html')
53
+ end
54
+
55
+ def read_file(filepath)
56
+ File.read(File.expand_path(filepath, __FILE__))
57
+ end
58
+
59
+ def stub_get(site_path, response_body)
60
+ url = "http://www.picturehouses.co.uk/#{site_path}"
61
+ response = { status: 200, body: response_body, headers: {} }
62
+ stub_request(:get, url).to_return(response)
63
+ end
64
+ end
@@ -1,41 +1,169 @@
1
1
  require_relative '../../test_helper'
2
2
 
3
3
  describe PicturehouseUk::Screening do
4
+ let(:website) { MockWebsite.new }
4
5
 
5
6
  before { WebMock.disable_net_connect! }
6
7
 
7
- describe '#new film_name, cinema_name, date, time, variant' do
8
- it 'stores film_name, cinema_name & when (in UTC)' do
9
- screening = PicturehouseUk::Screening.new 'Iron Man 3', "Duke's At Komedia", Time.parse('2013-09-12 11:00')
10
- screening.film_name.must_equal 'Iron Man 3'
11
- screening.cinema_name.must_equal "Duke's At Komedia"
12
- screening.when.must_equal Time.utc(2013, 9, 12, 10, 0)
13
- screening.variant.must_equal nil
8
+ describe '.at(cinema_id)' do
9
+ subject { PicturehouseUk::Screening.at('Duke_Of_Yorks') }
10
+
11
+ it 'returns an array of screenings' do
12
+ PicturehouseUk::Internal::Website.stub :new, website do
13
+ subject.must_be_instance_of(Array)
14
+ subject.each do |screening|
15
+ screening.must_be_instance_of(PicturehouseUk::Screening)
16
+ end
17
+ end
18
+ end
19
+
20
+ it 'returns correct number of screenings' do
21
+ PicturehouseUk::Internal::Website.stub :new, website do
22
+ subject.count.must_equal 33
23
+ end
24
+ end
25
+ end
26
+
27
+ describe '.new' do
28
+ subject { PicturehouseUk::Screening.new(options) }
29
+
30
+ describe 'simple' do
31
+ let(:options) do
32
+ {
33
+ film_name: 'Iron Man 3',
34
+ cinema_id: 3,
35
+ cinema_name: 'Cineworld Brighton',
36
+ time: Time.utc(2013, 9, 12, 11, 0)
37
+ }
38
+ end
39
+
40
+ it 'sets cinema name and film name' do
41
+ subject.film_name.must_equal 'Iron Man 3'
42
+ subject.cinema_name.must_equal 'Cineworld Brighton'
43
+ end
44
+
45
+ it 'booking url, dimension & varient are set to defaults' do
46
+ subject.booking_url.must_equal nil
47
+ subject.dimension.must_equal '2d'
48
+ subject.variant.must_equal []
49
+ end
50
+ end
51
+ end
52
+
53
+ describe '#dimension' do
54
+ let(:options) do
55
+ {
56
+ film_name: 'Iron Man 3',
57
+ dimension: '3d',
58
+ cinema_id: 3,
59
+ cinema_name: 'Cineworld Brighton',
60
+ time: Time.utc(2013, 9, 12, 11, 0)
61
+ }
14
62
  end
15
63
 
16
- it 'stores variant if passed' do
17
- screening = PicturehouseUk::Screening.new 'Iron Man 3', "Duke's At Komedia", Time.utc(2013, 9, 12, 11, 0), 'baby'
18
- screening.film_name.must_equal 'Iron Man 3'
19
- screening.cinema_name.must_equal "Duke's At Komedia"
20
- screening.when.must_equal Time.utc(2013, 9, 12, 11, 0)
21
- screening.variant.must_equal 'baby'
64
+ subject { PicturehouseUk::Screening.new(options).dimension }
65
+
66
+ it 'returns 2d or 3d' do
67
+ subject.must_be_instance_of(String)
68
+ subject.must_equal '3d'
22
69
  end
23
70
  end
24
71
 
25
- describe '#date' do
26
- subject { PicturehouseUk::Screening.new('Iron Man 3', "Duke's At Komedia", Time.utc(2013, 9, 12, 11, 0), '3d').date }
27
- it 'should return date of showing' do
72
+ describe '#showing_at' do
73
+ subject { PicturehouseUk::Screening.new(options).showing_at }
74
+
75
+ describe 'with utc time' do
76
+ let(:options) do
77
+ {
78
+ film_name: 'Iron Man 3',
79
+ cinema_id: 3,
80
+ cinema_name: 'Cineworld Brighton',
81
+ time: Time.utc(2013, 9, 12, 11, 0)
82
+ }
83
+ end
84
+
85
+ it 'returns UTC time' do
86
+ subject.must_be_instance_of Time
87
+ subject.must_equal Time.utc(2013, 9, 12, 11, 0)
88
+ end
89
+ end
90
+
91
+ describe 'with non-utc time' do
92
+ let(:options) do
93
+ {
94
+ film_name: 'Iron Man 3',
95
+ cinema_id: 3,
96
+ cinema_name: 'Cineworld Brighton',
97
+ time: Time.parse('2013-09-12 11:00')
98
+ }
99
+ end
100
+
101
+ it 'returns UTC time' do
102
+ subject.must_be_instance_of Time
103
+ subject.must_equal Time.utc(2013, 9, 12, 10, 0)
104
+ end
105
+ end
106
+ end
107
+
108
+ describe '#showing_on' do
109
+ let(:options) do
110
+ {
111
+ film_name: 'Iron Man 3',
112
+ cinema_id: 3,
113
+ cinema_name: 'Cineworld Brighton',
114
+ time: Time.utc(2013, 9, 12, 11, 0)
115
+ }
116
+ end
117
+
118
+ subject { PicturehouseUk::Screening.new(options).showing_on }
119
+
120
+ it 'returns date of showing' do
28
121
  subject.must_be_instance_of(Date)
29
122
  subject.must_equal Date.new(2013, 9, 12)
30
123
  end
31
124
  end
32
125
 
33
- describe '#varient (DEPRECATED)' do
34
- subject { screening.varient }
35
- let(:screening) { PicturehouseUk::Screening.new('Iron Man 3', "Duke's At Komedia", Time.utc(2013, 9, 12, 11, 0), '3d') }
126
+ describe '#variant' do
127
+ subject { PicturehouseUk::Screening.new(options).variant }
36
128
 
37
- it 'should return variant' do
38
- subject.must_equal '3d'
129
+ let(:options) do
130
+ {
131
+ film_name: 'Iron Man 3',
132
+ cinema_id: 3,
133
+ cinema_name: 'Cineworld Brighton',
134
+ time: Time.utc(2013, 9, 12, 11, 0),
135
+ variant: ['Kids']
136
+ }
137
+ end
138
+
139
+ it 'is an alphabetically ordered array of lower-cased strings' do
140
+ subject.must_be_instance_of Array
141
+ subject.each do |tag|
142
+ tag.must_be_instance_of String
143
+ end
144
+ subject.must_equal %w(kids)
145
+ end
146
+ end
147
+
148
+ private
149
+
150
+ class MockWebsite
151
+ def home
152
+ read_file('../../../fixtures/home.html')
153
+ end
154
+
155
+ def cinema(filename)
156
+ read_file("../../../fixtures/cinema/#{filename}.html")
157
+ end
158
+
159
+ def contact_us(filename)
160
+ read_file("../../../fixtures/contact_us/#{filename}.html")
161
+ end
162
+
163
+ private
164
+
165
+ def read_file(filepath)
166
+ File.read(File.expand_path(filepath, __FILE__))
39
167
  end
40
168
  end
41
169
  end
@@ -0,0 +1,68 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/reporters'
3
+ reporter_options = { color: true, slow_count: 5 }
4
+ Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(reporter_options)]
5
+
6
+ require File.expand_path('../../../lib/picturehouse_uk.rb', __FILE__)
7
+
8
+ describe PicturehouseUk::Cinema do
9
+ let(:described_class) { PicturehouseUk::Cinema }
10
+
11
+ describe '.all' do
12
+ subject { described_class.all }
13
+
14
+ it 'returns an Array of CineworldUK::Cinemas' do
15
+ subject.must_be_instance_of(Array)
16
+ subject.each do |value|
17
+ value.must_be_instance_of(PicturehouseUk::Cinema)
18
+ end
19
+ end
20
+
21
+ it 'returns the correctly sized array' do
22
+ subject.size.must_be :>, 18
23
+ end
24
+
25
+ it 'returns the right cinemas' do
26
+ subject.first.name.must_equal 'Clapham Picturehouse'
27
+ subject.last.name.must_equal 'City Screen Picturehouse'
28
+ end
29
+ end
30
+ end
31
+
32
+ describe PicturehouseUk::Film do
33
+ let(:described_class) { PicturehouseUk::Film }
34
+
35
+ describe '.at(cinema_id)' do
36
+ subject { described_class.at('Duke_Of_Yorks') }
37
+
38
+ it 'returns an array of films' do
39
+ subject.must_be_instance_of(Array)
40
+ subject.each do |film|
41
+ film.must_be_instance_of(PicturehouseUk::Film)
42
+ end
43
+ end
44
+
45
+ it 'returns a decent number of films' do
46
+ subject.count.must_be :>, 5
47
+ end
48
+ end
49
+ end
50
+
51
+ describe PicturehouseUk::Screening do
52
+ let(:described_class) { PicturehouseUk::Screening }
53
+
54
+ describe '.at(cinema_id)' do
55
+ subject { described_class.at('Duke_Of_Yorks') }
56
+
57
+ it 'returns an array of screenings' do
58
+ subject.must_be_instance_of(Array)
59
+ subject.each do |screening|
60
+ screening.must_be_instance_of(PicturehouseUk::Screening)
61
+ end
62
+ end
63
+
64
+ it 'returns correct number of screenings' do
65
+ subject.count.must_be :>, 10
66
+ end
67
+ end
68
+ end