tivohmo 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/CHANGELOG +30 -0
  4. data/Gemfile +2 -0
  5. data/README.md +4 -6
  6. data/TODO +1 -0
  7. data/contrib/tivohmo.conf +2 -2
  8. data/contrib/tivohmo.plist +1 -1
  9. data/contrib/tivohmo.yml +60 -0
  10. data/lib/tivohmo/adapters/filesystem/file_item.rb +2 -3
  11. data/lib/tivohmo/adapters/plex/category.rb +87 -6
  12. data/lib/tivohmo/adapters/plex/episode.rb +30 -11
  13. data/lib/tivohmo/adapters/plex/group.rb +20 -0
  14. data/lib/tivohmo/adapters/plex/movie.rb +15 -3
  15. data/lib/tivohmo/adapters/plex/qualified_category.rb +14 -3
  16. data/lib/tivohmo/adapters/plex/season.rb +2 -2
  17. data/lib/tivohmo/adapters/plex/section.rb +5 -5
  18. data/lib/tivohmo/adapters/plex/transcoder.rb +5 -1
  19. data/lib/tivohmo/adapters/plex.rb +1 -0
  20. data/lib/tivohmo/adapters/settings/application.rb +37 -0
  21. data/lib/tivohmo/adapters/settings/display_item.rb +35 -0
  22. data/lib/tivohmo/adapters/settings/key_container.rb +35 -0
  23. data/lib/tivohmo/adapters/settings/metadata.rb +26 -0
  24. data/lib/tivohmo/adapters/settings/reset_defaults_item.rb +39 -0
  25. data/lib/tivohmo/adapters/settings/set_value_item.rb +38 -0
  26. data/lib/tivohmo/adapters/settings/transcoder.rb +23 -0
  27. data/lib/tivohmo/adapters/settings.rb +7 -0
  28. data/lib/tivohmo/adapters/streamio/transcoder.rb +39 -1
  29. data/lib/tivohmo/api/container.rb +5 -1
  30. data/lib/tivohmo/api/item.rb +2 -0
  31. data/lib/tivohmo/api/subtitle.rb +13 -0
  32. data/lib/tivohmo/api/transcoder.rb +1 -3
  33. data/lib/tivohmo/api.rb +1 -0
  34. data/lib/tivohmo/beacon.rb +3 -3
  35. data/lib/tivohmo/cli.rb +175 -48
  36. data/lib/tivohmo/config.rb +157 -0
  37. data/lib/tivohmo/server/views/_container.builder +1 -1
  38. data/lib/tivohmo/server.rb +6 -3
  39. data/lib/tivohmo/version.rb +1 -1
  40. data/lib/tivohmo.rb +1 -0
  41. data/spec/adapters/filesystem/file_item_spec.rb +1 -1
  42. data/spec/adapters/plex/application_spec.rb +10 -1
  43. data/spec/adapters/plex/category_spec.rb +93 -20
  44. data/spec/adapters/plex/episode_spec.rb +34 -15
  45. data/spec/adapters/plex/metadata_spec.rb +5 -7
  46. data/spec/adapters/plex/movie_spec.rb +10 -7
  47. data/spec/adapters/plex/qualified_category_spec.rb +17 -17
  48. data/spec/adapters/plex/season_spec.rb +23 -4
  49. data/spec/adapters/plex/section_spec.rb +4 -4
  50. data/spec/adapters/plex/show_spec.rb +19 -4
  51. data/spec/adapters/plex/transcoder_spec.rb +2 -8
  52. data/spec/adapters/settings/application_spec.rb +25 -0
  53. data/spec/adapters/settings/display_item_spec.rb +29 -0
  54. data/spec/adapters/settings/key_container_spec.rb +33 -0
  55. data/spec/adapters/settings/metadata_spec.rb +33 -0
  56. data/spec/adapters/settings/reset_defaults_item_spec.rb +54 -0
  57. data/spec/adapters/settings/set_value_item_spec.rb +54 -0
  58. data/spec/api/container_spec.rb +12 -0
  59. data/spec/api/item_spec.rb +2 -0
  60. data/spec/api/transcoder_spec.rb +0 -1
  61. data/spec/beacon_spec.rb +3 -1
  62. data/spec/cli_spec.rb +57 -19
  63. data/spec/config_spec.rb +224 -0
  64. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Application/_children/should_get_children.yml +61 -0
  65. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Category/_children/should_allow_disabling_subtitles.yml +424 -0
  66. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Category/_children/should_display_non-zero_child_count_once_children_fetched.yml +653 -0
  67. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Category/_children/should_have_children.yml +599 -0
  68. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Category/_children/should_have_children_with_embedded_subtitles.yml +595 -0
  69. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Category/_children/should_have_children_with_subtitles.yml +482 -0
  70. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Category/_children/should_memoize.yml +478 -0
  71. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Category/_children/should_refresh_children_when_config_changes.yml +1245 -0
  72. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Category/_children/should_use_category_value_for_children.yml +395 -0
  73. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Category/_initialize/should_instantiate.yml +61 -0
  74. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Category/_initialize/should_set_presorted_if_present.yml +61 -0
  75. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Category/_initialize/should_use_category_value_for_title_if_present.yml +61 -0
  76. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Episode/_initialize/should_instantiate.yml +444 -0
  77. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Episode/_metadata/should_allow_disabling_series_id_in_metadata.yml +444 -0
  78. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Episode/_metadata/should_populate_metadata.yml +579 -0
  79. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Metadata/_initialize/should_instantiate.yml +296 -0
  80. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Movie/_initialize/should_instantiate.yml +296 -0
  81. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Movie/_metadata/should_populate_metadata.yml +296 -0
  82. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_QualifiedCategory/_children/should_display_non-zero_child_count_once_children_fetched.yml +220 -0
  83. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_QualifiedCategory/_children/should_have_children.yml +393 -0
  84. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_QualifiedCategory/_children/should_memoize.yml +219 -0
  85. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_QualifiedCategory/_initialize/should_instantiate.yml +61 -0
  86. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Season/_children/should_have_children.yml +444 -0
  87. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Season/_children/should_memoize.yml +444 -0
  88. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Season/_initialize/should_instantiate.yml +250 -0
  89. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Section/_children/should_have_category_children.yml +61 -0
  90. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Section/_children/should_memoize.yml +61 -0
  91. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Section/_initialize/should_instantiate.yml +61 -0
  92. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Show/_children/should_have_children.yml +250 -0
  93. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Show/_children/should_memoize.yml +250 -0
  94. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Show/_initialize/should_instantiate.yml +166 -0
  95. data/spec/fixtures/vcr/TivoHMO_Adapters_Plex_Transcoder/_initialize/should_instantiate.yml +296 -0
  96. data/spec/server_spec.rb +31 -2
  97. data/spec/spec_helper.rb +24 -36
  98. data/tivohmo.gemspec +2 -2
  99. metadata +109 -3
