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,221 +1,223 @@
1
1
  require 'simple_pvr'
2
2
 
3
- describe SimplePvr::RecordingPlanner do
4
- before do
5
- SimplePvr::Model::DatabaseInitializer.prepare_for_test
6
- SimplePvr::Model::DatabaseInitializer.clear
7
- @dr_1 = SimplePvr::Model::Channel.create(name: 'DR 1')
8
- @dr_k = SimplePvr::Model::Channel.create(name: 'DR K')
9
- @next_year = Time.now.year + 1
10
- @start_time_1, @start_time_2 = Time.local(@next_year, 7, 10, 20, 50), Time.local(@next_year, 7, 17, 20, 50)
11
- @old_start_time = Time.local(@next_year, 8, 10, 20, 50)
12
- @programme_duration = 60.minutes.to_i
13
-
14
- @scheduler = double('Scheduler')
15
- SimplePvr::PvrInitializer.stub(scheduler: @scheduler)
16
-
17
- Time.stub!(now: Time.local(@next_year, 7, 9, 20, 50))
18
- end
19
-
20
- it 'adjusts end time for single programme schedules' do
21
- SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_k, start_time: @start_time_1, duration: @programme_duration)
22
- SimplePvr::Model::Schedule.create(type: :specification, title: 'Borgias', channel: @dr_k, start_time: @start_time_1)
23
- @scheduler.should_receive(:recordings=)
24
-
25
- SimplePvr::RecordingPlanner.reload
26
-
27
- schedule = SimplePvr::Model::Schedule.all[0]
28
- schedule.end_time.should == @start_time_1 + @programme_duration.seconds + 5.minutes
29
- end
30
-
31
- it 'adjusts end time for exceptions' do
32
- SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_k, start_time: @start_time_1, duration: @programme_duration)
33
- SimplePvr::Model::Schedule.create(type: :specification, title: 'Borgias')
34
- SimplePvr::Model::Schedule.create(type: :exception, title: 'Borgias', channel: @dr_k, start_time: @start_time_1)
35
- @scheduler.should_receive(:recordings=)
36
-
37
- SimplePvr::RecordingPlanner.reload
38
-
39
- schedule = SimplePvr::Model::Schedule.all(type: :exception)[0]
40
- schedule.end_time.should == @start_time_1 + @programme_duration.seconds + 5.minutes
41
- end
42
-
43
- it 'leaves end time alone for schedules' do
44
- SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_k, start_time: @start_time_1, duration: @programme_duration)
45
- SimplePvr::Model::Schedule.create(type: :specification, title: 'Borgias', channel: @dr_k)
46
- @scheduler.should_receive(:recordings=)
47
-
48
- SimplePvr::RecordingPlanner.reload
49
-
50
- schedule = SimplePvr::Model::Schedule.first
51
- schedule.end_time.should be_nil
52
- end
53
-
54
- it 'cleans up outdated schedules' do
55
- SimplePvr::Model::Schedule.should_receive(:cleanup)
56
- @scheduler.should_receive(:recordings=).with([])
57
-
58
- SimplePvr::RecordingPlanner.reload
59
- end
3
+ module SimplePvr
4
+ describe RecordingPlanner do
5
+ before do
6
+ Model::DatabaseInitializer.prepare_for_test
7
+ Model::DatabaseInitializer.clear
8
+ @dr_1 = Model::Channel.create(name: 'DR 1')
9
+ @dr_k = Model::Channel.create(name: 'DR K')
10
+ @next_year = Time.now.year + 1
11
+ @start_time_1, @start_time_2 = Time.local(@next_year, 7, 10, 20, 50), Time.local(@next_year, 7, 17, 20, 50)
12
+ @old_start_time = Time.local(@next_year, 8, 10, 20, 50)
13
+ @programme_duration = 60.minutes.to_i
14
+
15
+ @scheduler = double('Scheduler')
16
+ PvrInitializer.stub(scheduler: @scheduler)
60
17
 
61
- it 'resets the recordings when no schedules exist' do
62
- SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_k, start_time: @start_time_1, duration: @programme_duration)
63
- SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_k, start_time: @start_time_2, duration: @programme_duration)
64
- SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: @start_time_2, duration: @programme_duration)
65
- SimplePvr::Model::Programme.create(title: 'Borgias' + "-", channel: @dr_k, start_time: @start_time_2, duration: @programme_duration)
66
-
67
- @scheduler.should_receive(:recordings=).with([])
68
-
69
- SimplePvr::RecordingPlanner.reload
70
- end
18
+ Time.stub(now: Time.local(@next_year, 7, 9, 20, 50))
19
+ end
20
+
21
+ it 'adjusts end time for single programme schedules' do
22
+ Model::Programme.create(title: 'Borgias', channel: @dr_k, start_time: @start_time_1, duration: @programme_duration)
23
+ Model::Schedule.create(type: :specification, title: 'Borgias', channel: @dr_k, start_time: @start_time_1)
24
+ @scheduler.should_receive(:recordings=)
25
+
26
+ RecordingPlanner.reload
27
+
28
+ schedule = Model::Schedule.all[0]
29
+ schedule.end_time.should == @start_time_1 + @programme_duration.seconds + 5.minutes
30
+ end
31
+
32
+ it 'adjusts end time for exceptions' do
33
+ Model::Programme.create(title: 'Borgias', channel: @dr_k, start_time: @start_time_1, duration: @programme_duration)
34
+ Model::Schedule.create(type: :specification, title: 'Borgias')
35
+ Model::Schedule.create(type: :exception, title: 'Borgias', channel: @dr_k, start_time: @start_time_1)
36
+ @scheduler.should_receive(:recordings=)
71
37
 
