poms 0.0.10 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Poms::Builder do
4
-
5
4
  let(:poms_broadcast) { Fabricate(:poms_broadcast) }
6
5
 
7
6
  it 'correctly sets the class of a POMS broadcast hash' do
@@ -13,7 +12,42 @@ describe Poms::Builder do
13
12
  end
14
13
 
15
14
  it 'correctly converts start times to Time-object' do
16
- expect(poms_broadcast.schedule_events.first.start).to eq(Time.parse '2013-05-28 18:08:55 +0200')
15
+ expect(poms_broadcast.schedule_events.first.start)
16
+ .to eq(Time.parse '2013-05-28 18:08:55 +0200')
17
+ end
18
+
19
+ describe '.pomsify_class_name' do
20
+ it 'returns "Typeless" for nothing' do
21
+ expect(described_class.pomsify_class_name(''))
22
+ .to eq('Typeless')
23
+ end
24
+
25
+ it 'returns a supported class' do
26
+ expect(described_class.pomsify_class_name('Broadcast'))
27
+ .to eq('Broadcast')
28
+ end
29
+
30
+ it 'preprends Poms to an unsupported class' do
31
+ expect(described_class.pomsify_class_name('Other'))
32
+ .to eq('PomsOther')
33
+ end
34
+
35
+ it 'capitalizes' do
36
+ expect(described_class.pomsify_class_name('broadcast'))
37
+ .to eq('Broadcast')
38
+ end
17
39
  end
18
40
 
41
+ describe '.poms_class' do
42
+ it 'gets the Poms class if it exists' do
43
+ expect(described_class.poms_class('Broadcast'))
44
+ .to eq(Poms::Broadcast)
45
+ end
46
+
47
+ it 'sets a NestedOpenStruct if it does not exist' do
48
+ poms_other = described_class.poms_class('PomsOther')
49
+ expect(poms_other).to eq(Poms::PomsOther)
50
+ expect(poms_other.ancestors).to include(Poms::Builder::NestedOpenStruct)
51
+ end
52
+ end
19
53
  end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Poms::MergedSeries do
4
+ let(:url) { described_class::API_URL }
5
+
6
+ it 'turns the json into a hash' do
7
+ mids = subject.serie_mids
8
+ expect(mids.keys).to include('POMS_S_EO_097367')
9
+ expect(mids.values).to include('VPWON_1257896')
10
+ end
11
+
12
+ it 'throws an error on a network error' do
13
+ FakeWeb.register_uri(:get, url, body:
14
+ '', status: 500)
15
+ expect { subject.serie_mids }.to raise_error(Poms::PomsError)
16
+ end
17
+
18
+ it 'throws an error on invalid json' do
19
+ FakeWeb.register_uri(:get, url, body:
20
+ 'Test')
21
+ expect { subject.serie_mids }.to raise_error(Poms::PomsError)
22
+ end
23
+
24
+ it 'throws an error on timeout' do
25
+ allow(Timeout).to receive(:timeout).and_raise(Timeout::Error)
26
+ expect { subject.serie_mids }.to raise_error(Poms::PomsError)
27
+ end
28
+ end
@@ -2,14 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  describe Poms::ScheduleEvent do
4
4
  let(:poms_broadcast) { Fabricate(:poms_broadcast) }
5
- let(:schedule_event) {poms_broadcast.schedule_events.first}
5
+ let(:schedule_event) { poms_broadcast.schedule_events.first }
6
6
 
7
7
  it 'sets the start time' do
8
- expect(schedule_event.starts_at).to eq(Time.parse '2013-05-28 18:08:55 +0200')
8
+ expect(schedule_event.starts_at)
9
+ .to eq(Time.parse '2013-05-28 18:08:55 +0200')
9
10
  end
10
11
 
11
12
  it 'knows the end time' do
12
13
  expect(schedule_event.ends_at).to eq(Time.parse '2013-05-28 18:26:24 +0200')
13
14
  end
14
-
15
15
  end
