ruku 0.1
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.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +96 -0
- data/Rakefile +33 -0
- data/bin/ruku +50 -0
- data/lib/ruku/clients/simple.rb +232 -0
- data/lib/ruku/clients/tk.rb +36 -0
- data/lib/ruku/clients/web.rb +117 -0
- data/lib/ruku/clients/web_static/css/ruku.css +196 -0
- data/lib/ruku/clients/web_static/images/box-medium.png +0 -0
- data/lib/ruku/clients/web_static/images/box-small.png +0 -0
- data/lib/ruku/clients/web_static/images/remote/back-over.png +0 -0
- data/lib/ruku/clients/web_static/images/remote/back.png +0 -0
- data/lib/ruku/clients/web_static/images/remote/down-over.png +0 -0
- data/lib/ruku/clients/web_static/images/remote/down.png +0 -0
- data/lib/ruku/clients/web_static/images/remote/fwd-over.png +0 -0
- data/lib/ruku/clients/web_static/images/remote/fwd.png +0 -0
- data/lib/ruku/clients/web_static/images/remote/home-over.png +0 -0
- data/lib/ruku/clients/web_static/images/remote/home.png +0 -0
- data/lib/ruku/clients/web_static/images/remote/left-over.png +0 -0
- data/lib/ruku/clients/web_static/images/remote/left.png +0 -0
- data/lib/ruku/clients/web_static/images/remote/pause-over.png +0 -0
- data/lib/ruku/clients/web_static/images/remote/pause.png +0 -0
- data/lib/ruku/clients/web_static/images/remote/right-over.png +0 -0
- data/lib/ruku/clients/web_static/images/remote/right.png +0 -0
- data/lib/ruku/clients/web_static/images/remote/select-over.png +0 -0
- data/lib/ruku/clients/web_static/images/remote/select.png +0 -0
- data/lib/ruku/clients/web_static/images/remote/space1.png +0 -0
- data/lib/ruku/clients/web_static/images/remote/space2.png +0 -0
- data/lib/ruku/clients/web_static/images/remote/space3.png +0 -0
- data/lib/ruku/clients/web_static/images/remote/up-over.png +0 -0
- data/lib/ruku/clients/web_static/images/remote/up.png +0 -0
- data/lib/ruku/clients/web_static/images/spacer.gif +0 -0
- data/lib/ruku/clients/web_static/index.html +203 -0
- data/lib/ruku/clients/web_static/js/jquery-1.4.2.js +154 -0
- data/lib/ruku/clients/web_static/js/ruku.js +447 -0
- data/lib/ruku/remote.rb +138 -0
- data/lib/ruku/remotes.rb +78 -0
- data/lib/ruku/storage.rb +77 -0
- data/lib/ruku.rb +5 -0
- data/ruku.gemspec +31 -0
- data/test/helper.rb +11 -0
- data/test/js/qunit.css +119 -0
- data/test/js/qunit.js +1069 -0
- data/test/js/runner.html +29 -0
- data/test/js/test_remote.js +37 -0
- data/test/js/test_remote_manager.js +186 -0
- data/test/js/test_remote_menu.js +208 -0
- data/test/js/test_util.js +15 -0
- data/test/test_remote.rb +89 -0
- data/test/test_remotes.rb +144 -0
- data/test/test_simple_client.rb +166 -0
- data/test/test_simple_storage.rb +70 -0
- data/test/test_web_client.rb +46 -0
- data/test/test_yaml_storage.rb +54 -0
- metadata +156 -0
@@ -0,0 +1,144 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
+
|
3
|
+
class TestRemotes < Test::Unit::TestCase
|
4
|
+
TEST_NAME_1 = 'Remote 1'
|
5
|
+
TEST_NAME_2 = 'Remote 2'
|
6
|
+
TEST_NAME_3 = 'Remote 3'
|
7
|
+
TEST_HOST_1 = '192.168.1.5'
|
8
|
+
TEST_HOST_2 = '192.168.1.6'
|
9
|
+
TEST_HOST_3 = '192.168.1.7'
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@test_storage_path = File.join(File.dirname(__FILE__), 'tmp', '.ruku')
|
13
|
+
cleanup
|
14
|
+
@remote1 = Remote.new(TEST_HOST_1, TEST_NAME_1)
|
15
|
+
@remote2 = Remote.new(TEST_HOST_2, TEST_NAME_2)
|
16
|
+
@remote3 = Remote.new(TEST_HOST_3, TEST_NAME_3)
|
17
|
+
end
|
18
|
+
|
19
|
+
def teardown
|
20
|
+
cleanup
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_initialize_adds_boxes
|
24
|
+
assert Remotes.new.empty?
|
25
|
+
|
26
|
+
m = Remotes.new([@remote1])
|
27
|
+
assert_equal 1, m.boxes.size
|
28
|
+
assert m.boxes.include?(@remote1)
|
29
|
+
|
30
|
+
m = Remotes.new([@remote1, @remote2])
|
31
|
+
assert_equal 2, m.boxes.size
|
32
|
+
assert m.boxes.include?(@remote1)
|
33
|
+
assert m.boxes.include?(@remote2)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_active_box_defaults_to_first
|
37
|
+
assert_equal @remote1, Remotes.new([@remote1]).active
|
38
|
+
assert_equal @remote1, Remotes.new([@remote1, @remote2]).active
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_active_box_is_nil_if_no_boxes
|
42
|
+
assert_nil Remotes.new.active
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_set_active
|
46
|
+
m = Remotes.new([@remote1, @remote2])
|
47
|
+
assert_equal @remote1, m.active
|
48
|
+
m.set_active(@remote2)
|
49
|
+
assert_equal @remote2, m.active
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_add
|
53
|
+
m = Remotes.new([@remote1, @remote2])
|
54
|
+
assert_equal 2, m.boxes.size
|
55
|
+
m.add(@remote3)
|
56
|
+
assert_equal 3, m.boxes.size
|
57
|
+
m.boxes.include?(@remote3)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_add_does_not_add_duplicates
|
61
|
+
m = Remotes.new([@remote1, @remote2])
|
62
|
+
assert_equal 2, m.boxes.size
|
63
|
+
m.add(@remote2)
|
64
|
+
assert_equal 2, m.boxes.size
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_remove
|
68
|
+
m = Remotes.new([@remote1, @remote2])
|
69
|
+
assert_equal 2, m.boxes.size
|
70
|
+
|
71
|
+
m.remove(@remote2)
|
72
|
+
assert_equal 1, m.boxes.size
|
73
|
+
assert !m.boxes.include?(@remote2)
|
74
|
+
|
75
|
+
m.remove(@remote1)
|
76
|
+
assert m.boxes.empty?
|
77
|
+
assert !m.boxes.include?(@remote2)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_remove_adjusts_active
|
81
|
+
m = Remotes.new([@remote1, @remote2])
|
82
|
+
m.set_active(@remote2)
|
83
|
+
assert_equal @remote2, m.active
|
84
|
+
m.remove(@remote2)
|
85
|
+
assert_equal @remote1, m.active
|
86
|
+
|
87
|
+
m = Remotes.new([@remote1, @remote2])
|
88
|
+
assert_equal @remote1, m.active
|
89
|
+
m.remove(@remote1)
|
90
|
+
assert_equal @remote2, m.active
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_remove_non_existent
|
94
|
+
m = Remotes.new([@remote1, @remote2])
|
95
|
+
assert_equal 2, m.boxes.size
|
96
|
+
|
97
|
+
m.remove(@remote3)
|
98
|
+
assert_equal 2, m.boxes.size
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_store_and_load
|
102
|
+
storage = YAMLStorage.new(@test_storage_path)
|
103
|
+
Remotes.new([@remote1, @remote2], storage).store
|
104
|
+
m = Remotes.new
|
105
|
+
m.storage = storage
|
106
|
+
m.load
|
107
|
+
|
108
|
+
assert_equal 2, m.boxes.size
|
109
|
+
assert_equal @remote1, m.boxes[0]
|
110
|
+
assert_equal @remote2, m.boxes[1]
|
111
|
+
assert_equal @remote1, m.active
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_each
|
115
|
+
m = Remotes.new([@remote1, @remote2])
|
116
|
+
hosts = []
|
117
|
+
m.each {|b| hosts << b.host}
|
118
|
+
assert_equal 2, hosts.size
|
119
|
+
assert hosts.include?(TEST_HOST_1)
|
120
|
+
assert hosts.include?(TEST_HOST_2)
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_subscript_reader
|
124
|
+
m = Remotes.new([@remote1, @remote2])
|
125
|
+
assert_equal TEST_HOST_1, m[0].host
|
126
|
+
assert_equal TEST_HOST_2, m[1].host
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_subscript_writer
|
130
|
+
m = Remotes.new
|
131
|
+
m[0] = @remote1
|
132
|
+
assert_equal TEST_HOST_1, m[0].host
|
133
|
+
m[0] = @remote2
|
134
|
+
assert_equal TEST_HOST_2, m[0].host
|
135
|
+
m[1] = @remote3
|
136
|
+
assert_equal TEST_HOST_3, m[1].host
|
137
|
+
end
|
138
|
+
|
139
|
+
protected
|
140
|
+
|
141
|
+
def cleanup
|
142
|
+
File.delete(@test_storage_path) if File.exist?(@test_storage_path)
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
+
require 'ruku/clients/simple'
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
# Tests for Ruku::Clients::Simple; most of these are more integration tests
|
6
|
+
# since the client is just a UI wrapper around the important stuff
|
7
|
+
class TestSimpleClient < Test::Unit::TestCase
|
8
|
+
TEST_NAME_1 = 'Remote 1'
|
9
|
+
TEST_NAME_2 = 'Remote 2'
|
10
|
+
TEST_NAME_3 = 'Remote 3'
|
11
|
+
TEST_HOST_1 = '192.168.1.5'
|
12
|
+
TEST_HOST_2 = '192.168.1.6'
|
13
|
+
TEST_HOST_3 = '192.168.1.7'
|
14
|
+
|
15
|
+
def setup
|
16
|
+
@output = ''
|
17
|
+
@output_stream = StringIO.new(@output, 'w')
|
18
|
+
end
|
19
|
+
|
20
|
+
def teardown
|
21
|
+
@output_stream.close
|
22
|
+
end
|
23
|
+
|
24
|
+
# Tests output of 'list' command line operation, trying to ignore slight
|
25
|
+
# changes in UI like the header and making sure things like the names
|
26
|
+
# and hosts of the remotes are displayed
|
27
|
+
def test_cmd_line_list
|
28
|
+
sc, out = get_test_client_and_output
|
29
|
+
sc.list
|
30
|
+
|
31
|
+
lines_method = ''.respond_to?(:lines) ? :lines : :to_s
|
32
|
+
active1 = out.send(lines_method).find {|l| l.include? TEST_HOST_1}
|
33
|
+
inactive2 = out.send(lines_method).find {|l| l.include? TEST_HOST_2}
|
34
|
+
inactive3 = out.send(lines_method).find {|l| l.include? TEST_HOST_3}
|
35
|
+
|
36
|
+
assert active1, 'Active box host found in output'
|
37
|
+
assert active1.include?(TEST_NAME_1), 'Active box name on same line as host'
|
38
|
+
assert active1.include?('active'), 'Active box marked as such in output'
|
39
|
+
|
40
|
+
assert inactive2, 'First inactive box host found in output'
|
41
|
+
assert inactive2.include?(TEST_NAME_2), 'First inactive box name on same line as host'
|
42
|
+
assert !inactive2.include?('active'), 'First inactive box not marked as active'
|
43
|
+
|
44
|
+
assert inactive3, 'Second inactive box host found in output'
|
45
|
+
assert inactive3.include?(TEST_NAME_3), 'Second inactive box name on same line as host'
|
46
|
+
assert !inactive3.include?('active'), 'Second inactive box not marked as active'
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_add
|
50
|
+
sc, out = get_test_client_and_output
|
51
|
+
storage_mock = mock()
|
52
|
+
sc.remotes = Remotes.new([], storage_mock)
|
53
|
+
storage_mock.expects(:store).with(sc.remotes).once
|
54
|
+
|
55
|
+
sc.add(TEST_HOST_1)
|
56
|
+
|
57
|
+
assert sc.remotes.find {|b| b.host == TEST_HOST_1}, 'Box has been added'
|
58
|
+
|
59
|
+
assert out.include?('Added'), 'Output indicates addition'
|
60
|
+
assert out.include?(TEST_HOST_1), 'Output includes correct host'
|
61
|
+
assert out.include?('My Roku Box'), 'Output shows (default) box name'
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_add_with_name
|
65
|
+
sc, out = get_test_client_and_output
|
66
|
+
storage_mock = mock()
|
67
|
+
sc.remotes = Remotes.new([], storage_mock)
|
68
|
+
storage_mock.expects(:store).with(sc.remotes).once
|
69
|
+
|
70
|
+
sc.add(TEST_HOST_1, TEST_NAME_1)
|
71
|
+
|
72
|
+
assert sc.remotes.find {|b| b.host == TEST_HOST_1}, 'Box has been added'
|
73
|
+
|
74
|
+
assert out.include?('Added'), 'Output indicates addition'
|
75
|
+
assert out.include?(TEST_HOST_1), 'Output includes correct host'
|
76
|
+
assert out.include?(TEST_NAME_1), 'Output shows correct box name'
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_add_changes_existing_box_name
|
80
|
+
sc, out = get_test_client_and_output
|
81
|
+
storage_mock = mock()
|
82
|
+
sc.remotes = Remotes.new([Remote.new(TEST_HOST_1, TEST_NAME_1)], storage_mock)
|
83
|
+
storage_mock.expects(:store).with(sc.remotes).once
|
84
|
+
|
85
|
+
new_name = 'Brand New Name'
|
86
|
+
sc.add(TEST_HOST_1, new_name)
|
87
|
+
|
88
|
+
assert sc.remotes.find {|b| b.host == TEST_HOST_1}, 'Box is still there'
|
89
|
+
assert_equal new_name, sc.remotes.find {|b| b.host == TEST_HOST_1}.name, 'Name changed correctly'
|
90
|
+
|
91
|
+
assert out.include?('Added'), 'Output indicates addition (even though it is not, really)'
|
92
|
+
assert out.include?(TEST_HOST_1), 'Output includes correct host'
|
93
|
+
assert out.include?(new_name), 'Output shows changed box name'
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_remove_by_host
|
97
|
+
sc, out = get_test_client_and_output
|
98
|
+
storage_mock = mock()
|
99
|
+
sc.remotes.storage = storage_mock
|
100
|
+
storage_mock.expects(:store).with(sc.remotes).once
|
101
|
+
|
102
|
+
sc.remove(TEST_HOST_2)
|
103
|
+
|
104
|
+
assert_equal 2, sc.remotes.size, 'There is one less remote'
|
105
|
+
assert sc.remotes.find {|b| b.host == TEST_HOST_1}, 'Did not remove the wrong remote'
|
106
|
+
assert sc.remotes.find {|b| b.host == TEST_HOST_3}, 'Did not remove the wrong remote'
|
107
|
+
|
108
|
+
assert out.include?('removed'), 'Output indicates removal'
|
109
|
+
assert out.include?(TEST_HOST_2), 'Output includes correct host'
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_name_with_host
|
113
|
+
sc, out = get_test_client_and_output
|
114
|
+
storage_mock = mock()
|
115
|
+
sc.remotes.storage = storage_mock
|
116
|
+
storage_mock.expects(:store).with(sc.remotes).once
|
117
|
+
|
118
|
+
new_name = 'Renamed!'
|
119
|
+
sc.name(TEST_HOST_3, new_name)
|
120
|
+
|
121
|
+
assert_equal 3, sc.remotes.size, 'Did not add or remove any remotes'
|
122
|
+
assert_equal new_name, sc.remotes.find {|r| r.host == TEST_HOST_3}.name, 'The name is changed'
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_activate_with_host
|
126
|
+
sc, out = get_test_client_and_output
|
127
|
+
storage_mock = mock()
|
128
|
+
sc.remotes.storage = storage_mock
|
129
|
+
storage_mock.expects(:store).with(sc.remotes).once
|
130
|
+
|
131
|
+
assert_equal TEST_HOST_1, sc.remotes.active.host
|
132
|
+
|
133
|
+
sc.activate(TEST_HOST_3)
|
134
|
+
|
135
|
+
assert_equal TEST_HOST_3, sc.remotes.active.host
|
136
|
+
assert out.include?('activated'), 'Activation indicated'
|
137
|
+
assert out.include?(TEST_HOST_3), 'Output includes correct host'
|
138
|
+
end
|
139
|
+
|
140
|
+
private
|
141
|
+
|
142
|
+
def get_test_remotes
|
143
|
+
@remote1 = Remote.new(TEST_HOST_1, TEST_NAME_1)
|
144
|
+
@remote2 = Remote.new(TEST_HOST_2, TEST_NAME_2)
|
145
|
+
@remote3 = Remote.new(TEST_HOST_3, TEST_NAME_3)
|
146
|
+
Remotes.new([@remote1, @remote2, @remote3])
|
147
|
+
end
|
148
|
+
|
149
|
+
def get_test_client_and_output
|
150
|
+
sc = Clients::Simple.new(get_test_remotes)
|
151
|
+
sc.output_stream = @output_stream
|
152
|
+
[sc, @output]
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
class Ruku::Clients::Simple
|
157
|
+
attr_accessor :output_stream
|
158
|
+
|
159
|
+
def puts(str)
|
160
|
+
@output_stream.puts str
|
161
|
+
end
|
162
|
+
|
163
|
+
def print(str)
|
164
|
+
@output_stream.print str
|
165
|
+
end
|
166
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
+
|
3
|
+
class TestSimpleStorage < Test::Unit::TestCase
|
4
|
+
TMP_DIR = File.join(File.dirname(__FILE__), 'tmp')
|
5
|
+
BOXES_FILE = File.join(TMP_DIR, 'boxes.txt')
|
6
|
+
|
7
|
+
TEST_NAME_1 = 'Living Room'
|
8
|
+
TEST_NAME_2 = 'Upstairs'
|
9
|
+
TEST_NAME_3 = nil
|
10
|
+
TEST_HOST_1 = '192.168.1.5'
|
11
|
+
TEST_HOST_2 = 'NP-20F8A0003472'
|
12
|
+
TEST_HOST_3 = '192.168.1.7'
|
13
|
+
|
14
|
+
def setup
|
15
|
+
cleanup
|
16
|
+
@remote1 = Remote.new(TEST_HOST_1, TEST_NAME_1)
|
17
|
+
@remote2 = Remote.new(TEST_HOST_2, TEST_NAME_2)
|
18
|
+
@remote3 = Remote.new(TEST_HOST_3, TEST_NAME_3)
|
19
|
+
@test_remotes = [@remote1, @remote2, @remote3]
|
20
|
+
@remotes = Remotes.new(@test_remotes)
|
21
|
+
end
|
22
|
+
|
23
|
+
def teardown; cleanup; end
|
24
|
+
|
25
|
+
def test_initialize_and_read_storage_path
|
26
|
+
assert_equal BOXES_FILE, SimpleStorage.new(BOXES_FILE).storage_path
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_store_and_load_box_manager
|
30
|
+
SimpleStorage.new(BOXES_FILE).store(@remotes)
|
31
|
+
boxes = SimpleStorage.new(BOXES_FILE).load
|
32
|
+
assert_equal @remotes.boxes.size, boxes.boxes.size
|
33
|
+
assert_equal @remotes.active, boxes.active
|
34
|
+
|
35
|
+
box1, box2, box3 = boxes.boxes[0], boxes.boxes[1], boxes.boxes[2]
|
36
|
+
assert_equal TEST_NAME_1, box1.name
|
37
|
+
assert_equal TEST_HOST_1, box1.host
|
38
|
+
assert_equal TEST_NAME_2, box2.name
|
39
|
+
assert_equal TEST_HOST_2, box2.host
|
40
|
+
assert_equal TEST_NAME_3, box3.name
|
41
|
+
assert_equal TEST_HOST_3, box3.host
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_store_no_boxes
|
45
|
+
SimpleStorage.new(BOXES_FILE).store(Remotes.new)
|
46
|
+
boxes = SimpleStorage.new(BOXES_FILE).load
|
47
|
+
assert boxes.boxes.empty?
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_load_from_non_existent_file
|
51
|
+
boxes = SimpleStorage.new(BOXES_FILE).load
|
52
|
+
assert boxes.boxes.empty?
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_box_config_format_is_correct
|
56
|
+
SimpleStorage.new(BOXES_FILE).store(@remotes)
|
57
|
+
lines = IO.read(BOXES_FILE).split("\n")
|
58
|
+
assert_equal 3, lines.size
|
59
|
+
|
60
|
+
assert_equal '192.168.1.5:Living Room', lines[0]
|
61
|
+
assert_equal 'NP-20F8A0003472:Upstairs', lines[1]
|
62
|
+
assert_equal '192.168.1.7', lines[2]
|
63
|
+
end
|
64
|
+
|
65
|
+
protected
|
66
|
+
|
67
|
+
def cleanup
|
68
|
+
File.delete(BOXES_FILE) if File.exist?(BOXES_FILE)
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
+
require 'ruku/clients/web'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
class TestWebClient < Test::Unit::TestCase
|
6
|
+
TEST_HOST_1 = "192.168.1.5"
|
7
|
+
TEST_NAME_1 = "Living room"
|
8
|
+
TEST_HOST_2 = "192.168.1.17"
|
9
|
+
TEST_NAME_2 = "Basement"
|
10
|
+
TEST_PORT_2 = 9090
|
11
|
+
|
12
|
+
def test_remote_to_json
|
13
|
+
parsed = JSON.parse(test_remotes.first.to_json)
|
14
|
+
assert_equal TEST_HOST_1, parsed['host']
|
15
|
+
assert_equal TEST_NAME_1, parsed['name']
|
16
|
+
assert_equal 8080, parsed['port']
|
17
|
+
|
18
|
+
parsed = JSON.parse(test_remotes.last.to_json)
|
19
|
+
assert_equal TEST_HOST_2, parsed['host']
|
20
|
+
assert_equal TEST_NAME_2, parsed['name']
|
21
|
+
assert_equal TEST_PORT_2, parsed['port']
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_remote_manager_remotes_from_json
|
25
|
+
json = "{\"remotes\":[" +
|
26
|
+
"{\"host\":\"#{TEST_HOST_1}\",\"name\":\"#{TEST_NAME_1}\"}," +
|
27
|
+
"{\"host\":\"#{TEST_HOST_2}\",\"name\":\"#{TEST_NAME_2}\", \"port\":#{TEST_PORT_2}}" +
|
28
|
+
"],\"active\":1}"
|
29
|
+
rm = Remotes.new
|
30
|
+
rm.remotes_from_json(json)
|
31
|
+
assert_equal 2, rm.boxes.size
|
32
|
+
assert_equal TEST_HOST_1, rm.boxes.first.host
|
33
|
+
assert_equal TEST_NAME_1, rm.boxes.first.name
|
34
|
+
assert_equal 8080, rm.boxes.first.port
|
35
|
+
assert_equal TEST_HOST_2, rm.boxes.last.host
|
36
|
+
assert_equal TEST_NAME_2, rm.boxes.last.name
|
37
|
+
assert_equal TEST_PORT_2, rm.boxes.last.port
|
38
|
+
assert_equal TEST_HOST_2, rm.active.host
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
def test_remotes
|
44
|
+
[Remote.new(TEST_HOST_1, TEST_NAME_1), Remote.new(TEST_HOST_2, TEST_NAME_2, TEST_PORT_2)]
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
|
+
|
3
|
+
class TestYAMLStorage < Test::Unit::TestCase
|
4
|
+
TMP_DIR = File.join(File.dirname(__FILE__), 'tmp', '.ruku')
|
5
|
+
|
6
|
+
TEST_NAME_1 = 'Remote 1'
|
7
|
+
TEST_NAME_2 = 'Remote 2'
|
8
|
+
TEST_HOST_1 = '192.168.1.5'
|
9
|
+
TEST_HOST_2 = '192.168.1.6'
|
10
|
+
|
11
|
+
def setup
|
12
|
+
cleanup
|
13
|
+
@remote1 = Remote.new(TEST_HOST_1, TEST_NAME_1)
|
14
|
+
@remote2 = Remote.new(TEST_HOST_2, TEST_NAME_2)
|
15
|
+
@test_remotes = [@remote1, @remote2]
|
16
|
+
@box_manager = Remotes.new(@test_remotes)
|
17
|
+
end
|
18
|
+
|
19
|
+
def teardown; cleanup; end
|
20
|
+
|
21
|
+
def test_initialize_and_read_storage_path
|
22
|
+
assert_equal TMP_DIR, YAMLStorage.new(TMP_DIR).storage_path
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_store_and_load_box_manager
|
26
|
+
YAMLStorage.new(TMP_DIR).store(@box_manager)
|
27
|
+
m = YAMLStorage.new(TMP_DIR).load
|
28
|
+
assert_equal @box_manager.boxes.size, m.boxes.size
|
29
|
+
assert_equal @box_manager.active, m.active
|
30
|
+
|
31
|
+
box1, box2 = m.boxes[0], m.boxes[1]
|
32
|
+
assert_equal TEST_NAME_1, box1.name
|
33
|
+
assert_equal TEST_HOST_1, box1.host
|
34
|
+
assert_equal TEST_NAME_2, box2.name
|
35
|
+
assert_equal TEST_HOST_2, box2.host
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_store_no_boxes
|
39
|
+
YAMLStorage.new(TMP_DIR).store(Remotes.new)
|
40
|
+
m = YAMLStorage.new(TMP_DIR).load
|
41
|
+
assert_equal 0, m.boxes.size
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_load_from_non_existent_file
|
45
|
+
m = YAMLStorage.new(TMP_DIR).load
|
46
|
+
assert m.boxes.empty?
|
47
|
+
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
|
51
|
+
def cleanup
|
52
|
+
File.delete(TMP_DIR) if File.exist?(TMP_DIR)
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruku
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Aaron Royer
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-02-01 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: json_pure
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 11
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 4
|
32
|
+
- 6
|
33
|
+
version: 1.4.6
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: mocha
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 41
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
- 9
|
48
|
+
- 9
|
49
|
+
version: 0.9.9
|
50
|
+
type: :development
|
51
|
+
version_requirements: *id002
|
52
|
+
description: "Roku\xE2\x84\xA2 set-top box remote control, command line and web interfaces"
|
53
|
+
email: aaronroyer@gmail.com
|
54
|
+
executables:
|
55
|
+
- ruku
|
56
|
+
extensions: []
|
57
|
+
|
58
|
+
extra_rdoc_files:
|
59
|
+
- MIT-LICENSE
|
60
|
+
files:
|
61
|
+
- bin/ruku
|
62
|
+
- lib/ruku/clients/simple.rb
|
63
|
+
- lib/ruku/clients/tk.rb
|
64
|
+
- lib/ruku/clients/web.rb
|
65
|
+
- lib/ruku/clients/web_static/css/ruku.css
|
66
|
+
- lib/ruku/clients/web_static/images/box-medium.png
|
67
|
+
- lib/ruku/clients/web_static/images/box-small.png
|
68
|
+
- lib/ruku/clients/web_static/images/remote/back-over.png
|
69
|
+
- lib/ruku/clients/web_static/images/remote/back.png
|
70
|
+
- lib/ruku/clients/web_static/images/remote/down-over.png
|
71
|
+
- lib/ruku/clients/web_static/images/remote/down.png
|
72
|
+
- lib/ruku/clients/web_static/images/remote/fwd-over.png
|
73
|
+
- lib/ruku/clients/web_static/images/remote/fwd.png
|
74
|
+
- lib/ruku/clients/web_static/images/remote/home-over.png
|
75
|
+
- lib/ruku/clients/web_static/images/remote/home.png
|
76
|
+
- lib/ruku/clients/web_static/images/remote/left-over.png
|
77
|
+
- lib/ruku/clients/web_static/images/remote/left.png
|
78
|
+
- lib/ruku/clients/web_static/images/remote/pause-over.png
|
79
|
+
- lib/ruku/clients/web_static/images/remote/pause.png
|
80
|
+
- lib/ruku/clients/web_static/images/remote/right-over.png
|
81
|
+
- lib/ruku/clients/web_static/images/remote/right.png
|
82
|
+
- lib/ruku/clients/web_static/images/remote/select-over.png
|
83
|
+
- lib/ruku/clients/web_static/images/remote/select.png
|
84
|
+
- lib/ruku/clients/web_static/images/remote/space1.png
|
85
|
+
- lib/ruku/clients/web_static/images/remote/space2.png
|
86
|
+
- lib/ruku/clients/web_static/images/remote/space3.png
|
87
|
+
- lib/ruku/clients/web_static/images/remote/up-over.png
|
88
|
+
- lib/ruku/clients/web_static/images/remote/up.png
|
89
|
+
- lib/ruku/clients/web_static/images/spacer.gif
|
90
|
+
- lib/ruku/clients/web_static/index.html
|
91
|
+
- lib/ruku/clients/web_static/js/jquery-1.4.2.js
|
92
|
+
- lib/ruku/clients/web_static/js/ruku.js
|
93
|
+
- lib/ruku/remote.rb
|
94
|
+
- lib/ruku/remotes.rb
|
95
|
+
- lib/ruku/storage.rb
|
96
|
+
- lib/ruku.rb
|
97
|
+
- test/helper.rb
|
98
|
+
- test/js/qunit.css
|
99
|
+
- test/js/qunit.js
|
100
|
+
- test/js/runner.html
|
101
|
+
- test/js/test_remote.js
|
102
|
+
- test/js/test_remote_manager.js
|
103
|
+
- test/js/test_remote_menu.js
|
104
|
+
- test/js/test_util.js
|
105
|
+
- test/test_remote.rb
|
106
|
+
- test/test_remotes.rb
|
107
|
+
- test/test_simple_client.rb
|
108
|
+
- test/test_simple_storage.rb
|
109
|
+
- test/test_web_client.rb
|
110
|
+
- test/test_yaml_storage.rb
|
111
|
+
- README.rdoc
|
112
|
+
- MIT-LICENSE
|
113
|
+
- ruku.gemspec
|
114
|
+
- Rakefile
|
115
|
+
has_rdoc: true
|
116
|
+
homepage: http://github.com/aaronroyer/ruku
|
117
|
+
licenses: []
|
118
|
+
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options:
|
121
|
+
- --line-numbers
|
122
|
+
- --inline-source
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
hash: 3
|
131
|
+
segments:
|
132
|
+
- 0
|
133
|
+
version: "0"
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
none: false
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
hash: 3
|
140
|
+
segments:
|
141
|
+
- 0
|
142
|
+
version: "0"
|
143
|
+
requirements: []
|
144
|
+
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 1.3.7
|
147
|
+
signing_key:
|
148
|
+
specification_version: 3
|
149
|
+
summary: "Ruku provides command line and web remote control interfaces for controlling all your Roku\xE2\x84\xA2 set-top boxes over a network."
|
150
|
+
test_files:
|
151
|
+
- test/test_remote.rb
|
152
|
+
- test/test_remotes.rb
|
153
|
+
- test/test_simple_client.rb
|
154
|
+
- test/test_simple_storage.rb
|
155
|
+
- test/test_web_client.rb
|
156
|
+
- test/test_yaml_storage.rb
|