simple_pvr 1.0.0 → 1.1.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.
Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +1 -4
  5. data/Gemfile.lock +72 -61
  6. data/README.md +51 -33
  7. data/bin/pvr_server +14 -6
  8. data/changelog.txt +11 -0
  9. data/development_server +14 -6
  10. data/features/channel_overview.feature +1 -1
  11. data/features/recordings.feature +30 -0
  12. data/features/step_definitions/pvr_steps.rb +34 -0
  13. data/features/support/env.rb +1 -2
  14. data/features/support/paths.rb +2 -0
  15. data/lib/simple_pvr.rb +2 -0
  16. data/lib/simple_pvr/model/database_initializer.rb +8 -0
  17. data/lib/simple_pvr/model/programme.rb +12 -2
  18. data/lib/simple_pvr/model/programme_actor.rb +14 -0
  19. data/lib/simple_pvr/model/programme_category.rb +14 -0
  20. data/lib/simple_pvr/model/programme_director.rb +13 -0
  21. data/lib/simple_pvr/model/programme_presenter.rb +13 -0
  22. data/lib/simple_pvr/model/recording.rb +12 -0
  23. data/lib/simple_pvr/programme_icon_fetcher.rb +15 -0
  24. data/lib/simple_pvr/pvr_initializer.rb +4 -4
  25. data/lib/simple_pvr/recorder.rb +4 -3
  26. data/lib/simple_pvr/recording_manager.rb +44 -24
  27. data/lib/simple_pvr/recording_planner.rb +3 -3
  28. data/lib/simple_pvr/scheduler.rb +12 -4
  29. data/lib/simple_pvr/server/base_controller.rb +12 -13
  30. data/lib/simple_pvr/server/channels_controller.rb +5 -5
  31. data/lib/simple_pvr/server/programmes_controller.rb +2 -2
  32. data/lib/simple_pvr/server/schedules_controller.rb +4 -4
  33. data/lib/simple_pvr/server/secured_controller.rb +71 -0
  34. data/lib/simple_pvr/server/shows_controller.rb +13 -8
  35. data/lib/simple_pvr/server/status_controller.rb +1 -1
  36. data/lib/simple_pvr/server/upcoming_recordings_controller.rb +1 -1
  37. data/lib/simple_pvr/version.rb +1 -1
  38. data/lib/simple_pvr/xmltv_reader.rb +37 -4
  39. data/public/css/typeahead.js-bootstrap.css +83 -0
  40. data/public/index.html +45 -37
  41. data/public/js/angular/http-auth-interceptor.js +122 -0
  42. data/public/js/app.js +4 -37
  43. data/public/js/controllers.js +22 -14
  44. data/public/js/directives.js +102 -0
  45. data/public/js/filters.js +0 -31
  46. data/public/js/services.js +64 -0
  47. data/public/js/typeahead/typeahead.min.js +7 -0
  48. data/public/partials/about.html +15 -13
  49. data/public/partials/channels.html +41 -36
  50. data/public/partials/programme.html +20 -4
  51. data/public/partials/programmeListing.html +14 -13
  52. data/public/partials/schedule.html +91 -86
  53. data/public/partials/schedules.html +28 -16
  54. data/public/partials/search.html +10 -11
  55. data/public/partials/show.html +26 -9
  56. data/public/partials/shows.html +5 -6
  57. data/public/partials/status.html +1 -1
  58. data/public/templates/loginDialog.html +30 -0
  59. data/public/templates/logoutLink.html +1 -0
  60. data/public/templates/titleSearch.html +5 -3
  61. data/simple_pvr.gemspec +6 -4
  62. data/spec/resources/dummyImage.png +1 -0
  63. data/spec/resources/programmes-with-categories.xmltv +27 -0
  64. data/spec/resources/programmes-with-credits.xmltv +24 -0
  65. data/spec/resources/programmes-with-icons.xmltv +25 -0
  66. data/spec/resources/programmes-with-presenters.xmltv +19 -0
  67. data/spec/resources/{programs-without-icon.xmltv → programmes-without-icon.xmltv} +0 -0
  68. data/spec/resources/{programs.xmltv → programmes.xmltv} +0 -4
  69. data/spec/simple_pvr/ffmpeg_spec.rb +24 -22
  70. data/spec/simple_pvr/hdhomerun_spec.rb +69 -67
  71. data/spec/simple_pvr/model/channel_spec.rb +101 -101
  72. data/spec/simple_pvr/model/programme_spec.rb +104 -104
  73. data/spec/simple_pvr/model/schedule_spec.rb +74 -74
  74. data/spec/simple_pvr/programme_icon_fetcher_spec.rb +25 -0
  75. data/spec/simple_pvr/pvr_initializer_spec.rb +40 -38
  76. data/spec/simple_pvr/recorder_spec.rb +37 -26
  77. data/spec/simple_pvr/recording_manager_spec.rb +160 -133
  78. data/spec/simple_pvr/recording_planner_spec.rb +213 -211
  79. data/spec/simple_pvr/scheduler_spec.rb +189 -172
  80. data/spec/simple_pvr/server/secured_controller_spec.rb +118 -0
  81. data/spec/simple_pvr/xmltv_reader_spec.rb +89 -41
  82. data/test/karma.conf.js +7 -4
  83. data/test/unit/filtersSpec.js +0 -36
  84. metadata +79 -63
  85. data/public/css/bootstrap-responsive.min.css +0 -9
  86. data/public/css/bootstrap.min.css +0 -9
  87. data/public/img/glyphicons-halflings-white.png +0 -0
  88. data/public/img/glyphicons-halflings.png +0 -0
  89. data/public/js/angular/angular-resource.min.js +0 -10
  90. data/public/js/angular/angular.min.js +0 -162
  91. data/public/js/bootstrap/bootstrap.min.js +0 -6
  92. data/public/js/jquery/jquery.min.js +0 -5
  93. data/test/lib/angular/angular-mocks.js +0 -1768