72
- it 'can set up schedules from channel and programme title' do
73
- SimplePvr::Model::Schedule.create(type: :specification, title: 'Borgias', channel: @dr_k)
74
- @programme_1 = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_k, start_time: @start_time_1, duration: @programme_duration)
75
- @programme_2 = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_k, start_time: @start_time_2, duration: @programme_duration)
76
- SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: @start_time_2, duration: @programme_duration)
77
- SimplePvr::Model::Programme.create(title: 'Irrelevant programme', channel: @dr_k, start_time: @start_time_2, duration: @programme_duration)
38
+ RecordingPlanner.reload
39
+
40
+ schedule = Model::Schedule.all(type: :exception)[0]
41
+ schedule.end_time.should == @start_time_1 + @programme_duration.seconds + 5.minutes
42
+ end
43
+
44
+ it 'leaves end time alone for schedules' do
45
+ Model::Programme.create(title: 'Borgias', channel: @dr_k, start_time: @start_time_1, duration: @programme_duration)
46
+ Model::Schedule.create(type: :specification, title: 'Borgias', channel: @dr_k)
47
+ @scheduler.should_receive(:recordings=)
48
+
49
+ RecordingPlanner.reload
50
+
51
+ schedule = Model::Schedule.first
52
+ schedule.end_time.should be_nil
53
+ end
54
+
55
+ it 'cleans up outdated schedules' do
56
+ Model::Schedule.should_receive(:cleanup)
57
+ @scheduler.should_receive(:recordings=).with([])
58
+
59
+ RecordingPlanner.reload
60
+ end
78
61
 
79
- @scheduler.should_receive(:recordings=).with([
80
- SimplePvr::Model::Recording.new(@dr_k, 'Borgias', Time.local(@next_year, 7, 10, 20, 48), 67.minutes, @programme_1),
81
- SimplePvr::Model::Recording.new(@dr_k, 'Borgias', Time.local(@next_year, 7, 17, 20, 48), 67.minutes, @programme_2)
82
- ])
83
-
84
- SimplePvr::RecordingPlanner.reload
85
- end
86
-
87
- it 'takes the start early and end late minutes from schedule' do
88
- SimplePvr::Model::Schedule.create(type: :specification, title: 'Borgias', channel: @dr_k, custom_start_early_minutes: 4, custom_end_late_minutes: 10)
89
- @programme_1 = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_k, start_time: @start_time_1, duration: @programme_duration)
62
+ it 'resets the recordings when no schedules exist' do
63
+ Model::Programme.create(title: 'Borgias', channel: @dr_k, start_time: @start_time_1, duration: @programme_duration)
64
+ Model::Programme.create(title: 'Borgias', channel: @dr_k, start_time: @start_time_2, duration: @programme_duration)
65
+ Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: @start_time_2, duration: @programme_duration)
66
+ Model::Programme.create(title: 'Borgias' + "-", channel: @dr_k, start_time: @start_time_2, duration: @programme_duration)
67
+
68
+ @scheduler.should_receive(:recordings=).with([])
69
+
70
+ RecordingPlanner.reload
71
+ end
90
72
 
91
- @scheduler.should_receive(:recordings=).with([
92
- SimplePvr::Model::Recording.new(@dr_k, 'Borgias', Time.local(@next_year, 7, 10, 20, 46), 74.minutes, @programme_1),
93
- ])
94
-
95
- SimplePvr::RecordingPlanner.reload
96
- end
97
-
98
- it 'can set up schedules from channel, programme title, and start time' do
99
- SimplePvr::Model::Schedule.create(type: :specification, title: 'Borgias', channel: @dr_k, start_time: @start_time_2)
100
- SimplePvr::Model::Programme.create(title: 'Borgias', channel:@dr_k, start_time: @start_time_1, duration: @programme_duration)
101
- @programme_to_be_recorded = SimplePvr::Model::Programme.create(title: 'Borgias', channel:@dr_k, start_time: @start_time_2, duration: @programme_duration)
102
-
103
- @scheduler.should_receive(:recordings=).with([
104
- SimplePvr::Model::Recording.new(@dr_k, 'Borgias', @start_time_2.advance(minutes: -2), 2.minutes + @programme_duration + 5.minutes, @programme_to_be_recorded)
105
- ])
106
-
107
- SimplePvr::RecordingPlanner.reload
108
- end
109
-
110
- it 'can set up schedules from programme title only' do
111
- SimplePvr::Model::Schedule.create(type: :specification, title: 'Borgias')
112
- @programme_1 = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: @start_time_1, duration: @programme_duration)
113
- @programme_2 = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_k, start_time: @start_time_2, duration: @programme_duration)
114
- SimplePvr::Model::Programme.create(title: 'Irrelevant programme', channel: @dr_k, start_time: @start_time_2, duration: @programme_duration)
115
-
116
- @scheduler.should_receive(:recordings=).with([
117
- SimplePvr::Model::Recording.new(@dr_1, 'Borgias', Time.local(@next_year, 7, 10, 20, 48), 67.minutes, @programme_1),
118
- SimplePvr::Model::Recording.new(@dr_k, 'Borgias', Time.local(@next_year, 7, 17, 20, 48), 67.minutes, @programme_2)
119
- ])
120
-
121
- SimplePvr::RecordingPlanner.reload
122
- end
73
+ it 'can set up schedules from channel and programme title' do
74
+ Model::Schedule.create(type: :specification, title: 'Borgias', channel: @dr_k)
75
+ @programme_1 = Model::Programme.create(title: 'Borgias', channel: @dr_k, start_time: @start_time_1, duration: @programme_duration)
76
+ @programme_2 = Model::Programme.create(title: 'Borgias', channel: @dr_k, start_time: @start_time_2, duration: @programme_duration)
77
+ Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: @start_time_2, duration: @programme_duration)
78
+ Model::Programme.create(title: 'Irrelevant programme', channel: @dr_k, start_time: @start_time_2, duration: @programme_duration)
79
+
80
+ @scheduler.should_receive(:recordings=).with([
81
+ Model::Recording.new(@dr_k, 'Borgias', Time.local(@next_year, 7, 10, 20, 48), 67.minutes, @programme_1),
82
+ Model::Recording.new(@dr_k, 'Borgias', Time.local(@next_year, 7, 17, 20, 48), 67.minutes, @programme_2)
83
+ ])
123
84
 
