mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
255e3b9819
Ruby 3.1 extracts some gems to bundled one, which requires to add these gems to Gemfile explicitly. `net/smtp` is one of them, which affected Action Mailbox bug report templates. * Steps to reproduce Install `ruby 3.1.0dev` ``` git clone https://github.com/rails/rails.git cd rails/guides ruby bug_report_templates/action_mailbox_gem.rb ruby bug_report_templates/action_mailbox_main.rb ``` * This commit addresses the following error `cannot load such file -- net/smtp (LoadError)` ``` $ ruby bug_report_templates/action_mailbox_gem.rb ... snip ... Using rails 6.1.0 /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `require': cannot load such file -- net/smtp (LoadError) from /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `block in require' from /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:299:in `load_dependency' from /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `require' from /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/mail-2.7.1/lib/mail.rb:9:in `<module:Mail>' from /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/mail-2.7.1/lib/mail.rb:3:in `<top (required)>' from /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `require' from /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `block in require' from /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:299:in `load_dependency' from /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `require' from /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/actionmailbox-6.1.0/lib/action_mailbox/mail_ext.rb:3:in `<top (required)>' from /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `require' from /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `block in require' from /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:299:in `load_dependency' from /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `require' from /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/actionmailbox-6.1.0/lib/action_mailbox.rb:3:in `<top (required)>' from /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `require' from /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `block in require' from /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:299:in `load_dependency' from /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `require' from /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/actionmailbox-6.1.0/lib/action_mailbox/engine.rb:9:in `<top (required)>' from /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `require' from /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `block in require' from /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:299:in `load_dependency' from /home/yahonda/.rbenv/versions/3.1.0-dev/lib/ruby/gems/3.1.0/gems/activesupport-6.1.0/lib/active_support/dependencies.rb:332:in `require' from bug_report_templates/action_mailbox_gem.rb:17:in `<main>' ``` * Added comment when this dependency can be removed based on https://bugs.ruby-lang.org/issues/17873 Refer https://github.com/ruby/ruby/pull/4530 https://github.com/rails/rails/pull/42308 Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
79 lines
2 KiB
Ruby
79 lines
2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "bundler/inline"
|
|
|
|
gemfile(true) do
|
|
source "https://rubygems.org"
|
|
|
|
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
|
|
|
gem "rails", github: "rails/rails", branch: "main"
|
|
gem "sqlite3"
|
|
if RUBY_VERSION >= "3.1"
|
|
# net-smtp, net-imap and net-pop were removed from default gems in Ruby 3.1, but is used by the `mail` gem.
|
|
# So we need to add them as dependencies until `mail` is fixed: https://github.com/mikel/mail/pull/1439
|
|
gem "net-smtp", require: false
|
|
end
|
|
end
|
|
|
|
require "active_record/railtie"
|
|
require "active_storage/engine"
|
|
require "action_mailbox/engine"
|
|
require "tmpdir"
|
|
|
|
class TestApp < Rails::Application
|
|
config.root = __dir__
|
|
config.hosts << "example.org"
|
|
config.eager_load = false
|
|
config.session_store :cookie_store, key: "cookie_store_key"
|
|
secrets.secret_key_base = "secret_key_base"
|
|
|
|
config.logger = Logger.new($stdout)
|
|
Rails.logger = config.logger
|
|
|
|
config.active_storage.service = :local
|
|
config.active_storage.service_configurations = {
|
|
local: {
|
|
root: Dir.tmpdir,
|
|
service: "Disk"
|
|
}
|
|
}
|
|
|
|
config.action_mailbox.ingress = :relay
|
|
end
|
|
|
|
ENV["DATABASE_URL"] = "sqlite3::memory:"
|
|
|
|
Rails.application.initialize!
|
|
|
|
require ActiveStorage::Engine.root.join("db/migrate/20170806125915_create_active_storage_tables.rb").to_s
|
|
require ActionMailbox::Engine.root.join("db/migrate/20180917164000_create_action_mailbox_tables.rb").to_s
|
|
|
|
ActiveRecord::Schema.define do
|
|
CreateActiveStorageTables.new.change
|
|
CreateActionMailboxTables.new.change
|
|
end
|
|
|
|
class ApplicationMailbox < ActionMailbox::Base
|
|
routing (/^replies@/i) => :replies
|
|
end
|
|
|
|
class RepliesMailbox < ActionMailbox::Base
|
|
def process
|
|
$processed = mail.subject
|
|
end
|
|
end
|
|
|
|
require "minitest/autorun"
|
|
|
|
class RepliesMailboxTest < ActionMailbox::TestCase
|
|
setup do
|
|
$processed = false
|
|
@inbound_email = receive_inbound_email_from_mail \
|
|
to: "replies@example.com", subject: "Here is a reply"
|
|
end
|
|
|
|
test "successful mailbox processing" do
|
|
assert_equal "Here is a reply", $processed
|
|
end
|
|
end
|