@@ -1,114 +1,114 @@
1
1
  require 'simple_pvr'
2
2
 
3
- describe SimplePvr::Model::Channel do
4
- Channel, Programme = SimplePvr::Model::Channel, SimplePvr::Model::Programme
3
+ module SimplePvr::Model
4
+ describe Channel do
5
+ before :all do
6
+ DatabaseInitializer.prepare_for_test
7
+ end
8
+
9
+ before :each do
10
+ DatabaseInitializer.clear
11
+ end
12
+
13
+ it 'can insert channels' do
14
+ 3.times {|i| Channel.add("Channel #{i}", 23000000, 1098) }
5
15
 
6
- before :all do
7
- SimplePvr::Model::DatabaseInitializer.prepare_for_test
8
- end
16
+ Channel.all.length.should == 3
17
+ end
9
18
 
10
- before :each do
11
- SimplePvr::Model::DatabaseInitializer.clear
12
- end
19
+ it 'can clear channels' do
20
+ 3.times {|i| Channel.add("Channel #{i}", 23000000, 1098) }
21
+ Channel.clear
22
+
23
+ Channel.all.length.should == 0
24
+ end
13
25
 
14
- it 'can insert channels' do
15
- 3.times {|i| Channel.add("Channel #{i}", 23000000, 1098) }
16
-
17
- Channel.all.length.should == 3
18
- end
19
-
20
- it 'can clear channels' do
21
- 3.times {|i| Channel.add("Channel #{i}", 23000000, 1098) }
22
- Channel.clear
26
+ it 'clears all programmes when clearing channels' do
27
+ channel = Channel.add("DR 1", 23000000, 1098)
28
+ 3.times { Programme.add(channel, 'Title', 'Subtitle', 'Description', Time.local(2012, 7, 17, 20, 30), 50.minutes, nil) }
29
+ Channel.clear
23
30
 
24
- Channel.all.length.should == 0
25
- end
26
-
27
- it 'clears all programmes when clearing channels' do
28
- channel = Channel.add("DR 1", 23000000, 1098)
29
- 3.times { Programme.add(channel, 'Title', 'Subtitle', 'Description', Time.local(2012, 7, 17, 20, 30), 50.minutes, nil) }
30
- Channel.clear
31
-
32
- Programme.all.length.should == 0
33
- end
31
+ Programme.all.length.should == 0
32
+ end
33
+
34
+ it 'can find channels' do
35
+ Channel.add('Known channel', 23000000, 1098)
36
+
37
+ channel = Channel.with_name('Known channel')
38
+ channel.name.should == 'Known channel'
39
+ channel.frequency.should == 23000000
40
+ channel.channel_id.should == 1098
41
+ end
34
42
 
35
- it 'can find channels' do
36
- Channel.add('Known channel', 23000000, 1098)
43
+ it 'complains when asked for non-existing channel' do
44
+ expect { Channel.with_name('unknown') }.to raise_error "Unknown channel: 'unknown'"
45
+ end
37
46
 
38
- channel = Channel.with_name('Known channel')
39
- channel.name.should == 'Known channel'
40
- channel.frequency.should == 23000000
41
- channel.channel_id.should == 1098
42
- end
43
-
44
- it 'complains when asked for non-existing channel' do
45
- expect { Channel.with_name('unknown') }.to raise_error "Unknown channel: 'unknown'"
46
- end
47
+ it 'can fetch a channel along with the current and next 3 programmes' do
48
+ channel = Channel.create(name: 'Channel 1')
47
49
 