124
- it 'can set up schedules for specific days of the week' do
125
- @monday = Time.local(2012, 12, 10, 20, 50)
126
- @tuesday, @wednesday, @thursday, @friday, @saturday, @sunday = @monday + 1.day, @monday + 2.days, @monday + 3.days, @monday + 4.days, @monday + 5.days, @monday + 6.days
127
- @monday_programme = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: @monday, duration: @programme_duration)
128
- @tuesday_programme = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: @tuesday, duration: @programme_duration)
129
- @wednesday_programme = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: @wednesday, duration: @programme_duration)
130
- @thursday_programme = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: @thursday, duration: @programme_duration)
131
- @friday_programme = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: @friday, duration: @programme_duration)
132
- @saturday_programme = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: @saturday, duration: @programme_duration)
133
- @sunday_programme = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: @sunday, duration: @programme_duration)
134
-
135
- SimplePvr::Model::Schedule.create(type: :specification, title: 'Borgias', filter_by_weekday: true, monday: false, tuesday: true, wednesday: true, thursday: false, friday: false, saturday: true, sunday: true)
136
-
137
- @scheduler.should_receive(:recordings=).with([
138
- SimplePvr::Model::Recording.new(@dr_1, 'Borgias', @tuesday - 2.minutes, 67.minutes, @tuesday_programme),
139
- SimplePvr::Model::Recording.new(@dr_1, 'Borgias', @wednesday - 2.minutes, 67.minutes, @wednesday_programme),
140
- SimplePvr::Model::Recording.new(@dr_1, 'Borgias', @saturday - 2.minutes, 67.minutes, @saturday_programme),
141
- SimplePvr::Model::Recording.new(@dr_1, 'Borgias', @sunday - 2.minutes, 67.minutes, @sunday_programme),
142
- ])
85
+ RecordingPlanner.reload
86
+ end
87
+
88
+ it 'takes the start early and end late minutes from schedule' do
89
+ Model::Schedule.create(type: :specification, title: 'Borgias', channel: @dr_k, custom_start_early_minutes: 4, custom_end_late_minutes: 10)
90
+ @programme_1 = Model::Programme.create(title: 'Borgias', channel: @dr_k, start_time: @start_time_1, duration: @programme_duration)
91
+
92
+ @scheduler.should_receive(:recordings=).with([
93
+ Model::Recording.new(@dr_k, 'Borgias', Time.local(@next_year, 7, 10, 20, 46), 74.minutes, @programme_1),
94
+ ])
95
+
96
+ RecordingPlanner.reload
97
+ end
98
+
99
+ it 'can set up schedules from channel, programme title, and start time' do
100
+ Model::Schedule.create(type: :specification, title: 'Borgias', channel: @dr_k, start_time: @start_time_2)
101
+ Model::Programme.create(title: 'Borgias', channel:@dr_k, start_time: @start_time_1, duration: @programme_duration)
102
+ @programme_to_be_recorded = Model::Programme.create(title: 'Borgias', channel:@dr_k, start_time: @start_time_2, duration: @programme_duration)
103
+
104
+ @scheduler.should_receive(:recordings=).with([
105
+ Model::Recording.new(@dr_k, 'Borgias', @start_time_2.advance(minutes: -2), 2.minutes + @programme_duration + 5.minutes, @programme_to_be_recorded)
106
+ ])
107
+
108
+ RecordingPlanner.reload
109
+ end
110
+
111
+ it 'can set up schedules from programme title only' do
112
+ Model::Schedule.create(type: :specification, title: 'Borgias')
113
+ @programme_1 = Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: @start_time_1, duration: @programme_duration)
114
+ @programme_2 = Model::Programme.create(title: 'Borgias', channel: @dr_k, start_time: @start_time_2, duration: @programme_duration)
115
+ Model::Programme.create(title: 'Irrelevant programme', channel: @dr_k, start_time: @start_time_2, duration: @programme_duration)
116
+
117
+ @scheduler.should_receive(:recordings=).with([
118
+ Model::Recording.new(@dr_1, 'Borgias', Time.local(@next_year, 7, 10, 20, 48), 67.minutes, @programme_1),
119
+ Model::Recording.new(@dr_k, 'Borgias', Time.local(@next_year, 7, 17, 20, 48), 67.minutes, @programme_2)
120
+ ])
121
+
122
+ RecordingPlanner.reload
123
+ end
143
124
 