@@ -1,19 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Poms::Views do
4
- describe "#get" do
5
- let(:response) { File.read 'spec/fixtures/poms_broadcast.json' }
4
+ describe '#get' do
5
+ let(:response) { File.read 'spec/fixtures/poms_broadcast.json' }
6
6
 
7
7
  it 'returns a metadata object' do
8
- FakeWeb.register_uri(:get, "http://docs.poms.omroep.nl/media/KRO_1614405", :body => response)
8
+ FakeWeb.register_uri(:get, 'http://docs.poms.omroep.nl/media/KRO_1614405',
9
+ body: response)
9
10
  expect(subject.get('KRO_1614405')).to eq(JSON.parse response)
10
11
  end
11
12
  end
12
13
 
13
- describe "#by_group" do
14
-
14
+ describe '#by_group' do
15
15
  it 'returns the correct group url' do
16
- expect(subject.by_group('POMS_S_NPO_823012')).to eq("http://docs.poms.omroep.nl/media/_design/media/_view/by-group?include_docs=true&key=%22POMS_S_NPO_823012%22&reduce=false")
16
+ expect(subject.by_group('POMS_S_NPO_823012')).to eq('http://docs.poms.omroep.nl/media/_design/media/_view/by-group?include_docs=true&key=%22POMS_S_NPO_823012%22&reduce=false')
17
17
  end
18
18
  end
19
19
  end
@@ -2,25 +2,24 @@ require 'timecop'
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Poms do
5
-
6
5
  describe '#fetch' do
7
-
8
6
  let(:response) { File.read 'spec/fixtures/poms_broadcast.json' }
9
7
 
10
8
  before do
11
- FakeWeb.register_uri(:get, "http://docs.poms.omroep.nl/media/KRO_1614405", :body => response)
9
+ FakeWeb.register_uri(:get, 'http://docs.poms.omroep.nl/media/KRO_1614405',
10
+ body: response)
12
11
  end
13
12
 
14
- it "fetches a broadcast" do
15
- expect(Poms.fetch_raw_json('KRO_1614405')).to eq(JSON.parse response)
13
+ it 'fetches a broadcast' do
14
+ expect(Poms.fetch_raw_json('KRO_1614405')).to eq(JSON.parse response)
16
15
  end
17
16
 
18
- it "fetches a broadcast and parses it correctly" do
17
+ it 'fetches a broadcast and parses it correctly' do
19
18
  expect(Poms::Builder).to receive(:process_hash).with(JSON.parse response)
20
19
  Poms.fetch('KRO_1614405')
21
20
  end
22
21
 
23
- it "fetches a group" do
22
+ it 'fetches a group' do
24
23
  response = File.read 'spec/fixtures/poms_broadcast.json'
25
24
  url = 'http://docs.poms.omroep.nl/media/_design/media/_view/by-group?include_docs=true&key=%22POMS_S_NPO_823012%22&reduce=false'
26
25
  FakeWeb.register_uri(:get, url, body: response)
@@ -28,7 +27,8 @@ describe Poms do
28
27
  end
29
28
 
30
29
  it 'returns nil when a broadcast does not exits' do
31
- FakeWeb.register_uri(:get, "http://docs.poms.omroep.nl/media/BLA", :status => [404, "Not Found"])
30
+ FakeWeb.register_uri(:get, 'http://docs.poms.omroep.nl/media/BLA',
31
+ status: [404, 'Not Found'])
32
32
  expect(Poms.fetch('BLA')).to eq(nil)
33
33
  end
34
34
  end
@@ -41,33 +41,35 @@ describe Poms do
41
41
 
42
42
  describe '#fetch_broadcasts_for_serie' do
43
43
  it 'returns nil when a broadcast does not exist' do
44
- FakeWeb.register_uri(:get, "http://docs.poms.omroep.nl/media/_design/media/_view/by-ancestor-and-type?reduce=false&key=[%22BLA%22,%22BROADCAST%22]&include_docs=true", :status => [404, "Not Found"])
44
+ FakeWeb.register_uri(:get, 'http://docs.poms.omroep.nl/media/_design/media/_view/by-ancestor-and-type?reduce=false&key=[%22BLA%22,%22BROADCAST%22]&include_docs=true',
45
+ status: [404, 'Not Found'])
45
46
  expect(Poms.fetch_broadcasts_for_serie('BLA')).to eq([])
