diff --git a/app/controllers/internal/welcome_controller.rb b/app/controllers/internal/welcome_controller.rb
index f95558e62..2d5fe905b 100644
--- a/app/controllers/internal/welcome_controller.rb
+++ b/app/controllers/internal/welcome_controller.rb
@@ -8,7 +8,7 @@ class Internal::WelcomeController < Internal::ApplicationController
def create
welcome_thread = Article.create(
body_markdown: welcome_thread_content,
- user_id: ApplicationConfig["DEVTO_USER_ID"],
+ user: User.dev_account,
)
redirect_to welcome_thread.path + "/edit"
end
diff --git a/app/models/notification.rb b/app/models/notification.rb
index ab5f15729..07bb7234d 100644
--- a/app/models/notification.rb
+++ b/app/models/notification.rb
@@ -152,7 +152,7 @@ class Notification < ApplicationRecord
welcome_broadcast = Broadcast.find_by(title: "Welcome Notification")
return if welcome_broadcast == nil
- dev_account = User.find_by_id(ENV["DEVTO_USER_ID"])
+ dev_account = User.dev_account
json_data = {
user: user_data(dev_account),
broadcast: {
@@ -174,7 +174,7 @@ class Notification < ApplicationRecord
return if available_moderators.empty?
moderator = available_moderators.sample
- dev_account = User.find_by_id(ENV["DEVTO_USER_ID"])
+ dev_account = User.dev_account
json_data = {
user: user_data(dev_account)
}
diff --git a/app/models/user.rb b/app/models/user.rb
index 4e0e801f5..6ac0b922f 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -126,6 +126,8 @@ class User < ApplicationRecord
validate :validate_feed_url
validate :unique_including_orgs
+ scope :dev_account, -> { find_by_id(ApplicationConfig["DEVTO_USER_ID"]) }
+
after_create :send_welcome_notification
after_save :bust_cache
after_save :subscribe_to_mailchimp_newsletter
diff --git a/app/views/notifications/_aggregated_reactions.html.erb b/app/views/notifications/_aggregated_reactions.html.erb
index f77b4a45a..c591d973c 100644
--- a/app/views/notifications/_aggregated_reactions.html.erb
+++ b/app/views/notifications/_aggregated_reactions.html.erb
@@ -1,5 +1,4 @@
<%# TODO: change to map of IDs %>
-<% siblings = notification.json_data["reaction"]["aggregated_siblings"].select{|n| n["created_at"] > 24.hours.ago } %>
<% cache "activity-aggregated-reactions-#{siblings}" do %>
<% actors = siblings.map { |n| n["user"] }.uniq %>
<% reactable_data = notification.json_data["reaction"]["reactable"] %>
diff --git a/app/views/notifications/_reaction.html.erb b/app/views/notifications/_reaction.html.erb
index d2f89afd8..e63c157d0 100644
--- a/app/views/notifications/_reaction.html.erb
+++ b/app/views/notifications/_reaction.html.erb
@@ -21,5 +21,5 @@
<% else %>
- <%= render "aggregated_reactions", notification: notification %>
+ <%= render "aggregated_reactions", notification: notification, siblings: siblings %>
<% end %>
diff --git a/spec/requests/notifications_spec.rb b/spec/requests/notifications_spec.rb
index d9b37a39c..94e7de4c1 100644
--- a/spec/requests/notifications_spec.rb
+++ b/spec/requests/notifications_spec.rb
@@ -1,8 +1,17 @@
require "rails_helper"
RSpec.describe "NotificationsIndex", type: :request do
+ let(:dev_account) { create(:user) }
let(:user) { create(:user) }
+ before do
+ allow(User).to receive(:dev_account).and_return(dev_account)
+ end
+
+ def has_both_names(response_body)
+ response_body.include?(CGI.escapeHTML(User.last.name)) && response_body.include?(CGI.escapeHTML(User.second_to_last.name))
+ end
+
describe "GET notifications" do
it "renders page with the proper heading" do
get "/notifications"
@@ -12,23 +21,20 @@ RSpec.describe "NotificationsIndex", type: :request do
context "when signed out" do
it "renders the signup cue" do
get "/notifications"
- expect(response.body).to include "
#{CGI.escapeHTML(User.second_to_last.name)} followed you!"
- expect(response.body).to include CGI.escapeHTML(follow_message)
+ expect(has_both_names(response.body)).to be true
end
- xit "renders the proper message for three or more notifications in the same day" do
+ it "renders the proper message for three or more notifications in the same day" do
mock_follow_notifications(rand(3..10))
get "/notifications"
follow_message = "others followed you!"
@@ -69,11 +73,9 @@ RSpec.describe "NotificationsIndex", type: :request do
context "when a user has new reaction notifications" do
let(:article1) { create(:article, user_id: user.id) }
let(:article2) { create(:article, user_id: user.id) }
- let(:special_characters_article) { create(:article, user_id: user.id, title: "Nothing like good ol' blah blah blah") }
+ let(:special_characters_article) { create(:article, user_id: user.id, title: "What's Become of Waring") }
- before do
- sign_in user
- end
+ before { sign_in user }
def mock_heart_reaction_notifications(amount, categories, reactable = article1)
create_list :user, amount
@@ -89,32 +91,23 @@ RSpec.describe "NotificationsIndex", type: :request do
reactions.each { |reaction| Notification.send_reaction_notification_without_delay(reaction) }
end
- xit "renders the proper message for a single public reaction" do
+ it "renders the correct user for a single reaction" do
mock_heart_reaction_notifications(1, %w(like unicorn))
get "/notifications"
- message = "#{CGI.escapeHTML(User.last.name)} reacted to"
- expect(response.body).to include message
+ expect(response.body).to include CGI.escapeHTML(User.last.name)
end
- xit "renders the proper message for a single private reaction" do
- mock_heart_reaction_notifications(1, %w(readinglist))
- get "/notifications"
- message = "Someone reacted to"
- expect(response.body).to include message
- end
-
- xit "renders the proper message for two or more public reactions" do
+ it "renders the correct usernames for two or more reactions" do
mock_heart_reaction_notifications(2, %w(like unicorn))
get "/notifications"
- message = "#{User.last.name} and
#{CGI.escapeHTML(User.second_to_last.name)}\n reacted to"
- expect(response.body).to include CGI.escapeHTML(message)
+ expect(has_both_names(response.body)).to be true
end
- xit "renders the proper message for multiple public reactions" do
- mock_heart_reaction_notifications(3, %w(unicorn like))
+ it "renders the proper message for multiple reactions" do
+ random_amount = rand(3..10)
+ mock_heart_reaction_notifications(random_amount, %w(unicorn like))
get "/notifications"
- message = "#{User.last.name} and 2 others\n reacted to"
- expect(response.body).to include CGI.escapeHTML(message)
+ expect(response.body).to include CGI.escapeHTML("and #{random_amount - 1} others")
end
xit "does not group notifications that are on different days but have the same reactable" do
@@ -125,7 +118,7 @@ RSpec.describe "NotificationsIndex", type: :request do
expect(notifications.count).to eq 2
end
- xit "does not group notifications that are on the same day but have different reactables" do
+ it "does not group notifications that are on the same day but have different reactables" do
mock_heart_reaction_notifications(1, %w(unicorn like readinglist), article1)
mock_heart_reaction_notifications(1, %w(unicorn like readinglist), article2)
get "/notifications"
@@ -158,20 +151,20 @@ RSpec.describe "NotificationsIndex", type: :request do
get "/notifications"
end
- xit "renders the correct message" do
+ it "renders the correct message" do
expect(response.body).to include "commented on"
end
- xit "does not render the moderation message" do
+ it "does not render the moderation message" do
expect(response.body).not_to include "As a trusted member"
end
- xit "renders the original article's title" do
- expect(response.body).to include CGI.escapeHTML(article.title)
+ it "renders the article's path" do
+ expect(response.body).to include article.path
end
- xit "renders the comment's processed HTML" do
- expect(response.body).to include CGI.escapeHTML(comment.processed_html)
+ it "renders the comment's processed HTML" do
+ expect(response.body).to include comment.processed_html
end
it "renders the reaction as previously reacted if it was reacted on" do
@@ -191,37 +184,35 @@ RSpec.describe "NotificationsIndex", type: :request do
let(:comment) { create(:comment, user_id: user2.id, commentable_id: article.id, commentable_type: "Article") }
before do
- user.update(id: 1)
user.add_role :trusted
sign_in user
Notification.send_moderation_notification_without_delay(comment)
get "/notifications"
end
- xit "renders the proper message" do
+ it "renders the proper message" do
expect(response.body).to include "As a trusted member"
end
- xit "renders the article's title" do
- expect(response.body).to include CGI.escapeHTML(article.title)
+ it "renders the article's path" do
+ expect(response.body).to include article.path
end
- xit "renders the comment's processed HTML" do
- expect(response.body).to include CGI.escapeHTML(comment.processed_html)
+ it "renders the comment's processed HTML" do
+ expect(response.body).to include comment.processed_html
end
end
context "when a user has a new welcome notification" do
before do
- user.update(id: 1)
sign_in user
end
- xit "renders the welcome notification" do
+ it "renders the welcome notification" do
broadcast = create(:broadcast, :onboarding)
Notification.send_welcome_notification_without_delay(user.id)
get "/notifications"
- expect(response.body).to include CGI.escapeHTML(broadcast.processed_html)
+ expect(response.body).to include broadcast.processed_html
end
end
@@ -234,20 +225,19 @@ RSpec.describe "NotificationsIndex", type: :request do
get "/notifications"
end
- xit "renders the proper message with the badge's title" do
- message = "You received the
#{Badge.first.title}"
- expect(response.body).to include CGI.escapeHTML(message)
+ it "renders the badge's title" do
+ expect(response.body).to include Badge.first.title
end
- xit "renders the rewarding context message" do
- expect(response.body).to include CGI.escapeHTML(user.badge_achievements.first.rewarding_context_message)
+ it "renders the rewarding context message" do
+ expect(response.body).to include user.badge_achievements.first.rewarding_context_message
end
- xit "renders the badge's description" do
+ it "renders the badge's description" do
expect(response.body).to include CGI.escapeHTML(Badge.first.description)
end
- xit "renders the CHECK YOUR PROFILE button" do
+ it "renders the CHECK YOUR PROFILE button" do
expect(response.body).to include "CHECK YOUR PROFILE"
end
end
@@ -266,20 +256,19 @@ RSpec.describe "NotificationsIndex", type: :request do
end
before do
- user.update(id: 1)
- sign_in user
comment
- Mention.create_all(comment)
+ Mention.create_all_without_delay(comment)
Notification.send_mention_notification_without_delay(Mention.first)
+ sign_in user
get "/notifications"
end
- xit "renders the proper message" do
+ it "renders the proper message" do
expect(response.body).to include "mentioned you in a comment"
end
- xit "renders the processed HTML of the comment where they were mentioned" do
- expect(response.body).to include CGI.escapeHTML(comment.processed_html)
+ it "renders the processed HTML of the comment where they were mentioned" do
+ expect(response.body).to include comment.processed_html
end
end
@@ -294,15 +283,15 @@ RSpec.describe "NotificationsIndex", type: :request do
get "/notifications"
end
- xit "renders the proper message" do
+ it "renders the proper message" do
expect(response.body).to include "made a new post:"
end
- xit "renders the article's title" do
- expect(response.body).to include CGI.escapeHTML(article.title)
+ it "renders the article's path" do
+ expect(response.body).to include article.path
end
- xit "renders the author's name" do
+ it "renders the author's name" do
expect(response.body).to include CGI.escapeHTML(article.user.name)
end