page.emails.create( subject: email.subject, body: email.body ) if email.has_attachments? email.attachments.each do |attachment| page.attachments.create({file: attachment, description:email.subject}) end end end end $ rails runner 'Mailman.receive(STDIN.read)' 18
true class ForwardsMailbox < ApplicationMailbox def process if forwarder record_forward else bounce_with Forwards::BounceMailer.missing_forward( inbound_email, forwarder: forwarder ) end end private def forwarder Person.where(email_address: mail.from) end def record_forward Forward.new forwarder: forwarder, subject: message.subject, content: mail.content end end 22
for a forwarder and forwardee corresponding to one project" do assert_difference -> { people(:david).buckets.first.recordings.count } do receive_inbound_email_from_mail \ to: '[email protected]', from: people(:david).email_address, subject: "Fwd: Status update?", body: <<~BODY --- Begin forwarded message --- From: Frank Holland <[email protected]> What's the status? BODY end recording = people(:david).buckets.first.recordings.last assert_equal people(:david), recording.creator assert_equal "Status update?", recording.forward.subject assert_match "What's the status?", recording.forward.content.to_s end end 24
application. All is good! -classic mode infers file names from missing constant names (underscore): "FOO".underscore is "foo" -zeitwerk mode infers constant names from file names (camelize): "foo".camelize is "Foo", not "FOO"
# All IPv6 addresses. "localhost" # The localhost reserved domain. ] # Allow requests only from `product.com` Rails.application.config.hosts << "product.com" # Allow requests from subdomains like `www.product.com` and # `beta1.product.com`. Rails.application.config.hosts << /.*\.product\.com/ 44
123).to_sql => # SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123 /* this is a comment */ - Add support for setting Optimizer Hints on databases class Job < ApplicationRecord default_scope { optimizer_hints("MAX_EXECUTION_TIME(50000) NO_INDEX_MERGE(jobs)") } end 72
Simulate a connection opening by calling the `connect` method connect params: { user_id: 42 } # You can access the Connection object via `connection` in tests assert_equal connection.user_id, "42" end test "rejects connection without params" do # Use `assert_reject_connection` matcher to verify that # connection is rejected assert_reject_connection { connect } end end 78
for room" do # Simulate a subscription creation by calling `subscribe` subscribe room: "15" # You can access the Channel object via `subscription` in tests assert subscription.confirmed? assert_has_stream "chat_15" end end 80
room, text: message end end # test/jobs/chat_relay_job_test.rb require 'test_helper' class ChatRelayJobTest < ActiveJob::TestCase include ActionCable::TestHelper test "broadcast message to room" do room = rooms(:all) assert_broadcast_on(ChatChannel.broadcasting_for(room), text: "Hi!") do ChatRelayJob.perform_now(room, "Hi!") end end end 81