Skip to content

Instantly share code, notes, and snippets.

@lisasy
Created September 30, 2020 19:49
Show Gist options
  • Save lisasy/b03ab465ae303c19ff6a8938270ef20e to your computer and use it in GitHub Desktop.
Save lisasy/b03ab465ae303c19ff6a8938270ef20e to your computer and use it in GitHub Desktop.
Boilerplate Notification (Forem)
me = User.find_by(username: "lisasy")
3.times do |i|
follow = Follow.create!(followable: me, follower: User.find(i+1))
follow_data = follow.attributes.slice("follower_id", "followable_id", "followable_type").symbolize_keys
Notification.send_new_follower_notification_without_delay(follow)
end
BadgeAchievement.last.update(user_id: me.id)
Notifications::NewBadgeAchievement::Send.call(BadgeAchievement.last)
markdown = <<~MARKDOWN
---
title: #{Faker::Book.title} #{Faker::Lorem.sentence(word_count: 2).chomp('.')}
published: true
cover_image: #{Faker::Company.logo}
tags: beginners, career, computerscience
---
#{Faker::Hipster.paragraph(sentence_count: 2)}
#{Faker::Markdown.random}
#{Faker::Hipster.paragraph(sentence_count: 2)}
MARKDOWN
article = Article.create!(
body_markdown: markdown,
featured: true,
show_comments: true,
user: me,
)
attributes = {
body_markdown: Faker::Hipster.paragraph(sentence_count: 1),
user_id: me.id,
commentable_id: article.id,
commentable_type: "Article"
}
your_comment = Comment.create!(attributes)
attributes[:user_id] = 1
attributes[:body_markdown] = "@#{me.username} cool post OP!"
someone_else_comment = Comment.create!(attributes)
# mention notification created asynchronously
3.times do |i|
rxn = Reaction.create!(reactable: article, user_id: i+1, category: "like")
Notification.send_reaction_notification_without_delay(rxn, me)
end
rxn = Reaction.create!(reactable: article, user_id: 5, category: "like", created_at: Time.current - 2.days)
Notification.send_reaction_notification_without_delay(rxn, me)
comment_rxn = Reaction.create!(reactable: your_comment, user_id: 5, category: "like")
Notification.send_reaction_notification_without_delay(comment_rxn, me)
Notifications::Moderation::Send.call(me, your_comment)
tag = Tag.find_by(name: "beginners")
User.find(5).add_role :super_admin
tag_adjustment = TagAdjustment.create!(
tag_id: tag.id,
adjustment_type: "removal",
article_id: article.id,
reason_for_adjustment: "This is not for beginners :(",
status: "resolved",
user_id: 5,
tag_name: "beginners"
)
Notifications::TagAdjustmentNotification::Send.call(tag_adjustment)
Notifications::Milestone::Send.call("View", article)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment