Create DelayedJob config and misc DX changes (#979)

* Change from #after_save to #after_create

* Update .babelrc

* Update cloud_name for test

* Update SlackBot's RssReader channel

* Update helpful-hints.md

* Create .gitdocs.json

* Remove serve-docs script

* Update docs/helpful-hints.md

* Update approval

* Revert "Change from #after_save to #after_create"

This reverts commit 548ee0d2c0d56a1aa67316468f4106ac9f437662.

* Create delayed_job.rb

* Bump ancestry gem to 3.0.3

* Fix broken spec

* Remove manual Delayed::Job config in test

* Update spec_helper.rb

* Fix broken specs

* Mute SlackBot in test

* Remove weekly-dgiest.yml

* Create PodcastEpisodeDecorator
This commit is contained in:
Mac Siri 2018-10-26 13:15:14 -04:00 committed by Ben Halpern
parent 2b2a7afb03
commit 5287d4a03b
26 changed files with 75 additions and 65 deletions

View file

@ -1,37 +1,21 @@
{
"presets": [
["env", {
"modules": false,
"targets": {
"browsers": "> 1%",
"uglify": true
},
"useBuiltIns": true
}],
"preact"
["env", { "modules": false, "targets": { "browsers": "> 1%", "uglify": true }, "useBuiltIns": true }],
"preact",
],
"env": {
"test": {
"plugins": [
"transform-es2015-modules-commonjs",
["transform-react-jsx", { "pragma":"h" }],
"transform-class-properties"
]
}
},
"plugins": [
"syntax-dynamic-import",
"transform-object-rest-spread",
["transform-class-properties",
{
"spec": true
}
],
[
"transform-react-jsx",
{
"pragma": "h"
}
]
["transform-class-properties", { "spec": true }],
[ "transform-react-jsx", { "pragma": "h" }]
]
}

11
.gitdocs.js Normal file
View file

@ -0,0 +1,11 @@
/*
* This file is created so that it's possible to
* Run `gitdocs serve` from root
*/
var config = require('./docs/.gitdocs.json');
module.exports = new Promise((resolve, reject) => {
config.root = 'docs/';
resolve(config);
});

View file

@ -1,7 +0,0 @@
# Configuration for weekly-digest - https://github.com/apps/weekly-digest
publishDay: mon
canPublishIssues: true
canPublishPullRequests: true
canPublishContributors: true
canPublishStargazers: true
canPublishCommits: true

View file

@ -123,7 +123,7 @@ GEM
algorithmia (1.0.1)
httparty (~> 0.13)
json (~> 1.8)
ancestry (3.0.2)
ancestry (3.0.3)
activerecord (>= 3.2.0)
approvals (0.0.24)
nokogiri (~> 1.6)

View file

@ -0,0 +1,11 @@
class PodcastEpisodeDecorator < ApplicationDecorator
delegate_all
def comments_to_show_count
cached_tag_list_array.include?("discuss") ? 75 : 25
end
def cached_tag_list_array
(tag_list || "").split(", ")
end
end

View file

@ -26,7 +26,7 @@ class RateLimitChecker
end
def ping_admins
return unless user
return unless user && Rails.env.production?
SlackBot.ping(
"Rate limit exceeded. https://dev.to#{user.path}",
channel: "abuse-reports",

View file

@ -72,9 +72,10 @@ class RssReader
organization_id: user.organization_id.present? ? user.organization_id : nil
}
article = Article.create!(article_params)
return unless Rails.env.production?
SlackBot.delay.ping(
"New Article Retrieved via RSS: #{article.title}\nhttps://dev.to#{article.path}",
channel: "activity",
channel: Rails.env.production? ? "activity" : "test",
username: "article_bot",
icon_emoji: ":robot_face:",
)

View file

@ -27,7 +27,6 @@ class ParlerTag < LiquidTagBase
end
def valid_id?(id)
puts id
id =~ /\A(https:\/\/www.parler.io\/audio\/\d{1,11}\/[a-zA-Z0-9]{11,40}.[0-9a-zA-Z-]{11,36}.mp3)\Z/
end
end

View file

@ -228,7 +228,7 @@ class Comment < ApplicationRecord
def self.comment_async_bust(commentable, username)
commentable.touch
commentable.touch(:last_comment_at)
commentable.touch(:last_comment_at) if commentable.respond_to?(:last_comment_at)
CacheBuster.new.bust_comment(commentable, username)
commentable.index!
end

View file

@ -135,7 +135,7 @@ class Reaction < ApplicationRecord
errors.add(:category, "is not valid.")
end
if reactable_type == "Article" && !reactable.published
if reactable_type == "Article" && !reactable&.published
errors.add(:reactable_id, "is not valid.")
end
end

View file

@ -1,5 +1,5 @@
Cloudinary.config do |config|
config.cloud_name = ApplicationConfig["CLOUDINARY_CLOUD_NAME"]
config.cloud_name = Rails.env.test? ? "TEST-CLOUD" : ApplicationConfig["CLOUDINARY_CLOUD_NAME"]
config.api_key = ApplicationConfig["CLOUDINARY_API_KEY"]
config.api_secret = ApplicationConfig["CLOUDINARY_API_SECRET"]
config.secure = ApplicationConfig["CLOUDINARY_SECURE"]

View file

@ -0,0 +1,6 @@
Delayed::Worker.destroy_failed_jobs = true
Delayed::Worker.sleep_delay = 60
Delayed::Worker.max_attempts = 10
Delayed::Worker.max_run_time = 30.minutes
Delayed::Worker.read_ahead = 5
Delayed::Worker.delay_jobs = !Rails.env.test?

View file

@ -7,4 +7,7 @@ You can view the previews at (for example) `http://localhost:3000/rails/mailers/
## Previewing these docs in development
Run `yarn run serve-docs` and visit `http://localhost:8000` in your browser.
0. Make sure you are at the base of the repository
1. Install gitdocs `npm install -g gitdocs@next`
1. Serve it `gitdocs serve`
1. Visit `http://localhost:8000`

View file

@ -13,8 +13,7 @@
"test:watch": "jest app/javascript/ --watch",
"storybook": "start-storybook -p 6006 -c app/javascript/.storybook -s app/javascript/.storybook/assets",
"build-storybook": "build-storybook -c app/javascript/.storybook -s app/javascript/.storybook/assets",
"precommit": "lint-staged",
"serve-docs": "cd docs && gitdocs serve"
"precommit": "lint-staged"
},
"lint-staged": {
"*.{js,jsx}": [

View file

@ -8,6 +8,8 @@ FactoryBot.define do
image { image }
description { Faker::Hipster.paragraph(1) }
slug { "slug-#{rand(10_000)}" }
feed_url { "slug-#{rand(10_000)}" }
feed_url { Faker::Internet.url }
after(:build) { |pod| pod.define_singleton_method(:pull_all_episodes) {} }
end
end

View file

@ -1,7 +1,7 @@
FactoryBot.define do
factory :reaction do
reactable_id { rand(10000) }
user_id { rand(10000) }
user
reactable_type { "Article" }
category { "like" }
end

View file

@ -27,6 +27,7 @@ RSpec.describe "Editing A Comment", type: :feature, js: true do
context "when user edits via permalinks" do
it "updates" do
user.reload
visit user.comments.last.path.to_s
click_link("EDIT")
assert_updated

View file

@ -13,7 +13,6 @@ RSpec.describe "Looking For Work" do
visit "/settings"
page.check "Looking for work"
click_button("submit")
Delayed::Worker.new.work_off
expect(user.follows.count).to eq(1)
end
end

View file

@ -13,14 +13,9 @@ RSpec.describe EmailDigest do
before do
allow(DigestMailer).to receive(:digest_email) { mock_delegator }
allow(mock_delegator).to receive(:deliver).and_return(true)
Delayed::Worker.delay_jobs = false
user
end
after do
Delayed::Worker.delay_jobs = true
end
describe "::send_digest_email" do
context "when there's article to be sent" do
before { user.follow(author) }

View file

@ -21,7 +21,6 @@ RSpec.describe ParlerTag, type: :liquid_template do
it "accepts a valid Parler URL" do
liquid = generate_new_liquid(valid_id)
puts liquid
expect(liquid.render).to eq(generate_iframe(valid_id))
end

View file

@ -414,15 +414,13 @@ RSpec.describe Article, type: :model do
end
it "updates main_image_background_hex_color" do
article = build(:article)
allow(article).to receive(:update_main_image_background_hex).and_call_original
article.save
expect(article.update_main_image_background_hex_without_delay).to eq(true)
expect(article).to have_received(:update_main_image_background_hex)
end
describe "#async_score_calc" do
before { Delayed::Worker.delay_jobs = false }
after { Delayed::Worker.delay_jobs = true }
context "when published" do
let(:article) { create(:article) }

View file

@ -14,11 +14,6 @@ RSpec.describe Mention, type: :model do
)
end
before do
# Run workers synchronously
# Delayed::Worker.delay_jobs = false
end
it "creates mention if there is a user mentioned" do
comment.body_markdown = "Hello @#{user.username}, you are cool."
comment.save

View file

@ -29,7 +29,9 @@ RSpec.describe MentorRelationship, type: :model do
it "sends an email to both users" do
relationship.save!
expect(EmailMessage.all.size).to eq(2)
["mentor_email", "mentee_email"].each do |campaign|
expect(EmailMessage.where(utm_campaign: campaign).count).to eq(1)
end
end
it "finds unmatched mentors" do

View file

@ -9,7 +9,20 @@ RSpec.describe Reaction, type: :model do
create(:comment, user_id: user.id, commentable_id: article.id, commentable_type: "Article")
end
let(:reaction) do
build(:reaction, user_id: user.id, reactable_id: comment.id, reactable_type: "Comment")
build(:reaction, reactable: comment, reactable_type: "Comment")
end
describe "actual validation" do
subject { Reaction.new(reactable: article, reactable_type: "Article", user: user) }
before { user.add_role(:trusted) }
it { is_expected.to belong_to(:user) }
it { is_expected.to validate_inclusion_of(:category).in_array(%w(like thinking hands unicorn thumbsdown vomit readinglist)) }
it { is_expected.to validate_uniqueness_of(:user_id).scoped_to(%i[reactable_id reactable_type category]) }
# Thumbsdown and Vomits test needed
# it { is_expected.to validate_inclusion_of(:reactable_type).in_array(%w(Comment Article)) }
end
describe "validations" do
@ -46,7 +59,7 @@ RSpec.describe Reaction, type: :model do
end
context "when user is trusted" do
before { user.add_role(:trusted) }
before { reaction.user.add_role(:trusted) }
it "allows vomit reactions for users with trusted role" do
reaction.category = "vomit"
@ -64,10 +77,8 @@ RSpec.describe Reaction, type: :model do
it "runs async jobs effectively" do
u2 = create(:user)
c2 = create(:comment, commentable_id: article.id)
Delayed::Worker.delay_jobs = false
create(:reaction, user_id: u2.id, reactable_id: c2.id, reactable_type: "Comment")
create(:reaction, user_id: u2.id, reactable_id: article.id, reactable_type: "Article")
Delayed::Worker.delay_jobs = true
expect(reaction).to be_valid
end
end

View file

@ -422,6 +422,7 @@ RSpec.describe User, type: :model do
it "returns onboarding checklist leave_your_first_comment if has left comment" do
create(:comment, user_id: user.id, commentable_id: article.id, commentable_type: "Article")
user.reload
checklist = UserStates.new(user).cached_onboarding_checklist[:leave_your_first_comment]
expect(checklist).to eq(true)
end

View file

@ -24,8 +24,8 @@
<ol><li>Item 2a</li>
</ol></li>
</ol><p><a href="https://res.cloudinary.com/Optional/image/fetch/s---YMUCaHJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/link" class="article-body-image-wrapper"><img src="https://res.cloudinary.com/Optional/image/fetch/s---YMUCaHJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/link" alt="GitHub Logo" /></a><br />
Format: <a href="https://res.cloudinary.com/Optional/image/fetch/s--6OyC0V7g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/url" class="article-body-image-wrapper"><img src="https://res.cloudinary.com/Optional/image/fetch/s--6OyC0V7g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/url" alt="Alt Text" /></a></p>
</ol><p><a href="https://res.cloudinary.com/TEST-CLOUD/image/fetch/s---YMUCaHJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/link" class="article-body-image-wrapper"><img src="https://res.cloudinary.com/TEST-CLOUD/image/fetch/s---YMUCaHJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/link" alt="GitHub Logo" /></a><br />
Format: <a href="https://res.cloudinary.com/TEST-CLOUD/image/fetch/s--6OyC0V7g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/url" class="article-body-image-wrapper"><img src="https://res.cloudinary.com/TEST-CLOUD/image/fetch/s--6OyC0V7g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/url" alt="Alt Text" /></a></p>
<ol><li>
<p><strong>Line break in ul/ol spacing test</strong></p>