class SupportMailbox < ApplicationMailbox
def process
ticket = Ticket.find_or_create_by!(message_id: mail.message_id) do |t|
t.subject = mail.subject
t.from_email = mail.from&.first
t.body = mail.decoded
FactoryBot.define do
factory :post do
association :author, factory: :user
sequence(:title) { |n| "Post Title #{n}" }
body { Faker::Lorem.paragraphs(number: 3).join("\n\n") }
status { :draft }
class AtLeastOneOfValidator < ActiveModel::Validator
def validate(record)
fields = Array(options[:fields])
raise ArgumentError, "provide :fields" if fields.empty?
return if fields.any? { |field| filled?(record.public_send(field)) }
class CircuitBreaker
class CircuitOpenError < StandardError; end
INCREMENT = <<~LUA.freeze
local n = redis.call('INCR', KEYS[1])
if n == 1 then redis.call('EXPIRE', KEYS[1], ARGV[1]) end
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :authenticate_user!
end
<%= turbo_frame_tag 'quick_view' do %>
<div class="text-gray-500">Select a post…</div>
<% end %>
<% @posts.each do |post| %>
<%= link_to post.title, post_path(post), data: { turbo_frame: 'quick_view' }, class: 'block py-1 hover:underline' %>
class CheckoutService
def initialize(cart:, user:)
@cart = cart
@user = user
end
Rails.application.config.content_security_policy do |policy|
policy.default_src :self
policy.font_src :self, :https, :data
policy.img_src :self, :https, :data, "https://cdn.example.com"
policy.object_src :none
policy.script_src :self, :https
<div class="post">
<h1><%= @post.title %></h1>
<%= turbo_frame_tag "post_#{@post.id}" do %>
<div class="post-content">
<%= simple_format @post.body %>
import { Controller } from "@hotwired/stimulus"
import consumer from "../channels/consumer"
export default class extends Controller {
static values = { roomId: Number }
module ExistenceChecks
extend ActiveSupport::Concern
class_methods do
def has_any?(conditions = {})
relation = conditions.present? ? where(conditions) : all
class NotifyFollowersJob
include Sidekiq::Job
sidekiq_options queue: :notifications, retry: 5
def perform(post_id, actor_id)