@@ -1,9 +1,9 @@
1
1
  require_relative "../../spec_helper"
2
2
  require 'tivohmo/adapters/plex'
3
3
 
4
- describe TivoHMO::Adapters::Plex::Show do
4
+ describe TivoHMO::Adapters::Plex::Show, :vcr do
5
5
 
6
- let(:plex_delegate) { plex_stub(::Plex::Show) }
6
+ let(:plex_delegate) { plex_tv_section.all.first }
7
7
 
8
8
  describe "#initialize" do
9
9
 
@@ -13,8 +13,23 @@ describe TivoHMO::Adapters::Plex::Show do
13
13
  expect(show).to be_a TivoHMO::API::Container
14
14
  expect(show.title).to eq(plex_delegate.title)
15
15
  expect(show.identifier).to eq(plex_delegate.key)
16
- expect(show.modified_at).to eq(Time.at(plex_delegate.updated_at))
17
- expect(show.created_at).to eq(Time.at(plex_delegate.added_at))
16
+ expect(show.modified_at).to eq(Time.at(plex_delegate.updated_at.to_i))
17
+ expect(show.created_at).to eq(Time.at(plex_delegate.added_at.to_i))
18
+ end
19
+
20
+ end
21
+
22
+ describe "#children" do
23
+
24
+ it "should memoize" do
25
+ show = described_class.new(plex_delegate)
26
+ expect(show.children.object_id).to eq(show.children.object_id)
27
+ end
28
+
29
+ it "should have children" do
30
+ show = described_class.new(plex_delegate)
31
+ expect(show.children).to_not be_empty
32
+ show.children.all? {|c| expect(c).to be_instance_of(TivoHMO::Adapters::Plex::Season) }
18
33
  end
