FIX: suggested topics sometimes adds new topics from other categories before new topics of the current category
This commit is contained in:
parent
819ac61eb9
commit
e7a05c54e8
|
@ -31,14 +31,19 @@ class SuggestedTopicsBuilder
|
|||
end
|
||||
|
||||
def splice_results(results, priority)
|
||||
if @category_id &&
|
||||
priority == :high &&
|
||||
non_category_index = @results.index{|r| r.category_id != @category_id}
|
||||
if @category_id && priority == :high
|
||||
|
||||
category_results, non_category_results = results.partition{|r| r.category_id == @category_id}
|
||||
# Topics from category @category_id need to be first in the list, all others after.
|
||||
|
||||
@results.insert non_category_index, *category_results
|
||||
@results.concat non_category_results
|
||||
other_category_index = @results.index { |r| r.category_id != @category_id }
|
||||
category_results, other_category_results = results.partition{ |r| r.category_id == @category_id }
|
||||
|
||||
if other_category_index
|
||||
@results.insert other_category_index, *category_results
|
||||
else
|
||||
@results.concat category_results
|
||||
end
|
||||
@results.concat other_category_results
|
||||
else
|
||||
@results.concat results
|
||||
end
|
||||
|
|
|
@ -37,6 +37,11 @@ describe SuggestedTopicsBuilder do
|
|||
|
||||
builder.results.map(&:id).should == [2,3]
|
||||
end
|
||||
|
||||
it "inserts multiple results and puts topics in the correct order" do
|
||||
builder.splice_results([fake_topic(2,1), fake_topic(3,2), fake_topic(4,1)], :high)
|
||||
builder.results.map(&:id).should == [2,4,3]
|
||||
end
|
||||
end
|
||||
|
||||
it "has the correct defaults" do
|
||||
|
|
Loading…
Reference in New Issue