2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-12-23 18:50:36 -05:00
|
|
|
|
|
|
|
describe TopTopic do
|
|
|
|
|
2016-01-08 05:53:52 -05:00
|
|
|
describe '#sorted_periods' do
|
|
|
|
context "verify enum sequence" do
|
|
|
|
before do
|
|
|
|
@sorted_periods = TopTopic.sorted_periods
|
|
|
|
end
|
|
|
|
|
|
|
|
it "'daily' should be at 1st position" do
|
|
|
|
expect(@sorted_periods[:daily]).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "'all' should be at 6th position" do
|
|
|
|
expect(@sorted_periods[:all]).to eq(6)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-25 11:18:35 -04:00
|
|
|
it { is_expected.to belong_to :topic }
|
2013-12-23 18:50:36 -05:00
|
|
|
|
|
|
|
context "refresh!" do
|
|
|
|
|
|
|
|
let!(:t1) { Fabricate(:topic) }
|
|
|
|
let!(:t2) { Fabricate(:topic) }
|
|
|
|
|
|
|
|
it "begins blank" do
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(TopTopic.all).to be_blank
|
2013-12-23 18:50:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "after calculating" do
|
|
|
|
|
|
|
|
before do
|
|
|
|
TopTopic.refresh!
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should have top topics" do
|
2015-04-25 11:18:35 -04:00
|
|
|
expect(TopTopic.pluck(:topic_id)).to match_array([t1.id, t2.id])
|
2013-12-23 18:50:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|