From c93bc4801064df873846aca41c4c6cfd478e41d0 Mon Sep 17 00:00:00 2001 From: Ben Halpern Date: Fri, 1 Mar 2019 13:51:06 -0800 Subject: [PATCH] Fix issue with boosted article in email digest (#1936) * Adjust email digest * Fix for missing user.experience_level * Fix direction of greater than * Adjust tests for new criteria --- app/labor/email_logic.rb | 9 +++++---- app/mailers/digest_mailer.rb | 6 ------ .../mailers/digest_mailer/digest_email.html.erb | 6 ------ spec/factories/articles.rb | 1 + spec/labor/email_digest_spec.rb | 2 +- spec/labor/email_logic_spec.rb | 14 +++++++------- 6 files changed, 14 insertions(+), 24 deletions(-) diff --git a/app/labor/email_logic.rb b/app/labor/email_logic.rb index 91811c136..a9074d938 100644 --- a/app/labor/email_logic.rb +++ b/app/labor/email_logic.rb @@ -35,16 +35,17 @@ class EmailLogic where("published_at > ?", fresh_date). where(published: true, email_digest_eligible: true). where.not(user_id: @user.id). - where("positive_reactions_count > ?", 15). - order("positive_reactions_count DESC"). + where("score > ?", 12). + where("experience_level_rating > ? AND experience_level_rating < ?", (@user.experience_level || 5) - 3.6, (@user.experience_level || 5) + 3.6). + order("score DESC"). limit(6) else Article. where("published_at > ?", fresh_date). where(published: true, featured: true, email_digest_eligible: true). where.not(user_id: @user.id). - where("positive_reactions_count > ?", 30). - order("positive_reactions_count DESC"). + where("score > ?", 25). + order("score DESC"). limit(6) end if articles.length < 3 diff --git a/app/mailers/digest_mailer.rb b/app/mailers/digest_mailer.rb index 88627c6eb..ef4f9987f 100644 --- a/app/mailers/digest_mailer.rb +++ b/app/mailers/digest_mailer.rb @@ -5,12 +5,6 @@ class DigestMailer < ApplicationMailer @user = user @articles = articles.first(6) @unsubscribe = generate_unsubscribe_token(@user.id, :email_digest_periodic) - @boosted_article = Suggester::Articles::Boosted.new( - @user, - @articles.first, - not_ids: @articles.pluck(:id), - area: "dev_digest_email", - ).suggest subject = generate_title mail(to: @user.email, subject: subject) end diff --git a/app/views/mailers/digest_mailer/digest_email.html.erb b/app/views/mailers/digest_mailer/digest_email.html.erb index b8cd0ba9b..915c3d580 100644 --- a/app/views/mailers/digest_mailer/digest_email.html.erb +++ b/app/views/mailers/digest_mailer/digest_email.html.erb @@ -8,12 +8,6 @@ <%= article.title.strip %> <%= truncate(article.description, length: 80) %> <% end %> - <% if @boosted_article && @user.display_sponsors %> -

And sponsor-boosted

-
  • - " style="font-weight: bold;color:#0045ff;font-size:1.06em;"><%= @boosted_article.title.strip %> <%= truncate(@boosted_article.description, length: 80) %> -
  • - <% end %>
    diff --git a/spec/factories/articles.rb b/spec/factories/articles.rb index 377ba44c1..223524000 100644 --- a/spec/factories/articles.rb +++ b/spec/factories/articles.rb @@ -17,6 +17,7 @@ FactoryBot.define do description { Faker::Hipster.paragraph(1)[0..100] } main_image { Faker::Avatar.image } language { "en" } + experience_level_rating { rand(4..6) } body_markdown do <<~HEREDOC --- diff --git a/spec/labor/email_digest_spec.rb b/spec/labor/email_digest_spec.rb index 9fd352287..c1e76a8ea 100644 --- a/spec/labor/email_digest_spec.rb +++ b/spec/labor/email_digest_spec.rb @@ -21,7 +21,7 @@ RSpec.describe EmailDigest do before { user.follow(author) } it "send digest email when there's atleast 3 hot articles" do - create_list(:article, 3, user_id: author.id, positive_reactions_count: 20) + create_list(:article, 3, user_id: author.id, positive_reactions_count: 20, score: 20) described_class.send_periodic_digest_email expect(DigestMailer).to have_received(:digest_email).with( user, [instance_of(Article), instance_of(Article), instance_of(Article)] diff --git a/spec/labor/email_logic_spec.rb b/spec/labor/email_logic_spec.rb index c0c50daba..3042e5431 100644 --- a/spec/labor/email_logic_spec.rb +++ b/spec/labor/email_logic_spec.rb @@ -10,24 +10,24 @@ RSpec.describe EmailLogic do it "returns 0.5 for open_percentage" do author = create(:user) user.follow(author) - create_list(:article, 3, user_id: author.id, positive_reactions_count: 20) + create_list(:article, 3, user_id: author.id, positive_reactions_count: 20, score: 20) h = described_class.new(user).analyze expect(h.open_percentage).to eq(0.5) end it "provides top 3 articles" do - create_list(:article, 3, positive_reactions_count: 40, featured: true) + create_list(:article, 3, positive_reactions_count: 40, featured: true, score: 40) h = described_class.new(user).analyze expect(h.articles_to_send.length).to eq(3) end it "marks as not ready if there isn't atleast 3 articles" do - create_list(:article, 2, positive_reactions_count: 40) + create_list(:article, 2, positive_reactions_count: 40, score: 40) h = described_class.new(user).analyze expect(h.should_receive_email?).to eq(false) end it "marks as not ready if there isn't at least 3 email-digest-eligible articles" do - create_list(:article, 2, positive_reactions_count: 40) + create_list(:article, 2, positive_reactions_count: 40, score: 40) create_list(:article, 2, positive_reactions_count: 40, email_digest_eligible: false) h = described_class.new(user).analyze expect(h.should_receive_email?).to eq(false) @@ -38,7 +38,7 @@ RSpec.describe EmailLogic do before do author = create(:user) user.follow(author) - create_list(:article, 3, user_id: author.id, positive_reactions_count: 20) + create_list(:article, 3, user_id: author.id, positive_reactions_count: 20, score: 20) 10.times do Ahoy::Message.create(mailer: "DigestMailer#digest_email", user_id: user.id, sent_at: Time.current.utc) @@ -58,7 +58,7 @@ RSpec.describe EmailLogic do sent_at: Time.current.utc, opened_at: Time.current.utc) author = create(:user) user.follow(author) - create_list(:article, 3, user_id: author.id, positive_reactions_count: 40) + create_list(:article, 3, user_id: author.id, positive_reactions_count: 40, score: 40) end end @@ -75,7 +75,7 @@ RSpec.describe EmailLogic do it "refelcts @ready_to_receive_email" do author = create(:user) user.follow(author) - create_list(:article, 3, user_id: author.id, positive_reactions_count: 20) + create_list(:article, 3, user_id: author.id, positive_reactions_count: 20, score: 20) h = described_class.new(user).analyze expect(h.should_receive_email?).to eq(true) end