48
- it 'can fetch a channel along with the current and next 3 programmes' do
49
- channel = Channel.create(name: 'Channel 1')
50
-
51
- now = Time.now
52
- ten_minutes = 10.minutes.to_i
53
- current = Programme.create(channel: channel, title: 'Current programme on channel 1', subtitle: 'Current programme subtitle', start_time: now.advance(minutes: -3), duration: ten_minutes)
54
- programme_2 = Programme.create(channel: channel, title: 'Next programme', subtitle: 'Next programme subtitle', start_time: now.advance(minutes: 7), duration: ten_minutes)
55
- programme_3 = Programme.create(channel: channel, title: 'Programme 3', start_time: now.advance(minutes: 17), duration: ten_minutes)
56
- programme_4 = Programme.create(channel: channel, title: 'Programme 4', start_time: now.advance(minutes: 27), duration: ten_minutes)
57
-
58
- channel_and_programmes = Channel.with_current_programmes(channel.id)
59
-
60
- channel_and_programmes[:channel].should == channel
61
- channel_and_programmes[:current_programme].should == current
62
- channel_and_programmes[:upcoming_programmes].should == [programme_2, programme_3, programme_4]
63
- end
50
+ now = Time.now
51
+ ten_minutes = 10.minutes.to_i
52
+ current = Programme.create(channel: channel, title: 'Current programme on channel 1', subtitle: 'Current programme subtitle', start_time: now.advance(minutes: -3), duration: ten_minutes)
53
+ programme_2 = Programme.create(channel: channel, title: 'Next programme', subtitle: 'Next programme subtitle', start_time: now.advance(minutes: 7), duration: ten_minutes)
54
+ programme_3 = Programme.create(channel: channel, title: 'Programme 3', start_time: now.advance(minutes: 17), duration: ten_minutes)
55
+ programme_4 = Programme.create(channel: channel, title: 'Programme 4', start_time: now.advance(minutes: 27), duration: ten_minutes)
64
56
 
65
- it 'does not fetch programmes for hidden channels' do
66
- channel = Channel.create(name: 'Channel 1')
67
- channel.hidden = true
68
- channel.save!
69
-
70
- now = Time.now
71
- ten_minutes = 10.minutes.to_i
72
- current = Programme.create(channel: channel, title: 'Current programme on channel 1', subtitle: 'Current programme subtitle', start_time: now.advance(minutes: -3), duration: ten_minutes)
73
- programme_2 = Programme.create(channel: channel, title: 'Next programme', subtitle: 'Next programme subtitle', start_time: now.advance(minutes: 7), duration: ten_minutes)
74
-
75
- channel_and_programmes = Channel.with_current_programmes(channel.id)
76
-
77
- channel_and_programmes[:channel].should == channel
78
- channel_and_programmes[:current_programme].should be_nil
79
- channel_and_programmes[:upcoming_programmes].should == []
80
- end
81
-
82
- it 'can fetch all channels, along with the current and next 3 programmes' do
83
- channel_1 = Channel.add('Channel 1', 23000000, 1098)
84
- channel_2 = Channel.add('Channel 2', 23000000, 1098)
85
- channel_3 = Channel.add('Channel 3', 23000000, 1098)
57
+ channel_and_programmes = Channel.with_current_programmes(channel.id)
58
+
59
+ channel_and_programmes[:channel].should == channel
60
+ channel_and_programmes[:current_programme].should == current
61
+ channel_and_programmes[:upcoming_programmes].should == [programme_2, programme_3, programme_4]
62
+ end
86
63
 
