addic7ed 3.0.0 → 4.0.0.pre.beta.5

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 (46) hide show
  1. checksums.yaml +4 -4
  2. data/lib/addic7ed.rb +5 -10
  3. data/lib/addic7ed/common.rb +13 -1285
  4. data/lib/addic7ed/config.json +1417 -0
  5. data/lib/addic7ed/errors.rb +8 -7
  6. data/lib/addic7ed/models/episode.rb +112 -0
  7. data/lib/addic7ed/models/search.rb +90 -0
  8. data/lib/addic7ed/models/subtitle.rb +109 -0
  9. data/lib/addic7ed/models/subtitles_collection.rb +63 -0
  10. data/lib/addic7ed/models/video_file.rb +147 -0
  11. data/lib/addic7ed/service.rb +13 -0
  12. data/lib/addic7ed/services/check_compatibility.rb +44 -0
  13. data/lib/addic7ed/services/download_subtitle.rb +53 -0
  14. data/lib/addic7ed/services/get_shows_list.rb +29 -0
  15. data/lib/addic7ed/services/{addic7ed_comment_normalizer.rb → normalize_comment.rb} +4 -8
  16. data/lib/addic7ed/services/normalize_version.rb +22 -0
  17. data/lib/addic7ed/services/parse_page.rb +43 -0
  18. data/lib/addic7ed/services/parse_subtitle.rb +79 -0
  19. data/lib/addic7ed/services/url_encode_show_name.rb +46 -0
  20. data/lib/addic7ed/version.rb +1 -1
  21. metadata +63 -50
  22. data/bin/addic7ed +0 -144
  23. data/lib/addic7ed/episode.rb +0 -95
  24. data/lib/addic7ed/parser.rb +0 -105
  25. data/lib/addic7ed/services/addic7ed_version_normalizer.rb +0 -24
  26. data/lib/addic7ed/show_list.rb +0 -61
  27. data/lib/addic7ed/subtitle.rb +0 -72
  28. data/lib/addic7ed/video_file.rb +0 -41
  29. data/spec/lib/addic7ed/common_spec.rb +0 -21
  30. data/spec/lib/addic7ed/episode_spec.rb +0 -165
  31. data/spec/lib/addic7ed/services/addic7ed_comment_normalizer_spec.rb +0 -12
  32. data/spec/lib/addic7ed/services/addic7ed_version_normalizer_spec.rb +0 -73
  33. data/spec/lib/addic7ed/show_list_spec.rb +0 -42
  34. data/spec/lib/addic7ed/subtitle_spec.rb +0 -182
  35. data/spec/lib/addic7ed/video_file_spec.rb +0 -159
  36. data/spec/responses/basic_redirection.http +0 -13
  37. data/spec/responses/homepage.http +0 -921
  38. data/spec/responses/redirection_loop.http +0 -12
  39. data/spec/responses/walking-dead-3-2-1.http +0 -770
  40. data/spec/responses/walking-dead-3-2-48.http +0 -2117
  41. data/spec/responses/walking-dead-3-2-7.http +0 -659
  42. data/spec/responses/walking-dead-3-2-8.http +0 -815
  43. data/spec/responses/walking-dead-3-2-8_best_subtitle.http +0 -1928
  44. data/spec/responses/walking-dead-3-4-8.http +0 -732
  45. data/spec/responses/walking-dead-3-42-8.http +0 -13
  46. data/spec/spec_helper.rb +0 -26
