DEV: Apply syntax_tree formatting to spec/*

This commit is contained in:
David Taylor
2023-01-09 11:18:21 +00:00
parent 0cf6421716
commit cb932d6ee1
907 changed files with 58693 additions and 45909 deletions

View File

@@ -7,9 +7,7 @@ RSpec.describe PublishedPagesController do
fab!(:user2) { Fabricate(:user) }
context "when enabled" do
before do
SiteSetting.enable_page_publishing = true
end
before { SiteSetting.enable_page_publishing = true }
context "when checking slug availability" do
it "returns true for a new slug" do
@@ -40,12 +38,9 @@ RSpec.describe PublishedPagesController do
end
describe "#show" do
it 'records a view' do
it "records a view" do
sign_in(user2)
expect do
get published_page.path
end.to change(TopicViewItem, :count).by(1)
expect do get published_page.path end.to change(TopicViewItem, :count).by(1)
end
it "returns 404 for a missing article" do
@@ -57,9 +52,7 @@ RSpec.describe PublishedPagesController do
fab!(:group) { Fabricate(:group) }
fab!(:private_category) { Fabricate(:private_category, group: group) }
before do
published_page.topic.update!(category: private_category)
end
before { published_page.topic.update!(category: private_category) }
it "returns 403 for a topic you can't see" do
get published_page.path
@@ -67,9 +60,9 @@ RSpec.describe PublishedPagesController do
end
context "when published page is public" do
fab!(:public_published_page) {
fab!(:public_published_page) do
Fabricate(:published_page, public: true, slug: "a-public-page")
}
end
it "returns 200 for a topic you can't see" do
get public_published_page.path
@@ -78,9 +71,7 @@ RSpec.describe PublishedPagesController do
end
context "as an admin" do
before do
sign_in(admin)
end
before { sign_in(admin) }
it "returns 200" do
get published_page.path
@@ -120,7 +111,9 @@ RSpec.describe PublishedPagesController do
it "works even if image logos are not available" do
SiteSetting.logo_small = nil
get published_page.path
expect(response.body).to include("<img class=\"published-page-logo\" src=\"#{SiteSetting.logo.url}\"/>")
expect(response.body).to include(
"<img class=\"published-page-logo\" src=\"#{SiteSetting.logo.url}\"/>",
)
SiteSetting.logo = nil
get published_page.path
@@ -129,7 +122,9 @@ 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.slug} 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 "when login is required" do
@@ -139,9 +134,7 @@ RSpec.describe PublishedPagesController do
end
context "when a user is connected" do
before do
sign_in(user)
end
before { sign_in(user) }
it "returns 200" do
get published_page.path
@@ -155,9 +148,7 @@ RSpec.describe PublishedPagesController do
end
context "when login required is enabled" do
before do
SiteSetting.show_published_pages_login_required = true
end
before { SiteSetting.show_published_pages_login_required = true }
it "returns 200" do
get published_page.path
@@ -174,54 +165,63 @@ RSpec.describe PublishedPagesController do
it "returns invalid access for non-staff" do
sign_in(user)
put "/pub/by-topic/#{topic.id}.json", params: { published_page: { slug: 'cant-do-this' } }
put "/pub/by-topic/#{topic.id}.json", params: { published_page: { slug: "cant-do-this" } }
expect(response.status).to eq(403)
end
context "with a valid staff account" do
before do
sign_in(admin)
end
before { sign_in(admin) }
it "creates the published page record" do
put "/pub/by-topic/#{topic.id}.json", params: { published_page: { slug: 'i-hate-salt' } }
put "/pub/by-topic/#{topic.id}.json", params: { published_page: { slug: "i-hate-salt" } }
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(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?(
acting_user_id: admin.id,
action: UserHistory.actions[:page_published],
topic_id: topic.id
)).to be(true)
expect(
PublishedPage.exists?(topic_id: response.parsed_body["published_page"]["id"]),
).to eq(true)
expect(
UserHistory.exists?(
acting_user_id: admin.id,
action: UserHistory.actions[:page_published],
topic_id: topic.id,
),
).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 } }
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(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)
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' } }
PublishedPage.create!(slug: "i-hate-salt", topic: Fabricate(:topic))
put "/pub/by-topic/#{topic.id}.json", params: { published_page: { slug: "i-hate-salt" } }
expect(response).not_to be_successful
expect(response.parsed_body['errors']).to eq(['Slug has already been taken'])
expect(response.parsed_body["errors"]).to eq(["Slug has already been taken"])
end
it "returns an error if the topic already has been published" do
PublishedPage.create!(slug: 'already-done-pal', topic: topic)
put "/pub/by-topic/#{topic.id}.json", params: { published_page: { slug: 'i-hate-salt' } }
PublishedPage.create!(slug: "already-done-pal", topic: topic)
put "/pub/by-topic/#{topic.id}.json", params: { published_page: { slug: "i-hate-salt" } }
expect(response).to be_successful
expect(PublishedPage.exists?(topic_id: topic.id)).to eq(true)
end
end
end
@@ -233,9 +233,7 @@ RSpec.describe PublishedPagesController do
end
context "with a valid staff account" do
before do
sign_in(admin)
end
before { sign_in(admin) }
it "deletes the record" do
topic_id = published_page.topic_id
@@ -244,20 +242,20 @@ RSpec.describe PublishedPagesController do
expect(response).to be_successful
expect(PublishedPage.exists?(slug: published_page.slug)).to eq(false)
expect(UserHistory.exists?(
acting_user_id: admin.id,
action: UserHistory.actions[:page_unpublished],
topic_id: topic_id
)).to be(true)
expect(
UserHistory.exists?(
acting_user_id: admin.id,
action: UserHistory.actions[:page_unpublished],
topic_id: topic_id,
),
).to be(true)
end
end
end
end
context "when disabled" do
before do
SiteSetting.enable_page_publishing = false
end
before { SiteSetting.enable_page_publishing = false }
it "returns 404 for any article" do
get published_page.path