87
- now = Time.now
88
- ten_minutes = 10.minutes.to_i
89
- current_on_channel_1 = Programme.create(channel: channel_1, title: 'Current programme on channel 1', subtitle: 'Current programme subtitle', start_time: now.advance(minutes: -3), duration: ten_minutes)
90
- programme_2_on_channel_1 = Programme.create(channel: channel_1, title: 'Next programme', subtitle: 'Next programme subtitle', start_time: now.advance(minutes: 7), duration: ten_minutes)
91
- programme_3_on_channel_1 = Programme.create(channel: channel_1, title: 'Programme 3', start_time: now.advance(minutes: 17), duration: ten_minutes)
92
- programme_4_on_channel_1 = Programme.create(channel: channel_1, title: 'Programme 4', start_time: now.advance(minutes: 27), duration: ten_minutes)
93
- programme_5_on_channel_1 = Programme.create(channel: channel_1, title: 'Programme 5', start_time: now.advance(minutes: 37), duration: ten_minutes)
94
-
95
- programme_1_on_channel_2 = Programme.create(channel: channel_2, title: 'Next programme on channel 2', start_time: now.advance(minutes: 17), duration: ten_minutes)
96
-
97
- old_programme_on_channel_3 = Programme.create(channel: channel_2, title: 'Obsolete programme', start_time: now.advance(minutes: -20), duration: ten_minutes)
98
-
99
- channels = Channel.all_with_current_programmes
100
- channels.length.should == 3
101
-
102
- channels[0][:channel].should == channel_1
103
- channels[0][:current_programme].should == current_on_channel_1
104
- channels[0][:upcoming_programmes].should == [programme_2_on_channel_1, programme_3_on_channel_1, programme_4_on_channel_1]
105
-
106
- channels[1][:channel].should == channel_2
107
- channels[1][:current_programme].should be_nil
108
- channels[1][:upcoming_programmes].should == [programme_1_on_channel_2]
109
-
110
- channels[2][:channel].should == channel_3
111
- channels[2][:current_programme].should be_nil
112
- channels[2][:upcoming_programmes].should == []
64
+ it 'does not fetch programmes for hidden channels' do
65
+ channel = Channel.create(name: 'Channel 1')
66
+ channel.hidden = true
67
+ channel.save!
68
+
69
+ now = Time.now
70
+ ten_minutes = 10.minutes.to_i
71
+ current = Programme.create(channel: channel, title: 'Current programme on channel 1', subtitle: 'Current programme subtitle', start_time: now.advance(minutes: -3), duration: ten_minutes)
72
+ programme_2 = Programme.create(channel: channel, title: 'Next programme', subtitle: 'Next programme subtitle', start_time: now.advance(minutes: 7), duration: ten_minutes)
73
+
74
+ channel_and_programmes = Channel.with_current_programmes(channel.id)
75
+
76
+ channel_and_programmes[:channel].should == channel
77
+ channel_and_programmes[:current_programme].should be_nil
78
+ channel_and_programmes[:upcoming_programmes].should == []
79
+ end
80
+
81
+ it 'can fetch all channels, along with the current and next 3 programmes' do
82
+ channel_1 = Channel.add('Channel 1', 23000000, 1098)
83
+ channel_2 = Channel.add('Channel 2', 23000000, 1098)
84
+ channel_3 = Channel.add('Channel 3', 23000000, 1098)
85
+
86
+ now = Time.now
87
+ ten_minutes = 10.minutes.to_i
88
+ current_on_channel_1 = Programme.create(channel: channel_1, title: 'Current programme on channel 1', subtitle: 'Current programme subtitle', start_time: now.advance(minutes: -3), duration: ten_minutes)
89
+ programme_2_on_channel_1 = Programme.create(channel: channel_1, title: 'Next programme', subtitle: 'Next programme subtitle', start_time: now.advance(minutes: 7), duration: ten_minutes)
90
+ programme_3_on_channel_1 = Programme.create(channel: channel_1, title: 'Programme 3', start_time: now.advance(minutes: 17), duration: ten_minutes)
91
+ programme_4_on_channel_1 = Programme.create(channel: channel_1, title: 'Programme 4', start_time: now.advance(minutes: 27), duration: ten_minutes)
92
+ programme_5_on_channel_1 = Programme.create(channel: channel_1, title: 'Programme 5', start_time: now.advance(minutes: 37), duration: ten_minutes)
93
+
94
+ programme_1_on_channel_2 = Programme.create(channel: channel_2, title: 'Next programme on channel 2', start_time: now.advance(minutes: 17), duration: ten_minutes)
95
+
96
+ old_programme_on_channel_3 = Programme.create(channel: channel_2, title: 'Obsolete programme', start_time: now.advance(minutes: -20), duration: ten_minutes)
97
+
98
+ channels = Channel.all_with_current_programmes
99
+ channels.length.should == 3
100
+
101
+ channels[0][:channel].should == channel_1
102
+ channels[0][:current_programme].should == current_on_channel_1
103
+ channels[0][:upcoming_programmes].should == [programme_2_on_channel_1, programme_3_on_channel_1, programme_4_on_channel_1]
104
+
105
+ channels[1][:channel].should == channel_2
106
+ channels[1][:current_programme].should be_nil
107
+ channels[1][:upcoming_programmes].should == [programme_1_on_channel_2]
108
+
109
+ channels[2][:channel].should == channel_3
110
+ channels[2][:current_programme].should be_nil
111
+ channels[2][:upcoming_programmes].should == []
112
+ end
113
113
  end
114
114
  end
@@ -1,121 +1,121 @@
1
1
  require 'simple_pvr'
2
2
 
3
- describe SimplePvr::Model::Programme do
4
- Channel, Programme = SimplePvr::Model::Channel, SimplePvr::Model::Programme
3
+ module SimplePvr::Model
4
+ describe Programme do
5
+ before :all do
6
+ DatabaseInitializer.prepare_for_test
7
+ end
8
+
9
+ before :each do
10
+ DatabaseInitializer.clear
11
+ end
5
12
 