144
- SimplePvr::RecordingPlanner.reload
145
- end
146
-
147
- it 'can set up schedules for programmes starting before specific time of day' do
148
- @early_programme = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 12, 9, 30), duration: @programme_duration)
149
- @late_programme = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 12, 17, 0), duration: @programme_duration)
150
- @too_late_programme = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 12, 17, 01), duration: @programme_duration)
151
-
152
- SimplePvr::Model::Schedule.create(type: :specification, title: 'Borgias', filter_by_time_of_day: true, to_time_of_day: '17:00')
153
-
154
- @scheduler.should_receive(:recordings=).with([
155
- SimplePvr::Model::Recording.new(@dr_1, 'Borgias', @early_programme.start_time - 2.minutes, 67.minutes, @early_programme),
156
- SimplePvr::Model::Recording.new(@dr_1, 'Borgias', @late_programme.start_time - 2.minutes, 67.minutes, @late_programme)
157
- ])
158
-
159
- SimplePvr::RecordingPlanner.reload
160
- end
161
-
162
- it 'can set up schedules for programmes starting after a specific time of day' do
163
- @too_early_programme = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 12, 16, 59), duration: @programme_duration)
164
- @early_programme = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 12, 17, 0), duration: @programme_duration)
165
- @late_programme = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 12, 19, 30), duration: @programme_duration)
166
-
167
- SimplePvr::Model::Schedule.create(type: :specification, title: 'Borgias', filter_by_time_of_day: true, from_time_of_day: '17:00')
168
-
169
- @scheduler.should_receive(:recordings=).with([
170
- SimplePvr::Model::Recording.new(@dr_1, 'Borgias', @early_programme.start_time - 2.minutes, 67.minutes, @early_programme),
171
- SimplePvr::Model::Recording.new(@dr_1, 'Borgias', @late_programme.start_time - 2.minutes, 67.minutes, @late_programme)
172
- ])
173
-
174
- SimplePvr::RecordingPlanner.reload
175
- end
176
-
177
- it 'can set up schedules for programmes starting in certain interval during day' do
178
- @too_early_programme = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 12, 16, 59), duration: @programme_duration)
179
- @early_programme = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 12, 17, 0), duration: @programme_duration)
180
- @late_programme = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 12, 19, 0), duration: @programme_duration)
181
- @too_late_programme = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 12, 19, 1), duration: @programme_duration)
182
-
183
- SimplePvr::Model::Schedule.create(type: :specification, title: 'Borgias', filter_by_time_of_day: true, from_time_of_day: '17:00', to_time_of_day: '19:00')
184
-
185
- @scheduler.should_receive(:recordings=).with([
186
- SimplePvr::Model::Recording.new(@dr_1, 'Borgias', @early_programme.start_time - 2.minutes, 67.minutes, @early_programme),
187
- SimplePvr::Model::Recording.new(@dr_1, 'Borgias', @late_programme.start_time - 2.minutes, 67.minutes, @late_programme)
188
- ])
189
-
190
- SimplePvr::RecordingPlanner.reload
191
- end
192
-
193
- it 'can set up schedules for programmes starting in certain intervals during day, stretching across midnight' do
194
- @too_early_programme = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 12, 16, 59), duration: @programme_duration)
195
- @early_programme = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 12, 17, 0), duration: @programme_duration)
196
- @late_programme = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 13, 5, 0), duration: @programme_duration)
197
- @too_late_programme = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 13, 5, 1), duration: @programme_duration)
198
-
199
- SimplePvr::Model::Schedule.create(type: :specification, title: 'Borgias', filter_by_time_of_day: true, from_time_of_day: '17:00', to_time_of_day: '5:00')
200
-
201
- @scheduler.should_receive(:recordings=).with([
202
- SimplePvr::Model::Recording.new(@dr_1, 'Borgias', @early_programme.start_time - 2.minutes, 67.minutes, @early_programme),
203
- SimplePvr::Model::Recording.new(@dr_1, 'Borgias', @late_programme.start_time - 2.minutes, 67.minutes, @late_programme)
204
- ])
205
-
206
- SimplePvr::RecordingPlanner.reload
207
- end
208
-
209
- it 'ignores programmes for which exceptions exist' do
210
- SimplePvr::Model::Schedule.create(type: :specification, title: 'Borgias')
211
- SimplePvr::Model::Schedule.create(type: :exception, title: 'Borgias', channel: @dr_1, start_time: @start_time_1)
212
- SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: @start_time_1, duration: @programme_duration)
213
- @programme_to_be_recorded = SimplePvr::Model::Programme.create(title: 'Borgias', channel: @dr_k, start_time: @start_time_2, duration: @programme_duration)
214
-
215
- @scheduler.should_receive(:recordings=).with([
216
- SimplePvr::Model::Recording.new(@dr_k, 'Borgias', Time.local(@next_year, 7, 17, 20, 48), 67.minutes, @programme_to_be_recorded)
217
- ])
218
-
219
- SimplePvr::RecordingPlanner.reload
125
+ it 'can set up schedules for specific days of the week' do
126
+ @monday = Time.local(2012, 12, 10, 20, 50)
127
+ @tuesday, @wednesday, @thursday, @friday, @saturday, @sunday = @monday + 1.day, @monday + 2.days, @monday + 3.days, @monday + 4.days, @monday + 5.days, @monday + 6.days
128
+ @monday_programme = Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: @monday, duration: @programme_duration)
129
+ @tuesday_programme = Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: @tuesday, duration: @programme_duration)
130
+ @wednesday_programme = Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: @wednesday, duration: @programme_duration)
131
+ @thursday_programme = Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: @thursday, duration: @programme_duration)
132
+ @friday_programme = Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: @friday, duration: @programme_duration)
133
+ @saturday_programme = Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: @saturday, duration: @programme_duration)
134
+ @sunday_programme = Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: @sunday, duration: @programme_duration)
135
+
136
+ Model::Schedule.create(type: :specification, title: 'Borgias', filter_by_weekday: true, monday: false, tuesday: true, wednesday: true, thursday: false, friday: false, saturday: true, sunday: true)
137
+
138
+ @scheduler.should_receive(:recordings=).with([
139
+ Model::Recording.new(@dr_1, 'Borgias', @tuesday - 2.minutes, 67.minutes, @tuesday_programme),
140
+ Model::Recording.new(@dr_1, 'Borgias', @wednesday - 2.minutes, 67.minutes, @wednesday_programme),
141
+ Model::Recording.new(@dr_1, 'Borgias', @saturday - 2.minutes, 67.minutes, @saturday_programme),
142
+ Model::Recording.new(@dr_1, 'Borgias', @sunday - 2.minutes, 67.minutes, @sunday_programme),
143
+ ])
144
+
145
+ RecordingPlanner.reload
146
+ end
147
+
148
+ it 'can set up schedules for programmes starting before specific time of day' do
149
+ @early_programme = Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 12, 9, 30), duration: @programme_duration)
150
+ @late_programme = Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 12, 17, 0), duration: @programme_duration)
151
+ @too_late_programme = Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 12, 17, 01), duration: @programme_duration)
152
+
153
+ Model::Schedule.create(type: :specification, title: 'Borgias', filter_by_time_of_day: true, to_time_of_day: '17:00')
154
+
155
+ @scheduler.should_receive(:recordings=).with([
156
+ Model::Recording.new(@dr_1, 'Borgias', @early_programme.start_time - 2.minutes, 67.minutes, @early_programme),
157
+ Model::Recording.new(@dr_1, 'Borgias', @late_programme.start_time - 2.minutes, 67.minutes, @late_programme)
158
+ ])
159
+
160
+ RecordingPlanner.reload
161
+ end
162
+
163
+ it 'can set up schedules for programmes starting after a specific time of day' do
164
+ @too_early_programme = Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 12, 16, 59), duration: @programme_duration)
165
+ @early_programme = Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 12, 17, 0), duration: @programme_duration)
166
+ @late_programme = Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 12, 19, 30), duration: @programme_duration)
167
+
168
+ Model::Schedule.create(type: :specification, title: 'Borgias', filter_by_time_of_day: true, from_time_of_day: '17:00')
169
+
170
+ @scheduler.should_receive(:recordings=).with([
171
+ Model::Recording.new(@dr_1, 'Borgias', @early_programme.start_time - 2.minutes, 67.minutes, @early_programme),
172
+ Model::Recording.new(@dr_1, 'Borgias', @late_programme.start_time - 2.minutes, 67.minutes, @late_programme)
173
+ ])
174
+
175
+ RecordingPlanner.reload
176
+ end
177
+
178
+ it 'can set up schedules for programmes starting in certain interval during day' do
179
+ @too_early_programme = Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 12, 16, 59), duration: @programme_duration)
180
+ @early_programme = Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 12, 17, 0), duration: @programme_duration)
181
+ @late_programme = Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 12, 19, 0), duration: @programme_duration)
182
+ @too_late_programme = Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 12, 19, 1), duration: @programme_duration)
183
+
184
+ Model::Schedule.create(type: :specification, title: 'Borgias', filter_by_time_of_day: true, from_time_of_day: '17:00', to_time_of_day: '19:00')
185
+
186
+ @scheduler.should_receive(:recordings=).with([
187
+ Model::Recording.new(@dr_1, 'Borgias', @early_programme.start_time - 2.minutes, 67.minutes, @early_programme),
188
+ Model::Recording.new(@dr_1, 'Borgias', @late_programme.start_time - 2.minutes, 67.minutes, @late_programme)
189
+ ])
190
+
191
+ RecordingPlanner.reload
192
+ end
193
+
194
+ it 'can set up schedules for programmes starting in certain intervals during day, stretching across midnight' do
195
+ @too_early_programme = Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 12, 16, 59), duration: @programme_duration)
196
+ @early_programme = Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 12, 17, 0), duration: @programme_duration)
197
+ @late_programme = Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 13, 5, 0), duration: @programme_duration)
198
+ @too_late_programme = Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: Time.local(2012, 12, 13, 5, 1), duration: @programme_duration)
199
+
200
+ Model::Schedule.create(type: :specification, title: 'Borgias', filter_by_time_of_day: true, from_time_of_day: '17:00', to_time_of_day: '5:00')
201
+
202
+ @scheduler.should_receive(:recordings=).with([
203
+ Model::Recording.new(@dr_1, 'Borgias', @early_programme.start_time - 2.minutes, 67.minutes, @early_programme),
204
+ Model::Recording.new(@dr_1, 'Borgias', @late_programme.start_time - 2.minutes, 67.minutes, @late_programme)
205
+ ])
206
+
207
+ RecordingPlanner.reload
208
+ end
209
+
210
+ it 'ignores programmes for which exceptions exist' do
211
+ Model::Schedule.create(type: :specification, title: 'Borgias')
212
+ Model::Schedule.create(type: :exception, title: 'Borgias', channel: @dr_1, start_time: @start_time_1)
213
+ Model::Programme.create(title: 'Borgias', channel: @dr_1, start_time: @start_time_1, duration: @programme_duration)
214
+ @programme_to_be_recorded = Model::Programme.create(title: 'Borgias', channel: @dr_k, start_time: @start_time_2, duration: @programme_duration)
215
+
216
+ @scheduler.should_receive(:recordings=).with([
217
+ Model::Recording.new(@dr_k, 'Borgias', Time.local(@next_year, 7, 17, 20, 48), 67.minutes, @programme_to_be_recorded)
218
+ ])
219
+
220
+ RecordingPlanner.reload
221
+ end
220
222
  end
