mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Show Gaps in the post stream when filters are active
Conflicts: app/assets/javascripts/discourse/templates/topic.js.handlebars
This commit is contained in:
81
spec/components/gaps_spec.rb
Normal file
81
spec/components/gaps_spec.rb
Normal file
@@ -0,0 +1,81 @@
|
||||
require 'spec_helper'
|
||||
require 'cache'
|
||||
|
||||
describe Gaps do
|
||||
|
||||
|
||||
it 'returns no gaps for empty data' do
|
||||
Gaps.new(nil, nil).should be_blank
|
||||
end
|
||||
|
||||
it 'returns no gaps with one element' do
|
||||
Gaps.new([1], [1]).should be_blank
|
||||
end
|
||||
|
||||
it 'returns no gaps when all elements are present' do
|
||||
Gaps.new([1,2,3], [1,2,3]).should be_blank
|
||||
end
|
||||
|
||||
context "single element gap" do
|
||||
let(:gap) { Gaps.new([1,3], [1,2,3]) }
|
||||
|
||||
it 'has a gap for post 3' do
|
||||
gap.should_not be_blank
|
||||
gap.before[3].should == [2]
|
||||
gap.after.should be_blank
|
||||
end
|
||||
end
|
||||
|
||||
context "larger gap" do
|
||||
let(:gap) { Gaps.new([1,2,3,6,7], [1,2,3,4,5,6,7]) }
|
||||
|
||||
it 'has a gap for post 6' do
|
||||
gap.should_not be_blank
|
||||
gap.before[6].should == [4,5]
|
||||
gap.after.should be_blank
|
||||
end
|
||||
end
|
||||
|
||||
context "multiple gaps" do
|
||||
let(:gap) { Gaps.new([1,5,6,7,10], [1,2,3,4,5,6,7,8,9,10]) }
|
||||
|
||||
it 'has both gaps' do
|
||||
gap.should_not be_blank
|
||||
gap.before[5].should == [2,3,4]
|
||||
gap.before[10].should == [8,9]
|
||||
gap.after.should be_blank
|
||||
end
|
||||
end
|
||||
|
||||
context "a gap in the beginning" do
|
||||
let(:gap) { Gaps.new([2,3,4], [1,2,3,4]) }
|
||||
|
||||
it 'has the gap' do
|
||||
gap.should_not be_blank
|
||||
gap.before[2].should == [1]
|
||||
gap.after.should be_blank
|
||||
end
|
||||
end
|
||||
|
||||
context "a gap in the ending" do
|
||||
let(:gap) { Gaps.new([1,2,3], [1,2,3,4]) }
|
||||
|
||||
it 'has the gap' do
|
||||
gap.should_not be_blank
|
||||
gap.before.should be_blank
|
||||
gap.after[3].should == [4]
|
||||
end
|
||||
end
|
||||
|
||||
context "a large gap in the ending" do
|
||||
let(:gap) { Gaps.new([1,2,3], [1,2,3,4,5,6]) }
|
||||
|
||||
it 'has the gap' do
|
||||
gap.should_not be_blank
|
||||
gap.before.should be_blank
|
||||
gap.after[3].should == [4,5,6]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
@@ -89,7 +89,6 @@ describe TopicView do
|
||||
|
||||
end
|
||||
|
||||
|
||||
it "raises NotLoggedIn if the user isn't logged in and is trying to view a private message" do
|
||||
Topic.any_instance.expects(:private_message?).returns(true)
|
||||
lambda { TopicView.new(topic.id, nil) }.should raise_error(Discourse::NotLoggedIn)
|
||||
@@ -233,6 +232,26 @@ describe TopicView do
|
||||
p6.save!
|
||||
end
|
||||
|
||||
describe "contains_gaps?" do
|
||||
it "does not contain contains_gaps with default filtering" do
|
||||
topic_view.contains_gaps?.should be_false
|
||||
end
|
||||
|
||||
it "contains contains_gaps when filtered by username" do
|
||||
TopicView.new(topic.id, coding_horror, username_filters: ['eviltrout']).contains_gaps?.should be_true
|
||||
end
|
||||
|
||||
it "contains contains_gaps when filtered by summary" do
|
||||
TopicView.new(topic.id, coding_horror, filter: 'summary').contains_gaps?.should be_true
|
||||
end
|
||||
|
||||
it "contains contains_gaps when filtered by best" do
|
||||
TopicView.new(topic.id, coding_horror, best: 5).contains_gaps?.should be_true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
describe '#filter_posts_paged' do
|
||||
before { SiteSetting.stubs(:posts_per_page).returns(2) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user