6
- before :all do
7
- SimplePvr::Model::DatabaseInitializer.prepare_for_test
8
- end
13
+ before do
14
+ @dr_1 = Channel.add('DR 1', 23000000, 1098)
15
+ @dr_2 = Channel.add('DR 2', 24000000, 1099)
16
+ end
9
17
 
10
- before :each do
11
- SimplePvr::Model::DatabaseInitializer.clear
12
- end
13
-
14
- before do
15
- @dr_1 = Channel.add('DR 1', 23000000, 1098)
16
- @dr_2 = Channel.add('DR 2', 24000000, 1099)
17
- end
18
-
19
- it 'knows its end time' do
20
- programme = Programme.new(start_time: Time.local(2012, 7, 17, 20, 30), duration: 50.minutes)
21
-
22
- programme.end_time.should == Time.local(2012, 7, 17, 21, 20)
23
- end
24
-
25
- it 'knows when it is outdated' do
26
- Programme.new(start_time: 10.minutes.ago, duration: 9.minutes).should be_outdated
27
- Programme.new(start_time: 10.minutes.ago, duration: 11.minutes).should_not be_outdated
28
- end
18
+ it 'knows its end time' do
19
+ programme = Programme.new(start_time: Time.local(2012, 7, 17, 20, 30), duration: 50.minutes)
29
20
 
30
- it 'can insert programmes' do
31
- 3.times { Programme.add(@dr_1, 'Title', 'Subtitle', 'Description', Time.local(2012, 7, 17, 20, 30), 50.minutes, ' .4/12. ') }
21
+ programme.end_time.should == Time.local(2012, 7, 17, 21, 20)
22
+ end
32
23
 
33
- Programme.all.length.should == 3
34
- end
35
-
36
- it 'can clear all programmes' do
37
- 3.times { Programme.add(@dr_1, 'Title', 'Subtitle', 'Description', Time.local(2012, 7, 17, 20, 30), 50.minutes, nil) }
38
- Programme.clear
24
+ it 'knows when it is outdated' do
25
+ Programme.new(start_time: 10.minutes.ago, duration: 9.minutes).should be_outdated
26
+ Programme.new(start_time: 10.minutes.ago, duration: 11.minutes).should_not be_outdated
27
+ end
28
+
29
+ it 'can insert programmes' do
30
+ 3.times { Programme.add(@dr_1, 'Title', 'Subtitle', 'Description', Time.local(2012, 7, 17, 20, 30), 50.minutes, ' .4/12. ') }
31
+
32
+ Programme.all.length.should == 3
33
+ end
39
34
 
40
- Programme.all.length.should == 0
41
- end
42
-
43
- it 'can find all programmes with a certain title' do
44
- Programme.add(@dr_2, 'Interesting', 'Second', 'Description', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil)
45
- Programme.add(@dr_1, 'Interesting', 'First', 'Description', Time.local(2012, 7, 17, 20, 30), 50.minutes, nil)
46
- Programme.add(@dr_1, 'Uninteresting', 'Subtitle', 'Description', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil)
47
-
48
- programmes = Programme.with_title('Interesting')
49
- programmes.length.should == 2
50
-
51
- programmes[0].channel.should == @dr_1
52
- programmes[0].title.should == 'Interesting'
53
- programmes[0].subtitle.should == 'First'
54
- programmes[0].description.should == 'Description'
55
- programmes[0].start_time.should == Time.local(2012, 7, 17, 20, 30)
56
- programmes[0].duration.should == 50.minutes
57
-
58
- programmes[1].channel.should == @dr_2
59
- programmes[1].title.should == 'Interesting'
60
- programmes[1].subtitle.should == 'Second'
61
- end
62
-
63
- it 'can find all programmes with a certain title for a specific channel' do
64
- Programme.add(@dr_1, 'Interesting', 'Second', 'Description', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil)
65
- Programme.add(@dr_1, 'Interesting', 'First', 'Description', Time.local(2012, 7, 17, 20, 30), 50.minutes, nil)
66
- Programme.add(@dr_2, 'Interesting', '...but on wrong channel...', 'Description', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil)
67
- Programme.add(@dr_1, 'Uninteresting', 'Subtitle', 'Description', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil)
35
+ it 'can clear all programmes' do
36
+ 3.times { Programme.add(@dr_1, 'Title', 'Subtitle', 'Description', Time.local(2012, 7, 17, 20, 30), 50.minutes, nil) }
37
+ Programme.clear
38
+
39
+ Programme.all.length.should == 0
40
+ end
68
41
 