221
223
  end
@@ -1,201 +1,218 @@
1
1
  require 'simple_pvr'
2
2
 
3
- describe SimplePvr::Scheduler do
4
- before do
5
- @channel = double('Channel DR K', name: 'DR K', frequency: 282000000, channel_id: 1098)
6
- @channel_dr1 = double('Channel DR 1', name: 'DR 1', frequency: 290000000, channel_id: 1099)
3
+ module SimplePvr
4
+ describe Scheduler do
5
+ before do
6
+ @channel = double('Channel DR K', name: 'DR K', frequency: 282000000, channel_id: 1098)
7
+ @channel_dr1 = double('Channel DR 1', name: 'DR 1', frequency: 290000000, channel_id: 1099)
8
+
9
+ @scheduler = Scheduler.new
10
+ end
7
11
 
8
- @scheduler = SimplePvr::Scheduler.new
9
- end
10
-
11
- it 'leaves recordings that are in the future' do
12
- start_time = Time.local(2012, 7, 15, 20, 15, 30)
13
- Time.stub(:now => start_time.advance(hours: -1))
14
-
15
- @scheduler.recordings = [SimplePvr::Model::Recording.new(@channel, 'Borgia', start_time, 60.minutes)]
16
- @scheduler.process
17
- end
12
+ it 'leaves recordings that are in the future' do
13
+ start_time = Time.local(2012, 7, 15, 20, 15, 30)
14
+ Time.stub(:now => start_time.advance(hours: -1))
18
15
 
19
- it 'marks conflicting future recordings' do
20
- first_start_time = Time.now.advance(days: 1)
21
- second_start_time = Time.now.advance(days: 1, minutes: 10)
22
- third_start_time = Time.now.advance(days: 1, minutes: 20)
23
- fourth_start_time = Time.now.advance(days: 2)
24
- first_recording = SimplePvr::Model::Recording.new(@channel, 'Borgia', first_start_time, 60.minutes)
25
- second_recording = SimplePvr::Model::Recording.new(@channel, 'Borgia', second_start_time, 60.minutes)
26
- third_recording = SimplePvr::Model::Recording.new(@channel, 'Borgia', third_start_time, 60.minutes)
27
- fourth_recording = SimplePvr::Model::Recording.new(@channel, 'Borgia', fourth_start_time, 60.minutes)
28
-
29
- @scheduler.recordings = [first_recording, third_recording, second_recording]
16
+ @scheduler.recordings = [Model::Recording.new(@channel, 'Borgia', start_time, 60.minutes)]
17
+ @scheduler.process
18
+ end
30
19
 