46
47
  end
47
48
  end
48
49
 
49
-
50
50
  describe '#upcoming_broadcasts' do
51
51
  let(:response) { File.read 'spec/fixtures/poms_zapp.json' }
52
52
  let(:start_time) { Time.parse '2013-05-28 17:32:10 +0200' }
53
53
  let(:end_time) { Time.parse '2013-06-11 17:32:50 +0200' }
54
54
 
55
55
  before do
56
- path = "http://docs.poms.omroep.nl/media/_design/media/_view/broadcasts-by-broadcaster-and-start?startkey=[%22Zapp%22,1369755130000]&endkey=[%22Zapp%22,1370964770000]&reduce=false&include_docs=true"
57
- FakeWeb.register_uri(:get, path, :body => response)
56
+ path = 'http://docs.poms.omroep.nl/media/_design/media/_view/broadcasts-by-broadcaster-and-start?startkey=[%22Zapp%22,1369755130000]&endkey=[%22Zapp%22,1370964770000]&reduce=false&include_docs=true'
57
+ FakeWeb.register_uri(:get, path, body: response)
58
58
  end
59
59
 
60
- it "fetches all broadcast by zapp and parses it correctly" do
60
+ it 'fetches all broadcast by zapp and parses it correctly' do
61
61
  expect(Poms::Builder).to receive(:process_hash).exactly(136).times
62
62
  Poms.upcoming_broadcasts('zapp', start_time, end_time)
63
63
  end
64
64
  end
65
65
 
66
66
  describe 'fetch broadcasts' do
67
- let(:response) { File.read 'spec/fixtures/poms_single_broadcast_by_channel.json' }
67
+ let(:response) do
68
+ File.read 'spec/fixtures/poms_single_broadcast_by_channel.json'
69
+ end
68
70
 
69
71
  before do
70
- Timecop.freeze(DateTime.strptime("1410969127",'%s'))
72
+ Timecop.freeze(DateTime.strptime('1410969127', '%s'))
71
73
  end
72
74
 
73
75
  after do
@@ -76,11 +78,11 @@ describe Poms do
76
78
 
77
79
  describe '#fetch_current_broadcast' do
78
80
  before do
79
- path = "http://docs.poms.omroep.nl/media/_design/media/_view/broadcasts-by-channel-and-start?startkey=[%22NED3%22,1410969127000]&endkey=[%22NED3%22,1410882727000]&reduce=false&include_docs=true&descending=true&limit=1"
80
- FakeWeb.register_uri(:get, path, :body => response)
81
+ path = 'http://docs.poms.omroep.nl/media/_design/media/_view/broadcasts-by-channel-and-start?startkey=[%22NED3%22,1410969127000]&endkey=[%22NED3%22,1410882727000]&reduce=false&include_docs=true&descending=true&limit=1'
82
+ FakeWeb.register_uri(:get, path, body: response)
81
83
  end
82
84
 
83
- it "fetches the current broadcast" do
85
+ it 'fetches the current broadcast' do
84
86
  expect(Poms::Builder).to receive(:process_hash).exactly(0).times
85
87
  Poms.fetch_current_broadcast('NED3')
86
88
  end
@@ -88,27 +90,28 @@ describe Poms do
88
90
 
89
91
  describe '#fetch_current_broadcast_and_key' do
90
92
  before do
91
- path = "http://docs.poms.omroep.nl/media/_design/media/_view/broadcasts-by-channel-and-start?startkey=[%22NED3%22,1410969127000]&endkey=[%22NED3%22,1410882727000]&reduce=false&include_docs=true&descending=true&limit=1"
92
- FakeWeb.register_uri(:get, path, :body => response)
93
+ path = 'http://docs.poms.omroep.nl/media/_design/media/_view/broadcasts-by-channel-and-start?startkey=[%22NED3%22,1410969127000]&endkey=[%22NED3%22,1410882727000]&reduce=false&include_docs=true&descending=true&limit=1'
94
+ FakeWeb.register_uri(:get, path, body: response)
93
95
  end