19
34
 
20
35
  end
@@ -1,15 +1,10 @@
1
1
  require_relative "../../spec_helper"
2
2
  require 'tivohmo/adapters/plex'
3
3
 
4
- describe TivoHMO::Adapters::Plex::Transcoder do
4
+ describe TivoHMO::Adapters::Plex::Transcoder, :vcr do
5
5
 
6
6
 
7
- let(:plex_delegate) { plex_stub(::Plex::Movie,
8
- summary: 'Summary',
9
- duration: 10000,
10
- medias: [double('media',
11
- parts: [double('part',
12
- file: '/foo%20bar')])])}
7
+ let(:plex_delegate) { plex_movie_section.all.first }
13
8
 
14
9
  let(:item) { double('item', identifier: plex_delegate.key, delegate: plex_delegate)}
15
10
 
@@ -19,7 +14,6 @@ describe TivoHMO::Adapters::Plex::Transcoder do
19
14
  trans = described_class.new(item)
20
15
  expect(trans).to be_a described_class
21
16
  expect(trans).to be_a TivoHMO::API::Transcoder
22
- expect(trans.source_filename).to eq '/foo bar'
23
17
  end
24
18
 
25
19
  end
@@ -0,0 +1,25 @@
1
+ require_relative "../../spec_helper"
2
+ require 'tivohmo/adapters/settings'
3
+
4
+ describe TivoHMO::Adapters::Settings::Application do
5
+
6
+
7
+ describe "#initialize" do
8
+
9
+ it "should instantiate" do
10
+ app = described_class.new('settings')
11
+ expect(app).to be_a described_class
12
+ expect(app.metadata_class).to eq TivoHMO::Adapters::Settings::Metadata
13
+ expect(app.transcoder_class).to eq TivoHMO::Adapters::Settings::Transcoder
14
+ expect(app.children.size).to eq(TivoHMO::Config.instance.known_config.keys.size + 1)
15
+ app.children[0..-2].all? do |c|
16
+ expect(c).to be_instance_of(TivoHMO::Adapters::Settings::KeyContainer)
17
+ expect(TivoHMO::Config.instance.known_config[c.identifier]).to_not be_nil
18
+ end
19
+ expect(app.children.last).to be_instance_of(TivoHMO::Adapters::Settings::ResetDefaultsItem)
20
+ expect(app.children.last.title).to eq("Reset Defaults")
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,29 @@
1
+ require_relative "../../spec_helper"
2
+ require 'tivohmo/adapters/settings'
3
+
4
+ describe TivoHMO::Adapters::Settings::DisplayItem do
5
+
6
+ describe "#initialize" do
7
+
8
+ it "should instantiate" do
9
+ item = described_class.new("Foo")
10
+ expect(item).to be_a described_class
11
+ expect(item.children.size).to eq(0)
12
+ expect(item.title).to eq("Foo")
13
+ end
14
+
15
+ it "should provide metadata description" do
16
+ item = described_class.new("Foo")
17
+ item.app = TivoHMO::Adapters::Settings::Application.new('settings')
18
+ expect(item.metadata.description).to eq("Nothing to do here, hit back to return")
19
+ end
20
+
21
+ it "should provide extended metadata description" do
22
+ item = described_class.new("Foo", "This is foo")
23
+ item.app = TivoHMO::Adapters::Settings::Application.new('settings')
24
+ expect(item.metadata.description).to eq("This is foo. Nothing to do here, hit back to return")
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,33 @@
1
+ require_relative "../../spec_helper"
2
+ require 'tivohmo/adapters/settings'
3
+
4
+ describe TivoHMO::Adapters::Settings::KeyContainer do
5
+
6
+ let (:config_key) do
7
+ TivoHMO::Config.instance.known_config.keys.first
8
+ end
9
+
10
+ let (:config_spec) do
11
+ TivoHMO::Config.instance.known_config[config_key]
12
+ end
13
+
14
+ describe "#initialize" do
15
+
16
+ it "should instantiate" do
17
+ cont = described_class.new(config_key)
18
+ expect(cont).to be_a described_class
19
+ expect(cont.children.size).to eq(4)
20
+ expect(cont.children[0]).to be_instance_of(TivoHMO::Adapters::Settings::DisplayItem)
21
+ expect(cont.children[0].title).to eq("Help")
22
+ expect(cont.children[1]).to be_instance_of(TivoHMO::Adapters::Settings::DisplayItem)
23
+ expect(cont.children[1].title).to eq("Default Value: #{config_spec[:default_value]}")
24
+ expect(cont.children[2]).to be_instance_of(TivoHMO::Adapters::Settings::DisplayItem)
25
+ val = !!TivoHMO::Config.instance.get(config_key)
26
+ expect(cont.children[2].title).to eq("Current Value: #{val}")
27
+ expect(cont.children[3]).to be_instance_of(TivoHMO::Adapters::Settings::SetValueItem)
28
+ expect(cont.children[3].title).to eq("Set value to #{!val}")
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,33 @@
1
+ require_relative "../../spec_helper"
2
+ require 'tivohmo/adapters/settings'
3
+
4
+ describe TivoHMO::Adapters::Settings::Metadata do
5
+
6
+ describe "#initialize" do
7
+
8
+ it "should instantiate" do
9
+ md = described_class.new(double('item'))
10
+ end
11
+
12
+ it "should allow not having a callback" do
13
+ md = described_class.new(double('item'))
14
+ expect(md.item_detail_callback).to be_nil
15
+
16
+ md.star_rating
17
+ end
18
+
19
+ it "should callback on star_rating" do
20
+ md = described_class.new(double('item'))
21
+
22
+ called = 0
23
+ md.item_detail_callback = Proc.new do
24
+ called += 1
25
+ end
26
+
27
+ md.star_rating
28
+ expect(called).to eq(1)
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,54 @@
1
+ require_relative "../../spec_helper"
2
+ require 'tivohmo/adapters/settings'
3
+
4
+ describe TivoHMO::Adapters::Settings::ResetDefaultsItem do
5
+
6
+ let (:config_key) do
7
+ TivoHMO::Config.instance.known_config.keys.first
8
+ end
9
+
10
+ let (:config_spec) do
11
+ TivoHMO::Config.instance.known_config[config_key]
12
+ end
13
+
14
+ describe "#initialize" do
15
+
16
+ it "should instantiate" do
17
+ item = described_class.new
18
+ expect(item).to be_a described_class
19
+ expect(item.children.size).to eq(0)
20
+ expect(item.title).to eq("Reset Defaults")
21
+ end
22
+
23
+ it "should provide metadata description" do
24
+ new_value = ! TivoHMO::Config.instance.get(config_key)
25
+ item = described_class.new
26
+ item.app = TivoHMO::Adapters::Settings::Application.new('settings')
27
+
28
+ expect(item.metadata).to_not be_nil
29
+ expect(item.metadata.description).to eq("All runtime config has now been reset to defaults, hit back to return")
30
+ end
31
+
32
+ it "should not change when reading metadata" do
33
+ expect(TivoHMO::Config.instance).to receive(:set).never
34
+ item = described_class.new
35
+ item.app = TivoHMO::Adapters::Settings::Application.new('settings')
36
+
37
+ expect(item.metadata).to_not be_nil
38
+ end
39
+
40
+ it "should change when reading metadata" do
41
+ app = TivoHMO::Adapters::Settings::Application.new('settings')
42
+ app.add_child(item = described_class.new)
43
+
44
+ TivoHMO::Config.instance.known_config.each do |key, spec|
45
+ expect(TivoHMO::Config.instance).to receive(:set).with(key, spec[:default_value])
46
+ end
47
+ expect(app.children).to receive(:clear)
48
+
49
+ item.metadata.star_rating
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,54 @@
1
+ require_relative "../../spec_helper"
2
+ require 'tivohmo/adapters/settings'
3
+
4
+ describe TivoHMO::Adapters::Settings::SetValueItem do
5
+
6
+ let (:config_key) do
7
+ TivoHMO::Config.instance.known_config.keys.first
8
+ end
9
+
10
+ let (:config_spec) do
11
+ TivoHMO::Config.instance.known_config[config_key]
12
+ end
13
+
14
+ describe "#initialize" do
15
+
16
+ it "should instantiate" do
17
+ new_value = ! TivoHMO::Config.instance.get(config_key)
18
+ item = described_class.new(config_key, new_value)
19
+ expect(item).to be_a described_class
20
+ expect(item.children.size).to eq(0)
21
+ expect(item.title).to eq("Set value to #{new_value}")
22
+ end
23
+
24
+ it "should provide metadata description" do
25
+ new_value = ! TivoHMO::Config.instance.get(config_key)
26
+ item = described_class.new(config_key, new_value)
27
+ item.app = TivoHMO::Adapters::Settings::Application.new('settings')
28
+
29
+ expect(item.metadata).to_not be_nil
30
+ expect(item.metadata.description).to eq("Value has now been set to #{new_value}, hit back to return")
31
+ end
32
+
33
+ it "should not change when reading metadata" do
34
+ new_value = ! TivoHMO::Config.instance.get(config_key)
35
+ item = described_class.new(config_key, new_value)
36
+ item.app = TivoHMO::Adapters::Settings::Application.new('settings')
37
+
38
+ expect(item.metadata).to_not be_nil
39
+ expect(TivoHMO::Config.instance.get(config_key)).to_not eq(new_value)
40
+ end
41
+
42
+ it "should change when reading metadata" do
43
+ new_value = ! TivoHMO::Config.instance.get(config_key)
44
+ app = TivoHMO::Adapters::Settings::Application.new('settings')
45
+ app.add_child(item = described_class.new(config_key, new_value))
46
+
47
+ expect(app.children).to receive(:clear)
48
+ item.metadata.star_rating
49
+ expect(TivoHMO::Config.instance.get(config_key)).to eq(new_value)
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -13,6 +13,7 @@ describe TivoHMO::API::Container do
13
13
  expect(node).to be_a(TivoHMO::API::Node)
