DEV: Speed up topics_controller_spec.rb (#12395)
This commit is contained in:
parent
482bcc8726
commit
9c3d5f861d
|
@ -5,16 +5,27 @@ require 'rails_helper'
|
|||
|
||||
RSpec.describe TopicsController do
|
||||
fab!(:topic) { Fabricate(:topic) }
|
||||
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:moderator) { Fabricate(:moderator) }
|
||||
fab!(:admin) { Fabricate(:admin) }
|
||||
fab!(:trust_level_4) { Fabricate(:trust_level_4) }
|
||||
|
||||
fab!(:category) { Fabricate(:category) }
|
||||
fab!(:staff_category) {
|
||||
Fabricate(:category).tap { |staff_category|
|
||||
staff_category.set_permissions(staff: :full)
|
||||
staff_category.save!
|
||||
}
|
||||
}
|
||||
|
||||
fab!(:group_user) { Fabricate(:group_user) }
|
||||
|
||||
describe '#wordpress' do
|
||||
let!(:user) { sign_in(moderator) }
|
||||
let(:p1) { Fabricate(:post, user: moderator) }
|
||||
let(:topic) { p1.topic }
|
||||
let!(:p2) { Fabricate(:post, topic: topic, user: moderator) }
|
||||
fab!(:p1) { Fabricate(:post, user: moderator) }
|
||||
fab!(:topic) { p1.topic }
|
||||
fab!(:p2) { Fabricate(:post, topic: topic, user: moderator) }
|
||||
|
||||
it "returns the JSON in the format our wordpress plugin needs" do
|
||||
SiteSetting.external_system_avatars_enabled = false
|
||||
|
@ -63,9 +74,9 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe 'moving to a new topic' do
|
||||
let(:p1) { Fabricate(:post, user: user, post_number: 1) }
|
||||
fab!(:p1) { Fabricate(:post, user: user, post_number: 1) }
|
||||
let(:p2) { Fabricate(:post, user: user, post_number: 2, topic: p1.topic) }
|
||||
let!(:topic) { p1.topic }
|
||||
let(:topic) { p1.topic }
|
||||
|
||||
it "raises an error without post_ids" do
|
||||
sign_in(moderator)
|
||||
|
@ -99,7 +110,6 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
context 'success' do
|
||||
fab!(:category) { Fabricate(:category) }
|
||||
|
||||
before { sign_in(admin) }
|
||||
|
||||
|
@ -191,12 +201,11 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe "moving to a new topic as a group moderator" do
|
||||
fab!(:group_user) { Fabricate(:group_user) }
|
||||
fab!(:category) { Fabricate(:category, reviewable_by_group: group_user.group) }
|
||||
fab!(:topic) { Fabricate(:topic, category: category) }
|
||||
fab!(:p1) { Fabricate(:post, user: group_user.user, post_number: 1, topic: topic) }
|
||||
fab!(:p2) { Fabricate(:post, user: group_user.user, post_number: 2, topic: topic) }
|
||||
let(:user) { group_user.user }
|
||||
let!(:user) { group_user.user }
|
||||
|
||||
before do
|
||||
sign_in(user)
|
||||
|
@ -219,10 +228,6 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
it "does not allow posts to be moved to a private category" do
|
||||
staff_category = Fabricate(:category)
|
||||
staff_category.set_permissions(staff: :full)
|
||||
staff_category.save!
|
||||
|
||||
post "/t/#{topic.id}/move-posts.json", params: {
|
||||
title: 'Logan is a good movie',
|
||||
post_ids: [p2.id],
|
||||
|
@ -245,14 +250,13 @@ RSpec.describe TopicsController do
|
|||
|
||||
describe 'moving to an existing topic' do
|
||||
let!(:user) { sign_in(moderator) }
|
||||
let(:p1) { Fabricate(:post, user: user) }
|
||||
let(:topic) { p1.topic }
|
||||
fab!(:p1) { Fabricate(:post, user: moderator) }
|
||||
fab!(:topic) { p1.topic }
|
||||
fab!(:dest_topic) { Fabricate(:topic) }
|
||||
let(:p2) { Fabricate(:post, user: user, topic: topic) }
|
||||
fab!(:p2) { Fabricate(:post, user: moderator, topic: topic) }
|
||||
|
||||
context 'success' do
|
||||
it "returns success" do
|
||||
user
|
||||
post "/t/#{topic.id}/move-posts.json", params: {
|
||||
post_ids: [p2.id],
|
||||
destination_topic_id: dest_topic.id
|
||||
|
@ -290,7 +294,7 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
context 'failure' do
|
||||
let(:p2) { Fabricate(:post, user: user) }
|
||||
fab!(:p2) { Fabricate(:post, user: moderator) }
|
||||
it "returns JSON with a false success" do
|
||||
post "/t/#{topic.id}/move-posts.json", params: {
|
||||
post_ids: [p2.id]
|
||||
|
@ -305,14 +309,13 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe "moving to an existing topic as a group moderator" do
|
||||
fab!(:group_user) { Fabricate(:group_user) }
|
||||
fab!(:category) { Fabricate(:category, reviewable_by_group: group_user.group) }
|
||||
fab!(:topic) { Fabricate(:topic, category: category) }
|
||||
fab!(:p1) { Fabricate(:post, user: group_user.user, post_number: 1, topic: topic) }
|
||||
fab!(:p2) { Fabricate(:post, user: group_user.user, post_number: 2, topic: topic) }
|
||||
fab!(:dest_topic) { Fabricate(:topic) }
|
||||
|
||||
let(:user) { group_user.user }
|
||||
let!(:user) { group_user.user }
|
||||
|
||||
before do
|
||||
sign_in(user)
|
||||
|
@ -332,9 +335,6 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
it "does not allow posts to be moved to a private category" do
|
||||
staff_category = Fabricate(:category)
|
||||
staff_category.set_permissions(staff: :full)
|
||||
staff_category.save!
|
||||
dest_topic.update!(category: staff_category)
|
||||
|
||||
post "/t/#{topic.id}/move-posts.json", params: {
|
||||
|
@ -358,9 +358,9 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe 'moving to a new message' do
|
||||
let!(:message) { Fabricate(:private_message_topic) }
|
||||
let!(:p1) { Fabricate(:post, user: user, post_number: 1, topic: message) }
|
||||
let!(:p2) { Fabricate(:post, user: user, post_number: 2, topic: message) }
|
||||
fab!(:message) { Fabricate(:private_message_topic) }
|
||||
fab!(:p1) { Fabricate(:post, user: user, post_number: 1, topic: message) }
|
||||
fab!(:p2) { Fabricate(:post, user: user, post_number: 2, topic: message) }
|
||||
|
||||
it "raises an error without post_ids" do
|
||||
sign_in(moderator)
|
||||
|
@ -446,10 +446,10 @@ RSpec.describe TopicsController do
|
|||
describe 'moving to an existing message' do
|
||||
let!(:user) { sign_in(admin) }
|
||||
fab!(:evil_trout) { Fabricate(:evil_trout) }
|
||||
let(:message) { Fabricate(:private_message_topic) }
|
||||
let(:p2) { Fabricate(:post, user: evil_trout, post_number: 2, topic: message) }
|
||||
fab!(:message) { Fabricate(:private_message_topic) }
|
||||
fab!(:p2) { Fabricate(:post, user: evil_trout, post_number: 2, topic: message) }
|
||||
|
||||
let(:dest_message) do
|
||||
fab!(:dest_message) do
|
||||
Fabricate(:private_message_topic, user: trust_level_4, topic_allowed_users: [
|
||||
Fabricate.build(:topic_allowed_user, user: evil_trout)
|
||||
])
|
||||
|
@ -457,7 +457,6 @@ RSpec.describe TopicsController do
|
|||
|
||||
context 'success' do
|
||||
it "returns success" do
|
||||
user
|
||||
post "/t/#{message.id}/move-posts.json", params: {
|
||||
post_ids: [p2.id],
|
||||
destination_topic_id: dest_message.id,
|
||||
|
@ -496,8 +495,9 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe 'merging into another topic' do
|
||||
let(:p1) { Fabricate(:post, user: user) }
|
||||
let(:topic) { p1.topic }
|
||||
fab!(:p1) { Fabricate(:post, user: user) }
|
||||
fab!(:topic) { p1.topic }
|
||||
fab!(:dest_topic) { Fabricate(:topic) }
|
||||
|
||||
it "raises an error without destination_topic_id" do
|
||||
sign_in(moderator)
|
||||
|
@ -511,8 +511,6 @@ RSpec.describe TopicsController do
|
|||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
let(:dest_topic) { Fabricate(:topic) }
|
||||
|
||||
context 'moves all the posts to the destination topic' do
|
||||
it "returns success" do
|
||||
sign_in(moderator)
|
||||
|
@ -529,13 +527,12 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe "merging into another topic as a group moderator" do
|
||||
fab!(:group_user) { Fabricate(:group_user) }
|
||||
fab!(:category) { Fabricate(:category, reviewable_by_group: group_user.group) }
|
||||
fab!(:topic) { Fabricate(:topic, category: category) }
|
||||
fab!(:p1) { Fabricate(:post, post_number: 1, topic: topic) }
|
||||
fab!(:p2) { Fabricate(:post, post_number: 2, topic: topic) }
|
||||
fab!(:dest_topic) { Fabricate(:topic) }
|
||||
let(:user) { group_user.user }
|
||||
let!(:user) { group_user.user }
|
||||
|
||||
before do
|
||||
sign_in(user)
|
||||
|
@ -554,9 +551,6 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
it "does not allow posts to be moved to a private category" do
|
||||
staff_category = Fabricate(:category)
|
||||
staff_category.set_permissions(staff: :full)
|
||||
staff_category.save!
|
||||
dest_topic.update!(category: staff_category)
|
||||
|
||||
post "/t/#{topic.id}/merge-topic.json", params: {
|
||||
|
@ -578,9 +572,15 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe 'merging into another message' do
|
||||
let(:message) { Fabricate(:private_message_topic, user: user) }
|
||||
let!(:p1) { Fabricate(:post, topic: message, user: trust_level_4) }
|
||||
let!(:p2) { Fabricate(:post, topic: message, reply_to_post_number: p1.post_number, user: user) }
|
||||
fab!(:message) { Fabricate(:private_message_topic, user: user) }
|
||||
fab!(:p1) { Fabricate(:post, topic: message, user: trust_level_4) }
|
||||
fab!(:p2) { Fabricate(:post, topic: message, reply_to_post_number: p1.post_number, user: user) }
|
||||
|
||||
fab!(:dest_message) do
|
||||
Fabricate(:private_message_topic, user: trust_level_4, topic_allowed_users: [
|
||||
Fabricate.build(:topic_allowed_user, user: moderator)
|
||||
])
|
||||
end
|
||||
|
||||
it "raises an error without destination_topic_id" do
|
||||
sign_in(moderator)
|
||||
|
@ -599,12 +599,6 @@ RSpec.describe TopicsController do
|
|||
expect(response).to be_forbidden
|
||||
end
|
||||
|
||||
let(:dest_message) do
|
||||
Fabricate(:private_message_topic, user: trust_level_4, topic_allowed_users: [
|
||||
Fabricate.build(:topic_allowed_user, user: moderator)
|
||||
])
|
||||
end
|
||||
|
||||
context 'moves all the posts to the destination message' do
|
||||
it "returns success" do
|
||||
sign_in(moderator)
|
||||
|
@ -658,10 +652,10 @@ RSpec.describe TopicsController do
|
|||
|
||||
describe 'changing ownership' do
|
||||
let!(:editor) { sign_in(admin) }
|
||||
let(:topic) { Fabricate(:topic) }
|
||||
fab!(:topic) { Fabricate(:topic) }
|
||||
fab!(:user_a) { Fabricate(:user) }
|
||||
let(:p1) { Fabricate(:post, topic: topic) }
|
||||
let(:p2) { Fabricate(:post, topic: topic) }
|
||||
fab!(:p1) { Fabricate(:post, topic: topic) }
|
||||
fab!(:p2) { Fabricate(:post, topic: topic) }
|
||||
|
||||
it "raises an error with a parameter missing" do
|
||||
[
|
||||
|
@ -736,7 +730,7 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe '#change_timestamps' do
|
||||
let(:params) { { timestamp: Time.zone.now } }
|
||||
let!(:params) { { timestamp: Time.zone.now } }
|
||||
|
||||
it 'needs you to be logged in' do
|
||||
put "/t/1/change-timestamp.json", params: params
|
||||
|
@ -760,8 +754,8 @@ RSpec.describe TopicsController do
|
|||
sign_in(moderator)
|
||||
end
|
||||
|
||||
let(:old_timestamp) { Time.zone.now }
|
||||
let(:new_timestamp) { old_timestamp - 1.day }
|
||||
let!(:old_timestamp) { Time.zone.now }
|
||||
let!(:new_timestamp) { old_timestamp - 1.day }
|
||||
let!(:topic) { Fabricate(:topic, created_at: old_timestamp) }
|
||||
let!(:p1) { Fabricate(:post, topic: topic, created_at: old_timestamp) }
|
||||
let!(:p2) { Fabricate(:post, topic: topic, created_at: old_timestamp + 1.day) }
|
||||
|
@ -802,8 +796,9 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
context 'when logged in' do
|
||||
let(:topic) { Fabricate(:topic) }
|
||||
let(:pm) { Fabricate(:private_message_topic) }
|
||||
fab!(:topic) { Fabricate(:topic) }
|
||||
fab!(:pm) { Fabricate(:private_message_topic) }
|
||||
|
||||
before do
|
||||
sign_in(user)
|
||||
end
|
||||
|
@ -833,7 +828,7 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe 'when logged in as a moderator' do
|
||||
let(:topic) { Fabricate(:topic) }
|
||||
fab!(:topic) { Fabricate(:topic) }
|
||||
before do
|
||||
sign_in(moderator)
|
||||
end
|
||||
|
@ -882,10 +877,9 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe 'when logged in as a group member with reviewable status' do
|
||||
fab!(:group_user) { Fabricate(:group_user) }
|
||||
fab!(:category) { Fabricate(:category, reviewable_by_group: group_user.group) }
|
||||
fab!(:topic) { Fabricate(:topic, category: category) }
|
||||
let(:user) { group_user.user }
|
||||
let!(:user) { group_user.user }
|
||||
|
||||
before do
|
||||
sign_in(user)
|
||||
|
@ -1097,7 +1091,7 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe 'when logged in' do
|
||||
let(:topic) { Fabricate(:topic, user: user, deleted_at: Time.now, deleted_by: moderator) }
|
||||
let!(:topic) { Fabricate(:topic, user: user, deleted_at: Time.now, deleted_by: moderator) }
|
||||
let!(:post) { Fabricate(:post, user: user, topic: topic, post_number: 1, deleted_at: Time.now, deleted_by: moderator) }
|
||||
|
||||
describe 'without access' do
|
||||
|
@ -1132,8 +1126,8 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe 'when logged in' do
|
||||
let(:topic) { Fabricate(:topic, user: user, created_at: 48.hours.ago) }
|
||||
let!(:post) { Fabricate(:post, topic: topic, user: user, post_number: 1) }
|
||||
fab!(:topic) { Fabricate(:topic, user: user, created_at: 48.hours.ago) }
|
||||
fab!(:post) { Fabricate(:post, topic: topic, user: user, post_number: 1) }
|
||||
|
||||
describe 'without access' do
|
||||
it "raises an exception when the user doesn't have permission to delete the topic" do
|
||||
|
@ -1159,8 +1153,8 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe '#id_for_slug' do
|
||||
let(:topic) { Fabricate(:post).topic }
|
||||
let(:pm) { Fabricate(:private_message_topic) }
|
||||
fab!(:topic) { Fabricate(:post).topic }
|
||||
fab!(:pm) { Fabricate(:private_message_topic) }
|
||||
|
||||
it "returns JSON for the slug" do
|
||||
get "/t/id_for/#{topic.slug}.json"
|
||||
|
@ -1184,7 +1178,7 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe 'when logged in' do
|
||||
let(:topic) { Fabricate(:topic, user: user) }
|
||||
fab!(:topic) { Fabricate(:topic, user: user) }
|
||||
|
||||
before do
|
||||
Fabricate(:post, topic: topic)
|
||||
|
@ -1193,7 +1187,6 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
it 'can not change category to a disallowed category' do
|
||||
category = Fabricate(:category)
|
||||
category.set_permissions(staff: :full)
|
||||
category.save!
|
||||
|
||||
|
@ -1204,7 +1197,6 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
it 'can not move to a category that requires topic approval' do
|
||||
category = Fabricate(:category)
|
||||
category.custom_fields[Category::REQUIRE_TOPIC_APPROVAL] = true
|
||||
category.save!
|
||||
|
||||
|
@ -1220,8 +1212,6 @@ RSpec.describe TopicsController do
|
|||
fab!(:shared_draft) { Fabricate(:shared_draft, topic: topic, category: Fabricate(:category)) }
|
||||
|
||||
it 'changes destination category' do
|
||||
category = Fabricate(:category)
|
||||
|
||||
put "/t/#{topic.id}.json", params: { category_id: category.id }
|
||||
|
||||
expect(response.status).to eq(403)
|
||||
|
@ -1260,7 +1250,7 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
it "can update a topic to an uncategorized topic" do
|
||||
topic.update!(category: Fabricate(:category))
|
||||
topic.update!(category: category)
|
||||
|
||||
put "/t/#{topic.slug}/#{topic.id}.json", params: {
|
||||
category_id: ""
|
||||
|
@ -1379,7 +1369,6 @@ RSpec.describe TopicsController do
|
|||
|
||||
it "can change the category and create a new tag" do
|
||||
SiteSetting.min_trust_to_create_tag = 0
|
||||
category = Fabricate(:category)
|
||||
expect do
|
||||
put "/t/#{topic.slug}/#{topic.id}.json", params: {
|
||||
tags: ["newtag"],
|
||||
|
@ -1463,12 +1452,11 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
context 'updating to a category with restricted tags' do
|
||||
fab!(:category) { Fabricate(:category) }
|
||||
fab!(:restricted_category) { Fabricate(:category) }
|
||||
fab!(:tag1) { Fabricate(:tag) }
|
||||
fab!(:tag2) { Fabricate(:tag) }
|
||||
let(:tag3) { Fabricate(:tag) }
|
||||
let!(:tag_group_1) { Fabricate(:tag_group, tag_names: [tag1.name]) }
|
||||
fab!(:tag3) { Fabricate(:tag) }
|
||||
fab!(:tag_group_1) { Fabricate(:tag_group, tag_names: [tag1.name]) }
|
||||
fab!(:tag_group_2) { Fabricate(:tag_group) }
|
||||
|
||||
before do
|
||||
|
@ -1597,8 +1585,6 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
it "can add a category to an uncategorized topic" do
|
||||
category = Fabricate(:category)
|
||||
|
||||
put "/t/#{topic.slug}/#{topic.id}.json", params: {
|
||||
category_id: category.id
|
||||
}
|
||||
|
@ -1612,8 +1598,8 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe '#show' do
|
||||
let(:private_topic) { Fabricate(:private_message_topic) }
|
||||
let(:topic) { Fabricate(:post).topic }
|
||||
fab!(:private_topic) { Fabricate(:private_message_topic) }
|
||||
let!(:topic) { Fabricate(:post).topic }
|
||||
|
||||
let!(:p1) { Fabricate(:post, user: topic.user) }
|
||||
let!(:p2) { Fabricate(:post, user: topic.user) }
|
||||
|
@ -1631,14 +1617,14 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe 'when topic is allowed to a group' do
|
||||
let(:group) { Fabricate(:group, public_admission: true) }
|
||||
let(:category) do
|
||||
fab!(:group) { Fabricate(:group, public_admission: true) }
|
||||
fab!(:category) do
|
||||
Fabricate(:category_with_definition).tap do |category|
|
||||
category.set_permissions(group => :full)
|
||||
category.save!
|
||||
end
|
||||
end
|
||||
let(:topic) { Fabricate(:topic, category: category) }
|
||||
fab!(:topic) { Fabricate(:topic, category: category) }
|
||||
|
||||
before do
|
||||
SiteSetting.detailed_404 = true
|
||||
|
@ -1759,9 +1745,9 @@ RSpec.describe TopicsController do
|
|||
|
||||
context 'permission errors' do
|
||||
fab!(:allowed_user) { Fabricate(:user) }
|
||||
let(:allowed_group) { Fabricate(:group) }
|
||||
let(:accessible_group) { Fabricate(:group, public_admission: true) }
|
||||
let(:secure_category) do
|
||||
fab!(:allowed_group) { Fabricate(:group) }
|
||||
fab!(:accessible_group) { Fabricate(:group, public_admission: true) }
|
||||
fab!(:secure_category) do
|
||||
c = Fabricate(:category)
|
||||
c.permissions = [[allowed_group, :full]]
|
||||
c.save
|
||||
|
@ -1769,26 +1755,26 @@ RSpec.describe TopicsController do
|
|||
allowed_user.save
|
||||
c
|
||||
end
|
||||
let(:accessible_category) do
|
||||
fab!(:accessible_category) do
|
||||
Fabricate(:category).tap do |c|
|
||||
c.set_permissions(accessible_group => :full)
|
||||
c.save!
|
||||
end
|
||||
end
|
||||
let(:normal_topic) { Fabricate(:topic) }
|
||||
let(:secure_topic) { Fabricate(:topic, category: secure_category) }
|
||||
let(:private_topic) { Fabricate(:private_message_topic, user: allowed_user) }
|
||||
fab!(:normal_topic) { Fabricate(:topic) }
|
||||
fab!(:secure_topic) { Fabricate(:topic, category: secure_category) }
|
||||
fab!(:private_topic) { Fabricate(:private_message_topic, user: allowed_user) }
|
||||
let(:deleted_topic) { Fabricate(:deleted_topic) }
|
||||
let(:deleted_secure_topic) { Fabricate(:topic, category: secure_category, deleted_at: 1.day.ago) }
|
||||
let(:deleted_private_topic) { Fabricate(:private_message_topic, user: allowed_user, deleted_at: 1.day.ago) }
|
||||
let(:nonexist_topic_id) { Topic.last.id + 10000 }
|
||||
let(:secure_accessible_topic) { Fabricate(:topic, category: accessible_category) }
|
||||
let!(:nonexist_topic_id) { Topic.last.id + 10000 }
|
||||
fab!(:secure_accessible_topic) { Fabricate(:topic, category: accessible_category) }
|
||||
|
||||
shared_examples "various scenarios" do |expected|
|
||||
expected.each do |key, value|
|
||||
it "returns #{value} for #{key}" do
|
||||
slug = key == :nonexist ? "garbage-slug" : eval(key.to_s).slug
|
||||
topic_id = key == :nonexist ? nonexist_topic_id : eval(key.to_s).id
|
||||
slug = key == :nonexist ? "garbage-slug" : send(key.to_s).slug
|
||||
topic_id = key == :nonexist ? nonexist_topic_id : send(key.to_s).id
|
||||
get "/t/#{slug}/#{topic_id}.json"
|
||||
expect(response.status).to eq(value)
|
||||
end
|
||||
|
@ -2143,16 +2129,16 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe '#show filters' do
|
||||
let(:post) { Fabricate(:post) }
|
||||
let(:topic) { post.topic }
|
||||
fab!(:post) { Fabricate(:post) }
|
||||
fab!(:topic) { post.topic }
|
||||
fab!(:post2) { Fabricate(:post, topic: topic) }
|
||||
|
||||
describe 'filter by replies to a post' do
|
||||
let!(:post2) { Fabricate(:post, topic: topic) }
|
||||
let!(:post3) { Fabricate(:post, topic: topic, reply_to_post_number: post2.post_number) }
|
||||
let!(:post4) { Fabricate(:post, topic: topic, reply_to_post_number: post2.post_number) }
|
||||
let!(:post5) { Fabricate(:post, topic: topic) }
|
||||
let!(:quote_reply) { Fabricate(:basic_reply, user: user, topic: topic) }
|
||||
let!(:post_reply) { PostReply.create(post_id: post2.id, reply_post_id: quote_reply.id) }
|
||||
fab!(:post3) { Fabricate(:post, topic: topic, reply_to_post_number: post2.post_number) }
|
||||
fab!(:post4) { Fabricate(:post, topic: topic, reply_to_post_number: post2.post_number) }
|
||||
fab!(:post5) { Fabricate(:post, topic: topic) }
|
||||
fab!(:quote_reply) { Fabricate(:basic_reply, user: user, topic: topic) }
|
||||
fab!(:post_reply) { PostReply.create(post_id: post2.id, reply_post_id: quote_reply.id) }
|
||||
|
||||
it 'should return the right posts' do
|
||||
get "/t/#{topic.id}.json", params: {
|
||||
|
@ -2172,11 +2158,10 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe 'filter upwards by post id' do
|
||||
let!(:post2) { Fabricate(:post, topic: topic) }
|
||||
let!(:post3) { Fabricate(:post, topic: topic) }
|
||||
let!(:post4) { Fabricate(:post, topic: topic, reply_to_post_number: post3.post_number) }
|
||||
let!(:post5) { Fabricate(:post, topic: topic, reply_to_post_number: post4.post_number) }
|
||||
let!(:post6) { Fabricate(:post, topic: topic) }
|
||||
fab!(:post3) { Fabricate(:post, topic: topic) }
|
||||
fab!(:post4) { Fabricate(:post, topic: topic, reply_to_post_number: post3.post_number) }
|
||||
fab!(:post5) { Fabricate(:post, topic: topic, reply_to_post_number: post4.post_number) }
|
||||
fab!(:post6) { Fabricate(:post, topic: topic) }
|
||||
|
||||
it 'should return the right posts' do
|
||||
get "/t/#{topic.id}.json", params: {
|
||||
|
@ -2392,8 +2377,8 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe '#post_ids' do
|
||||
let(:post) { Fabricate(:post) }
|
||||
let(:topic) { post.topic }
|
||||
fab!(:post) { Fabricate(:post) }
|
||||
fab!(:topic) { post.topic }
|
||||
|
||||
before do
|
||||
TopicView.stubs(:chunk_size).returns(1)
|
||||
|
@ -2416,9 +2401,9 @@ RSpec.describe TopicsController do
|
|||
|
||||
describe 'filtering by post number with filters' do
|
||||
describe 'username filters' do
|
||||
let(:post) { Fabricate(:post, user: user) }
|
||||
let!(:post2) { Fabricate(:post, topic: topic, user: user) }
|
||||
let!(:post3) { Fabricate(:post, topic: topic) }
|
||||
fab!(:post) { Fabricate(:post, user: user) }
|
||||
fab!(:post2) { Fabricate(:post, topic: topic, user: user) }
|
||||
fab!(:post3) { Fabricate(:post, topic: topic) }
|
||||
|
||||
it 'should return the right posts' do
|
||||
get "/t/#{topic.id}/post_ids.json", params: {
|
||||
|
@ -2435,8 +2420,8 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe 'summary filter' do
|
||||
let!(:post2) { Fabricate(:post, topic: topic, percent_rank: 0.2) }
|
||||
let!(:post3) { Fabricate(:post, topic: topic) }
|
||||
fab!(:post2) { Fabricate(:post, topic: topic, percent_rank: 0.2) }
|
||||
fab!(:post3) { Fabricate(:post, topic: topic) }
|
||||
|
||||
it 'should return the right posts' do
|
||||
get "/t/#{topic.id}/post_ids.json", params: {
|
||||
|
@ -2455,8 +2440,8 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe '#posts' do
|
||||
let(:post) { Fabricate(:post) }
|
||||
let(:topic) { post.topic }
|
||||
fab!(:post) { Fabricate(:post) }
|
||||
fab!(:topic) { post.topic }
|
||||
|
||||
after do
|
||||
Discourse.redis.flushdb
|
||||
|
@ -2484,8 +2469,8 @@ RSpec.describe TopicsController do
|
|||
|
||||
describe 'filtering by post number with filters' do
|
||||
describe 'username filters' do
|
||||
let!(:post2) { Fabricate(:post, topic: topic, user: user) }
|
||||
let!(:post3) { Fabricate(:post, topic: topic) }
|
||||
fab!(:post2) { Fabricate(:post, topic: topic, user: user) }
|
||||
fab!(:post3) { Fabricate(:post, topic: topic) }
|
||||
|
||||
it 'should return the right posts' do
|
||||
TopicView.stubs(:chunk_size).returns(2)
|
||||
|
@ -2505,8 +2490,8 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe 'summary filter' do
|
||||
let!(:post2) { Fabricate(:post, topic: topic, percent_rank: 0.2) }
|
||||
let!(:post3) { Fabricate(:post, topic: topic) }
|
||||
fab!(:post2) { Fabricate(:post, topic: topic, percent_rank: 0.2) }
|
||||
fab!(:post3) { Fabricate(:post, topic: topic) }
|
||||
|
||||
it 'should return the right posts' do
|
||||
TopicView.stubs(:chunk_size).returns(2)
|
||||
|
@ -2528,7 +2513,7 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe '#feed' do
|
||||
let(:topic) { Fabricate(:post).topic }
|
||||
fab!(:topic) { Fabricate(:post).topic }
|
||||
|
||||
it 'renders rss of the topic' do
|
||||
get "/t/foo/#{topic.id}.rss"
|
||||
|
@ -2558,7 +2543,7 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe '#invite_group' do
|
||||
let(:admins) { Group[:admins] }
|
||||
let!(:admins) { Group[:admins] }
|
||||
|
||||
before do
|
||||
sign_in(admin)
|
||||
|
@ -2645,9 +2630,11 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe "when logged in" do
|
||||
fab!(:tag) { Fabricate(:tag) }
|
||||
|
||||
before { sign_in(user) }
|
||||
let(:operation) { { type: 'change_category', category_id: '1' } }
|
||||
let(:topic_ids) { [1, 2, 3] }
|
||||
let!(:operation) { { type: 'change_category', category_id: '1' } }
|
||||
let!(:topic_ids) { [1, 2, 3] }
|
||||
|
||||
it "requires a list of topic_ids or filter" do
|
||||
put "/topics/bulk.json", params: { operation: operation }
|
||||
|
@ -2665,7 +2652,6 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
it "can mark sub-categories unread" do
|
||||
category = Fabricate(:category)
|
||||
sub = Fabricate(:category, parent_category_id: category.id)
|
||||
|
||||
topic.update!(category_id: sub.id)
|
||||
|
@ -2685,7 +2671,6 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
it "can mark tag topics unread" do
|
||||
tag = Fabricate(:tag)
|
||||
TopicTag.create!(
|
||||
topic_id: topic.id,
|
||||
tag_id: tag.id
|
||||
|
@ -2725,7 +2710,6 @@ RSpec.describe TopicsController do
|
|||
|
||||
it "respects the tracked parameter" do
|
||||
# untracked topic
|
||||
category = Fabricate(:category)
|
||||
CategoryUser.set_notification_level_for_category(user,
|
||||
NotificationLevels.all[:regular],
|
||||
category.id)
|
||||
|
@ -2881,7 +2865,6 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
context 'category' do
|
||||
fab!(:category) { Fabricate(:category) }
|
||||
fab!(:subcategory) { Fabricate(:category, parent_category_id: category.id) }
|
||||
fab!(:category_topic) { Fabricate(:topic, category: category) }
|
||||
fab!(:subcategory_topic) { Fabricate(:topic, category: subcategory) }
|
||||
|
@ -2924,7 +2907,6 @@ RSpec.describe TopicsController do
|
|||
context 'tag and category' do
|
||||
fab!(:tag) { Fabricate(:tag) }
|
||||
fab!(:tag_topic) { Fabricate(:topic) }
|
||||
fab!(:category) { Fabricate(:category) }
|
||||
fab!(:tag_and_category_topic) { Fabricate(:topic, category: category) }
|
||||
fab!(:topic_tag) { Fabricate(:topic_tag, topic: tag_topic, tag: tag) }
|
||||
fab!(:topic_tag2) { Fabricate(:topic_tag, topic: tag_and_category_topic, tag: tag) }
|
||||
|
@ -2991,8 +2973,8 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe 'converting public topic to private message' do
|
||||
let(:topic) { Fabricate(:topic, user: user) }
|
||||
let!(:post) { Fabricate(:post, topic: topic) }
|
||||
fab!(:topic) { Fabricate(:topic, user: user) }
|
||||
fab!(:post) { Fabricate(:post, topic: topic) }
|
||||
|
||||
it "raises an error when the user doesn't have permission to convert topic" do
|
||||
sign_in(user)
|
||||
|
@ -3017,8 +2999,8 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe 'converting private message to public topic' do
|
||||
let(:topic) { Fabricate(:private_message_topic, user: user) }
|
||||
let!(:post) { Fabricate(:post, topic: topic) }
|
||||
fab!(:topic) { Fabricate(:private_message_topic, user: user) }
|
||||
fab!(:post) { Fabricate(:post, topic: topic) }
|
||||
|
||||
it "raises an error when the user doesn't have permission to convert topic" do
|
||||
sign_in(user)
|
||||
|
@ -3027,8 +3009,6 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
context "success" do
|
||||
fab!(:category) { Fabricate(:category) }
|
||||
|
||||
it "returns success" do
|
||||
sign_in(admin)
|
||||
put "/t/#{topic.id}/convert-topic/public.json?category_id=#{category.id}"
|
||||
|
@ -3047,7 +3027,7 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe '#timings' do
|
||||
let(:post_1) { Fabricate(:post, topic: topic) }
|
||||
fab!(:post_1) { Fabricate(:post, topic: topic) }
|
||||
|
||||
it 'should record the timing' do
|
||||
sign_in(user)
|
||||
|
@ -3322,7 +3302,7 @@ RSpec.describe TopicsController do
|
|||
context 'auto-disable slow mode' do
|
||||
before { sign_in(admin) }
|
||||
|
||||
let(:timestamp) { 1.week.from_now.to_formatted_s(:iso8601) }
|
||||
let!(:timestamp) { 1.week.from_now.to_formatted_s(:iso8601) }
|
||||
|
||||
it 'sets a topic timer to clear the slow mode automatically' do
|
||||
put "/t/#{topic.id}/slow_mode.json", params: {
|
||||
|
@ -3385,7 +3365,7 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe 'as a valid user' do
|
||||
let(:topic) { Fabricate(:topic, user: user) }
|
||||
fab!(:topic) { Fabricate(:topic, user: user) }
|
||||
|
||||
it 'should return the right response' do
|
||||
user.update!(trust_level: TrustLevel[2])
|
||||
|
@ -3401,14 +3381,14 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe 'when user is a group manager' do
|
||||
let(:group) { Fabricate(:group).tap { |g| g.add_owner(user) } }
|
||||
let(:private_category) { Fabricate(:private_category, group: group) }
|
||||
fab!(:group) { Fabricate(:group).tap { |g| g.add_owner(user) } }
|
||||
fab!(:private_category) { Fabricate(:private_category, group: group) }
|
||||
|
||||
let(:group_private_topic) do
|
||||
fab!(:group_private_topic) do
|
||||
Fabricate(:topic, category: private_category, user: user)
|
||||
end
|
||||
|
||||
let(:recipient) { 'jake@adventuretime.ooo' }
|
||||
let!(:recipient) { 'jake@adventuretime.ooo' }
|
||||
|
||||
it "should attach group to the invite" do
|
||||
post "/t/#{group_private_topic.id}/invite.json", params: {
|
||||
|
@ -3470,9 +3450,9 @@ RSpec.describe TopicsController do
|
|||
|
||||
describe "when PM has reached maximum allowed numbers of recipients" do
|
||||
fab!(:user2) { Fabricate(:user) }
|
||||
let(:pm) { Fabricate(:private_message_topic, user: user) }
|
||||
fab!(:pm) { Fabricate(:private_message_topic, user: user) }
|
||||
|
||||
let(:moderator_pm) { Fabricate(:private_message_topic, user: moderator) }
|
||||
fab!(:moderator_pm) { Fabricate(:private_message_topic, user: moderator) }
|
||||
|
||||
before do
|
||||
SiteSetting.max_allowed_message_recipients = 2
|
||||
|
@ -3499,7 +3479,7 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe 'when user does not have permission to invite to the topic' do
|
||||
let(:topic) { Fabricate(:private_message_topic) }
|
||||
fab!(:topic) { Fabricate(:private_message_topic) }
|
||||
|
||||
it "should return the right response" do
|
||||
post "/t/#{topic.id}/invite.json", params: {
|
||||
|
@ -3512,7 +3492,7 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe "when inviting a group to a topic" do
|
||||
let(:group) { Fabricate(:group) }
|
||||
fab!(:group) { Fabricate(:group) }
|
||||
|
||||
before do
|
||||
sign_in(admin)
|
||||
|
@ -3535,8 +3515,8 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe 'invite_group' do
|
||||
let(:admins) { Group[:admins] }
|
||||
let(:pm) { Fabricate(:private_message_topic) }
|
||||
let!(:admins) { Group[:admins] }
|
||||
fab!(:pm) { Fabricate(:private_message_topic) }
|
||||
|
||||
def invite_group(topic, expected_status)
|
||||
post "/t/#{topic.id}/invite-group.json", params: { group: admins.name }
|
||||
|
@ -3591,10 +3571,10 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
context "when PM has reached maximum allowed numbers of recipients" do
|
||||
let(:group) { Fabricate(:group, messageable_level: 99) }
|
||||
let(:pm) { Fabricate(:private_message_topic, user: user) }
|
||||
fab!(:group) { Fabricate(:group, messageable_level: 99) }
|
||||
fab!(:pm) { Fabricate(:private_message_topic, user: user) }
|
||||
|
||||
let(:moderator_pm) { Fabricate(:private_message_topic, user: moderator) }
|
||||
fab!(:moderator_pm) { Fabricate(:private_message_topic, user: moderator) }
|
||||
|
||||
before do
|
||||
SiteSetting.max_allowed_message_recipients = 2
|
||||
|
@ -3622,16 +3602,15 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe 'shared drafts' do
|
||||
let(:shared_drafts_category) { Fabricate(:category) }
|
||||
fab!(:shared_drafts_category) { Fabricate(:category) }
|
||||
|
||||
before do
|
||||
SiteSetting.shared_drafts_category = shared_drafts_category.id
|
||||
end
|
||||
|
||||
describe "#update_shared_draft" do
|
||||
let(:other_cat) { Fabricate(:category) }
|
||||
let(:category) { Fabricate(:category) }
|
||||
let(:topic) { Fabricate(:topic, category: shared_drafts_category, visible: false) }
|
||||
fab!(:other_cat) { Fabricate(:category) }
|
||||
fab!(:topic) { Fabricate(:topic, category: shared_drafts_category, visible: false) }
|
||||
|
||||
context "anonymous" do
|
||||
it "doesn't allow staff to update the shared draft" do
|
||||
|
@ -3646,7 +3625,7 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
context "with a shared draft" do
|
||||
let!(:shared_draft) { Fabricate(:shared_draft, topic: topic, category: category) }
|
||||
fab!(:shared_draft) { Fabricate(:shared_draft, topic: topic, category: category) }
|
||||
it "allows staff to update the category id" do
|
||||
put "/t/#{topic.id}/shared-draft.json", params: { category_id: other_cat.id }
|
||||
expect(response.status).to eq(200)
|
||||
|
@ -3667,9 +3646,8 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe "#publish" do
|
||||
let(:category) { Fabricate(:category) }
|
||||
let(:topic) { Fabricate(:topic, category: shared_drafts_category, visible: false) }
|
||||
let!(:post) { Fabricate(:post, topic: topic) }
|
||||
fab!(:topic) { Fabricate(:topic, category: shared_drafts_category, visible: false) }
|
||||
fab!(:post) { Fabricate(:post, topic: topic) }
|
||||
|
||||
it "fails for anonymous users" do
|
||||
put "/t/#{topic.id}/publish.json", params: { destination_category_id: category.id }
|
||||
|
@ -3769,7 +3747,7 @@ RSpec.describe TopicsController do
|
|||
|
||||
context "canonical_url" do
|
||||
fab!(:topic_embed) { Fabricate(:topic_embed, embed_url: "https://markvanlan.com") }
|
||||
let(:user_agent) { "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" }
|
||||
let!(:user_agent) { "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" }
|
||||
|
||||
it "set to topic.url when embed_set_canonical_url is false" do
|
||||
get topic_embed.topic.url, env: { "HTTP_USER_AGENT" => user_agent }
|
||||
|
@ -3797,7 +3775,7 @@ RSpec.describe TopicsController do
|
|||
|
||||
describe "#reset_bump_date" do
|
||||
context "errors" do
|
||||
let(:topic) { Fabricate(:topic) }
|
||||
fab!(:topic) { Fabricate(:topic) }
|
||||
|
||||
it "needs you to be logged in" do
|
||||
put "/t/#{topic.id}/reset-bump-date.json"
|
||||
|
|
Loading…
Reference in New Issue