mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
FEATURE: allows published pages to be public (#10053)
This commit is contained in:
@ -59,6 +59,15 @@ RSpec.describe PublishedPagesController do
|
||||
expect(response.status).to eq(403)
|
||||
end
|
||||
|
||||
context "published page is public" do
|
||||
fab!(:public_published_page) { Fabricate(:published_page, public: true) }
|
||||
|
||||
it "returns 200 for a topic you can't see" do
|
||||
get public_published_page.path
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
end
|
||||
|
||||
context "as an admin" do
|
||||
before do
|
||||
sign_in(admin)
|
||||
@ -89,7 +98,42 @@ RSpec.describe PublishedPagesController do
|
||||
|
||||
it "defines correct css classes on body" do
|
||||
get published_page.path
|
||||
expect(response.body).to include("<body class=\"published-page published-page-test topic-#{published_page.topic_id} recipes uncategorized\">")
|
||||
expect(response.body).to include("<body class=\"published-page #{published_page.slug} topic-#{published_page.topic_id} recipes uncategorized\">")
|
||||
end
|
||||
|
||||
context "login is required" do
|
||||
before do
|
||||
SiteSetting.login_required = true
|
||||
SiteSetting.show_published_pages_login_required = false
|
||||
end
|
||||
|
||||
context "a user is connected" do
|
||||
before do
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
it "returns 200" do
|
||||
get published_page.path
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
end
|
||||
|
||||
context "no user connected" do
|
||||
it "redirects to login page" do
|
||||
expect(get(published_page.path)).to redirect_to("/login")
|
||||
end
|
||||
|
||||
context "show public pages with login required is enabled" do
|
||||
before do
|
||||
SiteSetting.show_published_pages_login_required = true
|
||||
end
|
||||
|
||||
it "returns 200" do
|
||||
get published_page.path
|
||||
expect(response.status).to eq(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -113,6 +157,7 @@ RSpec.describe PublishedPagesController do
|
||||
expect(response).to be_successful
|
||||
expect(response.parsed_body['published_page']).to be_present
|
||||
expect(response.parsed_body['published_page']['slug']).to eq("i-hate-salt")
|
||||
expect(response.parsed_body['published_page']['public']).to eq(false)
|
||||
|
||||
expect(PublishedPage.exists?(topic_id: response.parsed_body['published_page']['id'])).to eq(true)
|
||||
expect(UserHistory.exists?(
|
||||
@ -122,6 +167,16 @@ RSpec.describe PublishedPagesController do
|
||||
)).to be(true)
|
||||
end
|
||||
|
||||
it "allows to set public field" do
|
||||
put "/pub/by-topic/#{topic.id}.json", params: { published_page: { slug: 'i-hate-salt', public: true } }
|
||||
expect(response).to be_successful
|
||||
expect(response.parsed_body['published_page']).to be_present
|
||||
expect(response.parsed_body['published_page']['slug']).to eq("i-hate-salt")
|
||||
expect(response.parsed_body['published_page']['public']).to eq(true)
|
||||
|
||||
expect(PublishedPage.exists?(topic_id: response.parsed_body['published_page']['id'])).to eq(true)
|
||||
end
|
||||
|
||||
it "returns an error if the slug is already taken" do
|
||||
PublishedPage.create!(slug: 'i-hate-salt', topic: Fabricate(:topic))
|
||||
put "/pub/by-topic/#{topic.id}.json", params: { published_page: { slug: 'i-hate-salt' } }
|
||||
|
Reference in New Issue
Block a user