69
- programmes = Programme.on_channel_with_title(@dr_1, 'Interesting')
70
- programmes.length.should == 2
71
-
72
- programmes[0].channel.should == @dr_1
73
- programmes[0].title.should == 'Interesting'
74
- programmes[0].subtitle.should == 'First'
75
-
76
- programmes[1].channel.should == @dr_1
77
- programmes[1].title.should == 'Interesting'
78
- programmes[1].subtitle.should == 'Second'
79
- end
42
+ it 'can find all programmes with a certain title' do
43
+ Programme.add(@dr_2, 'Interesting', 'Second', 'Description', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil)
44
+ Programme.add(@dr_1, 'Interesting', 'First', 'Description', Time.local(2012, 7, 17, 20, 30), 50.minutes, nil)
45
+ Programme.add(@dr_1, 'Uninteresting', 'Subtitle', 'Description', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil)
80
46
 
81
- it 'can find titles containing a certain string' do
82
- Programme.add(@dr_1, 'First programme', '', '', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil)
83
- Programme.add(@dr_2, 'Second programme', '', '', Time.local(2012, 7, 17, 20, 30), 50.minutes, nil)
84
- Programme.add(@dr_1, 'Uninteresting', '', '', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil)
85
-
86
- titles = Programme.titles_containing('programme')
87
- titles.should == ['First programme', 'Second programme']
88
- end
47
+ programmes = Programme.with_title('Interesting')
48
+ programmes.length.should == 2
49
+
50
+ programmes[0].channel.should == @dr_1
51
+ programmes[0].title.should == 'Interesting'
52
+ programmes[0].subtitle.should == 'First'
53
+ programmes[0].description.should == 'Description'
54
+ programmes[0].start_time.should == Time.local(2012, 7, 17, 20, 30)
55
+ programmes[0].duration.should == 50.minutes
89
56
 
90
- it 'gives no duplicates as title search' do
91
- Programme.add(@dr_1, 'First programme', '', '', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil)
92
- Programme.add(@dr_1, 'First programme', '', '', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil)
93
- Programme.add(@dr_2, 'Second programme', '', '', Time.local(2012, 7, 17, 20, 30), 50.minutes, nil)
57
+ programmes[1].channel.should == @dr_2
58
+ programmes[1].title.should == 'Interesting'
59
+ programmes[1].subtitle.should == 'Second'
60
+ end
61
+
62
+ it 'can find all programmes with a certain title for a specific channel' do
63
+ Programme.add(@dr_1, 'Interesting', 'Second', 'Description', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil)
64
+ Programme.add(@dr_1, 'Interesting', 'First', 'Description', Time.local(2012, 7, 17, 20, 30), 50.minutes, nil)
65
+ Programme.add(@dr_2, 'Interesting', '...but on wrong channel...', 'Description', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil)
66
+ Programme.add(@dr_1, 'Uninteresting', 'Subtitle', 'Description', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil)
94
67
 
95
- titles = Programme.titles_containing('programme')
96
- titles.should == ['First programme', 'Second programme']
97
- end
68
+ programmes = Programme.on_channel_with_title(@dr_1, 'Interesting')
69
+ programmes.length.should == 2
98
70
 
99
- it 'finds at most 8 titles containing a certain string' do
100
- 20.times {|i| Programme.add(@dr_1, "Programme #{i}", '', '', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil) }
101
-
102
- titles = Programme.titles_containing('programme')
103
- titles.length.should == 8
104
- end
71
+ programmes[0].channel.should == @dr_1
72
+ programmes[0].title.should == 'Interesting'
73
+ programmes[0].subtitle.should == 'First'
105
74
 
106
- it 'can find programmes with titles containing a certain string, ordered by start time' do
107
- first_programme = Programme.add(@dr_1, 'First programme', '', '', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil)
108
- second_programme = Programme.add(@dr_2, 'Second programme', '', '', Time.local(2012, 7, 17, 20, 30), 50.minutes, nil)
109
- Programme.add(@dr_1, 'Uninteresting', '', '', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil)
75
+ programmes[1].channel.should == @dr_1
76
+ programmes[1].title.should == 'Interesting'
77
+ programmes[1].subtitle.should == 'Second'
78
+ end
110
79
 
111
- titles = Programme.with_title_containing('programme')
112
- titles.should == [second_programme, first_programme]
113
- end
80
+ it 'can find titles containing a certain string' do
81
+ Programme.add(@dr_1, 'First programme', '', '', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil)
82
+ Programme.add(@dr_2, 'Second programme', '', '', Time.local(2012, 7, 17, 20, 30), 50.minutes, nil)
83
+ Programme.add(@dr_1, 'Uninteresting', '', '', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil)
84
+
85
+ titles = Programme.titles_containing('programme')
86
+ titles.should == ['First programme', 'Second programme']
87
+ end
88
+
89
+ it 'gives no duplicates as title search' do
90
+ Programme.add(@dr_1, 'First programme', '', '', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil)
91
+ Programme.add(@dr_1, 'First programme', '', '', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil)
92
+ Programme.add(@dr_2, 'Second programme', '', '', Time.local(2012, 7, 17, 20, 30), 50.minutes, nil)
93
+
94
+ titles = Programme.titles_containing('programme')
95
+ titles.should == ['First programme', 'Second programme']
96
+ end
97
+
98
+ it 'finds at most 8 titles containing a certain string' do
99
+ 20.times {|i| Programme.add(@dr_1, "Programme #{i}", '', '', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil) }
114
100
 
