royw-dvdprofiler_collection 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -0
- data/VERSION.yml +2 -2
- data/spec/collection_spec.rb +92 -84
- data/spec/dvdprofiler_profile_spec.rb +45 -40
- metadata +2 -2
data/Rakefile
CHANGED
@@ -30,6 +30,7 @@ require 'spec/rake/spectask'
|
|
30
30
|
Spec::Rake::SpecTask.new(:spec) do |spec|
|
31
31
|
spec.libs << 'lib' << 'spec'
|
32
32
|
spec.spec_files = FileList['spec/**/*_spec.rb']
|
33
|
+
spec.spec_opts = ["--color", "--format nested"]
|
33
34
|
end
|
34
35
|
|
35
36
|
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
data/VERSION.yml
CHANGED
data/spec/collection_spec.rb
CHANGED
@@ -13,113 +13,121 @@ describe "Collection" do
|
|
13
13
|
|
14
14
|
before(:all) do
|
15
15
|
File.mkdirs(TMPDIR)
|
16
|
-
puts "\nCollection Specs"
|
17
16
|
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
describe "Parsing Collection.xml/yaml" do
|
19
|
+
it 'should build Collection.yaml when Collection.yaml does not exist' do
|
20
|
+
File.delete(COLLECTION_YAML) if File.exist?(COLLECTION_YAML)
|
21
|
+
collection = Collection.new(COLLECTION_XML)
|
22
|
+
File.exist?(COLLECTION_YAML).should be_true
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
it 'should build Collection.yaml when Collection.xml is newer than existing Collection.yaml' do
|
26
|
+
File.delete(COLLECTION_YAML) if File.exist?(COLLECTION_YAML)
|
27
|
+
Collection.new(COLLECTION_XML)
|
28
|
+
old_yaml_mtime = File.mtime(COLLECTION_YAML)
|
29
|
+
old_xml_mtime = File.mtime(COLLECTION_XML)
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
sleep(2) # make sure there will be a difference between old yaml and new xml
|
32
|
+
FileUtils.touch(COLLECTION_XML)
|
33
|
+
new_xml_mtime = File.mtime(COLLECTION_XML)
|
34
34
|
|
35
|
-
|
36
|
-
|
35
|
+
Collection.new(COLLECTION_XML)
|
36
|
+
new_yaml_mtime = File.mtime(COLLECTION_YAML)
|
37
37
|
|
38
|
-
|
39
|
-
|
38
|
+
old_yaml_mtime.should < new_yaml_mtime
|
39
|
+
end
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
it 'should not build Collection.yaml when existing Collection.yaml is newer than Collection.xml' do
|
42
|
+
File.delete(COLLECTION_YAML) if File.exist?(COLLECTION_YAML)
|
43
|
+
Collection.new(COLLECTION_XML)
|
44
|
+
old_yaml_mtime = File.mtime(COLLECTION_YAML)
|
45
|
+
sleep(2)
|
46
46
|
|
47
|
-
|
48
|
-
|
47
|
+
Collection.new(COLLECTION_XML)
|
48
|
+
new_yaml_mtime = File.mtime(COLLECTION_YAML)
|
49
49
|
|
50
|
-
|
50
|
+
old_yaml_mtime.should == new_yaml_mtime
|
51
|
+
end
|
51
52
|
end
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
describe "Collection contents" do
|
55
|
+
it 'should have values in isbn_title_hash' do
|
56
|
+
collection = Collection.new(COLLECTION_XML)
|
57
|
+
collection.isbn_title_hash.empty?.should be_false
|
58
|
+
end
|
57
59
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
it 'should have values in title_isbh_hash' do
|
61
|
+
collection = Collection.new(COLLECTION_XML)
|
62
|
+
collection.title_isbn_hash.empty?.should be_false
|
63
|
+
end
|
62
64
|
|
63
|
-
|
64
|
-
|
65
|
-
|
65
|
+
it 'should have values in isbn_dvd_hash' do
|
66
|
+
collection = Collection.new(COLLECTION_XML)
|
67
|
+
collection.isbn_dvd_hash.empty?.should be_false
|
68
|
+
end
|
66
69
|
end
|
67
70
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
71
|
+
describe "Title patterns" do
|
72
|
+
# dynamically create a set of specs for various title pattern generations
|
73
|
+
{
|
74
|
+
'Extra Spaces' => 'extra spaces',
|
75
|
+
' leading spaces' => 'leading spaces',
|
76
|
+
'trailing spaces ' => 'trailing spaces',
|
77
|
+
'multiple : * [] () {} ~!@#$%^; punctuation' => 'multiple punctuation',
|
78
|
+
'replace & with and' => 'replace and with and',
|
79
|
+
'remove [foo] square brackets' => 'remove square brackets',
|
80
|
+
'remove {foo} curly brackets' => 'remove curly brackets',
|
81
|
+
'remove (foo) parens' => 'remove parens',
|
82
|
+
'remove & html escapes' => 'remove html escapes',
|
83
|
+
'remove widescreen' => 'remove',
|
84
|
+
'remove special edition' => 'remove',
|
85
|
+
}.each do |title, pattern|
|
86
|
+
it "should replace '#{title}' with '#{pattern}'" do
|
87
|
+
Collection.title_pattern(title).should == pattern
|
88
|
+
end
|
84
89
|
end
|
85
90
|
end
|
86
91
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
92
|
+
describe "Title permutations" do
|
93
|
+
# dynamically create a set of specs to test title permutations
|
94
|
+
[
|
95
|
+
'foobar',
|
96
|
+
'a foobar',
|
97
|
+
'an foobar',
|
98
|
+
'the foobar'
|
99
|
+
].each do |title|
|
100
|
+
it "should create proper title permutations for '#{title}'" do
|
101
|
+
Collection.title_permutations(title).sort.should == ['foobar', 'a foobar', 'an foobar', 'the foobar'].sort
|
102
|
+
end
|
96
103
|
end
|
97
104
|
end
|
98
105
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
106
|
+
describe "Hash contents" do
|
107
|
+
it 'should use title patterns in title_isbn_hash' do
|
108
|
+
collection = Collection.new(COLLECTION_XML)
|
109
|
+
buf = []
|
110
|
+
collection.title_isbn_hash.each do |title, isbn|
|
111
|
+
buf << title unless title == Collection.title_pattern(title)
|
112
|
+
end
|
113
|
+
puts buf.join("\n") unless buf.empty?
|
114
|
+
buf.empty?.should be_true
|
104
115
|
end
|
105
|
-
puts buf.join("\n") unless buf.empty?
|
106
|
-
buf.empty?.should be_true
|
107
|
-
end
|
108
116
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
117
|
+
it 'should use actual titles in isbn_title_hash' do
|
118
|
+
collection = Collection.new(COLLECTION_XML)
|
119
|
+
buf = []
|
120
|
+
# collection.isbn_title_hash's value is the actual title
|
121
|
+
# collection.title_isbn_hash uses the title pattern as the key
|
122
|
+
# and returns an array of possible isbns, one of which should
|
123
|
+
# match the key from collection.isbn_title_hash
|
124
|
+
collection.isbn_title_hash.each do |isbn, actual_title|
|
125
|
+
title_pattern = Collection.title_pattern(actual_title)
|
126
|
+
isbns = collection.title_isbn_hash[title_pattern]
|
127
|
+
buf << actual_title unless isbns.include?(isbn)
|
128
|
+
end
|
129
|
+
puts buf.join("\n") unless buf.empty?
|
130
|
+
buf.empty?.should be_true
|
120
131
|
end
|
121
|
-
puts buf.join("\n") unless buf.empty?
|
122
|
-
buf.empty?.should be_true
|
123
132
|
end
|
124
|
-
|
125
133
|
end
|
@@ -14,7 +14,6 @@ describe "DvdprofilerProfile" do
|
|
14
14
|
# Log4r::Outputter[:console].formatter = Log4r::PatternFormatter.new(:pattern => "%m")
|
15
15
|
# @logger.level = Log4r::DEBUG
|
16
16
|
File.mkdirs(TMPDIR)
|
17
|
-
puts "\nDvdprofilerProfile Specs"
|
18
17
|
end
|
19
18
|
|
20
19
|
before(:each) do
|
@@ -26,56 +25,62 @@ describe "DvdprofilerProfile" do
|
|
26
25
|
Dir.glob(File.join(TMPDIR, "dvdprofiler_profile_spec*")).each { |filename| File.delete(filename) }
|
27
26
|
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
describe "Finders" do
|
29
|
+
it "should find by imdb_id" do
|
30
|
+
@profile.should_not == nil
|
31
|
+
end
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
it "should find by title" do
|
34
|
+
profile = DvdprofilerProfile.first(:title => 'National Treasure 2: Book of Secrets')
|
35
|
+
profile.should_not == nil
|
36
|
+
end
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
it "should find find by fuzzy title" do
|
39
|
+
profile = DvdprofilerProfile.first(:title => 'National Treasure 2 Book of Secrets')
|
40
|
+
profile.should_not == nil
|
41
|
+
end
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
it "should find by case insensitive title" do
|
44
|
+
profile = DvdprofilerProfile.first(:title => 'national treasure 2: book of secrets')
|
45
|
+
profile.should_not == nil
|
46
|
+
end
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
xml = @profile.to_xml
|
52
|
-
hash = XmlSimple.xml_in(xml)
|
53
|
-
rescue
|
54
|
-
hash = nil
|
48
|
+
it "should find multiple movies with the same title" do
|
49
|
+
profiles = DvdprofilerProfile.all(:title => 'Sabrina')
|
50
|
+
profiles.length.should == 2
|
55
51
|
end
|
56
|
-
hash.should_not be_nil
|
57
|
-
end
|
58
52
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
53
|
+
it "should find a single movie using the year when multiple movies have the same title" do
|
54
|
+
profiles = DvdprofilerProfile.all(:title => 'Sabrina', :year => '1995')
|
55
|
+
(profiles.length.should == 1) && (profiles.first.isbn.should == '097363304340')
|
56
|
+
end
|
63
57
|
|
64
|
-
|
65
|
-
|
66
|
-
|
58
|
+
it "should find the other single movie using the year when multiple movies have the same title" do
|
59
|
+
profiles = DvdprofilerProfile.all(:title => 'Sabrina', :year => '1954')
|
60
|
+
(profiles.length.should == 1) && (profiles.first.isbn.should == '097360540246')
|
61
|
+
end
|
67
62
|
end
|
68
63
|
|
69
|
-
|
70
|
-
|
71
|
-
|
64
|
+
describe "XML" do
|
65
|
+
it "should be able to convert to xml and then from xml" do
|
66
|
+
hash = nil
|
67
|
+
begin
|
68
|
+
xml = @profile.to_xml
|
69
|
+
hash = XmlSimple.xml_in(xml)
|
70
|
+
rescue
|
71
|
+
hash = nil
|
72
|
+
end
|
73
|
+
hash.should_not be_nil
|
74
|
+
end
|
72
75
|
end
|
73
76
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
77
|
+
describe "File" do
|
78
|
+
it "should save to a file" do
|
79
|
+
filespec = get_temp_filename
|
80
|
+
profile = DvdprofilerProfile.first(:title => 'Sabrina', :year => '1995')
|
81
|
+
profile.save(filespec)
|
82
|
+
(File.exist?(filespec) && (File.size(filespec) > 0)).should be_true
|
83
|
+
end
|
79
84
|
end
|
80
85
|
|
81
86
|
def get_temp_filename
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: royw-dvdprofiler_collection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roy Wright
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-24 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|