14
14
  expect(node.identifier).to eq('c')
15
15
  expect(node.uuid).to_not be_nil
16
+ expect(node.presorted).to eq(false)
16
17
  expect(node.content_type).to eq("x-tivo-container/tivo-videos")
17
18
  expect(node.source_format).to eq("x-tivo-container/folder")
18
19
  end
@@ -31,4 +32,15 @@ describe TivoHMO::API::Container do
31
32
 
32
33
  end
33
34
 
35
+ describe "#child_count" do
36
+
37
+ it "should count children" do
38
+ node = test_class.new('c')
39
+ expect(node.child_count).to eq(0)
40
+ node2 = node.add_child(test_class.new('c2'))
41
+ expect(node.child_count).to eq(1)
42
+ end
43
+
44
+ end
45
+
34
46
  end
@@ -14,6 +14,8 @@ describe TivoHMO::API::Item do
14
14
  expect(node).to be_a(TivoHMO::API::Node)
15
15
  expect(node.identifier).to eq('i')
16
16
  expect(node.title).to eq('i')
17
+ expect(node.file).to eq('i')
18
+ expect(node.subtitle).to be_nil
17
19
  expect(node.content_type).to eq("video/x-tivo-mpeg")
18
20
  expect(node.source_format).to eq("video/x-tivo-mpeg")