94
96
 
95
- it "fetches the current broadcast" do
97
+ it 'fetches the current broadcast' do
96
98
  expect(Poms::Builder).to receive(:process_hash).exactly(1).times
97
99
  Poms.fetch_current_broadcast_and_key('NED3')
98
100
  end
99
101
 
100
- it "returns the key" do
101
- expect(Poms.fetch_current_broadcast_and_key('NED3')[:key]).to eq(["NED3",1410966671000])
102
+ it 'returns the key' do
103
+ expect(Poms.fetch_current_broadcast_and_key('NED3')[:key])
104
+ .to eq(['NED3', 1_410_966_671_000])
102
105
  end
103
106
  end
104
107
 
105
108
  describe '#fetch_next_broadcast' do
106
109
  before do
107
- path = "http://docs.poms.omroep.nl/media/_design/media/_view/broadcasts-by-channel-and-start?startkey=[%22NED3%22,1410969127000]&endkey=[%22NED3%22,1411055527000]&reduce=false&include_docs=true&limit=1"
108
- FakeWeb.register_uri(:get, path, :body => response)
110
+ path = 'http://docs.poms.omroep.nl/media/_design/media/_view/broadcasts-by-channel-and-start?startkey=[%22NED3%22,1410969127000]&endkey=[%22NED3%22,1411055527000]&reduce=false&include_docs=true&limit=1'
111
+ FakeWeb.register_uri(:get, path, body: response)
109
112
  end
110
113
 
111
- it "fetches the next broadcast" do
114
+ it 'fetches the next broadcast' do
112
115
  expect(Poms::Builder).to receive(:process_hash).exactly(1).times
113
116
  Poms.fetch_next_broadcast('NED3')
114
117
  end
@@ -116,19 +119,19 @@ describe Poms do
116
119
 
117
120
  describe '#fetch_next_broadcast_and_key' do
118
121
  before do
119
- path = "http://docs.poms.omroep.nl/media/_design/media/_view/broadcasts-by-channel-and-start?startkey=[%22NED3%22,1410969127000]&endkey=[%22NED3%22,1411055527000]&reduce=false&include_docs=true&descending=true&limit=1"
120
- FakeWeb.register_uri(:get, path, :body => response)
122
+ path = 'http://docs.poms.omroep.nl/media/_design/media/_view/broadcasts-by-channel-and-start?startkey=[%22NED3%22,1410969127000]&endkey=[%22NED3%22,1411055527000]&reduce=false&include_docs=true&descending=true&limit=1'
123
+ FakeWeb.register_uri(:get, path, body: response)
121
124
  end
122
125
 
123
- it "fetches the current broadcast" do
126
+ it 'fetches the current broadcast' do
124
127
  expect(Poms::Builder).to receive(:process_hash).exactly(1).times
125
128
  Poms.fetch_next_broadcast_and_key('NED3')
126
129
  end
127
130
 
128
- it "returns the key" do
129
- expect(Poms.fetch_next_broadcast_and_key('NED3')[:key]).to eq(["NED3",1410966671000])
131
+ it 'returns the key' do
132
+ expect(Poms.fetch_next_broadcast_and_key('NED3')[:key])
133
+ .to eq(['NED3', 1_410_966_671_000])
130
134
  end
131
135
  end
132
136
  end
133
-
134
137
  end
@@ -9,7 +9,7 @@ require 'poms' # and any other gems you need
9
9
  FakeWeb.allow_net_connect = false
10
10
 
11
11
  VCR.configure do |config|
12
- config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
12
+ config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
13
13
  config.hook_into :fakeweb
14
14
  end
15
15
 
@@ -19,7 +19,9 @@ RSpec.configure do |config|
19
19
  if options[:record] == :skip
