Permalink
Browse files

Setup Hanami::Mailer as a component (#705)

- That ensures that the config is loaded and applied.
- Mailer component specs

* Missed some model => mailer conversions
  • Loading branch information...
mereghost committed Jan 2, 2017
1 parent 2934ded commit 69c5b20488b9da95100536514e39badf308ed614
@@ -13,7 +13,7 @@ module Components # rubocop:disable Metrics/ModuleLength
# @since 0.9.0
# @api private
register 'all' do
requires 'model', 'apps', 'finalizers'
requires 'mailer', 'model', 'apps', 'finalizers'

resolve { true }
end
@@ -135,6 +135,45 @@ module Components # rubocop:disable Metrics/ModuleLength
end
end

# Tries to evaluate hanami-mailer configuration
#
# @since 1.0.0.beta1
# @api private
#
# @example With hanami-mailer
# Hanami::Components.resolve('mailer.configuration')
# Hanami::Components['mailer.configuration'].class # => Hanami::Mailer::Configuration
register 'mailer.configuration' do
prepare do
require 'hanami/mailer'
require 'hanami/mailer/glue'
end

resolve do |configuration|
Hanami::Mailer.configure(&configuration.mailer)
Hanami::Mailer.configuration
end
end

# Tries to load hanami-mailer
#
# @since 1.0.0.beta1
# @api private
#
# @example
# Hanami::Components.resolve('mailer')
# Hanami::Components['mailer'] # => true
register 'mailer' do
requires 'mailer.configuration'

resolve do
if Components['mailer.configuration']
Hanami::Mailer.load!
true
end
end
end

# Loads the routes for all the mounted Hanami/Rack applications
#
# This is used only by `hanami routes` command.
@@ -12,6 +12,10 @@
expect(Hanami::Components['model.configuration']).to_not be(nil)
expect(Hanami::Components['model']).to_not be(nil)

expect(Hanami::Components['mailer.configuration']).to_not be(nil)
expect(Hanami::Components['mailer']).to_not be(nil)


expect(Hanami::Components['web']).to_not be(nil)
expect(Hanami::Components['admin']).to_not be(nil)

@@ -6,22 +6,26 @@
require Pathname.new(Dir.pwd).join("config", "environment")
Hanami::Components.resolve('all')

model_configuration = Hanami::Components['model.configuration']
model = Hanami::Components['model']
web_configuration = Hanami::Components['web.configuration']
web_app_config = Web::Application.configuration
admin_configuration = Hanami::Components['admin.configuration']
admin_app_config = Admin::Application.configuration
model_configuration = Hanami::Components['model.configuration']
model = Hanami::Components['model']
mailer = Hanami::Components['mailer']
web_configuration = Hanami::Components['web.configuration']
web_app_config = Web::Application.configuration
admin_configuration = Hanami::Components['admin.configuration']
admin_app_config = Admin::Application.configuration
mailer_configuration = Hanami::Mailer.configuration

# Simulate accidental double trigger
Hanami::Components.resolve('all')

expect(Hanami::Components['model.configuration']).to be(model_configuration)
expect(Hanami::Components['model']).to be(model)
expect(Hanami::Components['web.configuration']).to be(web_configuration)
expect(Web::Application.configuration).to be(web_app_config)
expect(Hanami::Components['admin.configuration']).to be(admin_configuration)
expect(Admin::Application.configuration).to be(admin_app_config)
expect(Hanami::Components['model.configuration']).to be(model_configuration)
expect(Hanami::Components['model']).to be(model)
expect(Hanami::Components['mailer.configuration']).to be(mailer_configuration)
expect(Hanami::Components['mailer']).to be(mailer)
expect(Hanami::Components['web.configuration']).to be(web_configuration)
expect(Web::Application.configuration).to be(web_app_config)
expect(Hanami::Components['admin.configuration']).to be(admin_configuration)
expect(Admin::Application.configuration).to be(admin_app_config)
end
end
end
@@ -0,0 +1,13 @@
RSpec.describe "Components: mailer", type: :cli do
context "with hanami-mailer" do
it "resolves mailer" do
with_project do
require Pathname.new(Dir.pwd).join("config", "environment")
Hanami::Components.resolve('mailer')

expect(Hanami::Components['mailer']).to be(true)
expect(Hanami::Components['mailer.configuration']).to be_truthy
end
end
end
end
@@ -0,0 +1,12 @@
RSpec.describe "Components: mailer.configuration", type: :cli do
context "with hanami-mailer" do
it "resolves mailer configuration" do
with_project do
require Pathname.new(Dir.pwd).join("config", "environment")
Hanami::Components.resolve('mailer.configuration')

expect(Hanami::Components['mailer.configuration']).to be_kind_of(Hanami::Mailer::Configuration)
end
end
end
end

0 comments on commit 69c5b20

Please sign in to comment.