19
21
  end
@@ -17,7 +17,6 @@ describe TivoHMO::API::Transcoder do
17
17
  trans = test_class.new(item)
18
18
  expect(trans).to be_a(TivoHMO::API::Transcoder)
19
19
  expect(trans.item).to eq(item)
20
- expect(trans.source_filename).to eq('foo')
21
20
  end
22
21
 
23
22
  end
data/spec/beacon_spec.rb CHANGED
@@ -77,7 +77,9 @@ describe TivoHMO::Beacon do
77
77
  it "sends a packet on the socket" do
78
78
  beacon = described_class.new(1234)
79
79
  expect(beacon).to receive(:beacon_data).with('broadcast').and_return('packet')
80
- socket = beacon.instance_variable_get(:@socket)
80
+ socket = instance_double("Socket")
81
+ expect(UDPSocket).to receive(:new).with(Socket::AF_INET).and_return(socket)
82
+ expect(socket).to receive(:setsockopt).with(Socket::SOL_SOCKET, Socket::SO_BROADCAST, true)
81
83
  expect(socket).to receive(:send).with('packet', 0, '<broadcast>', 2190)
82
84
  beacon.broadcast
83
85
  end
data/spec/cli_spec.rb CHANGED
@@ -3,10 +3,12 @@ require "tivohmo/cli"
3
3
 