20
20
  VCR.turned_off(&example)
21
21
  else
22
- name = example.metadata[:full_description].split(/\s+/, 2).join('/').underscore.gsub(/[^\w\/]+/, '_')
22
+ name = example.metadata[:full_description]
23
+ .split(/\s+/, 2).join('/')
24
+ .underscore.gsub(%r{[^\w\/]+}, '_')
23
25
  VCR.use_cassette(name, options, &example)
24
26
  end
25
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Kruijsen
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-10-23 00:00:00.000000000 Z
13
+ date: 2016-01-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -191,6 +191,8 @@ files:
191
191
  - lib/poms/fields.rb
192
192
  - lib/poms/has_ancestors.rb
193
193
  - lib/poms/has_base_attributes.rb
194
+ - lib/poms/merged_series.rb
195
+ - lib/poms/poms_error.rb
194
196
  - lib/poms/schedule_event.rb
195
197
  - lib/poms/season.rb
196
198
  - lib/poms/series.rb
@@ -210,6 +212,8 @@ files:
210
212
  - spec/fixtures/vcr_cassettes/poms/builderless/clip/has_a_video_url.yml
211
213
  - spec/fixtures/vcr_cassettes/poms/builderless/clip/has_an_image_id.yml
212
214
  - spec/fixtures/vcr_cassettes/poms/fetch_broadcasts_fetch_current_broadcast_fetches_the_current_broadcast.yml
215
+ - spec/fixtures/vcr_cassettes/poms/merged_series/is_enumerable.yml
216
+ - spec/fixtures/vcr_cassettes/poms/merged_series/turns_the_json_into_a_hash.yml
213
217
  - spec/fixtures/vcr_cassettes/poms_fetch/a_broadcast_has_scheduled_events_with_last_with_starts_at.yml
214
218
  - spec/fixtures/vcr_cassettes/poms_fetch/a_clip_has_a_title.yml
215
219
  - spec/fixtures/vcr_cassettes/poms_fetch/an_aankeiler_has_images.yml
@@ -225,6 +229,7 @@ files:
225
229
  - spec/lib/poms/broadcast_spec.rb
226
230
  - spec/lib/poms/builder_spec.rb
227
231
  - spec/lib/poms/builderless/clip_spec.rb
232
+ - spec/lib/poms/merged_series_spec.rb
228
233
  - spec/lib/poms/schedule_event_spec.rb
229
234
  - spec/lib/poms/views_spec.rb
230
235
  - spec/lib/poms_spec.rb
@@ -267,6 +272,8 @@ test_files:
267
272
  - spec/fixtures/vcr_cassettes/poms/builderless/clip/has_a_video_url.yml
268
273
  - spec/fixtures/vcr_cassettes/poms/builderless/clip/has_an_image_id.yml
269
274
  - spec/fixtures/vcr_cassettes/poms/fetch_broadcasts_fetch_current_broadcast_fetches_the_current_broadcast.yml
275
+ - spec/fixtures/vcr_cassettes/poms/merged_series/is_enumerable.yml
276
+ - spec/fixtures/vcr_cassettes/poms/merged_series/turns_the_json_into_a_hash.yml
270
277
  - spec/fixtures/vcr_cassettes/poms_fetch/a_broadcast_has_scheduled_events_with_last_with_starts_at.yml
271
278
  - spec/fixtures/vcr_cassettes/poms_fetch/a_clip_has_a_title.yml
272
279
  - spec/fixtures/vcr_cassettes/poms_fetch/an_aankeiler_has_images.yml
@@ -282,6 +289,7 @@ test_files:
282
289
  - spec/lib/poms/broadcast_spec.rb
283
290
  - spec/lib/poms/builder_spec.rb
284
291
  - spec/lib/poms/builderless/clip_spec.rb
292
+ - spec/lib/poms/merged_series_spec.rb
285
293
  - spec/lib/poms/schedule_event_spec.rb
286
294
  - spec/lib/poms/views_spec.rb
287
295
  - spec/lib/poms_spec.rb