* 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>
77 lines
3.7 KiB
Ruby
77 lines
3.7 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe Articles::ActiveThreadsQuery, type: :query do
|
|
before do
|
|
create(:article, score: described_class::MINIMUM_SCORE - 1, tags: "watercooler")
|
|
end
|
|
|
|
describe "::call" do
|
|
context "when time_ago is latest" do
|
|
it "returns the latest article with a good score", :aggregate_failures do
|
|
article = create(:article, tags: "discuss", score: described_class::MINIMUM_SCORE + 1)
|
|
create(:article, :past, past_published_at: 2.days.ago, tags: "discuss",
|
|
score: described_class::MINIMUM_SCORE + 1)
|
|
|
|
result = described_class.call(tags: "discuss", time_ago: "latest", count: 10)
|
|
expect(result.length).to eq(2)
|
|
expect(result.first.first).to eq(article.path)
|
|
end
|
|
|
|
it "returns any article if no higher-quality article is found", :aggregate_failures do
|
|
article = create(:article, tags: "discuss", score: described_class::MINIMUM_SCORE - 10)
|
|
|
|
result = described_class.call(tags: "discuss", time_ago: "latest", count: 10)
|
|
expect(result.length).to eq(1)
|
|
expect(result.first.first).to eq(article.path)
|
|
end
|
|
end
|
|
|
|
context "when given a precise time" do
|
|
it "returns article ordered_by comment_count based on time", :aggregate_failures do
|
|
time = 2.days.ago
|
|
article = create(:article, :past, comments_count: 20, past_published_at: time, tags: "discuss",
|
|
score: described_class::MINIMUM_SCORE)
|
|
create(:article, comments_count: 10, tags: "discuss", score: described_class::MINIMUM_SCORE)
|
|
create(:article, :past, past_published_at: time - 2.days, comments_count: 30, tags: "discuss",
|
|
score: described_class::MINIMUM_SCORE)
|
|
|
|
result = described_class.call(tags: "discuss", time_ago: time, count: 10)
|
|
expect(result.length).to eq(2)
|
|
expect(result.first.first).to eq(article.path)
|
|
end
|
|
|
|
it "returns any article when no higher-quality article could be found", :aggregate_failures do
|
|
time = 2.days.ago
|
|
article = create(:article, :past, comments_count: 20, past_published_at: time - 5.days, tags: "discuss",
|
|
score: described_class::MINIMUM_SCORE)
|
|
create(:article, comments_count: 10, tags: "discuss", score: described_class::MINIMUM_SCORE - 10)
|
|
|
|
result = described_class.call(tags: "discuss", time_ago: time, count: 10)
|
|
expect(result.length).to eq(2)
|
|
expect(result.first.first).to eq(article.path)
|
|
end
|
|
end
|
|
|
|
context "when time_ago is not given" do
|
|
it "returns articles ordered by last_comment_at, not based on time", :aggregate_failures do
|
|
article = create(:article, last_comment_at: Time.zone.now, tags: "discuss",
|
|
score: described_class::MINIMUM_SCORE)
|
|
create(:article, last_comment_at: nil, tags: "discuss", score: described_class::MINIMUM_SCORE)
|
|
|
|
result = described_class.call(tags: "discuss", time_ago: nil, count: 10)
|
|
expect(result.length).to eq(2)
|
|
expect(result.first.first).to eq(article.path)
|
|
end
|
|
|
|
it "returns any article, with nil articles last, if no higher-quality articles exist", :aggregate_failures do
|
|
article = create(:article, last_comment_at: Time.zone.now, tags: "discuss",
|
|
score: described_class::MINIMUM_SCORE - 10)
|
|
create(:article, last_comment_at: 2.days.ago, tags: "discuss", score: described_class::MINIMUM_SCORE - 10)
|
|
|
|
result = described_class.call(tags: "discuss", time_ago: nil, count: 10)
|
|
expect(result.length).to eq(2)
|
|
expect(result.first.first).to eq(article.path)
|
|
end
|
|
end
|
|
end
|
|
end
|