4
4
  describe TivoHMO::CLI do
5
5
 
6
+ let(:app_title) { 'app_title' }
6
7
  let(:app_name) { TestAPI::Application.name }
7
8
  let(:app_ident) { 'app_ident' }
8
9
  let(:minimal_args) do
9
10
  {
11
+ title: app_title,
10
12
  application: app_name,
11
13
  identifier: app_ident
12
14
  }
@@ -94,28 +96,71 @@ describe TivoHMO::CLI do
94
96
 
95
97
  describe "--configuration" do
96
98
 
97
- it "defaults to not loading config" do
98
- expect(YAML).to receive(:load_file).never
99
+ it "defaults to calling setup with nil" do
100
+ expect(TivoHMO::Config.instance).to receive(:setup).with(nil, nil)
99
101
  cli.run(argv(minimal_args))
100
102
  end
101
103
 
102
- it "sets log level to debug" do
103
- expect(YAML).to receive(:load_file).with('foo.yml').and_return({})
104
+ it "can supply a config file" do
105
+ expect(TivoHMO::Config.instance).to receive(:setup).with(/foo.yml$/, nil)
104
106
  cli.run(argv(minimal_args.merge(configuration: 'foo.yml')))
105
107
  end
106
108
 
107
- it "can supply config" do
108
- expect(YAML).to receive(:load_file).with('foo.yml').and_return({'port' => 1234})
109
+ it "can supply config values" do
110
+ cf = Tempfile.new('cli_config').path
111
+ File.write(cf, YAML.dump({'port' => 1234}))
109
112
  expect(TivoHMO::Server).to receive(:start).with(api_server, 1234)
110
- cli.run(argv(minimal_args.merge(configuration: 'foo.yml')))
113
+ cli.run(argv(minimal_args.merge(configuration: cf)))
114
+ expect(TivoHMO::Config.instance.get(:port)).to eq(1234)
111
115
  end
112
116
 
113
117
  it "supplies config that can be overriden from cli" do