115
- it 'finds at most 20 programmes with titles containing a certain string' do
116
- 30.times {|i| Programme.add(@dr_1, "Programme #{i}", '', '', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil) }
117
-
118
- titles = Programme.with_title_containing('programme')
119
- titles.length.should == 20
101
+ titles = Programme.titles_containing('programme')
102
+ titles.length.should == 8
103
+ end
104
+
105
+ it 'can find programmes with titles containing a certain string, ordered by start time' do
106
+ first_programme = Programme.add(@dr_1, 'First programme', '', '', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil)
107
+ second_programme = Programme.add(@dr_2, 'Second programme', '', '', Time.local(2012, 7, 17, 20, 30), 50.minutes, nil)
108
+ Programme.add(@dr_1, 'Uninteresting', '', '', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil)
109
+
110
+ titles = Programme.with_title_containing('programme')
111
+ titles.should == [second_programme, first_programme]
112
+ end
113
+
114
+ it 'finds at most 20 programmes with titles containing a certain string' do
115
+ 30.times {|i| Programme.add(@dr_1, "Programme #{i}", '', '', Time.local(2012, 7, 24, 20, 30), 50.minutes, nil) }
116
+
117
+ titles = Programme.with_title_containing('programme')
118
+ titles.length.should == 20
119
+ end
120
120
  end
121
121
  end
@@ -1,82 +1,82 @@
1
1
  require 'simple_pvr'
2
2
 
3
- describe SimplePvr::Model::Schedule do
4
- Channel, Schedule = SimplePvr::Model::Channel, SimplePvr::Model::Schedule
3
+ module SimplePvr::Model
4
+ describe Schedule do
5
+ before :all do
6
+ DatabaseInitializer.prepare_for_test
7
+ end
8
+
9
+ before :each do
10
+ DatabaseInitializer.clear
11
+ @dr_1 = Channel.add('DR 1', 23000000, 1098)
12
+ end
13
+
14
+ it 'can save a schedule with a title' do
15
+ Schedule.add_specification(title: 'Sports')
16
+
17
+ schedules = Schedule.all
18
+ schedules.length.should == 1
19
+ schedules[0].type.should == :specification
20
+ schedules[0].title.should == 'Sports'
21
+ schedules[0].channel.should be_nil
22
+ end
23
+
24
+ it 'can save a schedule with a title and a channel' do
25
+ Schedule.add_specification(title: 'Sports', channel: @dr_1)
26
+
27
+ schedules = Schedule.all
28
+ schedules.length.should == 1
29
+ schedules[0].type.should == :specification
30
+ schedules[0].title.should == 'Sports'
31
+ schedules[0].channel.name.should == 'DR 1'
32
+ end
5
33
 
6
- before :all do
7
- SimplePvr::Model::DatabaseInitializer.prepare_for_test
8
- end
34
+ it 'can save a schedule with a title and a channel and a start_time' do
35
+ start_time = Time.local(2012, 7, 10, 20, 50)
36
+ Schedule.add_specification(title: 'Sports', channel: @dr_1, start_time: start_time)
9
37
 
10
- before :each do
11
- SimplePvr::Model::DatabaseInitializer.clear
12
- @dr_1 = Channel.add('DR 1', 23000000, 1098)
13
- end
38
+ schedules = Schedule.all
39
+ schedules.length.should == 1
40
+ schedules[0].type.should == :specification
41
+ schedules[0].title.should == 'Sports'
42
+ schedules[0].channel.name.should == 'DR 1'
43
+ schedules[0].start_time.should == start_time
44
+ end
14
45
 
15
- it 'can save a schedule with a title' do
16
- Schedule.add_specification(title: 'Sports')
17
-
18
- schedules = Schedule.all
19
- schedules.length.should == 1
20
- schedules[0].type.should == :specification
21
- schedules[0].title.should == 'Sports'
22
- schedules[0].channel.should be_nil
23
- end
46
+ it 'starts 2 minutes early and 5 minutes late by default' do
47
+ schedule = Schedule.new
24
48
 
