2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-30 23:06:56 -05:00
|
|
|
RSpec.describe ListController do
|
2020-04-20 01:08:24 -05:00
|
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
fab!(:topic) { Fabricate(:topic, user: user) }
|
2021-04-19 23:55:31 -05:00
|
|
|
fab!(:group) { Fabricate(:group, name: "AwesomeGroup") }
|
2020-04-20 01:08:24 -05:00
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
2018-06-03 22:09:59 -05:00
|
|
|
|
|
|
|
before do
|
2018-12-12 04:46:14 -06:00
|
|
|
admin # to skip welcome wizard at home page `/`
|
2018-06-03 22:09:59 -05:00
|
|
|
SiteSetting.top_menu = "latest|new|unread|categories"
|
|
|
|
end
|
2017-08-30 23:06:56 -05:00
|
|
|
|
2017-10-01 21:45:54 -05:00
|
|
|
describe "#index" do
|
2018-08-14 02:01:04 -05:00
|
|
|
it "does not return a 500 for invalid input" do
|
|
|
|
get "/latest?min_posts=bob"
|
|
|
|
expect(response.status).to eq(400)
|
|
|
|
|
|
|
|
get "/latest?max_posts=bob"
|
|
|
|
expect(response.status).to eq(400)
|
2018-08-14 18:53:28 -05:00
|
|
|
|
2018-09-02 23:45:32 -05:00
|
|
|
get "/latest?max_posts=1111111111111111111111111111111111111111"
|
|
|
|
expect(response.status).to eq(400)
|
|
|
|
|
|
|
|
get "/latest?page=-1"
|
|
|
|
expect(response.status).to eq(400)
|
|
|
|
|
|
|
|
get "/latest?page=2147483648"
|
|
|
|
expect(response.status).to eq(400)
|
|
|
|
|
|
|
|
get "/latest?page=1111111111111111111111111111111111111111"
|
|
|
|
expect(response.status).to eq(400)
|
2023-01-16 11:20:19 -06:00
|
|
|
|
|
|
|
get "/latest?tags[1]=hello"
|
|
|
|
expect(response.status).to eq(400)
|
2018-08-14 02:01:04 -05:00
|
|
|
end
|
|
|
|
|
2018-08-14 20:31:42 -05:00
|
|
|
it "returns 200 for legit requests" do
|
2019-11-18 00:58:35 -06:00
|
|
|
get "/latest.json?no_definitions=true&no_subcategories=false&page=1&_=1534296100767"
|
2018-08-14 23:56:24 -05:00
|
|
|
expect(response.status).to eq(200)
|
2018-08-16 03:36:02 -05:00
|
|
|
|
|
|
|
get "/latest.json?max_posts=12"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
get "/latest.json?min_posts=0"
|
|
|
|
expect(response.status).to eq(200)
|
2018-08-14 20:31:42 -05:00
|
|
|
|
2018-09-05 13:43:05 -05:00
|
|
|
get "/latest?page=0"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
2018-09-02 23:45:32 -05:00
|
|
|
get "/latest?page=1"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
get "/latest.json?page=2147483647"
|
2018-06-07 03:11:09 -05:00
|
|
|
expect(response.status).to eq(200)
|
2020-09-10 09:49:11 -05:00
|
|
|
|
|
|
|
get "/latest?search="
|
|
|
|
expect(response.status).to eq(200)
|
2021-11-03 10:56:33 -05:00
|
|
|
|
|
|
|
get "/latest.json?topic_ids%5B%5D=14583&topic_ids%5B%5D=14584"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
get "/latest.json?topic_ids=14583%2C14584"
|
|
|
|
expect(response.status).to eq(200)
|
2023-01-16 11:20:19 -06:00
|
|
|
|
|
|
|
get "/latest?tags[]=hello"
|
|
|
|
expect(response.status).to eq(200)
|
2017-10-01 21:45:54 -05:00
|
|
|
end
|
2018-06-03 22:09:59 -05:00
|
|
|
|
|
|
|
(Discourse.anonymous_filters - [:categories]).each do |filter|
|
2023-03-14 05:42:11 -05:00
|
|
|
context "with #{filter}" do
|
2018-06-03 22:09:59 -05:00
|
|
|
it "succeeds" do
|
|
|
|
get "/#{filter}"
|
2018-06-07 03:11:09 -05:00
|
|
|
expect(response.status).to eq(200)
|
2018-06-03 22:09:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "allows users to filter on a set of topic ids" do
|
|
|
|
p = create_post
|
|
|
|
|
|
|
|
get "/latest.json", params: { topic_ids: "#{p.topic_id}" }
|
2018-06-07 03:11:09 -05:00
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 10:04:12 -05:00
|
|
|
parsed = response.parsed_body
|
2018-06-03 22:09:59 -05:00
|
|
|
expect(parsed["topic_list"]["topics"].length).to eq(1)
|
|
|
|
end
|
2018-12-12 04:46:14 -06:00
|
|
|
|
|
|
|
it "shows correct title if topic list is set for homepage" do
|
2020-04-20 01:08:24 -05:00
|
|
|
get "/latest"
|
2018-12-12 04:46:14 -06:00
|
|
|
|
|
|
|
expect(response.body).to have_tag "title", text: "Discourse"
|
|
|
|
|
|
|
|
SiteSetting.short_site_description = "Best community"
|
2020-04-20 01:08:24 -05:00
|
|
|
get "/latest"
|
2018-12-12 04:46:14 -06:00
|
|
|
|
|
|
|
expect(response.body).to have_tag "title", text: "Discourse - Best community"
|
|
|
|
end
|
2022-12-05 10:00:32 -06:00
|
|
|
|
|
|
|
it "returns structured data" do
|
|
|
|
get "/latest"
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
topic_list = Nokogiri.HTML5(response.body).css(".topic-list")
|
|
|
|
first_item = topic_list.css('[itemprop="itemListElement"]')
|
|
|
|
expect(first_item.css('[itemprop="position"]')[0]["content"]).to eq("1")
|
|
|
|
expect(first_item.css('[itemprop="url"]')[0]["href"]).to eq(topic.url)
|
|
|
|
end
|
2022-12-21 15:30:29 -06:00
|
|
|
|
2023-04-05 17:58:35 -05:00
|
|
|
it "does not result in N+1 queries when topics have tags and tagging_enabled site setting is enabled" do
|
|
|
|
SiteSetting.tagging_enabled = true
|
|
|
|
tag = Fabricate(:tag)
|
|
|
|
topic.tags << tag
|
|
|
|
|
|
|
|
# warm up
|
|
|
|
get "/latest.json"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
initial_sql_queries_count =
|
|
|
|
track_sql_queries do
|
|
|
|
get "/latest.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
body = response.parsed_body
|
|
|
|
|
|
|
|
expect(body["topic_list"]["topics"].map { |t| t["id"] }).to contain_exactly(topic.id)
|
|
|
|
expect(body["topic_list"]["topics"][0]["tags"]).to contain_exactly(tag.name)
|
|
|
|
end.count
|
|
|
|
|
|
|
|
tag2 = Fabricate(:tag)
|
|
|
|
topic2 = Fabricate(:topic, tags: [tag2])
|
|
|
|
|
|
|
|
new_sql_queries_count =
|
|
|
|
track_sql_queries do
|
|
|
|
get "/latest.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
body = response.parsed_body
|
|
|
|
|
|
|
|
expect(body["topic_list"]["topics"].map { |t| t["id"] }).to contain_exactly(
|
|
|
|
topic.id,
|
|
|
|
topic2.id,
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(body["topic_list"]["topics"][0]["tags"]).to contain_exactly(tag2.name)
|
|
|
|
expect(body["topic_list"]["topics"][1]["tags"]).to contain_exactly(tag.name)
|
|
|
|
end.count
|
|
|
|
|
|
|
|
expect(new_sql_queries_count).to eq(initial_sql_queries_count)
|
|
|
|
end
|
|
|
|
|
2022-12-21 15:30:29 -06:00
|
|
|
it "does not N+1 queries when topic featured users have different primary groups" do
|
|
|
|
user.update!(primary_group: group)
|
|
|
|
|
|
|
|
# warm up
|
|
|
|
get "/latest.json"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
initial_sql_queries_count =
|
|
|
|
track_sql_queries do
|
|
|
|
get "/latest.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
body = response.parsed_body
|
|
|
|
|
|
|
|
expect(body["topic_list"]["topics"].map { |t| t["id"] }).to contain_exactly(topic.id)
|
|
|
|
expect(
|
|
|
|
body["topic_list"]["topics"][0]["posters"].map { |p| p["user_id"] },
|
|
|
|
).to contain_exactly(user.id)
|
|
|
|
end.count
|
|
|
|
|
|
|
|
group2 = Fabricate(:group)
|
|
|
|
user2 = Fabricate(:user, primary_group: group2)
|
|
|
|
topic.update!(last_post_user_id: user2.id)
|
|
|
|
|
|
|
|
group3 = Fabricate(:group)
|
|
|
|
user3 = Fabricate(:user, flair_group: group3)
|
|
|
|
topic.update!(featured_user3_id: user3.id)
|
|
|
|
|
|
|
|
new_sql_queries_count =
|
|
|
|
track_sql_queries do
|
|
|
|
get "/latest.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
body = response.parsed_body
|
|
|
|
|
|
|
|
expect(body["topic_list"]["topics"].map { |t| t["id"] }).to contain_exactly(topic.id)
|
|
|
|
expect(
|
|
|
|
body["topic_list"]["topics"][0]["posters"].map { |p| p["user_id"] },
|
|
|
|
).to contain_exactly(user.id, user2.id, user3.id)
|
|
|
|
end.count
|
|
|
|
|
|
|
|
expect(new_sql_queries_count).to be <= initial_sql_queries_count
|
|
|
|
end
|
2023-07-28 06:53:50 -05:00
|
|
|
|
|
|
|
context "with topics with tags" do
|
|
|
|
let(:tag_group) { Fabricate.build(:tag_group) }
|
|
|
|
let(:tag_group_permission) { Fabricate.build(:tag_group_permission, tag_group: tag_group) }
|
|
|
|
let(:restricted_tag) { Fabricate(:tag) }
|
|
|
|
let(:public_tag) { Fabricate(:tag) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
tag_group.tag_group_permissions << tag_group_permission
|
|
|
|
tag_group.save!
|
|
|
|
tag_group_permission.tag_group.tags << restricted_tag
|
|
|
|
topic.tags << [public_tag, restricted_tag]
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not show hidden tags" do
|
|
|
|
get "/latest"
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.body).to include(public_tag.name)
|
|
|
|
expect(response.body).not_to include(restricted_tag.name)
|
|
|
|
end
|
|
|
|
end
|
2017-10-01 21:45:54 -05:00
|
|
|
end
|
|
|
|
|
2018-03-02 20:53:29 -06:00
|
|
|
describe "categories and X" do
|
2020-12-11 06:20:48 -06:00
|
|
|
let(:category) { Fabricate(:category_with_definition) }
|
|
|
|
let(:sub_category) { Fabricate(:category_with_definition, parent_category: category) }
|
|
|
|
|
2018-03-02 20:53:29 -06:00
|
|
|
it "returns top topics" do
|
|
|
|
Fabricate(:topic, like_count: 1000, posts_count: 100)
|
|
|
|
TopTopic.refresh!
|
|
|
|
|
|
|
|
get "/categories_and_top.json"
|
2020-05-07 10:04:12 -05:00
|
|
|
data = response.parsed_body
|
2018-03-02 20:53:29 -06:00
|
|
|
expect(data["topic_list"]["topics"].length).to eq(1)
|
|
|
|
|
|
|
|
get "/categories_and_latest.json"
|
2020-05-07 10:04:12 -05:00
|
|
|
data = response.parsed_body
|
2020-04-20 01:08:24 -05:00
|
|
|
expect(data["topic_list"]["topics"].length).to eq(2)
|
2018-03-02 20:53:29 -06:00
|
|
|
end
|
2020-12-11 06:20:48 -06:00
|
|
|
|
|
|
|
it "returns topics from subcategories when no_subcategories=false" do
|
|
|
|
Fabricate(:topic, category: sub_category)
|
|
|
|
get "/c/#{category.slug}/#{category.id}/l/latest.json?no_subcategories=false"
|
|
|
|
expect(response.parsed_body["topic_list"]["topics"].length).to eq(2)
|
|
|
|
end
|
2018-03-02 20:53:29 -06:00
|
|
|
end
|
|
|
|
|
2017-08-30 23:06:56 -05:00
|
|
|
describe "titles for crawler layout" do
|
|
|
|
it "has no title for the default URL" do
|
|
|
|
topic
|
|
|
|
filter = Discourse.anonymous_filters[0]
|
|
|
|
get "/#{filter}", params: { _escaped_fragment_: "true" }
|
|
|
|
|
|
|
|
expect(response.body).to include(I18n.t("rss_description.posts"))
|
|
|
|
|
|
|
|
expect(response.body).to_not include(I18n.t("js.filters.with_topics", filter: filter))
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has a title for non-default URLs" do
|
|
|
|
topic
|
|
|
|
filter = Discourse.anonymous_filters[1]
|
|
|
|
get "/#{filter}", params: { _escaped_fragment_: "true" }
|
|
|
|
|
|
|
|
expect(response.body).to include(I18n.t("js.filters.with_topics", filter: filter))
|
|
|
|
end
|
|
|
|
end
|
2018-02-22 08:57:02 -06:00
|
|
|
|
|
|
|
describe "filter private messages by tag" do
|
2021-12-20 12:59:10 -06:00
|
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
fab!(:moderator) { Fabricate(:moderator) }
|
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
2018-02-22 08:57:02 -06:00
|
|
|
let(:tag) { Fabricate(:tag) }
|
2020-05-22 23:56:13 -05:00
|
|
|
let(:private_message) { Fabricate(:private_message_topic, user: admin) }
|
2018-02-22 08:57:02 -06:00
|
|
|
|
|
|
|
before do
|
|
|
|
SiteSetting.tagging_enabled = true
|
2022-05-10 10:02:28 -05:00
|
|
|
SiteSetting.pm_tags_allowed_for_groups = "1|2|3"
|
2018-02-22 08:57:02 -06:00
|
|
|
Fabricate(:topic_tag, tag: tag, topic: private_message)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should fail for non-staff users" do
|
|
|
|
sign_in(user)
|
2018-03-10 23:29:34 -06:00
|
|
|
get "/topics/private-messages-tags/#{user.username}/#{tag.name}.json"
|
2018-02-22 08:57:02 -06:00
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
|
2022-05-10 10:02:28 -05:00
|
|
|
it "should fail for staff users if empty" do
|
|
|
|
SiteSetting.pm_tags_allowed_for_groups = ""
|
2020-06-22 08:48:24 -05:00
|
|
|
|
|
|
|
[moderator, admin].each do |user|
|
|
|
|
sign_in(user)
|
|
|
|
get "/topics/private-messages-tags/#{user.username}/#{tag.name}.json"
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-22 08:57:02 -06:00
|
|
|
it "should be success for staff users" do
|
|
|
|
[moderator, admin].each do |user|
|
|
|
|
sign_in(user)
|
2018-03-10 23:29:34 -06:00
|
|
|
get "/topics/private-messages-tags/#{user.username}/#{tag.name}.json"
|
2018-03-14 06:40:28 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
end
|
|
|
|
end
|
2020-05-22 23:56:13 -05:00
|
|
|
|
|
|
|
it "should work for tag with unicode name" do
|
|
|
|
unicode_tag = Fabricate(:tag, name: "hello-🇺🇸")
|
|
|
|
Fabricate(:topic_tag, tag: unicode_tag, topic: private_message)
|
|
|
|
|
|
|
|
sign_in(admin)
|
|
|
|
get "/topics/private-messages-tags/#{admin.username}/#{UrlHelper.encode_component(unicode_tag.name)}.json"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.parsed_body["topic_list"]["topics"].first["id"]).to eq(private_message.id)
|
|
|
|
end
|
2022-10-20 08:24:56 -05:00
|
|
|
|
|
|
|
it "should work for users who are allowed and direct links" do
|
|
|
|
SiteSetting.pm_tags_allowed_for_groups = group.name
|
|
|
|
group.add(user)
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get "/u/#{user.username}/messages/tags/#{tag.name}"
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
end
|
2018-03-14 06:40:28 -05:00
|
|
|
end
|
|
|
|
|
2018-03-15 03:01:40 -05:00
|
|
|
describe "#private_messages_group" do
|
2022-09-25 22:58:40 -05:00
|
|
|
describe "when user not in personal_message_enabled_groups group" do
|
2020-09-08 19:58:21 -05:00
|
|
|
let!(:topic) { Fabricate(:private_message_topic, allowed_groups: [group]) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
group.add(user)
|
2022-09-25 22:58:40 -05:00
|
|
|
SiteSetting.personal_message_enabled_groups = Group::AUTO_GROUPS[:staff]
|
|
|
|
Group.refresh_automatic_groups!
|
2020-09-08 19:58:21 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should display group private messages for an admin" do
|
|
|
|
sign_in(Fabricate(:admin))
|
|
|
|
|
|
|
|
get "/topics/private-messages-group/#{user.username}/#{group.name}.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
expect(response.parsed_body["topic_list"]["topics"].first["id"]).to eq(topic.id)
|
|
|
|
end
|
|
|
|
|
2020-10-05 11:38:08 -05:00
|
|
|
it "should display moderator group private messages for a moderator" do
|
|
|
|
moderator = Fabricate(:moderator)
|
|
|
|
group = Group.find(Group::AUTO_GROUPS[:moderators])
|
|
|
|
topic = Fabricate(:private_message_topic, allowed_groups: [group])
|
|
|
|
|
|
|
|
sign_in(moderator)
|
|
|
|
|
|
|
|
get "/topics/private-messages-group/#{moderator.username}/#{group.name}.json"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
end
|
|
|
|
|
2020-09-08 19:58:21 -05:00
|
|
|
it "should not display group private messages for a moderator's group" do
|
|
|
|
moderator = Fabricate(:moderator)
|
|
|
|
sign_in(moderator)
|
|
|
|
|
|
|
|
get "/topics/private-messages-group/#{user.username}/#{group.name}.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
2018-03-15 03:01:40 -05:00
|
|
|
end
|
|
|
|
|
2019-11-06 14:25:45 -06:00
|
|
|
describe "with unicode_usernames" do
|
2020-09-08 19:58:21 -05:00
|
|
|
before do
|
|
|
|
group.add(user)
|
|
|
|
sign_in(user)
|
|
|
|
SiteSetting.unicode_usernames = false
|
2022-10-04 19:50:20 -05:00
|
|
|
Group.refresh_automatic_groups!
|
2020-09-08 19:58:21 -05:00
|
|
|
end
|
2019-11-06 14:25:45 -06:00
|
|
|
|
2020-09-07 21:31:28 -05:00
|
|
|
it "should return the right response when user does not belong to group" do
|
|
|
|
Fabricate(:private_message_topic, allowed_groups: [group])
|
|
|
|
|
|
|
|
group.remove(user)
|
|
|
|
|
|
|
|
get "/topics/private-messages-group/#{user.username}/#{group.name}.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
|
2019-11-06 14:25:45 -06:00
|
|
|
it "should return the right response" do
|
|
|
|
topic = Fabricate(:private_message_topic, allowed_groups: [group])
|
2021-04-19 23:55:31 -05:00
|
|
|
get "/topics/private-messages-group/#{user.username}/awesomegroup.json"
|
2019-11-06 14:25:45 -06:00
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
2020-05-07 10:04:12 -05:00
|
|
|
expect(response.parsed_body["topic_list"]["topics"].first["id"]).to eq(topic.id)
|
2019-11-06 14:25:45 -06:00
|
|
|
end
|
2018-03-15 03:01:40 -05:00
|
|
|
end
|
|
|
|
|
2019-11-06 14:25:45 -06:00
|
|
|
describe "with unicode_usernames" do
|
2020-09-08 19:58:21 -05:00
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
SiteSetting.unicode_usernames = true
|
2022-10-04 19:50:20 -05:00
|
|
|
Group.refresh_automatic_groups!
|
2020-09-08 19:58:21 -05:00
|
|
|
end
|
2018-03-15 03:01:40 -05:00
|
|
|
|
2019-11-06 14:25:45 -06:00
|
|
|
it "Returns a 200 with unicode group name" do
|
|
|
|
unicode_group = Fabricate(:group, name: "群群组")
|
|
|
|
unicode_group.add(user)
|
|
|
|
topic = Fabricate(:private_message_topic, allowed_groups: [unicode_group])
|
2019-12-11 20:49:21 -06:00
|
|
|
get "/topics/private-messages-group/#{user.username}/#{UrlHelper.encode_component(unicode_group.name)}.json"
|
2019-11-06 14:25:45 -06:00
|
|
|
expect(response.status).to eq(200)
|
2018-03-15 03:01:40 -05:00
|
|
|
|
2020-05-07 10:04:12 -05:00
|
|
|
expect(response.parsed_body["topic_list"]["topics"].first["id"]).to eq(topic.id)
|
2019-11-06 14:25:45 -06:00
|
|
|
end
|
2018-03-15 03:01:40 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#group_topics" do
|
2018-03-14 06:40:28 -05:00
|
|
|
%i[user user2].each do |user|
|
|
|
|
let(user) do
|
|
|
|
user = Fabricate(:user)
|
|
|
|
group.add(user)
|
|
|
|
user
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:topic) { Fabricate(:topic, user: user) }
|
|
|
|
let!(:topic2) { Fabricate(:topic, user: user2) }
|
|
|
|
let!(:another_topic) { Fabricate(:topic) }
|
|
|
|
|
|
|
|
describe "when an invalid group name is given" do
|
|
|
|
it "should return the right response" do
|
|
|
|
get "/topics/groups/something.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "for an anon user" do
|
|
|
|
describe "public visible group" do
|
|
|
|
it "should return the right response" do
|
|
|
|
get "/topics/groups/#{group.name}.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 10:04:12 -05:00
|
|
|
expect(response.parsed_body["topic_list"]).to be_present
|
2018-03-14 06:40:28 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-08 14:09:50 -05:00
|
|
|
describe "group restricted to logged-on-users" do
|
|
|
|
before { group.update!(visibility_level: Group.visibility_levels[:logged_on_users]) }
|
|
|
|
|
|
|
|
it "should return the right response" do
|
|
|
|
get "/topics/groups/#{group.name}.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(403)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-14 06:40:28 -05:00
|
|
|
describe "restricted group" do
|
|
|
|
before { group.update!(visibility_level: Group.visibility_levels[:staff]) }
|
|
|
|
|
|
|
|
it "should return the right response" do
|
|
|
|
get "/topics/groups/#{group.name}.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(403)
|
|
|
|
end
|
|
|
|
end
|
2019-08-14 08:30:04 -05:00
|
|
|
|
|
|
|
describe "group members visibility restricted to logged-on-users" do
|
|
|
|
before do
|
|
|
|
group.update!(members_visibility_level: Group.visibility_levels[:logged_on_users])
|
2023-01-09 05:18:21 -06:00
|
|
|
end
|
2019-08-14 08:30:04 -05:00
|
|
|
|
|
|
|
it "should return the right response" do
|
|
|
|
get "/topics/groups/#{group.name}.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(403)
|
|
|
|
end
|
|
|
|
end
|
2018-03-14 06:40:28 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "for a normal user" do
|
|
|
|
before { sign_in(Fabricate(:user)) }
|
|
|
|
|
|
|
|
describe "restricted group" do
|
|
|
|
before { group.update!(visibility_level: Group.visibility_levels[:staff]) }
|
|
|
|
|
|
|
|
it "should return the right response" do
|
|
|
|
get "/topics/groups/#{group.name}.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(403)
|
|
|
|
end
|
2019-07-08 14:09:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "group restricted to logged-on-users" do
|
|
|
|
before { group.update!(visibility_level: Group.visibility_levels[:logged_on_users]) }
|
|
|
|
|
|
|
|
it "should return the right response" do
|
|
|
|
get "/topics/groups/#{group.name}.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
end
|
2018-03-14 06:40:28 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "for a group user" do
|
|
|
|
before { sign_in(user) }
|
|
|
|
|
|
|
|
it "should be able to view the topics started by group users" do
|
|
|
|
get "/topics/groups/#{group.name}.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
2020-05-07 10:04:12 -05:00
|
|
|
topics = response.parsed_body["topic_list"]["topics"]
|
2018-03-14 06:40:28 -05:00
|
|
|
|
|
|
|
expect(topics.map { |topic| topic["id"] }).to contain_exactly(topic.id, topic2.id)
|
2018-02-22 08:57:02 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-06-03 22:09:59 -05:00
|
|
|
|
|
|
|
describe "RSS feeds" do
|
|
|
|
it "renders latest RSS" do
|
|
|
|
get "/latest.rss"
|
2018-06-07 03:11:09 -05:00
|
|
|
expect(response.status).to eq(200)
|
2019-09-11 19:41:50 -05:00
|
|
|
expect(response.media_type).to eq("application/rss+xml")
|
2020-01-23 22:00:27 -06:00
|
|
|
expect(response.headers["X-Robots-Tag"]).to eq("noindex")
|
2018-06-03 22:09:59 -05:00
|
|
|
end
|
|
|
|
|
2020-08-03 02:03:58 -05:00
|
|
|
it "renders latest RSS with query params" do
|
|
|
|
get "/latest.rss?status=closed"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.media_type).to eq("application/rss+xml")
|
|
|
|
expect(response.body).to_not include("<item>")
|
|
|
|
end
|
|
|
|
|
2018-08-27 17:05:08 -05:00
|
|
|
it "renders links correctly with subfolder" do
|
2019-11-14 23:48:24 -06:00
|
|
|
set_subfolder "/forum"
|
2020-04-20 01:08:24 -05:00
|
|
|
_post = Fabricate(:post, topic: topic, user: user)
|
2018-08-27 17:05:08 -05:00
|
|
|
get "/latest.rss"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.body).to_not include("/forum/forum")
|
|
|
|
expect(response.body).to include("http://test.localhost/forum/t/#{topic.slug}")
|
|
|
|
end
|
|
|
|
|
2018-06-03 22:09:59 -05:00
|
|
|
it "renders top RSS" do
|
|
|
|
get "/top.rss"
|
2018-06-07 03:11:09 -05:00
|
|
|
expect(response.status).to eq(200)
|
2019-09-11 19:41:50 -05:00
|
|
|
expect(response.media_type).to eq("application/rss+xml")
|
2018-06-03 22:09:59 -05:00
|
|
|
end
|
2021-07-22 01:31:53 -05:00
|
|
|
|
|
|
|
it "errors for invalid periods on top RSS" do
|
|
|
|
get "/top.rss?period=decadely"
|
|
|
|
expect(response.status).to eq(400)
|
|
|
|
end
|
2018-06-03 22:09:59 -05:00
|
|
|
|
|
|
|
TopTopic.periods.each do |period|
|
|
|
|
it "renders #{period} top RSS" do
|
2021-07-06 04:55:11 -05:00
|
|
|
get "/top.rss?period=#{period}"
|
2018-06-07 03:11:09 -05:00
|
|
|
expect(response.status).to eq(200)
|
2019-09-11 19:41:50 -05:00
|
|
|
expect(response.media_type).to eq("application/rss+xml")
|
2018-06-03 22:09:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-23 15:58:10 -05:00
|
|
|
describe "Top" do
|
|
|
|
it "renders top" do
|
|
|
|
get "/top"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renders top with a period" do
|
|
|
|
get "/top?period=weekly"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "errors for invalid periods on top" do
|
|
|
|
get "/top?period=decadely"
|
|
|
|
expect(response.status).to eq(400)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-03 22:09:59 -05:00
|
|
|
describe "category" do
|
2022-07-27 11:14:14 -05:00
|
|
|
context "when in a category" do
|
2019-08-06 05:26:54 -05:00
|
|
|
let(:category) { Fabricate(:category_with_definition) }
|
2018-06-03 22:09:59 -05:00
|
|
|
let(:group) { Fabricate(:group) }
|
|
|
|
let(:private_category) { Fabricate(:private_category, group: group) }
|
|
|
|
|
|
|
|
context "without access to see the category" do
|
|
|
|
it "responds with a 404 error" do
|
|
|
|
get "/c/#{private_category.slug}/l/latest"
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with access to see the category" do
|
|
|
|
it "succeeds" do
|
2020-07-07 07:25:36 -05:00
|
|
|
get "/c/#{category.slug}/#{category.id}/l/latest"
|
2018-06-03 22:09:59 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-29 09:17:57 -05:00
|
|
|
context "with encoded slug in the category" do
|
|
|
|
let(:category) { Fabricate(:category, slug: "தமிழ்") }
|
|
|
|
|
|
|
|
before { SiteSetting.slug_generation_method = "encoded" }
|
|
|
|
|
|
|
|
it "succeeds" do
|
|
|
|
get "/c/#{category.slug}/#{category.id}/l/latest"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-03 22:09:59 -05:00
|
|
|
context "with a link that has a parent slug, slug and id in its path" do
|
2019-08-06 05:26:54 -05:00
|
|
|
let(:child_category) { Fabricate(:category_with_definition, parent_category: category) }
|
2018-06-03 22:09:59 -05:00
|
|
|
|
|
|
|
context "with valid slug" do
|
2019-10-30 12:22:32 -05:00
|
|
|
it "succeeds" do
|
|
|
|
get "/c/#{category.slug}/#{child_category.slug}/#{child_category.id}/l/latest"
|
|
|
|
expect(response.status).to eq(200)
|
2018-06-03 22:09:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with invalid slug" do
|
2020-09-08 14:23:11 -05:00
|
|
|
it "redirects" do
|
2019-10-30 12:22:32 -05:00
|
|
|
get "/c/random_slug/another_random_slug/#{child_category.id}/l/latest"
|
2020-09-08 14:23:11 -05:00
|
|
|
expect(response).to redirect_to("#{child_category.url}/l/latest")
|
2018-06-03 22:09:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 11:14:14 -05:00
|
|
|
context "when another category exists with a number at the beginning of its name" do
|
2018-06-03 22:09:59 -05:00
|
|
|
# One category has another category's id at the beginning of its name
|
2019-10-30 09:45:34 -05:00
|
|
|
let!(:other_category) do
|
|
|
|
# Our validations don't allow this to happen now, but did historically
|
2020-04-20 20:50:50 -05:00
|
|
|
Fabricate(
|
|
|
|
:category_with_definition,
|
|
|
|
name: "#{category.id} name",
|
|
|
|
slug: "will-be-changed",
|
|
|
|
).tap { |category| category.update_column(:slug, "#{category.id}-name") }
|
|
|
|
end
|
2018-06-03 22:09:59 -05:00
|
|
|
|
|
|
|
it "uses the correct category" do
|
2020-07-07 07:25:36 -05:00
|
|
|
get "/c/#{other_category.slug}/#{other_category.id}/l/latest.json"
|
2018-06-07 03:11:09 -05:00
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 10:04:12 -05:00
|
|
|
body = response.parsed_body
|
2018-06-03 22:09:59 -05:00
|
|
|
expect(body["topic_list"]["topics"].first["category_id"]).to eq(other_category.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 11:14:14 -05:00
|
|
|
context "with a child category" do
|
2019-08-06 05:26:54 -05:00
|
|
|
let(:sub_category) { Fabricate(:category_with_definition, parent_category_id: category.id) }
|
2018-06-03 22:09:59 -05:00
|
|
|
|
|
|
|
context "when parent and child are requested" do
|
|
|
|
it "succeeds" do
|
2020-07-07 07:25:36 -05:00
|
|
|
get "/c/#{category.slug}/#{sub_category.slug}/#{sub_category.id}/l/latest"
|
2018-06-03 22:09:59 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when child is requested with the wrong parent" do
|
|
|
|
it "responds with a 404 error" do
|
|
|
|
get "/c/not-the-right-slug/#{sub_category.slug}/l/latest"
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "feed" do
|
|
|
|
it "renders RSS" do
|
2020-07-07 07:25:36 -05:00
|
|
|
get "/c/#{category.slug}/#{category.id}.rss"
|
2018-06-07 03:11:09 -05:00
|
|
|
expect(response.status).to eq(200)
|
2019-09-11 19:41:50 -05:00
|
|
|
expect(response.media_type).to eq("application/rss+xml")
|
2018-06-03 22:09:59 -05:00
|
|
|
end
|
2018-09-07 09:03:30 -05:00
|
|
|
|
|
|
|
it "renders RSS in subfolder correctly" do
|
2019-11-14 23:48:24 -06:00
|
|
|
set_subfolder "/forum"
|
2020-07-07 07:25:36 -05:00
|
|
|
get "/c/#{category.slug}/#{category.id}.rss"
|
2018-09-07 09:03:30 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.body).to_not include("/forum/forum")
|
|
|
|
expect(response.body).to include("http://test.localhost/forum/c/#{category.slug}")
|
|
|
|
end
|
2018-06-03 22:09:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "category default views" do
|
|
|
|
it "has a top default view" do
|
2019-04-29 02:32:25 -05:00
|
|
|
category.update!(default_view: "top", default_top_period: "monthly")
|
2020-07-07 07:25:36 -05:00
|
|
|
get "/c/#{category.slug}/#{category.id}.json"
|
2018-06-07 03:11:09 -05:00
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 10:04:12 -05:00
|
|
|
json = response.parsed_body
|
2018-06-03 22:09:59 -05:00
|
|
|
expect(json["topic_list"]["for_period"]).to eq("monthly")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has a default view of nil" do
|
2019-04-29 02:32:25 -05:00
|
|
|
category.update!(default_view: nil)
|
2020-07-07 07:25:36 -05:00
|
|
|
get "/c/#{category.slug}/#{category.id}.json"
|
2018-06-07 03:11:09 -05:00
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 10:04:12 -05:00
|
|
|
json = response.parsed_body
|
2018-06-03 22:09:59 -05:00
|
|
|
expect(json["topic_list"]["for_period"]).to be_blank
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has a default view of ''" do
|
2019-04-29 02:32:25 -05:00
|
|
|
category.update!(default_view: "")
|
2020-07-07 07:25:36 -05:00
|
|
|
get "/c/#{category.slug}/#{category.id}.json"
|
2018-06-07 03:11:09 -05:00
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 10:04:12 -05:00
|
|
|
json = response.parsed_body
|
2018-06-03 22:09:59 -05:00
|
|
|
expect(json["topic_list"]["for_period"]).to be_blank
|
|
|
|
end
|
|
|
|
|
|
|
|
it "has a default view of latest" do
|
2019-04-29 02:32:25 -05:00
|
|
|
category.update!(default_view: "latest")
|
2020-07-07 07:25:36 -05:00
|
|
|
get "/c/#{category.slug}/#{category.id}.json"
|
2018-06-07 03:11:09 -05:00
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 10:04:12 -05:00
|
|
|
json = response.parsed_body
|
2018-06-03 22:09:59 -05:00
|
|
|
expect(json["topic_list"]["for_period"]).to be_blank
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "renders canonical tag" do
|
|
|
|
it "for category default view" do
|
2020-07-07 07:25:36 -05:00
|
|
|
get "/c/#{category.slug}/#{category.id}"
|
2018-06-07 03:11:09 -05:00
|
|
|
expect(response.status).to eq(200)
|
2018-06-03 22:09:59 -05:00
|
|
|
expect(css_select("link[rel=canonical]").length).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "for category latest view" do
|
2020-07-07 07:25:36 -05:00
|
|
|
get "/c/#{category.slug}/#{category.id}/l/latest"
|
2018-06-07 03:11:09 -05:00
|
|
|
expect(response.status).to eq(200)
|
2018-06-03 22:09:59 -05:00
|
|
|
expect(css_select("link[rel=canonical]").length).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
2019-07-08 01:12:39 -05:00
|
|
|
|
2022-07-27 11:14:14 -05:00
|
|
|
context "for category default view" do
|
2019-08-06 05:26:54 -05:00
|
|
|
let!(:amazing_category) { Fabricate(:category_with_definition, name: "Amazing Category") }
|
2019-07-08 01:12:39 -05:00
|
|
|
|
2022-07-27 11:14:14 -05:00
|
|
|
it "renders correct title" do
|
2020-07-07 07:25:36 -05:00
|
|
|
get "/c/#{amazing_category.slug}/#{amazing_category.id}"
|
2019-07-08 01:12:39 -05:00
|
|
|
|
|
|
|
expect(response.body).to have_tag "title", text: "Amazing Category - Discourse"
|
|
|
|
end
|
2022-07-27 11:14:14 -05:00
|
|
|
end
|
2019-07-08 01:12:39 -05:00
|
|
|
|
2022-07-27 11:14:14 -05:00
|
|
|
context "for category latest view" do
|
|
|
|
let!(:amazing_category) { Fabricate(:category_with_definition, name: "Amazing Category") }
|
|
|
|
|
|
|
|
it "renders correct title" do
|
2019-07-08 01:12:39 -05:00
|
|
|
SiteSetting.short_site_description = "Best community"
|
2020-07-07 07:25:36 -05:00
|
|
|
get "/c/#{amazing_category.slug}/#{amazing_category.id}/l/latest"
|
2019-07-08 01:12:39 -05:00
|
|
|
|
|
|
|
expect(response.body).to have_tag "title", text: "Amazing Category - Discourse"
|
|
|
|
end
|
|
|
|
end
|
2018-06-03 22:09:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "topics_by" do
|
2020-04-20 01:08:24 -05:00
|
|
|
fab!(:topic2) { Fabricate(:topic, user: user) }
|
|
|
|
fab!(:user2) { Fabricate(:user) }
|
|
|
|
|
|
|
|
before { sign_in(user2) }
|
2018-06-03 22:09:59 -05:00
|
|
|
|
|
|
|
it "should respond with a list" do
|
|
|
|
get "/topics/created-by/#{user.username}.json"
|
2018-06-07 03:11:09 -05:00
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 10:04:12 -05:00
|
|
|
json = response.parsed_body
|
2020-04-20 01:08:24 -05:00
|
|
|
expect(json["topic_list"]["topics"].size).to eq(2)
|
2018-11-23 11:41:41 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should work with period in username" do
|
|
|
|
user.update!(username: "myname.test")
|
|
|
|
get "/topics/created-by/#{user.username}", xhr: true
|
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 10:04:12 -05:00
|
|
|
json = response.parsed_body
|
2020-04-20 01:08:24 -05:00
|
|
|
expect(json["topic_list"]["topics"].size).to eq(2)
|
2018-06-03 22:09:59 -05:00
|
|
|
end
|
2020-06-03 08:33:02 -05:00
|
|
|
|
2022-07-27 11:14:14 -05:00
|
|
|
context "with unicode usernames" do
|
2022-05-04 20:48:22 -05:00
|
|
|
before { SiteSetting.unicode_usernames = true }
|
|
|
|
|
|
|
|
it "should return the more_topics_url in the encoded form" do
|
|
|
|
stub_const(TopicQuery, "DEFAULT_PER_PAGE_COUNT", 1) do
|
|
|
|
user.update!(username: "快快快")
|
|
|
|
|
|
|
|
get "/topics/created-by/#{UrlHelper.encode(user.username)}.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
json = response.parsed_body
|
|
|
|
|
|
|
|
expect(json["topic_list"]["more_topics_url"]).to eq(
|
|
|
|
"/topics/created-by/%E5%BF%AB%E5%BF%AB%E5%BF%AB?page=1",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-09 16:18:44 -05:00
|
|
|
context "when `hide_profile_and_presence` is true" do
|
|
|
|
before { user.user_option.update_columns(hide_profile_and_presence: true) }
|
|
|
|
|
|
|
|
it "returns 404" do
|
|
|
|
get "/topics/created-by/#{user.username}.json"
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond with a list when `allow_users_to_hide_profile` is false" do
|
|
|
|
SiteSetting.allow_users_to_hide_profile = false
|
|
|
|
get "/topics/created-by/#{user.username}.json"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
json = response.parsed_body
|
|
|
|
expect(json["topic_list"]["topics"].size).to eq(2)
|
|
|
|
end
|
2020-06-03 08:33:02 -05:00
|
|
|
end
|
2018-06-03 22:09:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "private_messages" do
|
|
|
|
it "returns 403 error when the user can't see private message" do
|
|
|
|
sign_in(Fabricate(:user))
|
|
|
|
get "/topics/private-messages/#{user.username}.json"
|
|
|
|
expect(response).to be_forbidden
|
|
|
|
end
|
|
|
|
|
|
|
|
it "succeeds when the user can see private messages" do
|
|
|
|
pm = Fabricate(:private_message_topic, user: Fabricate(:user))
|
|
|
|
pm.topic_allowed_users.create!(user: user)
|
|
|
|
sign_in(user)
|
|
|
|
get "/topics/private-messages/#{user.username}.json"
|
2018-06-07 03:11:09 -05:00
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 10:04:12 -05:00
|
|
|
json = response.parsed_body
|
2018-06-03 22:09:59 -05:00
|
|
|
expect(json["topic_list"]["topics"].size).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "private_messages_sent" do
|
|
|
|
before do
|
|
|
|
pm = Fabricate(:private_message_topic, user: user)
|
|
|
|
Fabricate(:post, user: user, topic: pm, post_number: 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns 403 error when the user can't see private message" do
|
|
|
|
sign_in(Fabricate(:user))
|
|
|
|
get "/topics/private-messages-sent/#{user.username}.json"
|
|
|
|
expect(response).to be_forbidden
|
|
|
|
end
|
|
|
|
|
|
|
|
it "succeeds when the user can see private messages" do
|
|
|
|
sign_in(user)
|
|
|
|
get "/topics/private-messages-sent/#{user.username}.json"
|
2018-06-07 03:11:09 -05:00
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 10:04:12 -05:00
|
|
|
json = response.parsed_body
|
2018-06-03 22:09:59 -05:00
|
|
|
expect(json["topic_list"]["topics"].size).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-14 23:55:50 -05:00
|
|
|
describe "#private_messages_unread" do
|
|
|
|
fab!(:pm_user) { Fabricate(:user) }
|
|
|
|
|
|
|
|
fab!(:pm) do
|
|
|
|
Fabricate(:private_message_topic).tap do |t|
|
|
|
|
t.allowed_users << pm_user
|
|
|
|
create_post(user: pm_user, topic_id: t.id)
|
|
|
|
end
|
2018-06-03 22:09:59 -05:00
|
|
|
end
|
|
|
|
|
2021-09-09 01:02:17 -05:00
|
|
|
it "returns 404 when the user can't see private message" do
|
2018-06-03 22:09:59 -05:00
|
|
|
sign_in(Fabricate(:user))
|
2020-09-14 23:55:50 -05:00
|
|
|
get "/topics/private-messages-unread/#{pm_user.username}.json"
|
2021-09-09 01:02:17 -05:00
|
|
|
expect(response.status).to eq(404)
|
2018-06-03 22:09:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "succeeds when the user can see private messages" do
|
2020-09-14 23:55:50 -05:00
|
|
|
TopicUser.find_by(topic: pm, user: pm_user).update!(
|
|
|
|
notification_level: TopicUser.notification_levels[:tracking],
|
|
|
|
last_read_post_number: 0,
|
|
|
|
)
|
|
|
|
|
|
|
|
sign_in(pm_user)
|
|
|
|
get "/topics/private-messages-unread/#{pm_user.username}.json"
|
|
|
|
|
2018-06-07 03:11:09 -05:00
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 10:04:12 -05:00
|
|
|
json = response.parsed_body
|
2018-06-03 22:09:59 -05:00
|
|
|
expect(json["topic_list"]["topics"].size).to eq(1)
|
2020-09-14 23:55:50 -05:00
|
|
|
expect(json["topic_list"]["topics"][0]["id"]).to eq(pm.id)
|
2018-06-03 22:09:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-14 16:01:17 -05:00
|
|
|
describe "#private_messages_warnings" do
|
2021-12-20 12:59:10 -06:00
|
|
|
fab!(:target_user) { Fabricate(:user) }
|
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
|
|
|
fab!(:moderator1) { Fabricate(:moderator) }
|
|
|
|
fab!(:moderator2) { Fabricate(:moderator) }
|
2021-06-14 16:01:17 -05:00
|
|
|
|
|
|
|
let(:create_args) do
|
|
|
|
{
|
|
|
|
title: "you need a warning buddy!",
|
|
|
|
raw: "you did something bad and I'm telling you about it!",
|
|
|
|
is_warning: true,
|
|
|
|
target_usernames: target_user.username,
|
|
|
|
archetype: Archetype.private_message,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:warning_post) do
|
|
|
|
creator = PostCreator.new(moderator1, create_args)
|
|
|
|
creator.create
|
|
|
|
end
|
|
|
|
let(:warning_topic) { warning_post.topic }
|
|
|
|
|
|
|
|
before { warning_topic }
|
|
|
|
|
|
|
|
it "returns 403 error for unrelated users" do
|
|
|
|
sign_in(Fabricate(:user))
|
|
|
|
get "/topics/private-messages-warnings/#{target_user.username}.json"
|
|
|
|
expect(response.status).to eq(403)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "shows the warning to moderators and admins" do
|
|
|
|
[moderator1, moderator2, admin].each do |viewer|
|
|
|
|
sign_in(viewer)
|
|
|
|
get "/topics/private-messages-warnings/#{target_user.username}.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
json = response.parsed_body
|
|
|
|
expect(json["topic_list"]["topics"].size).to eq(1)
|
|
|
|
expect(json["topic_list"]["topics"][0]["id"]).to eq(warning_topic.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not show the warning as applying to the authoring moderator" do
|
|
|
|
sign_in(admin)
|
|
|
|
get "/topics/private-messages-warnings/#{moderator1.username}.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
json = response.parsed_body
|
|
|
|
expect(json["topic_list"]["topics"].size).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-03 22:09:59 -05:00
|
|
|
describe "read" do
|
|
|
|
it "raises an error when not logged in" do
|
|
|
|
get "/read"
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when logged in" do
|
|
|
|
it "succeeds" do
|
|
|
|
sign_in(user)
|
|
|
|
get "/read"
|
2018-06-07 03:11:09 -05:00
|
|
|
expect(response.status).to eq(200)
|
2018-06-03 22:09:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "best_periods_for" do
|
2019-06-04 03:57:50 -05:00
|
|
|
it "works" do
|
|
|
|
expect(ListController.best_periods_for(nil)).to eq([:all])
|
|
|
|
expect(ListController.best_periods_for(5.years.ago)).to eq([:all])
|
|
|
|
expect(ListController.best_periods_for(2.years.ago)).to eq(%i[yearly all])
|
|
|
|
expect(ListController.best_periods_for(6.months.ago)).to eq(%i[quarterly yearly all])
|
|
|
|
expect(ListController.best_periods_for(2.months.ago)).to eq(%i[monthly quarterly yearly all])
|
|
|
|
expect(ListController.best_periods_for(2.weeks.ago)).to eq(
|
|
|
|
%i[weekly monthly quarterly yearly all],
|
|
|
|
)
|
|
|
|
expect(ListController.best_periods_for(2.days.ago)).to eq(
|
|
|
|
%i[daily weekly monthly quarterly yearly all],
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "supports default period" do
|
|
|
|
expect(ListController.best_periods_for(nil, :yearly)).to eq(%i[yearly all])
|
|
|
|
expect(ListController.best_periods_for(nil, :quarterly)).to eq(%i[quarterly all])
|
|
|
|
expect(ListController.best_periods_for(nil, :monthly)).to eq(%i[monthly all])
|
|
|
|
expect(ListController.best_periods_for(nil, :weekly)).to eq(%i[weekly all])
|
|
|
|
expect(ListController.best_periods_for(nil, :daily)).to eq(%i[daily all])
|
2018-06-03 22:09:59 -05:00
|
|
|
end
|
|
|
|
end
|
2020-06-03 08:33:02 -05:00
|
|
|
|
|
|
|
describe "user_topics_feed" do
|
|
|
|
it "returns 404 if `hide_profile_and_presence` user option is checked" do
|
|
|
|
user.user_option.update_columns(hide_profile_and_presence: true)
|
|
|
|
get "/u/#{user.username}/activity/topics.rss"
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
|
|
|
end
|
2020-07-07 07:25:36 -05:00
|
|
|
|
|
|
|
describe "set_category" do
|
|
|
|
let(:category) { Fabricate(:category_with_definition) }
|
|
|
|
let(:subcategory) { Fabricate(:category_with_definition, parent_category_id: category.id) }
|
|
|
|
let(:subsubcategory) do
|
|
|
|
Fabricate(:category_with_definition, parent_category_id: subcategory.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
before { SiteSetting.max_category_nesting = 3 }
|
2023-01-09 05:18:21 -06:00
|
|
|
|
2020-07-07 07:25:36 -05:00
|
|
|
it "redirects to URL with the updated slug" do
|
|
|
|
get "/c/hello/world/bye/#{subsubcategory.id}"
|
|
|
|
expect(response.status).to eq(301)
|
|
|
|
expect(response).to redirect_to(
|
|
|
|
"/c/#{category.slug}/#{subcategory.slug}/#{subsubcategory.slug}/#{subsubcategory.id}",
|
|
|
|
)
|
2021-02-16 09:54:50 -06:00
|
|
|
|
|
|
|
get "/c/#{category.slug}/#{subcategory.slug}/#{subsubcategory.slug}/#{subsubcategory.id}"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "redirects to URL with correct case slug" do
|
|
|
|
category.update!(slug: "hello")
|
|
|
|
|
|
|
|
get "/c/Hello/#{category.id}"
|
|
|
|
expect(response).to redirect_to("/c/hello/#{category.id}")
|
|
|
|
|
|
|
|
get "/c/hello/#{category.id}"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
end
|
|
|
|
|
2022-07-27 11:14:14 -05:00
|
|
|
context "with encoded slugs" do
|
|
|
|
it "does not create a redirect loop" do
|
2021-02-16 09:54:50 -06:00
|
|
|
category = Fabricate(:category)
|
|
|
|
category.update_columns(slug: CGI.escape("systèmes"))
|
|
|
|
|
|
|
|
get "/c/syst%C3%A8mes/#{category.id}"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
end
|
2022-07-27 11:14:14 -05:00
|
|
|
end
|
2021-02-16 09:54:50 -06:00
|
|
|
|
2022-07-27 11:14:14 -05:00
|
|
|
context "with lowercase encoded slugs" do
|
|
|
|
it "does not create a redirect loop" do
|
2021-02-16 09:54:50 -06:00
|
|
|
category = Fabricate(:category)
|
|
|
|
category.update_columns(slug: CGI.escape("systèmes").downcase)
|
|
|
|
|
|
|
|
get "/c/syst%C3%A8mes/#{category.id}"
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
end
|
2020-07-07 07:25:36 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with subfolder" do
|
2020-09-11 12:13:10 -05:00
|
|
|
it "main category redirects to URL containing the updated slug" do
|
|
|
|
set_subfolder "/forum"
|
|
|
|
get "/c/#{category.slug}"
|
|
|
|
|
|
|
|
expect(response.status).to eq(301)
|
|
|
|
expect(response).to redirect_to("/forum/c/#{category.slug}/#{category.id}")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "sub-sub-category redirects to URL containing the updated slug" do
|
2020-07-07 07:25:36 -05:00
|
|
|
set_subfolder "/forum"
|
|
|
|
get "/c/hello/world/bye/#{subsubcategory.id}"
|
|
|
|
|
|
|
|
expect(response.status).to eq(301)
|
|
|
|
expect(response).to redirect_to(
|
|
|
|
"/forum/c/#{category.slug}/#{subcategory.slug}/#{subsubcategory.slug}/#{subsubcategory.id}",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-02-01 12:29:04 -06:00
|
|
|
|
|
|
|
describe "shared drafts" do
|
|
|
|
fab!(:category1) { Fabricate(:category) }
|
|
|
|
fab!(:category2) { Fabricate(:category) }
|
|
|
|
|
|
|
|
fab!(:topic1) { Fabricate(:topic, category: category1) }
|
|
|
|
fab!(:topic2) { Fabricate(:topic, category: category2) }
|
|
|
|
|
|
|
|
fab!(:shared_draft_topic) { Fabricate(:topic, category: category1) }
|
|
|
|
fab!(:shared_draft) { Fabricate(:shared_draft, topic: shared_draft_topic, category: category2) }
|
|
|
|
|
|
|
|
it "are not displayed if they are disabled" do
|
|
|
|
SiteSetting.shared_drafts_category = ""
|
|
|
|
sign_in(admin)
|
|
|
|
|
|
|
|
get "/c/#{category1.slug}/#{category1.id}.json"
|
|
|
|
expect(response.parsed_body["topic_list"]["shared_drafts"]).to eq(nil)
|
|
|
|
expect(response.parsed_body["topic_list"]["topics"].map { |t| t["id"] }).to contain_exactly(
|
|
|
|
topic1.id,
|
|
|
|
shared_draft_topic.id,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "are displayed in both shared drafts category and target category" do
|
|
|
|
SiteSetting.shared_drafts_category = category1.id
|
|
|
|
sign_in(admin)
|
|
|
|
|
|
|
|
get "/c/#{category1.slug}/#{category1.id}.json"
|
|
|
|
expect(response.parsed_body["topic_list"]["shared_drafts"]).to be_nil
|
|
|
|
expect(response.parsed_body["topic_list"]["topics"].map { |t| t["id"] }).to contain_exactly(
|
|
|
|
topic1.id,
|
|
|
|
shared_draft_topic.id,
|
|
|
|
)
|
|
|
|
|
|
|
|
get "/c/#{category2.slug}/#{category2.id}.json"
|
|
|
|
expect(
|
|
|
|
response.parsed_body["topic_list"]["shared_drafts"].map { |t| t["id"] },
|
|
|
|
).to contain_exactly(shared_draft_topic.id)
|
|
|
|
expect(response.parsed_body["topic_list"]["topics"].map { |t| t["id"] }).to contain_exactly(
|
|
|
|
topic2.id,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2022-06-01 12:18:20 -05:00
|
|
|
|
|
|
|
describe "body class" do
|
|
|
|
it "pre-renders the correct body class for categories" do
|
|
|
|
c = Fabricate(:category, slug: "myparentslug")
|
|
|
|
sub_c = Fabricate(:category, parent_category: c, slug: "mychildslug")
|
|
|
|
|
|
|
|
get "/c/#{c.slug}/#{sub_c.slug}/#{sub_c.id}"
|
|
|
|
|
|
|
|
expect(response.body).to have_tag "body", with: { class: "category-myparentslug-mychildslug" }
|
|
|
|
end
|
|
|
|
end
|
2022-10-19 21:01:36 -05:00
|
|
|
|
2023-03-02 19:46:21 -06:00
|
|
|
describe "#filter" do
|
2023-05-08 01:04:47 -05:00
|
|
|
fab!(:category) { Fabricate(:category, slug: "category-slug") }
|
2023-03-29 20:00:42 -05:00
|
|
|
fab!(:tag) { Fabricate(:tag, name: "tag1") }
|
2023-04-11 20:25:06 -05:00
|
|
|
fab!(:group) { Fabricate(:group) }
|
2023-05-08 01:04:47 -05:00
|
|
|
fab!(:private_category) { Fabricate(:private_category, group:, slug: "private-category-slug") }
|
2023-04-11 20:25:06 -05:00
|
|
|
fab!(:private_message_topic) { Fabricate(:private_message_topic) }
|
|
|
|
fab!(:topic_in_private_category) { Fabricate(:topic, category: private_category) }
|
2023-03-29 20:00:42 -05:00
|
|
|
|
|
|
|
before { SiteSetting.experimental_topics_filter = true }
|
2023-03-02 19:46:21 -06:00
|
|
|
|
2023-04-11 20:25:06 -05:00
|
|
|
it "should not return topics that the user is not allowed to view" do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get "/filter.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
expect(
|
|
|
|
response.parsed_body["topic_list"]["topics"].map { |topic| topic["id"] },
|
|
|
|
).to contain_exactly(topic.id)
|
|
|
|
end
|
|
|
|
|
2023-03-29 20:00:42 -05:00
|
|
|
it "should respond with 403 response code for an anonymous user" do
|
2023-03-02 19:46:21 -06:00
|
|
|
get "/filter.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(403)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should respond with 404 response code when `experimental_topics_filter` site setting has not been enabled" do
|
|
|
|
SiteSetting.experimental_topics_filter = false
|
2023-03-29 20:00:42 -05:00
|
|
|
|
2023-03-02 19:46:21 -06:00
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get "/filter.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(404)
|
|
|
|
end
|
2023-03-29 20:00:42 -05:00
|
|
|
|
|
|
|
it "returns category definition topics if `show_category_definitions_in_topic_lists` site setting is enabled" do
|
|
|
|
category_topic = Fabricate(:topic, category: category)
|
|
|
|
category.update!(topic: category_topic)
|
|
|
|
|
|
|
|
SiteSetting.show_category_definitions_in_topic_lists = true
|
|
|
|
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get "/filter.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
2023-03-29 23:57:23 -05:00
|
|
|
expect(
|
|
|
|
response.parsed_body["topic_list"]["topics"].map { |topic| topic["id"] },
|
|
|
|
).to contain_exactly(topic.id, category_topic.id)
|
2023-03-29 20:00:42 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not return category definition topics if `show_category_definitions_in_topic_lists` site setting is disabled" do
|
|
|
|
category_topic = Fabricate(:topic, category: category)
|
|
|
|
category.update!(topic: category_topic)
|
|
|
|
|
|
|
|
SiteSetting.show_category_definitions_in_topic_lists = false
|
|
|
|
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get "/filter.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
2023-03-29 23:57:23 -05:00
|
|
|
expect(
|
|
|
|
response.parsed_body["topic_list"]["topics"].map { |topic| topic["id"] },
|
|
|
|
).to contain_exactly(topic.id)
|
2023-03-29 20:00:42 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should accept the `page` query parameter" do
|
2023-03-29 23:57:23 -05:00
|
|
|
topic_with_tag = Fabricate(:topic, tags: [tag])
|
|
|
|
topic2_with_tag = Fabricate(:topic, tags: [tag])
|
|
|
|
|
2023-03-29 20:00:42 -05:00
|
|
|
stub_const(TopicQuery, "DEFAULT_PER_PAGE_COUNT", 1) do
|
|
|
|
sign_in(user)
|
|
|
|
|
2023-03-29 23:57:23 -05:00
|
|
|
get "/filter.json", params: { q: "tags:tag1" }
|
2023-03-29 20:00:42 -05:00
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
parsed = response.parsed_body
|
|
|
|
|
|
|
|
expect(parsed["topic_list"]["topics"].length).to eq(1)
|
|
|
|
expect(parsed["topic_list"]["topics"].first["id"]).to eq(topic2_with_tag.id)
|
|
|
|
|
2023-03-29 23:57:23 -05:00
|
|
|
get "/filter.json", params: { q: "tags:tag1", page: 1 }
|
2023-03-29 20:00:42 -05:00
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
parsed = response.parsed_body
|
|
|
|
|
|
|
|
expect(parsed["topic_list"]["topics"].length).to eq(1)
|
|
|
|
expect(parsed["topic_list"]["topics"].first["id"]).to eq(topic_with_tag.id)
|
|
|
|
end
|
|
|
|
end
|
2023-03-29 21:57:26 -05:00
|
|
|
|
2023-04-11 20:25:06 -05:00
|
|
|
describe "when filtering with the `created-by:<username>` filter" do
|
|
|
|
fab!(:topic2) { Fabricate(:topic, user: admin) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
topic.update!(user: user)
|
|
|
|
user.update!(username: "username")
|
|
|
|
admin.update!(username: "username2")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns only topics created by the user when `q` query param is `created-by:username`" do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get "/filter.json", params: { q: "created-by:username" }
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
expect(
|
|
|
|
response.parsed_body["topic_list"]["topics"].map { |topic| topic["id"] },
|
|
|
|
).to contain_exactly(topic.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns only topics created by either user when `q` query param is `created-by:username,username2`" do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get "/filter.json", params: { q: "created-by:username,username2" }
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
expect(
|
|
|
|
response.parsed_body["topic_list"]["topics"].map { |topic| topic["id"] },
|
|
|
|
).to contain_exactly(topic.id, topic2.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-08 01:04:47 -05:00
|
|
|
describe "when filtering with the `category:<category_slug>` filter" do
|
|
|
|
fab!(:topic_in_category) { Fabricate(:topic, category:) }
|
|
|
|
|
|
|
|
it "does not return any topics when `q` query param is `category:private-category-slug` and user is not allowed to see category" do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get "/filter.json", params: { q: "category:private-category-slug" }
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.parsed_body["topic_list"]["topics"].map { |topic| topic["id"] }).to eq([])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns only topics in the category when `q` query param is `category:private-category-slug` and user can see category" do
|
|
|
|
group.add(user)
|
|
|
|
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get "/filter.json", params: { q: "category:private-category-slug" }
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
expect(
|
|
|
|
response.parsed_body["topic_list"]["topics"].map { |topic| topic["id"] },
|
|
|
|
).to contain_exactly(topic_in_private_category.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-04-10 19:48:07 -05:00
|
|
|
describe "when filtering with the `in:<topic_notification_level>` filter" do
|
|
|
|
fab!(:user_muted_topic) do
|
|
|
|
Fabricate(:topic).tap do |topic|
|
|
|
|
TopicUser.change(
|
|
|
|
user.id,
|
|
|
|
topic.id,
|
|
|
|
notification_level: TopicUser.notification_levels[:muted],
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
fab!(:user_tracking_topic) do
|
|
|
|
Fabricate(:topic).tap do |topic|
|
|
|
|
TopicUser.change(
|
|
|
|
user.id,
|
|
|
|
topic.id,
|
|
|
|
notification_level: TopicUser.notification_levels[:tracking],
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not return topics that are muted by the user when `q` query param does not include `in:muted`" do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get "/filter.json", params: { q: "in:tracking" }
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
expect(response.parsed_body["topic_list"]["topics"].map { |topic| topic["id"] }).to eq(
|
|
|
|
[user_tracking_topic.id],
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "only return topics that are muted by the user when `q` query param is `in:muted`" do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get "/filter.json", params: { q: "in:muted" }
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
expect(response.parsed_body["topic_list"]["topics"].map { |topic| topic["id"] }).to eq(
|
|
|
|
[user_muted_topic.id],
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-02 23:40:00 -05:00
|
|
|
describe "when ordering using the `order:` filter" do
|
|
|
|
fab!(:topic2) { Fabricate(:topic, views: 2) }
|
|
|
|
fab!(:topic3) { Fabricate(:topic, views: 3) }
|
|
|
|
fab!(:topic4) { Fabricate(:topic, views: 1) }
|
|
|
|
|
|
|
|
it "return topics ordered by topic bumped at date in descending order when `q` query param is not present" do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get "/filter.json"
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
expect(response.parsed_body["topic_list"]["topics"].map { |topic| topic["id"] }).to eq(
|
|
|
|
[topic4.id, topic3.id, topic2.id, topic.id],
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "return topics ordered by views when `q` query param is `order:views`" do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get "/filter.json", params: { q: "order:views" }
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
expect(response.parsed_body["topic_list"]["topics"].map { |topic| topic["id"] }).to eq(
|
|
|
|
[topic3.id, topic2.id, topic4.id, topic.id],
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-03-29 21:57:26 -05:00
|
|
|
describe "when filtering by status" do
|
|
|
|
fab!(:group) { Fabricate(:group) }
|
|
|
|
fab!(:private_category) { Fabricate(:private_category, group: group) }
|
|
|
|
fab!(:topic_in_private_category) { Fabricate(:topic, category: private_category) }
|
|
|
|
|
2023-03-29 23:57:23 -05:00
|
|
|
it "does not return topics that are unlisted when `q` query param is `status:unlisted` for a user that cannot view unlisted topics" do
|
|
|
|
Topic.update_all(deleted_at: true)
|
|
|
|
topic.update!(visible: false)
|
|
|
|
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get "/filter.json", params: { q: "status:unlisted" }
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.parsed_body["topic_list"]["topics"].map { |topic| topic["id"] }).to eq([])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns topics that are unlisted when `q` query param is `status:unlisted` for a user that can view unlisted topics" do
|
|
|
|
Topic.update_all(visible: true)
|
|
|
|
topic.update!(visible: false)
|
|
|
|
|
|
|
|
sign_in(admin)
|
|
|
|
|
|
|
|
get "/filter.json", params: { q: "status:unlisted" }
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
expect(
|
|
|
|
response.parsed_body["topic_list"]["topics"].map { |topic| topic["id"] },
|
|
|
|
).to contain_exactly(topic.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "ignores the `status` filter for a user that cannot view deleted topics when `q` query param is `status:deleted`" do
|
|
|
|
Topic.update_all(deleted_at: nil)
|
|
|
|
topic.update!(deleted_at: Time.zone.now)
|
|
|
|
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get "/filter.json", params: { q: "status:deleted" }
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(response.parsed_body["topic_list"]["topics"].map { |topic| topic["id"] }).to eq([])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns topics that are deleted when `q` query param is `status:deleted` for a user that can view deleted topics" do
|
|
|
|
Topic.update_all(deleted_at: nil)
|
|
|
|
topic.update!(deleted_at: Time.zone.now)
|
|
|
|
|
|
|
|
sign_in(admin)
|
|
|
|
|
|
|
|
get "/filter.json", params: { q: "status:deleted" }
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
expect(
|
|
|
|
response.parsed_body["topic_list"]["topics"].map { |topic| topic["id"] },
|
|
|
|
).to contain_exactly(topic.id)
|
|
|
|
end
|
|
|
|
|
2023-03-29 21:57:26 -05:00
|
|
|
it "does not return topics from read restricted categories when `q` query param is `status:public`" do
|
|
|
|
group.add(user)
|
|
|
|
|
|
|
|
sign_in(user)
|
|
|
|
|
2023-03-29 23:57:23 -05:00
|
|
|
get "/filter.json", params: { q: "status:public" }
|
2023-03-29 21:57:26 -05:00
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
|
|
|
|
expect(
|
|
|
|
response.parsed_body["topic_list"]["topics"].map { |topic| topic["id"] },
|
2023-03-29 23:57:23 -05:00
|
|
|
).to contain_exactly(topic.id)
|
2023-03-29 21:57:26 -05:00
|
|
|
end
|
|
|
|
end
|
2023-03-02 19:46:21 -06:00
|
|
|
end
|
2017-08-30 23:06:56 -05:00
|
|
|
end
|