* 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>
83 lines
2.9 KiB
Ruby
83 lines
2.9 KiB
Ruby
FactoryBot.define do
|
|
sequence(:title) { |n| "#{Faker::Book.title}#{n}" }
|
|
|
|
factory :article do
|
|
published_at { Time.current }
|
|
|
|
transient do
|
|
title { generate :title }
|
|
published { true }
|
|
date { "01/01/2015" }
|
|
tags { "javascript, html, discuss" }
|
|
canonical_url { Faker::Internet.url }
|
|
with_canonical_url { false }
|
|
with_main_image { true }
|
|
with_date { false }
|
|
with_tags { true }
|
|
with_hr_issue { false }
|
|
with_tweet_tag { false }
|
|
with_user_subscription_tag { false }
|
|
with_title { true }
|
|
with_collection { nil }
|
|
past_published_at { Time.current }
|
|
end
|
|
co_author_ids { [] }
|
|
association :user, factory: :user, strategy: :create
|
|
description { Faker::Hipster.paragraph(sentence_count: 1)[0..100] }
|
|
main_image do
|
|
if with_main_image
|
|
URL.url(ActionController::Base.helpers.asset_path("#{rand(1..40)}.png"))
|
|
end
|
|
end
|
|
experience_level_rating { rand(4..6) }
|
|
body_markdown do
|
|
<<~HEREDOC
|
|
---
|
|
title: #{title if with_title}
|
|
published: #{published}
|
|
tags: #{tags if with_tags}
|
|
date: #{date if with_date}
|
|
series: #{with_collection&.slug if with_collection}
|
|
canonical_url: #{canonical_url if with_canonical_url}
|
|
#{"cover_image: #{Faker::Avatar.image}" if with_main_image && main_image_from_frontmatter}
|
|
---
|
|
|
|
#{Faker::Hipster.paragraph(sentence_count: 2)}
|
|
#{'{% tweet 1018911886862057472 %}' if with_tweet_tag}
|
|
#{'{% user_subscription CTA text %}' if with_user_subscription_tag}
|
|
#{Faker::Hipster.paragraph(sentence_count: 1)}
|
|
#{"\n\n---\n\n something \n\n---\n funky in the code? \n---\n That's nice" if with_hr_issue}
|
|
HEREDOC
|
|
end
|
|
end
|
|
|
|
trait :video do
|
|
after(:build) do |article|
|
|
article.video = "https://s3.amazonaws.com/dev-to-input-v0/video-upload__2d7dc29e39a40c7059572bca75bb646b"
|
|
article.save
|
|
end
|
|
end
|
|
|
|
trait :with_notification_subscription do
|
|
after(:create) do |article|
|
|
create(:notification_subscription, user_id: article.user_id, notifiable: article)
|
|
end
|
|
end
|
|
|
|
trait :with_user_subscription_tag_role_user do
|
|
after(:build) { |article| article.user.add_role(:restricted_liquid_tag, LiquidTags::UserSubscriptionTag) }
|
|
end
|
|
|
|
trait :with_discussion_lock do
|
|
after(:create) { |article| create(:discussion_lock, locking_user_id: article.user_id, article_id: article.id) }
|
|
end
|
|
|
|
# NOTE: [@lightalloy] This trait is used to create articles published in the past (with past published_at)
|
|
# we can't do it directly because of the validation Article#has_correct_published_at?
|
|
# TODO: [@lightalloy] Remove the trait and its usage when has_correct_published_at? will be removed
|
|
trait :past do
|
|
after(:create) do |article, evaluator|
|
|
article.update_column(:published_at, evaluator.past_published_at)
|
|
end
|
|
end
|
|
end
|