royw-dvdprofiler2xbmc 0.0.6 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,146 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ require 'tempfile'
4
+
5
+ describe "App" do
6
+
7
+ before(:all) do
8
+ logger = Log4r::Logger.new('dvdprofiler2xbmc')
9
+ logger.outputters = Log4r::StdoutOutputter.new(:console)
10
+ Log4r::Outputter[:console].formatter = Log4r::PatternFormatter.new(:pattern => "%m")
11
+ logger.level = Log4r::WARN
12
+ AppConfig.default
13
+ AppConfig[:logger] = logger
14
+ AppConfig.load
15
+ File.mkdirs(TMPDIR)
16
+ AppConfig[:logger].warn { "\nApp Specs" }
17
+ end
18
+
19
+ after(:all) do
20
+ Dir.glob(File.join(TMPDIR, "app_*")).each do |filename|
21
+ File.delete(filename) if File.file?(filename)
22
+ Dir.rmdir(filename) if File.directory?(filename)
23
+ end
24
+ end
25
+
26
+ it 'should save a file' do
27
+ # get a temp filename to a non-existing file
28
+ outfile = Tempfile.new('tmdb_movie_spec_saving', TMPDIR)
29
+ filespec = outfile.path
30
+ outfile.unlink
31
+
32
+ data = 'Howdy Partner'
33
+
34
+ DvdProfiler2Xbmc.save_to_file(filespec, data)
35
+ open(filespec).read.should == "#{data}\n"
36
+ end
37
+
38
+ it 'should backup the file before saving' do
39
+ # get a temp filename to a non-existing file
40
+ outfile = Tempfile.new('tmdb_movie_spec_saving', TMPDIR)
41
+ filespec = outfile.path
42
+ backupspec = filespec + AppConfig[:extensions][:backup]
43
+ outfile.unlink
44
+
45
+ data = []
46
+ data[0] = 'Howdy Partner'
47
+ data[1] = 'Howdy Ho Neighbor'
48
+
49
+ DvdProfiler2Xbmc.save_to_file(filespec, data[0])
50
+ DvdProfiler2Xbmc.save_to_file(filespec, data[1])
51
+ open(filespec).read.should == "#{data[1]}\n" &&
52
+ open(backupspec).read.should == "#{data[0]}\n"
53
+ end
54
+
55
+ it 'should generate .nfo filespec for single part media' do
56
+ filespec = DvdProfiler2Xbmc.generate_filespec('/a/b/c.m4v', :nfo)
57
+ filespec.should == '/a/b/c.nfo'
58
+ end
59
+
60
+ it 'should generate .nfo filespec for multiple part media' do
61
+ filespec = DvdProfiler2Xbmc.generate_filespec('/a/b/c.cd1.m4v', :nfo)
62
+ filespec.should == '/a/b/c.nfo'
63
+ end
64
+
65
+ it 'should generate .tbn filespec for single part media' do
66
+ filespec = DvdProfiler2Xbmc.generate_filespec('/a/b/c.m4v', :thumbnail)
67
+ filespec.should == '/a/b/c.tbn'
68
+ end
69
+
70
+ it 'should generate .tbn filespec for multiple part media' do
71
+ filespec = DvdProfiler2Xbmc.generate_filespec('/a/b/c.cd1.m4v', :thumbnail)
72
+ filespec.should == '/a/b/c.tbn'
73
+ end
74
+
75
+ it 'should generate -fanart filespec for single part media' do
76
+ filespec = DvdProfiler2Xbmc.generate_filespec('/a/b/c.m4v', :fanart)
77
+ filespec.should == '/a/b/c-fanart'
78
+ end
79
+
80
+ it 'should generate -fanart filespec for multiple part media' do
81
+ filespec = DvdProfiler2Xbmc.generate_filespec('/a/b/c.cd1.m4v', :fanart)
82
+ filespec.should == '/a/b/c-fanart'
83
+ end
84
+
85
+ it 'should generate -fanart.jpg filespec for single part media' do
86
+ filespec = DvdProfiler2Xbmc.generate_filespec('/a/b/c.m4v', :fanart, :extension => File.extname('foo.jpg'))
87
+ filespec.should == '/a/b/c-fanart.jpg'
88
+ end
89
+
90
+ it 'should generate -fanart.jpg filespec for multiple part media' do
91
+ filespec = DvdProfiler2Xbmc.generate_filespec('/a/b/c.cd1.m4v', :fanart, :extension => File.extname('foo.jpg'))
92
+ filespec.should == '/a/b/c-fanart.jpg'
93
+ end
94
+
95
+ it 'should generate .imdb.xml filespec for single part media' do
96
+ filespec = DvdProfiler2Xbmc.generate_filespec('/a/b/c.m4v', :imdb_xml)
97
+ filespec.should == '/a/b/c.imdb.xml'
98
+ end
99
+
100
+ it 'should generate .imdb.xml filespec for multiple part media' do
101
+ filespec = DvdProfiler2Xbmc.generate_filespec('/a/b/c.cd1.m4v', :imdb_xml)
102
+ filespec.should == '/a/b/c.imdb.xml'
103
+ end
104
+
105
+ it 'should generate .tmdb.xml filespec for single part media' do
106
+ filespec = DvdProfiler2Xbmc.generate_filespec('/a/b/c.m4v', :tmdb_xml)
107
+ filespec.should == '/a/b/c.tmdb.xml'
108
+ end
109
+
110
+ it 'should generate .tmdb.xml filespec for multiple part media' do
111
+ filespec = DvdProfiler2Xbmc.generate_filespec('/a/b/c.cd1.m4v', :tmdb_xml)
112
+ filespec.should == '/a/b/c.tmdb.xml'
113
+ end
114
+
115
+ it 'should generate .dvdprofiler.xml filespec for single part media' do
116
+ filespec = DvdProfiler2Xbmc.generate_filespec('/a/b/c.m4v', :dvdprofiler_xml)
117
+ filespec.should == '/a/b/c.dvdprofiler.xml'
118
+ end
119
+
120
+ it 'should generate .dvdprofiler.xml filespec for multiple part media' do
121
+ filespec = DvdProfiler2Xbmc.generate_filespec('/a/b/c.cd1.m4v', :dvdprofiler_xml)
122
+ filespec.should == '/a/b/c.dvdprofiler.xml'
123
+ end
124
+
125
+ it 'should change file permissions' do
126
+ outfile = Tempfile.new('app_permission_check', TMPDIR)
127
+ filespec = outfile.path
128
+ File.chmod(0777, filespec)
129
+ AppConfig.config[:file_permissions] = 0642.to_s(8)
130
+ # set_permissions is protected method
131
+ DvdProfiler2Xbmc.instance.send('set_permissions', TMPDIR)
132
+ (File.stat(filespec).mode & 07777).should == 0642
133
+ end
134
+
135
+ it 'should change directory permissions' do
136
+ outdir = Tempfile.new('app_permission_check', TMPDIR)
137
+ dirspec = outdir.path
138
+ outdir.unlink
139
+ Dir.mkdir(dirspec)
140
+ File.chmod(0777, dirspec)
141
+ AppConfig.config[:dir_permissions] = 0642.to_s(8)
142
+ # set_permissions is protected method
143
+ DvdProfiler2Xbmc.instance.send('set_permissions', TMPDIR)
144
+ (File.stat(dirspec).mode & 07777).should == 0642
145
+ end
146
+ end
@@ -0,0 +1,301 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+ require File.join(File.dirname(__FILE__), '../lib/dvdprofiler2xbmc/views/config_editor')
3
+
4
+ require 'tempfile'
5
+
6
+ describe "ConfigEditor" do
7
+
8
+ before(:all) do
9
+ logger = Log4r::Logger.new('dvdprofiler2xbmc')
10
+ logger.outputters = Log4r::StdoutOutputter.new(:console)
11
+ Log4r::Outputter[:console].formatter = Log4r::PatternFormatter.new(:pattern => "%m")
12
+ logger.level = Log4r::WARN
13
+ AppConfig.default
14
+ AppConfig[:logger] = logger
15
+ AppConfig.load
16
+ File.mkdirs(TMPDIR)
17
+ AppConfig[:logger].warn { "\nConfigEditor Specs" }
18
+ end
19
+
20
+ before(:each) do
21
+ @input = StringIO.new
22
+ @output = StringIO.new
23
+ @old_terminal = $terminal
24
+ $terminal = HighLine.new(@input, @output)
25
+ @editor = ConfigEditor.new
26
+ end
27
+
28
+ after(:each) do
29
+ $terminal = @old_terminal
30
+ end
31
+
32
+ it "should return true for boolean data type edits that recieve y" do
33
+ @input << "y\n"
34
+ @input.rewind
35
+ value = @editor.data_type_editor('field_name', :BOOLEAN, false)
36
+ value.should be_true
37
+ end
38
+
39
+ it "should return false for boolean data type edits that recieve n" do
40
+ @input << "n\n"
41
+ @input.rewind
42
+ value = @editor.data_type_editor('field_name', :BOOLEAN, true)
43
+ value.should be_false
44
+ end
45
+
46
+ it "should return true for boolean data type edits that recieve yes" do
47
+ @input << "yes\n"
48
+ @input.rewind
49
+ value = @editor.data_type_editor('field_name', :BOOLEAN, false)
50
+ value.should be_true
51
+ end
52
+
53
+ it "should return false for boolean data type edits that recieve no" do
54
+ @input << "no\n"
55
+ @input.rewind
56
+ value = @editor.data_type_editor('field_name', :BOOLEAN, true)
57
+ value.should be_false
58
+ end
59
+
60
+ it "should return false for boolean data type edits that default to false" do
61
+ @input << "\n\n"
62
+ @input.rewind
63
+ value = @editor.data_type_editor('field_name', :BOOLEAN, false)
64
+ value.should be_false
65
+ end
66
+
67
+ it "should return true for boolean data type edits that default to true" do
68
+ @input << "\n"
69
+ @input.rewind
70
+ value = @editor.data_type_editor('field_name', :BOOLEAN, true)
71
+ value.should be_true
72
+ end
73
+
74
+ it "should handle ask commands" do
75
+ pathspec = File.expand_path(__FILE__)
76
+ @input << pathspec << "\n"
77
+ @input.rewind
78
+ value = ask('New filespec: ')
79
+ value.should == pathspec
80
+ end
81
+
82
+ it "should handle ask commands with validation" do
83
+ pathspec = File.expand_path(__FILE__)
84
+ @input << pathspec << "\n"
85
+ @input.rewind
86
+ value = ask('New filespec: ') do |q|
87
+ q.validate = lambda { |p| File.exist?(p) && File.file?(p) }
88
+ q.confirm = false
89
+ end
90
+ value.should == pathspec
91
+ end
92
+
93
+ it "should return pathspec" do
94
+ pathspec = File.expand_path(File.dirname(__FILE__))
95
+ default_pathspec = File.expand_path(File.join(File.dirname(__FILE__), '..'))
96
+ @input << pathspec << "\n"
97
+ @input.rewind
98
+ value = @editor.data_type_editor('images_dir', :PATHSPEC, default_pathspec)
99
+ value.should == pathspec
100
+ end
101
+
102
+ it "should return default pathspec" do
103
+ default_pathspec = File.expand_path(File.join(File.dirname(__FILE__), '..'))
104
+ @input << "\n"
105
+ @input.rewind
106
+ value = @editor.data_type_editor('images_dir', :PATHSPEC, default_pathspec)
107
+ value.should == default_pathspec
108
+ end
109
+
110
+ it "should reprompt for invalid pathspec" do
111
+ badpathspec = '/a123/b123/c123'
112
+ goodpathspec = File.expand_path(File.dirname(__FILE__))
113
+ default_pathspec = File.expand_path(File.join(File.dirname(__FILE__), '..'))
114
+ @input << badpathspec << "\n" << goodpathspec << "\n"
115
+ @input.rewind
116
+ value = @editor.data_type_editor('images_dir', :PATHSPEC, default_pathspec)
117
+ value.should == goodpathspec
118
+ end
119
+
120
+ it "should return filespec data type edits" do
121
+ filespec = File.expand_path(__FILE__)
122
+ default_filespec = File.expand_path(File.join(File.dirname(__FILE__), 'ruby_dragon'))
123
+ @input << filespec << "\n"
124
+ @input.rewind
125
+ value = @editor.data_type_editor('collection_filespec', :FILESPEC, default_filespec)
126
+ value.should == filespec
127
+ end
128
+
129
+ it "should reprompt for invalid filespec" do
130
+ badfilespec = File.expand_path(__FILE__) + 'jaberwooky'
131
+ goodfilespec = File.expand_path(__FILE__)
132
+ default_filespec = File.expand_path(File.join(File.dirname(__FILE__), 'ruby_dragon'))
133
+ @input << badfilespec << "\n" << goodfilespec << "\n"
134
+ @input.rewind
135
+ value = @editor.data_type_editor('collection_filespec', :FILESPEC, default_filespec)
136
+ value.should == goodfilespec
137
+ end
138
+
139
+ it "should accept valid permission 0" do
140
+ @input << "0" << "\n"
141
+ @input.rewind
142
+ value = @editor.data_type_editor('file_permissions', :PERMISSIONS, 0644.to_s(8))
143
+ value.should == 0.to_s(8)
144
+ end
145
+
146
+ it "should accept valid permission 7777" do
147
+ @input << "7777" << "\n"
148
+ @input.rewind
149
+ value = @editor.data_type_editor('file_permissions', :PERMISSIONS, 0644.to_s(8))
150
+ value.should == 07777.to_s(8)
151
+ end
152
+
153
+ it "should reject permission > 7777" do
154
+ @input << "65432" << "\n" << "6543" << "\n"
155
+ @input.rewind
156
+ value = @editor.data_type_editor('file_permissions', :PERMISSIONS, 0644.to_s(8))
157
+ value.should == 06543.to_s(8)
158
+ end
159
+
160
+ it "should accept array of strings" do
161
+ strings = %w(foo bar howdy)
162
+ @input << strings.join("\n") << "\n\n"
163
+ @input.rewind
164
+ value = @editor.data_type_editor('image_extensions', :ARRAY_OF_STRINGS)
165
+ value.should == strings
166
+ end
167
+
168
+ it "should accept empty array of strings" do
169
+ strings = []
170
+ @input << strings.join("\n") << "\n\n"
171
+ @input.rewind
172
+ value = @editor.data_type_editor('image_extensions', :ARRAY_OF_STRINGS)
173
+ value.should == strings
174
+ end
175
+
176
+ it "should accept array of pathspecs" do
177
+ cwd = File.expand_path(File.dirname(__FILE__))
178
+ pathspecs = [cwd, File.join(cwd, '..')]
179
+ @input << pathspecs.join("\n") << "\n\n\n\n"
180
+ @input.rewind
181
+ value = @editor.data_type_editor('directories', :ARRAY_OF_PATHSPECS)
182
+ value.should == pathspecs
183
+ end
184
+
185
+ it "should accept empty array of pathspecs" do
186
+ pathspecs = []
187
+ @input << pathspecs.join("\n") << "\n\n\n"
188
+ @input.rewind
189
+ value = @editor.data_type_editor('directories', :ARRAY_OF_PATHSPECS)
190
+ value.should == pathspecs
191
+ end
192
+
193
+ it "should reject empty directories" do
194
+ AppConfig.config['directories'] = []
195
+ AppConfig.validate['directories'].call([]).should be_false
196
+ end
197
+
198
+ it 'should indicate valid AppConfig' do
199
+ cwd = File.expand_path(File.dirname(__FILE__))
200
+ AppConfig.default
201
+ AppConfig.config.directories = [cwd, File.join(cwd, '..')]
202
+ AppConfig.config.collection_filespec = __FILE__
203
+ AppConfig.config.images_dir = cwd
204
+ AppConfig.valid?.should be_true
205
+ end
206
+
207
+ it 'should indicate invalid AppConfig with no directories' do
208
+ cwd = File.expand_path(File.dirname(__FILE__))
209
+ AppConfig.default
210
+ AppConfig.config.directories = []
211
+ AppConfig.config.collection_filespec = __FILE__
212
+ AppConfig.config.images_dir = cwd
213
+ AppConfig.valid?.should be_false
214
+ end
215
+
216
+ it 'should indicate invalid AppConfig with bad directory path' do
217
+ cwd = File.expand_path(File.dirname(__FILE__))
218
+ AppConfig.default
219
+ AppConfig.config.directories = [cwd, cwd + 'jaberwooky']
220
+ AppConfig.config.collection_filespec = __FILE__
221
+ AppConfig.config.images_dir = cwd
222
+ AppConfig.valid?.should be_false
223
+ end
224
+
225
+ it 'should indicate invalid AppConfig with empty collection.xml path' do
226
+ cwd = File.expand_path(File.dirname(__FILE__))
227
+ AppConfig.default
228
+ AppConfig.config.directories = [cwd, File.join(cwd, '..')]
229
+ AppConfig.config.collection_filespec = ''
230
+ AppConfig.config.images_dir = cwd
231
+ AppConfig.valid?.should be_false
232
+ end
233
+
234
+ it 'should indicate invalid AppConfig with bad collection.xml path' do
235
+ cwd = File.expand_path(File.dirname(__FILE__))
236
+ AppConfig.default
237
+ AppConfig.config.directories = [cwd, File.join(cwd, '..')]
238
+ AppConfig.config.collection_filespec = cwd + 'jaberwooky'
239
+ AppConfig.config.images_dir = cwd
240
+ AppConfig.valid?.should be_false
241
+ end
242
+
243
+ it 'should indicate invalid AppConfig with empty images path' do
244
+ cwd = File.expand_path(File.dirname(__FILE__))
245
+ AppConfig.default
246
+ AppConfig.config.directories = [cwd, File.join(cwd, '..')]
247
+ AppConfig.config.collection_filespec = __FILE__
248
+ AppConfig.config.images_dir = ''
249
+ AppConfig.valid?.should be_false
250
+ end
251
+
252
+ it 'should indicate invalid AppConfig with bad images path' do
253
+ cwd = File.expand_path(File.dirname(__FILE__))
254
+ AppConfig.default
255
+ AppConfig.config.directories = [cwd, File.join(cwd, '..')]
256
+ AppConfig.config.collection_filespec = __FILE__
257
+ AppConfig.config.images_dir = cwd + 'jaberwooky'
258
+ AppConfig.valid?.should be_false
259
+ end
260
+
261
+ it 'should indicate invalid AppConfig with no media extensions' do
262
+ cwd = File.expand_path(File.dirname(__FILE__))
263
+ AppConfig.default
264
+ AppConfig.config.directories = [cwd, File.join(cwd, '..')]
265
+ AppConfig.config.collection_filespec = __FILE__
266
+ AppConfig.config.images_dir = cwd
267
+ AppConfig.config.media_extensions = []
268
+ AppConfig.valid?.should be_false
269
+ end
270
+
271
+ it 'should indicate invalid AppConfig with no image extensions' do
272
+ cwd = File.expand_path(File.dirname(__FILE__))
273
+ AppConfig.default
274
+ AppConfig.config.directories = [cwd, File.join(cwd, '..')]
275
+ AppConfig.config.collection_filespec = __FILE__
276
+ AppConfig.config.images_dir = cwd
277
+ AppConfig.config.image_extensions = []
278
+ AppConfig.valid?.should be_false
279
+ end
280
+
281
+ it 'should indicate invalid AppConfig with invalid file permissions' do
282
+ cwd = File.expand_path(File.dirname(__FILE__))
283
+ AppConfig.default
284
+ AppConfig.config.directories = [cwd, File.join(cwd, '..')]
285
+ AppConfig.config.collection_filespec = __FILE__
286
+ AppConfig.config.images_dir = cwd
287
+ AppConfig.config.file_permissions = '-2'
288
+ AppConfig.valid?.should be_false
289
+ end
290
+
291
+ it 'should indicate invalid AppConfig with invalid directory permissions' do
292
+ cwd = File.expand_path(File.dirname(__FILE__))
293
+ AppConfig.default
294
+ AppConfig.config.directories = [cwd, File.join(cwd, '..')]
295
+ AppConfig.config.collection_filespec = __FILE__
296
+ AppConfig.config.images_dir = cwd
297
+ AppConfig.config.dir_permissions = '11111'
298
+ AppConfig.valid?.should be_false
299
+ end
300
+
301
+ end
@@ -33,7 +33,7 @@ describe "DvdprofilerProfile" do
33
33
  end
34
34
 
35
35
  it "should find by title" do
36
- profile = DvdprofilerProfile.first(:titles => ['National Treasure: Book of Secrets'])
36
+ profile = DvdprofilerProfile.first(:title => 'National Treasure 2: Book of Secrets')
37
37
  profile.should_not == nil
38
38
  end
39
39
 
@@ -48,4 +48,19 @@ describe "DvdprofilerProfile" do
48
48
  hash.should_not be_nil
49
49
  end
50
50
 
51
+ it "should find multiple movies with the same title" do
52
+ profiles = DvdprofilerProfile.all(:title => 'Sabrina')
53
+ profiles.length.should == 2
54
+ end
55
+
56
+ it "should find a single movie using the year when multiple movies have the same title" do
57
+ profiles = DvdprofilerProfile.all(:title => 'Sabrina', :year => '1995')
58
+ (profiles.length.should == 1) && (profiles.first.isbn.should == '097363304340')
59
+ end
60
+
61
+ it "should find the other single movie using the year when multiple movies have the same title" do
62
+ profiles = DvdprofilerProfile.all(:title => 'Sabrina', :year => '1954')
63
+ (profiles.length.should == 1) && (profiles.first.isbn.should == '097360540246')
64
+ end
65
+
51
66
  end