* Article query spec for scheduled articles * Added scheduled article badge on the user dashboard * Added published_at field to editor options * Accept and validate published_at from editor * Refactor published_at validation * Allow 1-minute difference in published_at * Notice on an unpublished article page * Added specs for 'Click to edit' link on scheduled article preview page * ContextNotification model * Articles::Publish worker * Added specs for articles publish worker * Schedule publish articles worker * Added tests to check for scheduled posts in feeds * Don't allow managing scheduled articles * Don't send notifications for scheduled articles * Set published_at in Articles::Updater when publishing * Published_at value in post options * Pass timezone and set published_at accordingly * Limit setting published_at to the future * Readonly published_at for articles that were already published * Chagning published_at format in editor v1 (start) * Changed published_at format in frontmatter, specs * Added specs for updating published_at from frontmatter * Fixed accepting past published_at for articles published_from_feed * Enabled published_at validation: don't allow updating published_at for already published articles * Validate published_at on create * Added a spec for updating published_at for exported articles * Fixed specs related to creating articles with past published_at * Fixed specs related to past published_at for articles * Added a hack so that admins would be able to update published_at * Switch button text schedule/publish when changin publishedAt * Fixed saving published_at with timezone * Added a feature flag for scheduling articles * Default text in markdown editor depends on feature flag * Enable article editor cache again * Fixed the default value in the markdown editor * Fix sitemaps spec * Removed tooltip * Fixed articles update specs * Added missing locales * Fixed article create specs * Fixed spec * Removed commented code * Returned enabling extensions in the schema * Returned accidentally deleted constraint * Make articles query spec more stable Co-authored-by: Jeremy Friesen <jeremy.n.friesen@gmail.com> * Removed commented code * Removed unused code * A clearer policy Co-authored-by: Jeremy Friesen <jeremy.n.friesen@gmail.com> * Use StringInquirer for article current state * Added a note and todo to articles factory past trait * Remove duplicated PropType Co-authored-by: Suzanne Aitchison <suzanne@forem.com> * Refactor query in the Articles::PublishWorker Co-authored-by: Mac Siri <krairit.siri@gmail.com> * Refactor articleForm.jsx Co-authored-by: Mac Siri <krairit.siri@gmail.com> * Removed specs that are no longer relevant * Removed useless onKeyUp on a hidden input * Refactored articleForm * Hide scheduling from post options when published_at is readonly * Run sends notifications worker every 5 minutes instead of every minute Co-authored-by: Jeremy Friesen <jeremy.n.friesen@gmail.com> Co-authored-by: Suzanne Aitchison <suzanne@forem.com> Co-authored-by: Mac Siri <krairit.siri@gmail.com>
167 lines
6.8 KiB
Ruby
167 lines
6.8 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "Sitemaps", type: :request do
|
|
describe "GET /sitemap-*" do
|
|
it "renders xml file" do
|
|
get "/sitemap-Mar-2011.xml"
|
|
expect(response.media_type).to eq("application/xml")
|
|
end
|
|
|
|
it "renders not found if incorrect input" do
|
|
expect { get "/sitemap-March-2011.xml" }.to raise_error(ActiveRecord::RecordNotFound)
|
|
end
|
|
|
|
it "renders not found if not valid date" do
|
|
expect { get "/sitemap-Mak-2011.xml" }.to raise_error(ActiveRecord::RecordNotFound)
|
|
end
|
|
|
|
it "renders proper surrogate header for recent sitemap" do
|
|
get "/sitemap-#{3.days.ago.strftime('%b-%Y')}.xml"
|
|
expect(response.header["Surrogate-Control"]).to include("8640")
|
|
end
|
|
|
|
it "renders proper surrogate header for older sitemap" do
|
|
get "/sitemap-#{35.days.ago.strftime('%b-%Y')}.xml"
|
|
expect(response.header["Surrogate-Control"]).to include("259200")
|
|
end
|
|
|
|
it "sends a surrogate key (for Fastly's user)" do
|
|
articles = create_list(:article, 4)
|
|
included_articles = articles.first(3)
|
|
included_articles.each { |a| a.update_columns(published_at: "2020-03-07T00:27:30Z", score: 10) }
|
|
|
|
get "/sitemap-Mar-2020.xml"
|
|
|
|
article = included_articles.first
|
|
|
|
expected_tag = "<loc>#{ApplicationConfig['APP_PROTOCOL']}#{ApplicationConfig['APP_DOMAIN']}#{article.path}</loc>"
|
|
expect(response.body).to include(expected_tag)
|
|
expect(response.body).to include("<lastmod>#{article.last_comment_at.strftime('%F')}</lastmod>")
|
|
expect(response.body).not_to include(articles.last.path)
|
|
expect(response.media_type).to eq("application/xml")
|
|
end
|
|
|
|
context "with index in param" do
|
|
it "renders basic index", :aggregate_failures do
|
|
get "/sitemap-index.xml"
|
|
expect(response.body).to include("<sitemapindex xmlns=")
|
|
expect(response.body).to include("sitemap-posts.xml")
|
|
expect(response.body).to include("sitemap-users.xml")
|
|
expect(response.body).to include("sitemap-tags.xml")
|
|
end
|
|
|
|
it "renders multiple posts pages if enough posts", :aggregate_failures do
|
|
create_list(:article, 13, score: 10)
|
|
get "/sitemap-index.xml"
|
|
expect(response.body).not_to include("sitemap-posts.xml")
|
|
expect(response.body).to include("sitemap-posts-0.xml")
|
|
expect(response.body).to include("sitemap-posts-2.xml")
|
|
expect(response.body).not_to include("sitemap-posts-3.xml")
|
|
end
|
|
end
|
|
|
|
context "with posts in param" do
|
|
before do
|
|
create_list(:article, 8, score: 10)
|
|
end
|
|
|
|
it "renders most recent posts if /sitemap-posts", :aggregate_failures do
|
|
get "/sitemap-posts.xml"
|
|
expect(response.body).to include(Article.order("published_at DESC").first.path)
|
|
expect(response.body).not_to include(Article.order("published_at DESC").last.path)
|
|
end
|
|
|
|
it "renders second page if /sitemap-posts-1", :aggregate_failures do
|
|
get "/sitemap-posts-1.xml"
|
|
expect(response.body).not_to include(Article.order("published_at DESC").first.path)
|
|
expect(response.body).to include(Article.order("published_at DESC").last.path)
|
|
end
|
|
|
|
it "renders first page if /sitemap-posts-randomn0tnumber", :aggregate_failures do
|
|
get "/sitemap-posts-randomn0tnumber.xml"
|
|
expect(response.body).to include(Article.order("published_at DESC").first.path)
|
|
expect(response.body).not_to include(Article.order("published_at DESC").last.path)
|
|
end
|
|
|
|
it "renders empty if /sitemap-posts-2", :aggregate_failures do
|
|
# no posts this far down.
|
|
get "/sitemap-posts-2.xml"
|
|
expect(response.body).not_to include(Article.order("published_at DESC").first.path)
|
|
expect(response.body).not_to include(Article.order("published_at DESC").last.path)
|
|
end
|
|
|
|
it "renders 'recent' version of surrogate control" do
|
|
get "/sitemap-posts-2.xml"
|
|
expect(response.header["Surrogate-Control"]).to include("8640")
|
|
end
|
|
end
|
|
|
|
context "with tags in param" do
|
|
before do
|
|
create_list(:tag, 8)
|
|
Tag.all.each do |tag|
|
|
tag.update_column(:hotness_score, rand(100_000))
|
|
end
|
|
end
|
|
|
|
it "renders hottest tags if /sitemap-tags", :aggregate_failures do
|
|
get "/sitemap-tags.xml"
|
|
expect(response.body).to include(Tag.order("hotness_score DESC").first.name)
|
|
expect(response.body).not_to include(Tag.order("hotness_score DESC").last.name)
|
|
end
|
|
|
|
it "renders second page if /sitemap-tags-1", :aggregate_failures do
|
|
get "/sitemap-tags-1.xml"
|
|
expect(response.body).not_to include(Tag.order("hotness_score DESC").first.name)
|
|
expect(response.body).to include(Tag.order("hotness_score DESC").last.name)
|
|
end
|
|
|
|
it "renders first page if /sitemap-tags-randomn0tnumber", :aggregate_failures do
|
|
get "/sitemap-tags-randomn0tnumber.xml"
|
|
expect(response.body).to include(Tag.order("hotness_score DESC").first.name)
|
|
expect(response.body).not_to include(Tag.order("hotness_score DESC").last.name)
|
|
end
|
|
|
|
it "renders empty if /sitemap-tags-2", :aggregate_failures do
|
|
# no posts this far down.
|
|
get "/sitemap-tags-2.xml"
|
|
expect(response.body).not_to include(Tag.order("hotness_score DESC").first.name)
|
|
expect(response.body).not_to include(Tag.order("hotness_score DESC").last.name)
|
|
end
|
|
end
|
|
|
|
context "with users in param" do
|
|
before do
|
|
create_list(:user, 8)
|
|
User.all.each do |user|
|
|
user.update_column(:comments_count, rand(100_000))
|
|
end
|
|
end
|
|
|
|
it "renders hottest tags if /sitemap-users", :aggregate_failures do
|
|
get "/sitemap-users.xml"
|
|
expect(response.body).to include(User.order("comments_count DESC").first.username)
|
|
expect(response.body).not_to include(User.order("comments_count DESC").last.username)
|
|
end
|
|
|
|
it "renders second page if /sitemap-users-1", :aggregate_failures do
|
|
get "/sitemap-users-1.xml"
|
|
expect(response.body).not_to include(User.order("comments_count DESC").first.username)
|
|
expect(response.body).to include(User.order("comments_count DESC").last.username)
|
|
end
|
|
|
|
it "renders first page if /sitemap-users-randomn0tnumber", :aggregate_failures do
|
|
get "/sitemap-users-randomn0tnumber.xml"
|
|
expect(response.body).to include(User.order("comments_count DESC").first.username)
|
|
expect(response.body).not_to include(User.order("comments_count DESC").last.username)
|
|
end
|
|
|
|
it "renders empty if /sitemap-users-2", :aggregate_failures do
|
|
# no posts this far down.
|
|
get "/sitemap-users-2.xml"
|
|
expect(response.body).not_to include(User.order("comments_count DESC").first.username)
|
|
expect(response.body).not_to include(User.order("comments_count DESC").last.username)
|
|
end
|
|
end
|
|
end
|
|
end
|