mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 19:01:52 +08:00
b58867b6e9
Includes support for flags, reviewable users and queued posts, with REST API backwards compatibility. Co-Authored-By: romanrizzi <romanalejandro@gmail.com> Co-Authored-By: jjaffeux <j.jaffeux@gmail.com>
60 lines
1.7 KiB
Ruby
60 lines
1.7 KiB
Ruby
require 'rails_helper'
|
|
|
|
describe UserSummary do
|
|
|
|
it "produces secure summaries" do
|
|
topic = create_post.topic
|
|
user = topic.user
|
|
_reply = create_post(user: topic.user, topic: topic)
|
|
|
|
summary = UserSummary.new(user, Guardian.new)
|
|
|
|
expect(summary.topics.length).to eq(1)
|
|
expect(summary.replies.length).to eq(1)
|
|
expect(summary.top_categories.length).to eq(1)
|
|
expect(summary.top_categories.first[:topic_count]).to eq(1)
|
|
expect(summary.top_categories.first[:post_count]).to eq(1)
|
|
|
|
topic.update_columns(deleted_at: Time.now)
|
|
|
|
expect(summary.topics.length).to eq(0)
|
|
expect(summary.replies.length).to eq(0)
|
|
expect(summary.top_categories.length).to eq(0)
|
|
|
|
topic.update_columns(deleted_at: nil, visible: false)
|
|
|
|
expect(summary.topics.length).to eq(0)
|
|
expect(summary.replies.length).to eq(0)
|
|
expect(summary.top_categories.length).to eq(0)
|
|
|
|
category = Fabricate(:category)
|
|
topic.update_columns(category_id: category.id, deleted_at: nil, visible: true)
|
|
|
|
category.set_permissions(staff: :full)
|
|
category.save
|
|
|
|
expect(summary.topics.length).to eq(0)
|
|
expect(summary.replies.length).to eq(0)
|
|
expect(summary.top_categories.length).to eq(0)
|
|
end
|
|
|
|
it "is robust enough to handle bad data" do
|
|
UserActionManager.enable
|
|
|
|
liked_post = create_post
|
|
user = Fabricate(:user)
|
|
PostActionCreator.like(user, liked_post)
|
|
|
|
users = UserSummary.new(user, Guardian.new).most_liked_users
|
|
|
|
expect(users.map(&:id)).to eq([liked_post.user_id])
|
|
|
|
# really we should not be corrupting stuff like this
|
|
# but in production dbs this can happens sometimes I guess
|
|
liked_post.user.delete
|
|
|
|
users = UserSummary.new(user, Guardian.new).most_liked_users
|
|
expect(users).to eq([])
|
|
end
|
|
end
|