31
- first_recording.should_not be_conflicting
32
- second_recording.should_not be_conflicting
33
- third_recording.should be_conflicting
34
- fourth_recording.should_not be_conflicting
35
- end
36
-
37
- it 'starts recordings at start time' do
38
- start_time = Time.local(2012, 7, 15, 20, 15, 30)
39
- starting_recording = SimplePvr::Model::Recording.new(@channel, 'Borgia', start_time, 60.minutes)
40
- Time.stub(:now => start_time)
41
- SimplePvr::Recorder.stub(:new).with(0, starting_recording).and_return(@recorder = double('Recorder'))
42
- @recorder.should_receive(:start!)
43
-
44
- @scheduler.recordings = [starting_recording]
45
- @scheduler.process
46
- end
47
-
48
- it 'starts recordings that are in progress' do
49
- start_time = Time.local(2012, 7, 15, 20, 15, 30)
50
- recording_in_progress = SimplePvr::Model::Recording.new(@channel, 'Borgia', start_time, 60.minutes)
51
- Time.stub(:now => start_time.advance(minutes: 30))
52
- SimplePvr::Recorder.stub(:new).with(0, recording_in_progress).and_return(@recorder = double('Recorder'))
53
- @recorder.should_receive(:start!)
54
-
55
- @scheduler.recordings = [recording_in_progress]
56
- @scheduler.process
57
- end
58
-
59
- it 'can start two recordings at once' do
60
- first_start_time = Time.local(2012, 7, 15, 19, 45, 30)
61
- second_start_time = Time.local(2012, 7, 15, 20, 15, 30)
62
- recording_in_progress = SimplePvr::Model::Recording.new(@channel, 'Borgia', first_start_time, 60.minutes)
63
- starting_recording = SimplePvr::Model::Recording.new(@channel, 'Borgia', second_start_time, 60.minutes)
64
- Time.stub(:now => second_start_time)
65
- SimplePvr::Recorder.stub(:new).with(0, recording_in_progress).and_return(@recorder0 = double('Recorder'))
66
- SimplePvr::Recorder.stub(:new).with(1, starting_recording).and_return(@recorder1 = double('Recorder'))
67
- @recorder0.should_receive(:start!)
68
- @recorder1.should_receive(:start!)
69
-
70
- @scheduler.recordings = [recording_in_progress, starting_recording]
71
- @scheduler.process
72
- end
20
+ it 'marks conflicting future recordings' do
21
+ first_start_time = Time.now.advance(days: 1)
22
+ second_start_time = Time.now.advance(days: 1, minutes: 10)
23
+ third_start_time = Time.now.advance(days: 1, minutes: 20)
24
+ fourth_start_time = Time.now.advance(days: 2)
25
+ first_recording = Model::Recording.new(@channel, 'Borgia', first_start_time, 60.minutes)
26
+ second_recording = Model::Recording.new(@channel, 'Borgia', second_start_time, 60.minutes)
27
+ third_recording = Model::Recording.new(@channel, 'Borgia', third_start_time, 60.minutes)
28
+ fourth_recording = Model::Recording.new(@channel, 'Borgia', fourth_start_time, 60.minutes)
73
29
 
74
- it 'rejects third recording at once, and marks the third recording as conflicting' do
75
- first_start_time = Time.local(2012, 7, 15, 19, 45, 30)
76
- second_start_time = Time.local(2012, 7, 15, 20, 15, 30)
77
- third_start_time = Time.local(2012, 7, 15, 20, 20, 0)
78
- recording_in_progress = SimplePvr::Model::Recording.new(@channel, 'Borgia', first_start_time, 60.minutes)
79
- starting_recording = SimplePvr::Model::Recording.new(@channel, 'Borgia', second_start_time, 60.minutes)
80
- rejected_recording = SimplePvr::Model::Recording.new(@channel, 'Borgia', third_start_time, 60.minutes)
81
- Time.stub(:now => second_start_time)
82
- SimplePvr::Recorder.stub(:new).with(0, recording_in_progress).and_return(@recorder0 = double('Recorder'))
83
- SimplePvr::Recorder.stub(:new).with(1, starting_recording).and_return(@recorder1 = double('Recorder'))
84
- @recorder0.should_receive(:start!)
85
- @recorder1.should_receive(:start!)
86
-
87
- @scheduler.recordings = [recording_in_progress, starting_recording, rejected_recording]
88
- @scheduler.process
30
+ @scheduler.recordings = [first_recording, third_recording, second_recording]
31
+
32
+ first_recording.should_not be_conflicting
33
+ second_recording.should_not be_conflicting
34
+ third_recording.should be_conflicting
35
+ fourth_recording.should_not be_conflicting
36
+ end
89
37
 
90
- recording_in_progress.should_not be_conflicting
91
- starting_recording.should_not be_conflicting
92
- rejected_recording.should be_conflicting
93
- end
94
-
95
- it 'ends recordings at end time' do
96
- start_time = Time.local(2012, 7, 15, 20, 15, 30)
97
- ending_recording = SimplePvr::Model::Recording.new(@channel, 'Borgia', start_time, 60.minutes)
98
- SimplePvr::Recorder.stub(:new).with(0, ending_recording).and_return(@recorder = double('Recorder'))
99
- @recorder.should_receive(:start!)
100
- Time.stub(:now => start_time)
101
-
102
- @scheduler.recordings = [ending_recording]
103
- @scheduler.process
104
-
105
- @recorder.should_receive(:stop!)
106
- Time.stub(:now => start_time.advance(hours: 1, minutes: 1))
107
-
108
- @scheduler.process
109
- end
38
+ it 'starts recordings at start time' do
39
+ start_time = Time.local(2012, 7, 15, 20, 15, 30)
40
+ starting_recording = Model::Recording.new(@channel, 'Borgia', start_time, 60.minutes)
41
+ Time.stub(:now => start_time)
42
+ Recorder.stub(:new).with(0, starting_recording).and_return(@recorder = double('Recorder'))
43
+ @recorder.should_receive(:start!)
110
44
 
111
- it 'skips recordings that have passed' do
112
- start_time = Time.local(2012, 7, 15, 20, 15, 30)
113
- passed_recording = SimplePvr::Model::Recording.new(@channel, 'Borgia', start_time - 65.minutes, 60.minutes)
114
- Time.stub(:now => start_time)
45
+ @scheduler.recordings = [starting_recording]
46
+ @scheduler.process
47
+ end
115
48
 