25
- it 'can save a schedule with a title and a channel' do
26
- Schedule.add_specification(title: 'Sports', channel: @dr_1)
27
-
28
- schedules = Schedule.all
29
- schedules.length.should == 1
30
- schedules[0].type.should == :specification
31
- schedules[0].title.should == 'Sports'
32
- schedules[0].channel.name.should == 'DR 1'
33
- end
34
-
35
- it 'can save a schedule with a title and a channel and a start_time' do
36
- start_time = Time.local(2012, 7, 10, 20, 50)
37
- Schedule.add_specification(title: 'Sports', channel: @dr_1, start_time: start_time)
38
-
39
- schedules = Schedule.all
40
- schedules.length.should == 1
41
- schedules[0].type.should == :specification
42
- schedules[0].title.should == 'Sports'
43
- schedules[0].channel.name.should == 'DR 1'
44
- schedules[0].start_time.should == start_time
45
- end
46
-
47
- it 'starts 2 minutes early and 5 minutes late by default' do
48
- schedule = Schedule.new
49
-
50
- schedule.custom_start_early_minutes.should be_nil
51
- schedule.custom_end_late_minutes.should be_nil
52
- schedule.start_early_minutes.should == 2
53
- schedule.end_late_minutes.should == 5
54
- end
55
-
56
- it 'can have custom start early and end late intervals' do
57
- schedule = Schedule.new(custom_start_early_minutes: 5, custom_end_late_minutes: 10)
58
-
59
- schedule.custom_start_early_minutes.should == 5
60
- schedule.custom_end_late_minutes.should == 10
61
- schedule.start_early_minutes.should == 5
62
- schedule.end_late_minutes.should == 10
63
- end
64
-
65
- it 'can clean up schedules that are out of date' do
66
- Schedule.add_specification(title: 'Old Sports News', start_time: 60.minutes.ago, end_time: 10.minutes.ago)
67
- Schedule.add_specification(title: 'Current Sports News', start_time: 5.minutes.ago, end_time: 10.minutes.from_now)
68
- Schedule.add_specification(title: 'Upcoming Sports News', start_time: 1.hour.from_now, end_time: 2.hours.from_now)
69
- Schedule.add_specification(title: 'Great movies')
70
- Schedule.add_exception(title: 'Irrelevant Past Sports News', start_time: 2.hour.ago, end_time: 1.hour.ago)
71
- Schedule.add_exception(title: 'Irrelevant Future Sports News', start_time: 1.hour.from_now, end_time: 2.hours.from_now)
72
-
73
- Schedule.cleanup
74
- remaining_names = Schedule.all.collect {|s| s.title }
75
- remaining_names.should include('Current Sports News')
76
- remaining_names.should include('Upcoming Sports News')
77
- remaining_names.should include('Great movies')
78
- remaining_names.should_not include('Old Sports News')
79
- remaining_names.should_not include('Irrelevant Past Sports News')
80
- remaining_names.should include('Irrelevant Future Sports News')
49
+ schedule.custom_start_early_minutes.should be_nil
50
+ schedule.custom_end_late_minutes.should be_nil
51
+ schedule.start_early_minutes.should == 2
52
+ schedule.end_late_minutes.should == 5
53
+ end
54
+
55
+ it 'can have custom start early and end late intervals' do
56
+ schedule = Schedule.new(custom_start_early_minutes: 5, custom_end_late_minutes: 10)
57
+
58
+ schedule.custom_start_early_minutes.should == 5
59
+ schedule.custom_end_late_minutes.should == 10
60
+ schedule.start_early_minutes.should == 5
61
+ schedule.end_late_minutes.should == 10
62
+ end
63
+
64
+ it 'can clean up schedules that are out of date' do
65
+ Schedule.add_specification(title: 'Old Sports News', start_time: 60.minutes.ago, end_time: 10.minutes.ago)
66
+ Schedule.add_specification(title: 'Current Sports News', start_time: 5.minutes.ago, end_time: 10.minutes.from_now)
67
+ Schedule.add_specification(title: 'Upcoming Sports News', start_time: 1.hour.from_now, end_time: 2.hours.from_now)
68
+ Schedule.add_specification(title: 'Great movies')
69
+ Schedule.add_exception(title: 'Irrelevant Past Sports News', start_time: 2.hour.ago, end_time: 1.hour.ago)
70
+ Schedule.add_exception(title: 'Irrelevant Future Sports News', start_time: 1.hour.from_now, end_time: 2.hours.from_now)
71
+
72
+ Schedule.cleanup
73
+ remaining_names = Schedule.all.collect {|s| s.title }
74
+ remaining_names.should include('Current Sports News')
75
+ remaining_names.should include('Upcoming Sports News')
76
+ remaining_names.should include('Great movies')
77
+ remaining_names.should_not include('Old Sports News')
78
+ remaining_names.should_not include('Irrelevant Past Sports News')
79
+ remaining_names.should include('Irrelevant Future Sports News')
80
+ end
81
81
  end
82
82
  end