2015-10-11 04:41:23 -05:00
|
|
|
require 'rails_helper'
|
2014-08-18 02:13:10 -05:00
|
|
|
|
|
|
|
describe TopicFeaturedUsers do
|
2016-06-21 11:59:33 -05:00
|
|
|
it 'ensures consistency' do
|
2014-08-18 02:13:10 -05:00
|
|
|
|
|
|
|
t = Fabricate(:topic)
|
|
|
|
Fabricate(:post, topic_id: t.id, user_id: t.user_id)
|
|
|
|
p2 = Fabricate(:post, topic_id: t.id)
|
2016-06-21 11:59:33 -05:00
|
|
|
p3 = Fabricate(:post, topic_id: t.id, user_id: p2.user_id)
|
2014-08-18 02:13:10 -05:00
|
|
|
p4 = Fabricate(:post, topic_id: t.id)
|
|
|
|
p5 = Fabricate(:post, topic_id: t.id)
|
|
|
|
|
|
|
|
t.update_columns(featured_user1_id: 66,
|
|
|
|
featured_user2_id: 70,
|
|
|
|
featured_user3_id: 12,
|
|
|
|
featured_user4_id: 7,
|
2016-06-21 11:59:33 -05:00
|
|
|
last_post_user_id: p5.user_id)
|
2014-08-18 02:13:10 -05:00
|
|
|
|
|
|
|
TopicFeaturedUsers.ensure_consistency!
|
|
|
|
t.reload
|
|
|
|
|
2014-12-31 08:55:03 -06:00
|
|
|
expect(t.featured_user1_id).to eq(p2.user_id)
|
|
|
|
expect(t.featured_user2_id).to eq(p4.user_id)
|
|
|
|
expect(t.featured_user3_id).to eq(nil)
|
|
|
|
expect(t.featured_user4_id).to eq(nil)
|
2014-08-18 02:13:10 -05:00
|
|
|
|
2016-06-21 11:59:33 -05:00
|
|
|
# after removing a post
|
|
|
|
p2.update_column(:deleted_at, Time.now)
|
|
|
|
p3.update_column(:hidden, true)
|
|
|
|
|
|
|
|
TopicFeaturedUsers.ensure_consistency!
|
|
|
|
t.reload
|
2014-08-18 02:13:10 -05:00
|
|
|
|
2016-06-21 11:59:33 -05:00
|
|
|
expect(t.featured_user1_id).to eq(p4.user_id)
|
|
|
|
expect(t.featured_user2_id).to eq(nil)
|
|
|
|
expect(t.featured_user3_id).to eq(nil)
|
|
|
|
expect(t.featured_user4_id).to eq(nil)
|
2014-08-18 02:13:10 -05:00
|
|
|
end
|
|
|
|
end
|