Skip to content

Commit

Permalink
Stop overriding select behaviour in SubtitlesCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbaudino committed Aug 23, 2017
1 parent f76db56 commit 086870d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/addic7ed/models/subtitles_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def initialize(subtitles = [])
# #=> [#<Addic7ed::Subtitle @version="LOL">, #<Addic7ed::Subtitle @version="DIMENSION">]

def compatible_with(group)
select { |subtitle| CheckCompatibility.call(subtitle, group) }
chainable(select { |subtitle| CheckCompatibility.call(subtitle, group) })
end

# Returns only completed subtitles.
Expand All @@ -53,7 +53,7 @@ def compatible_with(group)
# #=> [#<Addic7ed::Subtitle @status="Completed">]

def completed
select(&:completed?)
chainable(select(&:completed?))
end

# Returns the most downloaded subtitle.
Expand All @@ -74,8 +74,8 @@ def most_popular

private

def select
self.class.new(super)
def chainable(array)
self.class.new(array)
end
end
end
4 changes: 2 additions & 2 deletions spec/lib/addic7ed/models/subtitles_collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

subject { described_class.new([compatible_subtitle, incompatible_subtitle]) }

it "returns an Addic7ed::SubtitlesCollection" do
it "is chainable" do
expect(subject.compatible_with("group")).to be_a described_class
end

Expand All @@ -47,7 +47,7 @@

subject { described_class.new([completed_subtitle, incomplete_subtitle]) }

it "returns an Addic7ed::SubtitlesCollection" do
it "is chainable" do
expect(subject.completed).to be_a described_class
end

Expand Down

0 comments on commit 086870d

Please sign in to comment.