114
- expect(YAML).to receive(:load_file).with('foo.yml').and_return({'port' => 1234})
118
+ cf = Tempfile.new('cli_config').path
119
+ File.write(cf, YAML.dump({'port' => 1234}))
115
120
  expect(TivoHMO::Server).to receive(:start).with(api_server, 4321)
116
- cli.run(argv(minimal_args.merge(configuration: 'foo.yml', port: 4321)))
121
+ cli.run(argv(minimal_args.merge(configuration: cf, port: 4321)))
122
+ expect(TivoHMO::Config.instance.get(:port)).to eq(1234)
117
123
  end
118
124
 
125
+ it "merges/overrides app config from file with config from cli" do
126
+ cf = Tempfile.new('cli_config').path
127
+ OtherApp1 = Class.new(TestAPI::Application)
128
+ OtherApp2 = Class.new(TestAPI::Application)
129
+ File.write(cf,
130
+ YAML.dump({
131
+ 'applications' => {
132
+ "App1" => {
133
+ "application" => TestAPI::Application.name,
134
+ "identifier" => 'app_ident1'
135
+ },
136
+ "App2" => {
137
+ "application" => TestAPI::Application.name,
138
+ "identifier" => 'app_ident2'
139
+ }
140
+ }
141
+ }))
142
+ cli.run(argv(%W[
143
+ configuration #{cf}
144
+ title App1
145
+ application #{OtherApp1.name}
146
+ identifier other_ident1
147
+ title App2
148
+ application #{OtherApp2.name}
149
+ identifier other_ident2
150
+ ]))
151
+
152
+ expect(api_server.children.size).to eq(2)
153
+ app1 = api_server.children[0]
154
+ app2 = api_server.children[1]
155
+ expect(app1.title).to eq('App1')
156
+ expect(app1.class).to eq(OtherApp1)
157
+ expect(app1.identifier).to eq('other_ident1')
158
+ expect(app2.title).to eq('App2')
159
+ expect(app2.class).to eq(OtherApp2)
160
+ expect(app2.identifier).to eq('other_ident2')
161
+ end
162
+
163
+
119
164
  end
120
165
 
121
166
  describe "--port" do
@@ -167,7 +212,7 @@ describe TivoHMO::CLI do
167
212
 
168
213
  it "requires one init per app" do
169
214
  expect {
170
- described_class.new("").run(["-a", "foo"])
215
+ described_class.new("").run(["-t", "app", "-a", "foo"])
171
216
  }.to raise_error(Clamp::UsageError,
172
217
  'an initializer is needed for each application')
173
218
  end
@@ -183,21 +228,14 @@ describe TivoHMO::CLI do
183
228
  it "requires the adapter for the application" do
184
229
  require 'tivohmo/adapters/filesystem'
185
230
  expect(cli).to receive(:require).with('tivohmo/adapters/filesystem')
186
- cli.run(%w[-a TivoHMO::Adapters::Filesystem::Application -i .])
231
+ cli.run(%w[-t App -a TivoHMO::Adapters::Filesystem::Application -i .])
187
232
  end
188
233
 
189
234
  it "starts a server for the app" do
190
235
  cli.run(argv(minimal_args))
191
236
  expect(api_server.children.size).to eq(1)
192
237
  expect(api_server.children.first.class).to eq(TestAPI::Application)
193
- expect(api_server.children.first.title).to eq("#{app_ident} on #{api_server.title}")
194
- end
195
-
196
- it "starts a server with title" do
197
- cli.run(argv(minimal_args.merge(title: 'Foo')))
198
- expect(api_server.children.size).to eq(1)
199
- expect(api_server.children.first.class).to eq(TestAPI::Application)
200
- expect(api_server.children.first.title).to eq("Foo")
238
+ expect(api_server.children.first.title).to eq(app_title)
201
239
  end
202
240
 
203
241
  it "starts a server with alternate transcoder/metadata" do