116
- @scheduler.recordings = [passed_recording]
117
- @scheduler.process
118
- end
119
-
120
- it 'knows which programmes are being recorded' do
121
- start_time = Time.local(2012, 7, 15, 20, 15, 30)
122
- Time.stub(:now => start_time.advance(hours: -1))
123
- scheduled_programme = double(id: 2)
124
- unscheduled_programme = double(id: 3)
125
-
126
- @scheduler.recordings = [SimplePvr::Model::Recording.new(@channel, 'Borgia', start_time, 60.minutes, scheduled_programme)]
127
- @scheduler.scheduled?(scheduled_programme).should be_true
128
- @scheduler.scheduled?(unscheduled_programme).should be_false
129
- end
130
-
131
- it 'gives idle status when nothing is recording' do
132
- @scheduler.recordings = []
133
- @scheduler.process
134
-
135
- @scheduler.status_text.should == 'Idle'
136
- end
137
-
138
- it 'gives recording status when recording' do
139
- start_time = Time.local(2012, 7, 15, 20, 15, 30)
140
- Time.stub(:now => start_time.advance(minutes: 30))
141
- SimplePvr::Recorder.stub(new: (@recorder = double('Recorder')))
142
- @recorder.stub(:start!)
143
-
144
- @scheduler.recordings = [SimplePvr::Model::Recording.new(@channel, 'Borgia', start_time, 60.minutes)]
145
- @scheduler.process
146
-
147
- @scheduler.status_text.should == "Recording 'Borgia' on channel 'DR K'"
148
- end
149
-
150
- context 'when updating existing recordings' do
151
- it 'leaves running recording if new recording is equal' do
49
+ it 'starts recordings that are in progress' do
152
50
  start_time = Time.local(2012, 7, 15, 20, 15, 30)
153
- continuing_recording = SimplePvr::Model::Recording.new(@channel, 'Borgia', start_time, 60.minutes)
154
- Time.stub(:now => start_time)
155
- SimplePvr::Recorder.stub(:new).with(0, continuing_recording).and_return(@recorder = double('Recorder'))
51
+ recording_in_progress = Model::Recording.new(@channel, 'Borgia', start_time, 60.minutes)
52
+ Time.stub(:now => start_time.advance(minutes: 30))
53
+ Recorder.stub(:new).with(0, recording_in_progress).and_return(@recorder = double('Recorder'))
156
54
  @recorder.should_receive(:start!)
157
-
158
- @scheduler.recordings = [continuing_recording]
55
+
56
+ @scheduler.recordings = [recording_in_progress]
159
57
  @scheduler.process
160
-
161
- @scheduler.recordings = [SimplePvr::Model::Recording.new(@channel, 'Borgia', start_time, 60.minutes)]
58
+ end
59
+
60
+ it 'can start two recordings at once' do
61
+ first_start_time = Time.local(2012, 7, 15, 19, 45, 30)
62
+ second_start_time = Time.local(2012, 7, 15, 20, 15, 30)
63
+ recording_in_progress = Model::Recording.new(@channel, 'Borgia', first_start_time, 60.minutes)
64
+ starting_recording = Model::Recording.new(@channel, 'Borgia', second_start_time, 60.minutes)
65
+ Time.stub(:now => second_start_time)
66
+ Recorder.stub(:new).with(0, recording_in_progress).and_return(@recorder0 = double('Recorder'))
67
+ Recorder.stub(:new).with(1, starting_recording).and_return(@recorder1 = double('Recorder'))
68
+ @recorder0.should_receive(:start!)
69
+ @recorder1.should_receive(:start!)
70
+
71
+ @scheduler.recordings = [recording_in_progress, starting_recording]
72
+ @scheduler.process
73
+ end
74
+
75
+ it 'rejects third recording at once, and marks the third recording as conflicting' do
76
+ first_start_time = Time.local(2012, 7, 15, 19, 45, 30)
77
+ second_start_time = Time.local(2012, 7, 15, 20, 15, 30)
78
+ third_start_time = Time.local(2012, 7, 15, 20, 20, 0)
79
+ recording_in_progress = Model::Recording.new(@channel, 'Borgia', first_start_time, 60.minutes)
80
+ starting_recording = Model::Recording.new(@channel, 'Borgia', second_start_time, 60.minutes)
81
+ rejected_recording = Model::Recording.new(@channel, 'Borgia', third_start_time, 60.minutes)
82
+ Time.stub(:now => second_start_time)
83
+ Recorder.stub(:new).with(0, recording_in_progress).and_return(@recorder0 = double('Recorder'))
84
+ Recorder.stub(:new).with(1, starting_recording).and_return(@recorder1 = double('Recorder'))
85
+ @recorder0.should_receive(:start!)
86
+ @recorder1.should_receive(:start!)
87
+
88
+ @scheduler.recordings = [recording_in_progress, starting_recording, rejected_recording]
162
89
  @scheduler.process
90
+
91
+ recording_in_progress.should_not be_conflicting
92
+ starting_recording.should_not be_conflicting
93
+ rejected_recording.should be_conflicting
163
94
  end
164
95
 
165
- it 'stops existing recording if not present in new recording list' do
96
+ it 'ends recordings at end time' do
166
97
  start_time = Time.local(2012, 7, 15, 20, 15, 30)
167
- stopping_recording = SimplePvr::Model::Recording.new(@channel, 'Borgia', start_time, 60.minutes)
168
- upcoming_recording = SimplePvr::Model::Recording.new(@channel, 'Borgia', start_time + 10.minutes, 60.minutes)
169
- Time.stub(:now => start_time)
170
- SimplePvr::Recorder.stub(:new).with(0, stopping_recording).and_return(@recorder = double('Recorder'))
98
+ ending_recording = Model::Recording.new(@channel, 'Borgia', start_time, 60.minutes)
99
+ Recorder.stub(:new).with(0, ending_recording).and_return(@recorder = double('Recorder'))
171
100
  @recorder.should_receive(:start!)
172
-
173
- @scheduler.recordings = [stopping_recording]
101
+ Time.stub(:now => start_time)
102
+
103
+ @scheduler.recordings = [ending_recording]
174
104
  @scheduler.process
175
-
105
+
176
106
  @recorder.should_receive(:stop!)
177
-
178
- @scheduler.recordings = [upcoming_recording]
107
+ Time.stub(:now => start_time.advance(hours: 1, minutes: 1))
108
+
179
109
  @scheduler.process
180
110
  end
181
111
 
182
- it 'stops existing recording and starts new recording if new recording list has other current recording' do
112
+ it 'skips recordings that have passed' do
183
113
  start_time = Time.local(2012, 7, 15, 20, 15, 30)
