diff --git a/app/labor/user_states.rb b/app/labor/user_states.rb deleted file mode 100644 index efe005fc6..000000000 --- a/app/labor/user_states.rb +++ /dev/null @@ -1,44 +0,0 @@ -class UserStates - attr_accessor :user - - def initialize(user) - @user = user - end - - def cached_onboarding_checklist - Rails.cache.fetch("user-#{user.id}-#{user.updated_at}-#{user.comments_count}-#{user.articles_count}-#{user.reactions_count}/onboarding_checklist", expires_in: 100.hours) do - { - write_your_first_article: made_first_article, - follow_your_first_tag: follows_a_tag, - fill_out_your_profile: fill_out_your_profile, - leave_your_first_reaction: leave_reactions, - follow_your_first_dev: follow_people, - leave_your_first_comment: leave_comments - } - end - end - - def made_first_article - user.articles.published.any? - end - - def follows_a_tag - user.follows.where(followable_type: "ActsAsTaggableOn::Tag").any? - end - - def fill_out_your_profile - user.summary.present? - end - - def leave_reactions - user.reactions.any? - end - - def follow_people - user.follows.where(followable_type: "User").any? - end - - def leave_comments - user.comments.any? - end -end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ca14e5704..fb59a0ff5 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -568,62 +568,6 @@ RSpec.describe User, type: :model do expect(new_user.github_created_at).to be_kind_of(ActiveSupport::TimeWithZone) end - describe "onboarding checklist" do - it "returns onboarding checklist made first article if made first published article" do - article.update(published: true) - checklist = UserStates.new(user).cached_onboarding_checklist[:write_your_first_article] - expect(checklist).to eq(true) - end - - it "returns onboarding checklist made first article false if hasn't written article" do - article.update(published: false) - checklist = UserStates.new(user).cached_onboarding_checklist[:write_your_first_article] - expect(checklist).to eq(true) - end - - it "returns onboarding checklist follow_your_first_tag if has followed tag" do - user.follow(tag) - expect(UserStates.new(user).cached_onboarding_checklist[:follow_your_first_tag]).to eq(true) - end - - it "returns onboarding checklist follow_your_first_tag false if has not followed tag" do - expect(UserStates.new(user).cached_onboarding_checklist[:follow_your_first_tag]).to eq(false) - end - - it "returns onboarding checklist fill_out_your_profile if has filled out summary" do - user.update(summary: "Hello") - expect(UserStates.new(user).cached_onboarding_checklist[:fill_out_your_profile]).to eq(true) - end - - it "returns onboarding checklist fill_out_your_profile false if has not filled out summary" do - user.update(summary: "") - expect(UserStates.new(user).cached_onboarding_checklist[:fill_out_your_profile]).to eq(false) - end - - it "returns onboarding checklist leave_your_first_reaction if has reacted to a post" do - create(:reaction, user_id: user.id, reactable_id: article.id) - checklist = UserStates.new(user).cached_onboarding_checklist[:leave_your_first_reaction] - expect(checklist).to eq(true) - end - - it "returns onboarding checklist leave_your_first_reaction false if hasn't reacted to a post" do - checklist = UserStates.new(user).cached_onboarding_checklist[:leave_your_first_reaction] - expect(checklist).to eq(false) - end - - 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 - - it "returns onboarding checklist leave_your_first_comment false if has not left comment" do - checklist = UserStates.new(user).cached_onboarding_checklist[:leave_your_first_comment] - expect(checklist).to eq(false) - end - end - describe "cache counts" do it "has an accurate tag follow count" do user.follow(tag)