2013-02-05 14:16:51 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe CategoryFeaturedTopic do
|
|
|
|
|
2014-12-31 09:55:03 -05:00
|
|
|
it { is_expected.to belong_to :category }
|
|
|
|
it { is_expected.to belong_to :topic }
|
2013-02-25 11:42:20 -05:00
|
|
|
|
2013-06-20 16:07:53 -04:00
|
|
|
context 'feature_topics_for' do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:category) { Fabricate(:category) }
|
2013-07-17 18:58:25 -04:00
|
|
|
let!(:category_post) { PostCreator.create(user, raw: "I put this post in the category", title: "categorize THIS", category: category.id) }
|
2013-06-04 21:22:47 -04:00
|
|
|
|
2013-06-20 16:07:53 -04:00
|
|
|
it "should feature topics for a secure category" do
|
2013-06-04 21:22:47 -04:00
|
|
|
|
2013-06-20 16:07:53 -04:00
|
|
|
# so much dancing, I am thinking fixures make sense here.
|
2014-09-05 01:20:39 -04:00
|
|
|
user.change_trust_level!(TrustLevel[1])
|
2013-06-04 21:22:47 -04:00
|
|
|
|
2013-07-13 21:24:16 -04:00
|
|
|
category.set_permissions(:trust_level_1 => :full)
|
2013-06-20 16:07:53 -04:00
|
|
|
category.save
|
2013-06-04 21:22:47 -04:00
|
|
|
|
2014-09-05 01:20:39 -04:00
|
|
|
_uncategorized_post = PostCreator.create(user, raw: "this is my new post 123 post", title: "hello world")
|
2013-06-04 21:22:47 -04:00
|
|
|
|
2013-06-20 16:07:53 -04:00
|
|
|
CategoryFeaturedTopic.feature_topics_for(category)
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(CategoryFeaturedTopic.count).to be(1)
|
2013-06-20 16:07:53 -04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not include invisible topics' do
|
2013-07-17 18:58:25 -04:00
|
|
|
invisible_post = PostCreator.create(user, raw: "Don't look at this post because it's awful.", title: "not visible to anyone", category: category.id)
|
2013-06-20 16:07:53 -04:00
|
|
|
invisible_post.topic.update_status('visible', false, Fabricate(:admin))
|
|
|
|
CategoryFeaturedTopic.feature_topics_for(category)
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(CategoryFeaturedTopic.count).to be(1)
|
2013-06-20 16:07:53 -04:00
|
|
|
end
|
2015-02-24 22:24:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
it 'should feature stuff in the correct order' do
|
2015-06-10 14:36:47 -04:00
|
|
|
SiteSetting.stubs(:category_featured_topics).returns(3)
|
2015-02-24 22:24:25 -05:00
|
|
|
|
|
|
|
category = Fabricate(:category)
|
2015-06-10 14:36:47 -04:00
|
|
|
t4 = Fabricate(:topic, category_id: category.id, bumped_at: 10.minutes.ago)
|
|
|
|
t3 = Fabricate(:topic, category_id: category.id, bumped_at: 7.minutes.ago)
|
2015-02-24 22:24:25 -05:00
|
|
|
t2 = Fabricate(:topic, category_id: category.id, bumped_at: 4.minutes.ago)
|
|
|
|
t1 = Fabricate(:topic, category_id: category.id, bumped_at: 5.minutes.ago)
|
|
|
|
pinned = Fabricate(:topic, category_id: category.id, pinned_at: 10.minutes.ago, bumped_at: 10.minutes.ago)
|
|
|
|
|
|
|
|
CategoryFeaturedTopic.feature_topics_for(category)
|
|
|
|
|
|
|
|
expect(
|
|
|
|
CategoryFeaturedTopic.where(category_id: category.id).pluck(:topic_id)
|
2015-06-10 14:36:47 -04:00
|
|
|
).to eq([pinned.id, t2.id, t1.id, t3.id])
|
2015-02-24 22:24:25 -05:00
|
|
|
|
|
|
|
end
|
2013-06-04 21:22:47 -04:00
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|