184
- stopping_recording = SimplePvr::Model::Recording.new(@channel, 'Borgia', start_time, 60.minutes)
185
- starting_recording = SimplePvr::Model::Recording.new(@channel_dr1, 'Sports', start_time, 60.minutes)
114
+ passed_recording = Model::Recording.new(@channel, 'Borgia', start_time - 65.minutes, 60.minutes)
186
115
  Time.stub(:now => start_time)
187
- SimplePvr::Recorder.stub(:new).with(0, stopping_recording).and_return(@old_recorder = double('Recorder'))
188
- SimplePvr::Recorder.stub(:new).with(0, starting_recording).and_return(@new_recorder = double('New recorder'))
189
- @old_recorder.should_receive(:start!)
190
-
191
- @scheduler.recordings = [stopping_recording]
116
+
117
+ @scheduler.recordings = [passed_recording]
192
118
  @scheduler.process
193
-
194
- @old_recorder.should_receive(:stop!)
195
- @new_recorder.should_receive(:start!)
196
-
197
- @scheduler.recordings = [starting_recording]
119
+ end
120
+
121
+ it 'knows which programmes are being recorded' do
122
+ start_time = Time.local(2012, 7, 15, 20, 15, 30)
123
+ Time.stub(:now => start_time.advance(hours: -1))
124
+ scheduled_programme = double(id: 2)
125
+ unscheduled_programme = double(id: 3)
126
+
127
+ @scheduler.recordings = [Model::Recording.new(@channel, 'Borgia', start_time, 60.minutes, scheduled_programme)]
128
+ @scheduler.scheduled?(scheduled_programme).should be_true
129
+ @scheduler.scheduled?(unscheduled_programme).should be_false
130
+ end
131
+
132
+ it 'gives idle status when nothing is recording' do
133
+ @scheduler.recordings = []
134
+ @scheduler.process
135
+
136
+ @scheduler.status_text.should == 'Idle'
137
+ end
138
+
139
+ it 'gives recording status when recording' do
140
+ start_time = Time.local(2012, 7, 15, 20, 15, 30)
141
+ Time.stub(:now => start_time.advance(minutes: 30))
142
+ Recorder.stub(new: (@recorder = double('Recorder')))
143
+ @recorder.stub(:start!)
144
+
145
+ @scheduler.recordings = [Model::Recording.new(@channel, 'Borgia', start_time, 60.minutes)]
198
146
  @scheduler.process
147
+
148
+ @scheduler.status_text.should == "Recording 'Borgia' on channel 'DR K'"
149
+ end
150
+
151
+ context 'when updating existing recordings' do
152
+ it 'leaves running recording if new recording is equal' do
153
+ start_time = Time.local(2012, 7, 15, 20, 15, 30)
154
+ continuing_recording = Model::Recording.new(@channel, 'Borgia', start_time, 60.minutes)
155
+ Time.stub(:now => start_time)
156
+ Recorder.stub(:new).with(0, continuing_recording).and_return(@recorder = double('Recorder'))
157
+ @recorder.should_receive(:start!)
158
+
159
+ @scheduler.recordings = [continuing_recording]
160
+ @scheduler.process
161
+
162
+ @scheduler.recordings = [Model::Recording.new(@channel, 'Borgia', start_time, 60.minutes)]
163
+ @scheduler.process
164
+ end
165
+
166
+ it 'replaces underlying information for running recording if new recording has same name, channel, and start time' do
167
+ old_programme, new_programme = Model::Programme.new, Model::Programme.new
168
+ start_time = Time.local(2012, 7, 15, 20, 15, 30)
169
+ continuing_recording = Model::Recording.new(@channel, 'Borgia', start_time, 60.minutes, old_programme)
170
+ Time.stub(:now => start_time)
171
+ Recorder.should_receive(:new).with(0, continuing_recording).and_return(@recorder = double('Recorder 1'))
172
+ @recorder.should_receive(:start!)
173
+
174
+ @scheduler.recordings = [continuing_recording]
175
+ @scheduler.process
176
+
177
+ @scheduler.recordings = [Model::Recording.new(@channel, 'Borgia', start_time, 55.minutes, new_programme)]
178
+ @scheduler.process
179
+ end
180
+
181
+ it 'stops existing recording if not present in new recording list' do
182
+ start_time = Time.local(2012, 7, 15, 20, 15, 30)
183
+ stopping_recording = Model::Recording.new(@channel, 'Borgia', start_time, 60.minutes)
184
+ upcoming_recording = Model::Recording.new(@channel, 'Borgia', start_time + 10.minutes, 60.minutes)
185
+ Time.stub(:now => start_time)
186
+ Recorder.stub(:new).with(0, stopping_recording).and_return(@recorder = double('Recorder'))
187
+ @recorder.should_receive(:start!)
188
+
189
+ @scheduler.recordings = [stopping_recording]
190
+ @scheduler.process
191
+
192
+ @recorder.should_receive(:stop!)
193
+
194
+ @scheduler.recordings = [upcoming_recording]
195
+ @scheduler.process
196
+ end
197
+
198
+ it 'stops existing recording and starts new recording if new recording list has other current recording' do
199
+ start_time = Time.local(2012, 7, 15, 20, 15, 30)
200
+ stopping_recording = Model::Recording.new(@channel, 'Borgia', start_time, 60.minutes)
201
+ starting_recording = Model::Recording.new(@channel_dr1, 'Sports', start_time, 60.minutes)
202
+ Time.stub(:now => start_time)
203
+ Recorder.stub(:new).with(0, stopping_recording).and_return(@old_recorder = double('Recorder'))
204
+ Recorder.stub(:new).with(0, starting_recording).and_return(@new_recorder = double('New recorder'))
205
+ @old_recorder.should_receive(:start!)
206
+
207
+ @scheduler.recordings = [stopping_recording]
208
+ @scheduler.process
209
+
210
+ @old_recorder.should_receive(:stop!)
211
+ @new_recorder.should_receive(:start!)
212
+
213
+ @scheduler.recordings = [starting_recording]
214
+ @scheduler.process
215
+ end
199
216
  end
200
217
  end
201
218
  end