2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-11 04:41:23 -05:00
|
|
|
require 'rails_helper'
|
2015-07-15 07:54:28 -05:00
|
|
|
|
|
|
|
describe Admin::PermalinksController do
|
|
|
|
|
|
|
|
it "is a subclass of AdminController" do
|
|
|
|
expect(Admin::PermalinksController < Admin::AdminController).to eq(true)
|
|
|
|
end
|
|
|
|
|
2019-05-06 22:12:20 -05:00
|
|
|
fab!(:admin) { Fabricate(:admin) }
|
2015-07-15 07:54:28 -05:00
|
|
|
|
2018-06-10 23:37:21 -05:00
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#index' do
|
2015-07-15 07:54:28 -05:00
|
|
|
it 'filters url' do
|
|
|
|
Fabricate(:permalink, url: "/forum/23")
|
|
|
|
Fabricate(:permalink, url: "/forum/98")
|
|
|
|
Fabricate(:permalink, url: "/discuss/topic/45")
|
|
|
|
Fabricate(:permalink, url: "/discuss/topic/76")
|
|
|
|
|
2018-06-10 23:37:21 -05:00
|
|
|
get "/admin/permalinks.json", params: { filter: "topic" }
|
2015-07-15 07:54:28 -05:00
|
|
|
|
2018-06-07 03:11:09 -05:00
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 10:04:12 -05:00
|
|
|
result = response.parsed_body
|
2015-07-15 07:54:28 -05:00
|
|
|
expect(result.length).to eq(2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters external url' do
|
|
|
|
Fabricate(:permalink, external_url: "http://google.com")
|
|
|
|
Fabricate(:permalink, external_url: "http://wikipedia.org")
|
|
|
|
Fabricate(:permalink, external_url: "http://www.discourse.org")
|
|
|
|
Fabricate(:permalink, external_url: "http://try.discourse.org")
|
|
|
|
|
2018-06-10 23:37:21 -05:00
|
|
|
get "/admin/permalinks.json", params: { filter: "discourse" }
|
2015-07-15 07:54:28 -05:00
|
|
|
|
2018-06-07 03:11:09 -05:00
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 10:04:12 -05:00
|
|
|
result = response.parsed_body
|
2015-07-15 07:54:28 -05:00
|
|
|
expect(result.length).to eq(2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters url and external url both' do
|
|
|
|
Fabricate(:permalink, url: "/forum/23", external_url: "http://google.com")
|
|
|
|
Fabricate(:permalink, url: "/discourse/98", external_url: "http://wikipedia.org")
|
|
|
|
Fabricate(:permalink, url: "/discuss/topic/45", external_url: "http://discourse.org")
|
|
|
|
Fabricate(:permalink, url: "/discuss/topic/76", external_url: "http://try.discourse.org")
|
|
|
|
|
2018-06-10 23:37:21 -05:00
|
|
|
get "/admin/permalinks.json", params: { filter: "discourse" }
|
2015-07-15 07:54:28 -05:00
|
|
|
|
2018-06-07 03:11:09 -05:00
|
|
|
expect(response.status).to eq(200)
|
2020-05-07 10:04:12 -05:00
|
|
|
result = response.parsed_body
|
2015-07-15 07:54:28 -05:00
|
|
|
expect(result.length).to eq(3)
|
|
|
|
end
|
|
|
|
end
|
2020-05-25 04:48:54 -05:00
|
|
|
|
|
|
|
describe "#create" do
|
|
|
|
it "works for topics" do
|
|
|
|
topic = Fabricate(:topic)
|
|
|
|
|
|
|
|
post "/admin/permalinks.json", params: {
|
|
|
|
url: "/topics/771",
|
|
|
|
permalink_type: "topic_id",
|
|
|
|
permalink_type_value: topic.id
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(Permalink.last).to have_attributes(url: "topics/771", topic_id: topic.id, post_id: nil, category_id: nil, tag_id: nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "works for posts" do
|
|
|
|
some_post = Fabricate(:post)
|
|
|
|
|
|
|
|
post "/admin/permalinks.json", params: {
|
|
|
|
url: "/topics/771/8291",
|
|
|
|
permalink_type: "post_id",
|
|
|
|
permalink_type_value: some_post.id
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(Permalink.last).to have_attributes(url: "topics/771/8291", topic_id: nil, post_id: some_post.id, category_id: nil, tag_id: nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "works for categories" do
|
|
|
|
category = Fabricate(:category)
|
|
|
|
|
|
|
|
post "/admin/permalinks.json", params: {
|
|
|
|
url: "/forums/11",
|
|
|
|
permalink_type: "category_id",
|
|
|
|
permalink_type_value: category.id
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(Permalink.last).to have_attributes(url: "forums/11", topic_id: nil, post_id: nil, category_id: category.id, tag_id: nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "works for tags" do
|
|
|
|
tag = Fabricate(:tag)
|
|
|
|
|
|
|
|
post "/admin/permalinks.json", params: {
|
|
|
|
url: "/forums/12",
|
|
|
|
permalink_type: "tag_name",
|
|
|
|
permalink_type_value: tag.name
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(Permalink.last).to have_attributes(url: "forums/12", topic_id: nil, post_id: nil, category_id: nil, tag_id: tag.id)
|
|
|
|
end
|
|
|
|
end
|
2015-07-15 07:54:28 -05:00
|
|
|
end
|