@@ -1,41 +0,0 @@
1
- module Addic7ed
2
- class VideoFile
3
-
4
- TVSHOW_REGEX = /\A(?<showname>.*\w)[\[\. ]+S?(?<season>\d{1,2})[-\. ]?[EX]?(?<episode>\d{2})([-\. ]?[EX]?\d{2})*[\]\. ]+(?<tags>.*)-(?<group>\w*)\[?(?<distribution>\w*)\]?(\.\w{3})?\z/i
5
-
6
- attr_reader :filename, :showname, :season, :episode, :tags, :group, :distribution
7
-
8
- def initialize(filename)
9
- @filename = filename
10
- if match = TVSHOW_REGEX.match(basename)
11
- @showname = match[:showname]
12
- @season = match[:season].to_i
13
- @episode = match[:episode].to_i
14
- @tags = match[:tags].upcase.split(/[\. ]/)
15
- @group = match[:group].upcase
16
- @distribution = match[:distribution].upcase
17
- else
18
- raise InvalidFilename
19
- end
20
- end
21
-
22
- def basename
23
- @basename ||= ::File.basename(@filename)
24
- end
25
-
26
- def to_s
27
- @filename
28
- end
29
-
30
- def inspect
31
- "Guesses for #{@filename}:
32
- show: #{@showname}
33
- season: #{@season}
34
- episode: #{@episode}
35
- tags: #{@tags}
36
- group: #{@group}
37
- distribution: #{@distribution}"
38
- end
39
-
40
- end
41
- end
@@ -1,21 +0,0 @@
1
- require 'spec_helper'
2
- require './lib/addic7ed'
3
-
4
- describe Addic7ed do
5
- it 'defines SHOWS_URL' do
6
- expect(Addic7ed::SHOWS_URL).to_not be_nil
7
- end
8
-
9
- it 'defines EPISODES_URL' do
10
- expect(Addic7ed::EPISODES_URL).to_not be_nil
11
- end
12
-
13
- it 'defines EPISODE_REDIRECT_URL' do
14
- expect(Addic7ed::EPISODE_REDIRECT_URL).to_not be_nil
15
- end
16
-
17
- it 'defines LANGUAGES' do
18
- expect(Addic7ed::LANGUAGES).to_not be_nil
19
- expect(Addic7ed::LANGUAGES).to include 'fr' => {name: 'French', id: 8}
20
- end
21
- end
@@ -1,165 +0,0 @@
1
- require 'spec_helper'
2
- require './lib/addic7ed'
3
-
4
- describe Addic7ed::Episode do
5
- before :all do
6
- @filename = 'The.Walking.Dead.S03E02.720p.HDTV.x264-EVOLVE.mkv'
7
- @filename_show_not_found = 'Show.Not.Found.S03E02.720p.HDTV.x264-EVOLVE.mkv'
8
- @filename_episode_not_found = 'The.Walking.Dead.S03E42.720p.HDTV.x264-EVOLVE.mkv'
9
- @filename_compatible_group = 'The.Walking.Dead.S03E04.HDTV.XviD-ASAP.mkv'
10
- @filename_no_hi = 'The.Walking.Dead.S03E02.720p.HDTV.x264-KILLERS.mkv'
11
- @episode = Addic7ed::Episode.new(@filename)
12
- end
13
-
14
- it 'should create valid instance given valid argument' do
15
- expect{ Addic7ed::Episode.new(@filename) }.to_not raise_error
16
- end
17
-
18
- describe '#url' do
19
- it 'returns a show localized URL given existing episode' do
20
- expect(@episode.url('fr')).to eq 'http://www.addic7ed.com/serie/The_Walking_Dead/3/2/8'
21
- expect(@episode.url('es')).to eq 'http://www.addic7ed.com/serie/The_Walking_Dead/3/2/4'
22
- end
23
-
24
- it 'uses French as default language' do
25
- expect(@episode.url).to eq @episode.url('fr')
26
- end
27
-
28
- it 'raises LanguageNotSupported given an unsupported language code' do
29
- expect{ @episode.url('aa') }.to raise_error Addic7ed::LanguageNotSupported
30
- end
31
- end
32
-
33
- describe '#subtitles' do
34
- it 'should return an array of Addic7ed::Subtitle given valid episode and language' do
35
- %w{fr en it}.each do |lang|
36
- lang_id = Addic7ed::LANGUAGES[lang][:id]
37
- stub_request(:get, "http://www.addic7ed.com/serie/The_Walking_Dead/3/2/#{lang_id}")
38
- .to_return File.new("spec/responses/walking-dead-3-2-#{lang_id}.http")
39
- end
40
- expect(@episode.subtitles('fr').size).to eq 4
41
- expect(@episode.subtitles('en').size).to eq 3
42
- expect(@episode.subtitles('it').size).to eq 1
43
- end
44
-
45
- it 'uses French as default language' do
46
- expect(@episode.subtitles).to eq @episode.subtitles('fr')
47
- end
48
-
49
- it 'raises LanguageNotSupported given an unsupported language code' do
50
- expect{ @episode.subtitles('aa') }.to raise_error Addic7ed::LanguageNotSupported
51
- end
52
-
53
- it 'raises EpisodeNotFound given not existing episode' do
54
- stub_request(:get, 'http://www.addic7ed.com/serie/The_Walking_Dead/3/42/8')
55
- .to_return File.new('spec/responses/walking-dead-3-42-8.http')
56
- expect{ Addic7ed::Episode.new(@filename_episode_not_found).subtitles }.to raise_error Addic7ed::EpisodeNotFound
57
- end
58
-
59
- it 'raises NoSubtitleFound given valid episode which has no subtitle on Addic7ed' do
60
- stub_request(:get, 'http://www.addic7ed.com/serie/The_Walking_Dead/3/2/48')
61
- .to_return File.new('spec/responses/walking-dead-3-2-48.http')
62
- expect{ @episode.subtitles('az') }.to raise_error Addic7ed::NoSubtitleFound
63
- end
64
-
65
- it 'may raise a ParsingError, but I\'m not sure how...'
66
- end
67
-
68
- describe '#best_subtitle' do
69
- it 'finds the subtitle with status completed and same group name' do
70
- stub_request(:get, 'http://www.addic7ed.com/serie/The_Walking_Dead/3/2/8')
71
- .to_return File.new('spec/responses/walking-dead-3-2-8.http')
72
- expect(@episode.best_subtitle('fr').url).to eq 'http://www.addic7ed.com/original/68018/4'
73
- end
74
-
75
- it 'finds the subtitle with status completed, compatible group name and as many downloads as possible' do
76
- stub_request(:get, 'http://www.addic7ed.com/serie/The_Walking_Dead/3/4/8')
77
- .to_return File.new('spec/responses/walking-dead-3-4-8.http')
78
- compatible_episode = Addic7ed::Episode.new(@filename_compatible_group)
79
- expect(compatible_episode.best_subtitle('fr').url).to eq 'http://www.addic7ed.com/updated/8/68508/3'
80
- end
81
-
82
- it 'finds the subtitle with status completed, same group name and not hearing impaired' do
83
- stub_request(:get, 'http://www.addic7ed.com/serie/The_Walking_Dead/3/2/1')
84
- .to_return File.new('spec/responses/walking-dead-3-2-1.http')
85
- episode = Addic7ed::Episode.new(@filename_no_hi)
86
- expect(episode.best_subtitle('en', true).url).to eq 'http://www.addic7ed.com/updated/1/68018/0'
87
- end
88
-
89
- it 'uses French as default language' do
90
- expect(@episode.best_subtitle).to eq @episode.best_subtitle('fr')
91
- end
92
-
93
- it 'raises LanguageNotSupported given an unsupported language code' do
94
- expect{ @episode.best_subtitle('aa') }.to raise_error Addic7ed::LanguageNotSupported
95
- end
96
-
97
- it 'raises NoSubtitleFound given valid episode which has no subtitle on Addic7ed' do
98
- stub_request(:get, 'http://www.addic7ed.com/serie/The_Walking_Dead/3/2/48')
99
- .to_return File.new('spec/responses/walking-dead-3-2-48.http')
100
- expect{ @episode.best_subtitle('az') }.to raise_error Addic7ed::NoSubtitleFound
101
- end
102
- end
103
-
104
- describe '#download_best_subtitle!' do
105
- let(:episode) { Addic7ed::Episode.new(@filename) }
106
-
107
- before do
108
- WebMock.reset!
109
- @page_stub = stub_request(:get, 'http://www.addic7ed.com/serie/The_Walking_Dead/3/2/8')
110
- .to_return File.new('spec/responses/walking-dead-3-2-8.http')
111
- @sub_stub = stub_request(:get, 'http://www.addic7ed.com/original/68018/4')
112
- .to_return File.new('spec/responses/walking-dead-3-2-8_best_subtitle.http')
113
- # Prevent actual disk writing
114
- allow(Kernel).to receive(:open)
115
- end
116
-
117
- it 'gets the best subtitle candidate with a network request' do
118
- expect(episode).to receive(:best_subtitle).once.and_call_original
119
- episode.download_best_subtitle!('fr')
120
- expect(@page_stub).to have_been_requested
121
- expect(@sub_stub).to have_been_requested
122
- end
123
-
124
- it 'raises DownloadError when a network error happens' do
125
- stub_request(:get, 'http://www.addic7ed.com/original/68018/4').to_timeout
126
- expect{ episode.download_best_subtitle!('fr') }.to raise_error Addic7ed::DownloadError
127
- end
128
-
129
- it 'is called recursively' do
130
- stub_request(:get, 'http://www.addic7ed.com/original/68018/4').to_return File.new('spec/responses/basic_redirection.http')
131
- stub_request(:get, 'http://www.addic7ed.com/original/68018/4.redirected').to_return File.new('spec/responses/walking-dead-3-2-8_best_subtitle.http')
132
- expect(episode).to receive(:download_best_subtitle!).twice.and_call_original
133
- episode.download_best_subtitle!('fr')
134
- end
135
-
136
- it 'raises HTTPError when stuck in a HTTP redirections loop' do
137
- stub_request(:get, 'http://www.addic7ed.com/original/68018/4')
138
- .to_return File.new('spec/responses/redirection_loop.http')
139
- expect{ episode.download_best_subtitle!('fr') }.to raise_error Addic7ed::HTTPError
140
- end
141
-
142
- it 'creates a new file on disk' do
143
- file = double('file')
144
- expect(Kernel).to receive(:open).with('The.Walking.Dead.S03E02.720p.HDTV.x264-EVOLVE.fr.srt', 'w').and_yield(file)
145
- expect(file).to receive(:<<)
146
- episode.download_best_subtitle!('fr')
147
- end
148
-
149
- context "when untagged option is set" do
150
- let(:episode) { Addic7ed::Episode.new(@filename, true) }
151
-
152
- it "does not include language code in subtitle filename" do
153
- file = double('file')
154
- expect(Kernel).to receive(:open).with('The.Walking.Dead.S03E02.720p.HDTV.x264-EVOLVE.srt', 'w').and_yield(file)
155
- expect(file).to receive(:<<)
156
- episode.download_best_subtitle!('fr')
157
- end
158
- end
159
-
160
- it 'raises SubtitleCannotBeSaved when a disk error happens' do
161
- expect(Kernel).to receive(:open).with('The.Walking.Dead.S03E02.720p.HDTV.x264-EVOLVE.fr.srt', 'w').and_raise('Persmission denied')
162
- expect{ episode.download_best_subtitle!('fr') }.to raise_error Addic7ed::SubtitleCannotBeSaved
163
- end
164
- end
165
- end
@@ -1,12 +0,0 @@
1
- require "spec_helper"
2
- require "./lib/addic7ed"
3
-
4
- describe Addic7ed::Addic7edCommentNormalizer do
5
- def normalized_comment(comment)
6
- described_class.call(comment)
7
- end
8
-
9
- it "downcases everything" do
10
- expect(normalized_comment("DiMENSiON")).to eq "dimension"
11
- end
12
- end
@@ -1,73 +0,0 @@
1
- require "spec_helper"
2
- require "./lib/addic7ed"
3
-
4
- describe Addic7ed::Addic7edVersionNormalizer do
5
- def normalized_version(version)
6
- described_class.call(version)
7
- end
8
-
9
- it "upcases everything" do
10
- expect(normalized_version("DiMENSiON")).to eq "DIMENSION"
11
- end
12
-
13
- it "removes white spaces and line breaks and non-breaking spaces" do
14
- expect(normalized_version(" \n DIMENSION \u00a0 ")).to eq "DIMENSION"
15
- end
16
-
17
- it "removes the filesize" do
18
- expect(normalized_version("DIMENSION, 0.00 MBs")).to eq "DIMENSION"
19
- end
20
-
21
- it "removes heading or trailing dots" do
22
- expect(normalized_version(".DIMENSION.")).to eq "DIMENSION"
23
- end
24
-
25
- it "removes heading or trailing whitespaces" do
26
- expect(normalized_version(" DIMENSION ")).to eq "DIMENSION"
27
- end
28
-
29
- it "removes heading or trailing dashes" do
30
- expect(normalized_version("-DIMENSION-")).to eq "DIMENSION"
31
- end
32
-
33
- it "removes '720p' tag" do
34
- expect(normalized_version("720P DIMENSION")).to eq "DIMENSION"
35
- end
36
-
37
- it "removes '1080p' tag" do
38
- expect(normalized_version("1080P DIMENSION")).to eq "DIMENSION"
39
- end
40
-
41
- it "removes 'HDTV' tag" do
42
- expect(normalized_version("HDTV DIMENSION")).to eq "DIMENSION"
43
- end
44
-
45
- it "removes 'x264' tag" do
46
- expect(normalized_version("X264 DIMENSION")).to eq "DIMENSION"
47
- expect(normalized_version("X.264 DIMENSION")).to eq "DIMENSION"
48
- end
49
-
50
- it "removes 'PROPER' tag" do
51
- expect(normalized_version("PROPER DIMENSION")).to eq "DIMENSION"
52
- end
53
-
54
- it "removes 'RERIP' tag" do
55
- expect(normalized_version("RERIP DIMENSION")).to eq "DIMENSION"
56
- end
57
-
58
- it "removes 'INTERNAL' tag" do
59
- expect(normalized_version("INTERNAL DIMENSION")).to eq "DIMENSION"
60
- end
61
-
62
- it "removes the 'Version' prefix" do
63
- expect(normalized_version("Version DIMENSION")).to eq "DIMENSION"
64
- end
65
-
66
- it "removes combined tags" do
67
- expect(normalized_version("Version 720P PROPER X264 HDTV DIMENSION")).to eq "DIMENSION"
68
- end
69
-
70
- it "supports multiple concatenated versions" do
71
- expect(normalized_version("-TLA, -FoV")).to eq "TLA,FOV"
72
- end
73
- end
@@ -1,42 +0,0 @@
1
- require "spec_helper"
2
- require "./lib/addic7ed"
3
-
4
- describe Addic7ed::ShowList, ".url_segment_for" do
5
- it "changes all spaces to underscores" do
6
- expect(Addic7ed::ShowList.url_segment_for("The.Walking.Dead")).to eq "The_Walking_Dead"
7
- end
8
-
9
- it "wraps country code with parenthesis" do
10
- expect(Addic7ed::ShowList.url_segment_for("Shameless.US")).to eq "Shameless_(US)"
11
- expect(Addic7ed::ShowList.url_segment_for("Vikings.UK")).to eq "Vikings_(UK)"
12
- end
13
-
14
- it "is case-insensitive" do
15
- expect(Addic7ed::ShowList.url_segment_for("shameless.us")).to eq "Shameless_(US)"
16
- end
17
-
18
- it "wraps production year with parenthesis" do
19
- expect(Addic7ed::ShowList.url_segment_for("Vikings.2013")).to eq "Vikings_(2013)"
20
- end
21
-
22
- it "returns last show when production year is unspecified" do
23
- expect(Addic7ed::ShowList.url_segment_for("Empire")).to eq "Empire_(2015)"
24
- expect(Addic7ed::ShowList.url_segment_for("American.Crime")).to eq "American_Crime_(2015)"
25
- end
26
-
27
- it "handles when both country code and production year are present" do
28
- expect(Addic7ed::ShowList.url_segment_for("Legacy.2013.UK")).to eq "Legacy_(2013)_(UK)"
29
- end
30
-
31
- it "handles when show name contains a quote" do
32
- expect(Addic7ed::ShowList.url_segment_for("Greys.Anatomy")).to eq "Grey's_Anatomy"
33
- end
34
-
35
- it "handles when a show name contains dots" do
36
- expect(Addic7ed::ShowList.url_segment_for("The.O.C.")).to eq "The_O.C."
37
- end
38
-
39
- it "raises a ShowNotFound error when no matching show is found" do
40
- expect{Addic7ed::ShowList.url_segment_for("Not.an.existing.show")}.to raise_error Addic7ed::ShowNotFound
41
- end
42
- end
@@ -1,182 +0,0 @@
1
- require "spec_helper"
2
- require "./lib/addic7ed"
3
-
4
- describe Addic7ed::Subtitle, "#initialize" do
5
- let(:version) { "Version DIMENSiON" }
6
- let(:comment) { "Works for LOL" }
7
-
8
- subject { described_class.new(version: version, comment: comment) }
9
-
10
- it "normalizes Addic7ed version" do
11
- expect(Addic7ed::Addic7edVersionNormalizer).to receive(:call).with(version)
12
- subject
13
- end
14
-
15
- it "normalizes Addic7ed comment" do
16
- expect(Addic7ed::Addic7edCommentNormalizer).to receive(:call).with(comment)
17
- subject
18
- end
19
- end
20
-
21
- describe Addic7ed::Subtitle, "#to_s" do
22
- let(:subtitle) { Addic7ed::Subtitle.new(version: "DIMENSION", language: "fr", status: "Completed", url: "http://some.fancy.url", via: "http://addic7ed.com", downloads: "42") }
23
-
24
- it "prints a human readable version" do
25
- expect(subtitle.to_s).to eq "http://some.fancy.url\t->\tDIMENSION (fr, Completed) [42 downloads] (via http://addic7ed.com)"
26
- end
27
- end
28
-
29
- describe Addic7ed::Subtitle, "#works_for?" do
30
- let(:subtitle) { Addic7ed::Subtitle.new(version: "DIMENSION") }
31
-
32
- context "when it is incomplete" do
33
- before { allow(subtitle).to receive(:is_completed?).and_return(false) }
34
-
35
- it "returns false" do
36
- expect(subtitle.works_for? "DIMENSION").to be false
37
- end
38
- end
39
-
40
- context "when it is completed" do
41
- before { allow(subtitle).to receive(:is_completed?).and_return(true) }
42
-
43
- it "returns true given the exact same version" do
44
- expect(subtitle.works_for? "DIMENSION").to be true
45
- end
46
-
47
- it "returns true given a compatible version" do
48
- expect(subtitle.works_for? "LOL").to be true
49
- end
50
-
51
- it "returns false given an incompatible version" do
52
- expect(subtitle.works_for? "EVOLVE").to be false
53
- end
54
-
55
- context "when is has a compatibility comment" do
56
- let(:subtitle) { Addic7ed::Subtitle.new(version: "DIMENSION", comment: "Works with IMMERSE") }
57
-
58
- it "returns true given the same version as comment" do
59
- expect(subtitle.works_for? "IMMERSE").to be true
60
- end
61
-
62
- it "returns true given a compatible version as comment" do
63
- expect(subtitle.works_for? "ASAP").to be true
64
- end
65
-
66
- it "returns false given an incompatible version as comment" do
67
- expect(subtitle.works_for? "KILLERS").to be false
68
- end
69
- end
70
-
71
- context "when is has an incompatibility comment" do
72
- let(:subtitle) { Addic7ed::Subtitle.new(version: "DIMENSION", comment: "Doesn't work with IMMERSE") }
73
-
74
- it "returns false" do
75
- expect(subtitle.works_for? "IMMERSE").to be false
76
- end
77
- end
78
-
79
- context "when is has an ambiguous comment" do
80
- let(:subtitle) { Addic7ed::Subtitle.new(version: "DIMENSION", comment: "Resync from IMMERSE") }
81
-
82
- it "returns false" do
83
- expect(subtitle.works_for? "IMMERSE").to be false
84
- end
85
- end
86
-
87
- context "when it has multiple versions" do
88
- let(:subtitle) { Addic7ed::Subtitle.new(version: "FOV,TLA") }
89
-
90
- it "returns true if it works for one of them" do
91
- expect(subtitle.works_for? "TLA").to be true
92
- expect(subtitle.works_for? "FOV").to be true
93
- end
94
-
95
- it "returns false when none of them work" do
96
- expect(subtitle.works_for? "LOL").to be false
97
- end
98
- end
99
- end
100
- end
101
-
102
- describe Addic7ed::Subtitle, "#can_replace?" do
103
- let(:defaults) { {version: "DIMENSION", language: "fr", status: "Completed", downloads: "10"} }
104
- let(:subtitle) { Addic7ed::Subtitle.new(defaults) }
105
- let(:other_subtitle) { Addic7ed::Subtitle.new(defaults) }
106
-
107
- context "when it is incomplete" do
108
- before { allow(subtitle).to receive(:is_completed?).and_return(false) }
109
-
110
- it "returns false" do
111
- expect(subtitle.can_replace? other_subtitle).to be false
112
- end
113
- end
114
-
115
- context "when it is completed" do
116
- before { allow(subtitle).to receive(:is_completed?).and_return(true) }
117
-
118
- it "returns true given no other_subtitle" do
119
- expect(subtitle.can_replace? nil).to be true
120
- end
121
-
122
- context "when other_subtitle has a different language" do
123
- before { allow(other_subtitle).to receive(:language).and_return("en") }
124
-
125
- it "returns false" do
126
- expect(subtitle.can_replace? other_subtitle).to be false
127
- end
128
- end
129
-
130
- context "when other_subtitle has an incompatible version" do
131
- before { allow(subtitle).to receive(:is_compatible_with?).with(other_subtitle.version).and_return(false) }
132
-
133
- it "returns false" do
134
- expect(subtitle.can_replace? other_subtitle).to be false
135
- end
136
- end
137
-
138
- context "when other_subtitle is featured by Addic7ed" do
139
- before { allow(other_subtitle).to receive(:is_featured?).and_return(true) }
140
-
141
- it "returns false" do
142
- expect(subtitle.can_replace? other_subtitle).to be false
143
- end
144
- end
145
-
146
- context "when other_subtitle has more downloads" do
147
- before { allow(other_subtitle).to receive(:downloads).and_return(subtitle.downloads + 1) }
148
-
149
- it "returns false" do
150
- expect(subtitle.can_replace? other_subtitle).to be false
151
- end
152
- end
153
-
154
- context "when other_subtitle has less downloads" do
155
- before { allow(other_subtitle).to receive(:downloads).and_return(subtitle.downloads - 1) }
156
-
157
- it "returns true" do
158
- expect(subtitle.can_replace? other_subtitle).to be true
159
- end
160
- end
161
- end
162
- end
163
-
164
- describe Addic7ed::Subtitle, "#is_featured?" do
165
- it "returns true when 'via' is 'http://addic7ed.com'" do
166
- expect(Addic7ed::Subtitle.new(via: 'http://addic7ed.com').is_featured?).to be true
167
- end
168
-
169
- it "returns false otherwise" do
170
- expect(Addic7ed::Subtitle.new(via: 'anything else').is_featured?).to be false
171
- end
172
- end
173
-
174
- describe Addic7ed::Subtitle, "#is_completed?" do
175
- it "returns true when 'status' is 'Completed'" do
176
- expect(Addic7ed::Subtitle.new(status: 'Completed').is_completed?).to be true
177
- end
178
-
179
- it "returns false otherwise" do
180
- expect(Addic7ed::Subtitle.new(status: '80%').is_completed?).to be false
181
- end
182
- end