2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-10 01:42:47 +08:00

FIX: topic counts after converting topic to/from public and private

This commit is contained in:
Neil Lalonde 2017-11-09 15:33:26 -05:00
parent 6d3ed966cd
commit 16ff2a4715
3 changed files with 56 additions and 3 deletions

View file

@ -6,7 +6,9 @@ describe TopicConverter do
let(:admin) { Fabricate(:admin) }
let(:author) { Fabricate(:user) }
let(:category) { Fabricate(:category) }
let(:private_message) { Fabricate(:private_message_topic, user: author) }
let(:private_message) { Fabricate(:private_message_topic, user: author) } # creates a topic without a first post
let(:first_post) { Fabricate(:post, topic: private_message, user: author) }
let(:other_user) { private_message.topic_allowed_users.find { |u| u.user != author }.user }
context 'success' do
it "converts private message to regular topic" do
@ -48,12 +50,36 @@ describe TopicConverter do
end
it "updates user stats" do
first_post
topic_user = TopicUser.create!(user_id: author.id, topic_id: private_message.id, posted: true)
expect(private_message.user.user_stat.topic_count).to eq(0)
private_message.convert_to_public_topic(admin)
expect(private_message.reload.user.user_stat.topic_count).to eq(1)
expect(topic_user.reload.notification_level).to eq(TopicUser.notification_levels[:watching])
end
context "with a reply" do
before do
UserActionCreator.enable
first_post
create_post(topic: private_message, user: other_user)
private_message.reload
end
after do
UserActionCreator.disable
end
it "updates UserActions" do
TopicConverter.new(private_message, admin).convert_to_public_topic
expect(author.user_actions.where(action_type: UserAction::NEW_PRIVATE_MESSAGE).count).to eq(0)
expect(author.user_actions.where(action_type: UserAction::NEW_TOPIC).count).to eq(1)
# TODO:
# expect(other_user.user_actions.where(action_type: UserAction::NEW_PRIVATE_MESSAGE).count).to eq(0)
# expect(other_user.user_actions.where(action_type: UserAction::GOT_PRIVATE_MESSAGE).count).to eq(0)
# expect(other_user.user_actions.where(action_type: UserAction::REPLY).count).to eq(1)
end
end
end
end
@ -81,6 +107,14 @@ describe TopicConverter do
expect(topic.reload.user.user_stat.topic_count).to eq(0)
expect(topic_user.reload.notification_level).to eq(TopicUser.notification_levels[:watching])
end
it "changes user_action type" do
UserActionCreator.enable
topic.convert_to_private_message(admin)
expect(author.user_actions.where(action_type: UserAction::NEW_TOPIC).count).to eq(0)
expect(author.user_actions.where(action_type: UserAction::NEW_PRIVATE_MESSAGE).count).to eq(1)
UserActionCreator.disable
end
end
context 'topic has replies' do