Enforce rubocop rules for 2.0
This commit is contained in:
parent
d2b8a32ade
commit
bad15b904e
|
@ -1,7 +1,7 @@
|
|||
# Please keep AllCops, Bundler, Style, Metrics groups and then order cops
|
||||
# alphabetically
|
||||
inherit_from:
|
||||
- https://raw.githubusercontent.com/hanami/devtools/master/.rubocop.yml
|
||||
- https://raw.githubusercontent.com/hanami/devtools/master/.rubocop-unstable.yml
|
||||
Style/Documentation:
|
||||
Exclude:
|
||||
- "examples/*"
|
||||
|
|
20
Gemfile
20
Gemfile
|
@ -1,14 +1,16 @@
|
|||
source 'https://rubygems.org'
|
||||
# frozen_string_literal: true
|
||||
|
||||
source "https://rubygems.org"
|
||||
gemspec
|
||||
|
||||
unless ENV['TRAVIS']
|
||||
gem 'byebug', require: false, platforms: :mri
|
||||
gem 'allocation_stats', require: false
|
||||
gem 'benchmark-ips', require: false
|
||||
unless ENV["TRAVIS"]
|
||||
gem "byebug", require: false, platforms: :mri
|
||||
gem "allocation_stats", require: false
|
||||
gem "benchmark-ips", require: false
|
||||
end
|
||||
|
||||
gem 'hanami-utils', '2.0.0.alpha1', require: false, git: 'https://github.com/hanami/utils.git', branch: 'unstable'
|
||||
gem 'haml'
|
||||
gem "hanami-utils", "2.0.0.alpha1", require: false, git: "https://github.com/hanami/utils.git", branch: "unstable"
|
||||
gem "haml"
|
||||
|
||||
gem 'hanami-devtools', require: false, git: 'https://github.com/hanami/devtools.git'
|
||||
gem 'coveralls', require: false
|
||||
gem "hanami-devtools", require: false, git: "https://github.com/hanami/devtools.git"
|
||||
gem "coveralls", require: false
|
||||
|
|
16
Rakefile
16
Rakefile
|
@ -1,19 +1,21 @@
|
|||
require 'rake'
|
||||
require 'bundler/gem_tasks'
|
||||
require 'rspec/core/rake_task'
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rake"
|
||||
require "bundler/gem_tasks"
|
||||
require "rspec/core/rake_task"
|
||||
|
||||
namespace :spec do
|
||||
RSpec::Core::RakeTask.new(:unit) do |task|
|
||||
file_list = FileList['spec/**/*_spec.rb']
|
||||
file_list = FileList["spec/**/*_spec.rb"]
|
||||
file_list = file_list.exclude("spec/{integration,isolation}/**/*_spec.rb")
|
||||
|
||||
task.pattern = file_list
|
||||
end
|
||||
|
||||
task :coverage do
|
||||
ENV['COVERAGE'] = 'true'
|
||||
Rake::Task['spec:unit'].invoke
|
||||
ENV["COVERAGE"] = "true"
|
||||
Rake::Task["spec:unit"].invoke
|
||||
end
|
||||
end
|
||||
|
||||
task default: 'spec:unit'
|
||||
task default: "spec:unit"
|
||||
|
|
12
benchmark.rb
12
benchmark.rb
|
@ -1,10 +1,10 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'bundler/setup'
|
||||
require 'hanami/mailer'
|
||||
require 'benchmark/ips'
|
||||
require 'allocation_stats'
|
||||
require_relative './examples/base'
|
||||
require "bundler/setup"
|
||||
require "hanami/mailer"
|
||||
require "benchmark/ips"
|
||||
require "allocation_stats"
|
||||
require_relative "./examples/base"
|
||||
|
||||
configuration = Hanami::Mailer::Configuration.new do |config|
|
||||
config.root = "examples/base"
|
||||
|
@ -44,5 +44,5 @@ detailed_allocations = stats.allocations(alias_paths: true)
|
|||
.sort_by_count
|
||||
.to_text
|
||||
|
||||
puts 'allocations by source file and class:'
|
||||
puts "allocations by source file and class:"
|
||||
puts detailed_allocations
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'bundler/setup'
|
||||
require 'hanami/mailer'
|
||||
require "bundler/setup"
|
||||
require "hanami/mailer"
|
||||
|
||||
# You can add fixtures and/or initialization code here to make experimenting
|
||||
# with your gem easier. You can also use a different console, if you like.
|
||||
|
@ -10,5 +11,5 @@ require 'hanami/mailer'
|
|||
# require "pry"
|
||||
# Pry.start
|
||||
|
||||
require 'irb'
|
||||
require "irb"
|
||||
IRB.start
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'bundler/setup'
|
||||
require 'hanami/mailer'
|
||||
require "bundler/setup"
|
||||
require "hanami/mailer"
|
||||
|
||||
configuration = Hanami::Mailer::Configuration.new do |config|
|
||||
config.root = File.expand_path(__dir__, "base")
|
||||
|
|
|
@ -1,29 +1,31 @@
|
|||
lib = File.expand_path('../lib', __FILE__)
|
||||
# frozen_string_literal: true
|
||||
|
||||
lib = File.expand_path("../lib", __FILE__)
|
||||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
||||
require 'hanami/mailer/version'
|
||||
require "hanami/mailer/version"
|
||||
|
||||
Gem::Specification.new do |spec|
|
||||
spec.name = 'hanami-mailer'
|
||||
spec.name = "hanami-mailer"
|
||||
spec.version = Hanami::Mailer::VERSION
|
||||
spec.authors = ['Luca Guidi']
|
||||
spec.email = ['me@lucaguidi.com']
|
||||
spec.authors = ["Luca Guidi"]
|
||||
spec.email = ["me@lucaguidi.com"]
|
||||
|
||||
spec.summary = 'Mail for Ruby applications.'
|
||||
spec.description = 'Mail for Ruby applications and Hanami mailers'
|
||||
spec.homepage = 'http://hanamirb.org'
|
||||
spec.license = 'MIT'
|
||||
spec.summary = "Mail for Ruby applications."
|
||||
spec.description = "Mail for Ruby applications and Hanami mailers"
|
||||
spec.homepage = "http://hanamirb.org"
|
||||
spec.license = "MIT"
|
||||
|
||||
spec.files = `git ls-files -- lib/* CHANGELOG.md LICENSE.md README.md hanami-mailer.gemspec`.split($/) # rubocop:disable Style/SpecialGlobalVars
|
||||
spec.bindir = 'exe'
|
||||
spec.bindir = "exe"
|
||||
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
||||
spec.require_paths = ['lib']
|
||||
spec.required_ruby_version = '>= 2.3.0'
|
||||
spec.require_paths = ["lib"]
|
||||
spec.required_ruby_version = ">= 2.3.0"
|
||||
|
||||
spec.add_dependency 'hanami-utils', '2.0.0.alpha1'
|
||||
spec.add_dependency 'tilt', '~> 2.0', '>= 2.0.1'
|
||||
spec.add_dependency 'mail', '~> 2.6'
|
||||
spec.add_dependency "hanami-utils", "2.0.0.alpha1"
|
||||
spec.add_dependency "tilt", "~> 2.0", ">= 2.0.1"
|
||||
spec.add_dependency "mail", "~> 2.6"
|
||||
|
||||
spec.add_development_dependency 'bundler', '~> 1.15'
|
||||
spec.add_development_dependency 'rake', '~> 12'
|
||||
spec.add_development_dependency 'rspec', '~> 3.7'
|
||||
spec.add_development_dependency "bundler", "~> 1.15"
|
||||
spec.add_development_dependency "rake", "~> 12"
|
||||
spec.add_development_dependency "rspec", "~> 3.7"
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'mail'
|
||||
require 'concurrent'
|
||||
require "mail"
|
||||
require "concurrent"
|
||||
|
||||
# Hanami
|
||||
#
|
||||
|
@ -11,19 +11,19 @@ module Hanami
|
|||
#
|
||||
# @since 0.1.0
|
||||
class Mailer
|
||||
require 'hanami/mailer/version'
|
||||
require 'hanami/mailer/template'
|
||||
require 'hanami/mailer/finalizer'
|
||||
require 'hanami/mailer/configuration'
|
||||
require 'hanami/mailer/dsl'
|
||||
require "hanami/mailer/version"
|
||||
require "hanami/mailer/template"
|
||||
require "hanami/mailer/finalizer"
|
||||
require "hanami/mailer/configuration"
|
||||
require "hanami/mailer/dsl"
|
||||
|
||||
# Content types mapping
|
||||
#
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
CONTENT_TYPES = {
|
||||
html: 'text/html',
|
||||
txt: 'text/plain'
|
||||
html: "text/html",
|
||||
txt: "text/plain"
|
||||
}.freeze
|
||||
|
||||
private_constant(:CONTENT_TYPES)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'hanami/utils/kernel'
|
||||
require 'hanami/mailer/template_name'
|
||||
require 'hanami/mailer/templates_finder'
|
||||
require "hanami/utils/kernel"
|
||||
require "hanami/mailer/template_name"
|
||||
require "hanami/mailer/templates_finder"
|
||||
|
||||
module Hanami
|
||||
class Mailer
|
||||
|
@ -14,7 +14,7 @@ module Hanami
|
|||
#
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
DEFAULT_ROOT = '.'
|
||||
DEFAULT_ROOT = "."
|
||||
|
||||
# Default delivery method
|
||||
#
|
||||
|
@ -26,7 +26,7 @@ module Hanami
|
|||
#
|
||||
# @since 0.1.0
|
||||
# @api private
|
||||
DEFAULT_CHARSET = 'UTF-8'
|
||||
DEFAULT_CHARSET = "UTF-8"
|
||||
|
||||
private_constant(*constants(false))
|
||||
|
||||
|
@ -117,7 +117,7 @@ module Hanami
|
|||
#
|
||||
# @see Hanami::Mailer.configure
|
||||
def prepare(&blk)
|
||||
raise ArgumentError.new('Please provide a block') unless block_given?
|
||||
raise ArgumentError.new("Please provide a block") unless block_given?
|
||||
@modules.push(blk)
|
||||
end
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ module Hanami
|
|||
#
|
||||
# @since 0.1.0
|
||||
class Mailer
|
||||
require 'hanami/mailer/template_name'
|
||||
require "hanami/mailer/template_name"
|
||||
|
||||
# Class level DSL
|
||||
#
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'mail'
|
||||
require "mail"
|
||||
# require 'ice_nine'
|
||||
|
||||
module Hanami
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'tilt'
|
||||
require "tilt"
|
||||
|
||||
module Hanami
|
||||
class Mailer
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'hanami/utils/string'
|
||||
require "hanami/utils/string"
|
||||
|
||||
module Hanami
|
||||
class Mailer
|
||||
|
@ -12,7 +12,7 @@ module Hanami
|
|||
# @since next
|
||||
# @api unstable
|
||||
def self.call(name, namespace)
|
||||
Utils::String.new(name.gsub(/\A#{namespace}(::)*/, '')).underscore.to_s
|
||||
Utils::String.new(name.gsub(/\A#{namespace}(::)*/, "")).underscore.to_s
|
||||
end
|
||||
|
||||
class << self
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'hanami/mailer/template'
|
||||
require 'hanami/utils/file_list'
|
||||
require 'pathname'
|
||||
require "hanami/mailer/template"
|
||||
require "hanami/utils/file_list"
|
||||
require "pathname"
|
||||
|
||||
module Hanami
|
||||
class Mailer
|
||||
|
@ -17,19 +17,19 @@ module Hanami
|
|||
#
|
||||
# @api private
|
||||
# @since 0.1.0
|
||||
FORMAT = '*'
|
||||
FORMAT = "*"
|
||||
|
||||
# Default template engines
|
||||
#
|
||||
# @api private
|
||||
# @since 0.1.0
|
||||
ENGINES = '*'
|
||||
ENGINES = "*"
|
||||
|
||||
# Recursive pattern
|
||||
#
|
||||
# @api private
|
||||
# @since 0.1.0
|
||||
RECURSIVE = '**'
|
||||
RECURSIVE = "**"
|
||||
|
||||
# Format separator
|
||||
#
|
||||
|
@ -38,7 +38,7 @@ module Hanami
|
|||
#
|
||||
# @example
|
||||
# welcome.html.erb
|
||||
FORMAT_SEPARATOR = '.'
|
||||
FORMAT_SEPARATOR = "."
|
||||
|
||||
private_constant(*constants(true))
|
||||
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
module Hanami
|
||||
class Mailer
|
||||
# @since 0.1.0
|
||||
VERSION = '1.1.0'
|
||||
VERSION = "1.1.0"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Hanami::Mailer do
|
||||
describe '.deliver' do
|
||||
it 'can deliver with specified charset' do
|
||||
mail = CharsetMailer.new(configuration: configuration).deliver(charset: charset = 'iso-2022-jp')
|
||||
describe ".deliver" do
|
||||
it "can deliver with specified charset" do
|
||||
mail = CharsetMailer.new(configuration: configuration).deliver(charset: charset = "iso-2022-jp")
|
||||
|
||||
expect(mail.charset).to eq(charset)
|
||||
expect(mail.parts.first.charset).to eq(charset)
|
||||
|
@ -17,24 +17,24 @@ RSpec.describe Hanami::Mailer do
|
|||
expect { MissingToMailer.new(configuration: configuration).deliver({}) }.to raise_error(Hanami::Mailer::MissingDeliveryDataError)
|
||||
end
|
||||
|
||||
describe 'test delivery with hardcoded values' do
|
||||
describe "test delivery with hardcoded values" do
|
||||
subject { WelcomeMailer.new(configuration: configuration).deliver({}) }
|
||||
|
||||
it 'sends the correct information' do
|
||||
expect(subject.from).to eq(['noreply@sender.com'])
|
||||
expect(subject.to).to eq(['noreply@recipient.com', 'owner@recipient.com'])
|
||||
expect(subject.cc).to eq(['cc@recipient.com'])
|
||||
expect(subject.bcc).to eq(['bcc@recipient.com'])
|
||||
expect(subject.subject).to eq('Welcome')
|
||||
it "sends the correct information" do
|
||||
expect(subject.from).to eq(["noreply@sender.com"])
|
||||
expect(subject.to).to eq(["noreply@recipient.com", "owner@recipient.com"])
|
||||
expect(subject.cc).to eq(["cc@recipient.com"])
|
||||
expect(subject.bcc).to eq(["bcc@recipient.com"])
|
||||
expect(subject.subject).to eq("Welcome")
|
||||
end
|
||||
|
||||
it 'has the correct templates' do
|
||||
it "has the correct templates" do
|
||||
expect(subject.html_part.to_s).to include(%(template))
|
||||
expect(subject.text_part.to_s).to include(%(template))
|
||||
end
|
||||
|
||||
it 'interprets the prepare statement' do
|
||||
attachment = subject.attachments['invoice.pdf']
|
||||
it "interprets the prepare statement" do
|
||||
attachment = subject.attachments["invoice.pdf"]
|
||||
|
||||
expect(attachment).to be_kind_of(Mail::Part)
|
||||
|
||||
|
@ -42,29 +42,29 @@ RSpec.describe Hanami::Mailer do
|
|||
expect(attachment).to_not be_inline
|
||||
expect(attachment).to_not be_multipart
|
||||
|
||||
expect(attachment.filename).to eq('invoice.pdf')
|
||||
expect(attachment.filename).to eq("invoice.pdf")
|
||||
|
||||
expect(attachment.content_type).to match('application/pdf')
|
||||
expect(attachment.content_type).to match('filename=invoice.pdf')
|
||||
expect(attachment.content_type).to match("application/pdf")
|
||||
expect(attachment.content_type).to match("filename=invoice.pdf")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'test delivery with procs' do
|
||||
describe "test delivery with procs" do
|
||||
subject { ProcMailer.new(configuration: configuration).deliver(user: user) }
|
||||
let(:user) { User.new('Name', 'student@deigirls.com') }
|
||||
let(:user) { User.new("Name", "student@deigirls.com") }
|
||||
|
||||
it 'sends the correct information' do
|
||||
it "sends the correct information" do
|
||||
expect(subject.from).to eq(["hello-#{user.name.downcase}@example.com"])
|
||||
expect(subject.to).to eq([user.email])
|
||||
expect(subject.subject).to eq("[Hanami] Hello, #{user.name}")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'test delivery with locals' do
|
||||
describe "test delivery with locals" do
|
||||
subject { EventMailer.new(configuration: configuration) }
|
||||
let(:count) { 100 }
|
||||
|
||||
it 'delivers the message' do
|
||||
it "delivers the message" do
|
||||
threads = []
|
||||
mails = {}
|
||||
|
||||
|
@ -87,8 +87,8 @@ RSpec.describe Hanami::Mailer do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'multipart' do
|
||||
it 'delivers all the parts by default' do
|
||||
describe "multipart" do
|
||||
it "delivers all the parts by default" do
|
||||
mail = WelcomeMailer.new(configuration: configuration).deliver({})
|
||||
body = mail.body.encoded
|
||||
|
||||
|
@ -96,7 +96,7 @@ RSpec.describe Hanami::Mailer do
|
|||
expect(body).to include(%(This is a txt template))
|
||||
end
|
||||
|
||||
it 'can deliver only the text part' do
|
||||
it "can deliver only the text part" do
|
||||
mail = WelcomeMailer.new(configuration: configuration).deliver(format: :txt)
|
||||
body = mail.body.encoded
|
||||
|
||||
|
@ -104,7 +104,7 @@ RSpec.describe Hanami::Mailer do
|
|||
expect(body).to include(%(This is a txt template))
|
||||
end
|
||||
|
||||
it 'can deliver only the html part' do
|
||||
it "can deliver only the html part" do
|
||||
mail = WelcomeMailer.new(configuration: configuration).deliver(format: :html)
|
||||
body = mail.body.encoded
|
||||
|
||||
|
@ -113,7 +113,7 @@ RSpec.describe Hanami::Mailer do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'custom delivery' do
|
||||
describe "custom delivery" do
|
||||
before do
|
||||
mailer.deliver({})
|
||||
end
|
||||
|
@ -124,30 +124,30 @@ RSpec.describe Hanami::Mailer do
|
|||
|
||||
let(:configuration) do
|
||||
configuration = Hanami::Mailer::Configuration.new do |config|
|
||||
config.root = 'spec/support/fixtures'
|
||||
config.root = "spec/support/fixtures"
|
||||
config.delivery_method = MandrillDeliveryMethod, options
|
||||
end
|
||||
|
||||
Hanami::Mailer.finalize(configuration)
|
||||
end
|
||||
|
||||
it 'delivers the mail' do
|
||||
it "delivers the mail" do
|
||||
expect(options.fetch(:deliveries).size).to be(1)
|
||||
end
|
||||
|
||||
it 'sends the correct information' do
|
||||
expect(subject.from).to eq(['noreply@sender.com'])
|
||||
expect(subject.to).to eq(['noreply@recipient.com', 'owner@recipient.com'])
|
||||
it "sends the correct information" do
|
||||
expect(subject.from).to eq(["noreply@sender.com"])
|
||||
expect(subject.to).to eq(["noreply@recipient.com", "owner@recipient.com"])
|
||||
expect(subject.subject).to eq("Welcome")
|
||||
end
|
||||
|
||||
it 'has the correct templates' do
|
||||
it "has the correct templates" do
|
||||
expect(subject.html_part.to_s).to include(%(template))
|
||||
expect(subject.text_part.to_s).to include(%(template))
|
||||
end
|
||||
|
||||
it 'runs the before callback' do
|
||||
expect(subject.attachments['invoice.pdf']).to_not be(nil)
|
||||
it "runs the before callback" do
|
||||
expect(subject.attachments["invoice.pdf"]).to_not be(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@ RSpec.configure do |config|
|
|||
|
||||
config.warnings = true
|
||||
|
||||
config.default_formatter = 'doc' if config.files_to_run.one?
|
||||
config.default_formatter = "doc" if config.files_to_run.one?
|
||||
|
||||
config.profile_examples = 10
|
||||
|
||||
|
@ -24,9 +24,9 @@ RSpec.configure do |config|
|
|||
Kernel.srand config.seed
|
||||
end
|
||||
|
||||
require 'ostruct'
|
||||
require 'hanami/utils'
|
||||
require "ostruct"
|
||||
require "hanami/utils"
|
||||
|
||||
$LOAD_PATH.unshift 'lib'
|
||||
require 'hanami/mailer'
|
||||
$LOAD_PATH.unshift "lib"
|
||||
require "hanami/mailer"
|
||||
Hanami::Utils.require!("spec/support")
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module RSpec
|
||||
module Support
|
||||
module Context
|
||||
|
@ -5,7 +7,7 @@ module RSpec
|
|||
base.class_eval do
|
||||
let(:configuration) do
|
||||
configuration = Hanami::Mailer::Configuration.new do |config|
|
||||
config.root = 'spec/support/fixtures'
|
||||
config.root = "spec/support/fixtures"
|
||||
config.delivery_method = :test
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class InvoiceMailer < Hanami::Mailer
|
||||
template 'invoice'
|
||||
template "invoice"
|
||||
end
|
||||
|
||||
class RenderMailer < Hanami::Mailer
|
||||
|
@ -11,39 +11,39 @@ class TemplateEngineMailer < Hanami::Mailer
|
|||
end
|
||||
|
||||
class CharsetMailer < Hanami::Mailer
|
||||
from 'noreply@example.com'
|
||||
to 'user@example.com'
|
||||
subject 'こんにちは'
|
||||
from "noreply@example.com"
|
||||
to "user@example.com"
|
||||
subject "こんにちは"
|
||||
end
|
||||
|
||||
class MissingFromMailer < Hanami::Mailer
|
||||
template 'missing'
|
||||
template "missing"
|
||||
|
||||
to 'recipient@example.com'
|
||||
subject 'Hello'
|
||||
to "recipient@example.com"
|
||||
subject "Hello"
|
||||
end
|
||||
|
||||
class MissingToMailer < Hanami::Mailer
|
||||
template 'missing'
|
||||
template "missing"
|
||||
|
||||
from 'sender@example.com'
|
||||
subject 'Hello'
|
||||
from "sender@example.com"
|
||||
subject "Hello"
|
||||
end
|
||||
|
||||
class CcOnlyMailer < Hanami::Mailer
|
||||
template 'missing'
|
||||
template "missing"
|
||||
|
||||
cc 'recipient@example.com'
|
||||
from 'sender@example.com'
|
||||
subject 'Hello'
|
||||
cc "recipient@example.com"
|
||||
from "sender@example.com"
|
||||
subject "Hello"
|
||||
end
|
||||
|
||||
class BccOnlyMailer < Hanami::Mailer
|
||||
template 'missing'
|
||||
template "missing"
|
||||
|
||||
bcc 'recipient@example.com'
|
||||
from 'sender@example.com'
|
||||
subject 'Hello'
|
||||
bcc "recipient@example.com"
|
||||
from "sender@example.com"
|
||||
subject "Hello"
|
||||
end
|
||||
|
||||
User = Struct.new(:name, :email)
|
||||
|
@ -62,19 +62,19 @@ class ProcMailer < Hanami::Mailer
|
|||
end
|
||||
|
||||
class WelcomeMailer < Hanami::Mailer
|
||||
from 'noreply@sender.com'
|
||||
to ['noreply@recipient.com', 'owner@recipient.com']
|
||||
cc 'cc@recipient.com'
|
||||
bcc 'bcc@recipient.com'
|
||||
from "noreply@sender.com"
|
||||
to ["noreply@recipient.com", "owner@recipient.com"]
|
||||
cc "cc@recipient.com"
|
||||
bcc "bcc@recipient.com"
|
||||
|
||||
subject 'Welcome'
|
||||
subject "Welcome"
|
||||
|
||||
before do |mail|
|
||||
mail.attachments['invoice.pdf'] = "/path/to/invoice-#{invoice_code}.pdf"
|
||||
mail.attachments["invoice.pdf"] = "/path/to/invoice-#{invoice_code}.pdf"
|
||||
end
|
||||
|
||||
def greeting
|
||||
'Ahoy'
|
||||
"Ahoy"
|
||||
end
|
||||
|
||||
def invoice_code
|
||||
|
@ -83,7 +83,7 @@ class WelcomeMailer < Hanami::Mailer
|
|||
end
|
||||
|
||||
class EventMailer < Hanami::Mailer
|
||||
from 'events@domain.test'
|
||||
from "events@domain.test"
|
||||
to ->(locals) { locals.fetch(:user).email }
|
||||
subject ->(locals) { "Invitation: #{locals.fetch(:event).title}" }
|
||||
|
||||
|
@ -124,6 +124,6 @@ end
|
|||
|
||||
module DefaultSubject
|
||||
def self.included(mailer)
|
||||
mailer.subject 'default subject'
|
||||
mailer.subject "default subject"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,23 +3,23 @@
|
|||
RSpec.describe Hanami::Mailer::Configuration do
|
||||
subject { described_class.new }
|
||||
|
||||
describe '#root=' do
|
||||
describe 'when a value is given' do
|
||||
describe 'and it is a string' do
|
||||
it 'sets it as a Pathname' do
|
||||
subject.root = 'spec'
|
||||
expect(subject.root).to eq(Pathname.new('spec').realpath)
|
||||
describe "#root=" do
|
||||
describe "when a value is given" do
|
||||
describe "and it is a string" do
|
||||
it "sets it as a Pathname" do
|
||||
subject.root = "spec"
|
||||
expect(subject.root).to eq(Pathname.new("spec").realpath)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'and it is a pathname' do
|
||||
it 'sets it' do
|
||||
subject.root = Pathname.new('spec')
|
||||
expect(subject.root).to eq(Pathname.new('spec').realpath)
|
||||
describe "and it is a pathname" do
|
||||
it "sets it" do
|
||||
subject.root = Pathname.new("spec")
|
||||
expect(subject.root).to eq(Pathname.new("spec").realpath)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'and it implements #to_pathname' do
|
||||
describe "and it implements #to_pathname" do
|
||||
before do
|
||||
RootPath = Struct.new(:path) do
|
||||
def to_pathname
|
||||
|
@ -32,71 +32,71 @@ RSpec.describe Hanami::Mailer::Configuration do
|
|||
Object.send(:remove_const, :RootPath)
|
||||
end
|
||||
|
||||
it 'sets the converted value' do
|
||||
subject.root = RootPath.new('spec')
|
||||
expect(subject.root).to eq(Pathname.new('spec').realpath)
|
||||
it "sets the converted value" do
|
||||
subject.root = RootPath.new("spec")
|
||||
expect(subject.root).to eq(Pathname.new("spec").realpath)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'and it is an unexisting path' do
|
||||
it 'raises an error' do
|
||||
describe "and it is an unexisting path" do
|
||||
it "raises an error" do
|
||||
expect do
|
||||
subject.root = '/path/to/unknown'
|
||||
subject.root = "/path/to/unknown"
|
||||
end.to raise_error(Errno::ENOENT)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when a value is not given' do
|
||||
it 'defaults to the current path' do
|
||||
expect(subject.root).to eq(Pathname.new('.').realpath)
|
||||
describe "when a value is not given" do
|
||||
it "defaults to the current path" do
|
||||
expect(subject.root).to eq(Pathname.new(".").realpath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#delivery_method' do
|
||||
describe 'when not previously set' do
|
||||
it 'defaults to SMTP' do
|
||||
describe "#delivery_method" do
|
||||
describe "when not previously set" do
|
||||
it "defaults to SMTP" do
|
||||
expect(subject.delivery_method).to eq(:smtp)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'set with a symbol' do
|
||||
describe "set with a symbol" do
|
||||
before do
|
||||
subject.delivery_method = :exim, { location: '/path/to/exim' }
|
||||
subject.delivery_method = :exim, { location: "/path/to/exim" }
|
||||
end
|
||||
|
||||
it 'saves the delivery method in the configuration' do
|
||||
expect(subject.delivery_method).to eq([:exim, { location: '/path/to/exim' }])
|
||||
it "saves the delivery method in the configuration" do
|
||||
expect(subject.delivery_method).to eq([:exim, { location: "/path/to/exim" }])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'set with a class' do
|
||||
describe "set with a class" do
|
||||
before do
|
||||
subject.delivery_method = MandrillDeliveryMethod,
|
||||
{ username: 'mandrill-username', password: 'mandrill-api-key' }
|
||||
{ username: "mandrill-username", password: "mandrill-api-key" }
|
||||
end
|
||||
|
||||
it 'saves the delivery method in the configuration' do
|
||||
expect(subject.delivery_method).to eq([MandrillDeliveryMethod, username: 'mandrill-username', password: 'mandrill-api-key'])
|
||||
it "saves the delivery method in the configuration" do
|
||||
expect(subject.delivery_method).to eq([MandrillDeliveryMethod, username: "mandrill-username", password: "mandrill-api-key"])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#default_charset' do
|
||||
describe 'when not previously set' do
|
||||
it 'defaults to UTF-8' do
|
||||
expect(subject.default_charset).to eq('UTF-8')
|
||||
describe "#default_charset" do
|
||||
describe "when not previously set" do
|
||||
it "defaults to UTF-8" do
|
||||
expect(subject.default_charset).to eq("UTF-8")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when set' do
|
||||
describe "when set" do
|
||||
before do
|
||||
subject.default_charset = 'iso-8859-1'
|
||||
subject.default_charset = "iso-8859-1"
|
||||
end
|
||||
|
||||
it 'saves the delivery method in the configuration' do
|
||||
expect(subject.default_charset).to eq('iso-8859-1')
|
||||
it "saves the delivery method in the configuration" do
|
||||
expect(subject.default_charset).to eq("iso-8859-1")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,117 +3,117 @@
|
|||
RSpec.describe Hanami::Mailer::Dsl do
|
||||
let(:mailer) { Class.new { extend Hanami::Mailer::Dsl } }
|
||||
|
||||
describe '.from' do
|
||||
it 'returns the default value' do
|
||||
describe ".from" do
|
||||
it "returns the default value" do
|
||||
expect(mailer.from).to be(nil)
|
||||
end
|
||||
|
||||
it 'sets the value' do
|
||||
sender = 'sender@hanami.test'
|
||||
it "sets the value" do
|
||||
sender = "sender@hanami.test"
|
||||
mailer.from sender
|
||||
|
||||
expect(mailer.from).to eq(sender)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.to' do
|
||||
it 'returns the default value' do
|
||||
describe ".to" do
|
||||
it "returns the default value" do
|
||||
expect(mailer.to).to be(nil)
|
||||
end
|
||||
|
||||
it 'sets a single value' do
|
||||
recipient = 'recipient@hanami.test'
|
||||
it "sets a single value" do
|
||||
recipient = "recipient@hanami.test"
|
||||
mailer.to recipient
|
||||
|
||||
expect(mailer.to).to eq(recipient)
|
||||
end
|
||||
|
||||
it 'sets an array of values' do
|
||||
recipients = ['recipient@hanami.test']
|
||||
it "sets an array of values" do
|
||||
recipients = ["recipient@hanami.test"]
|
||||
mailer.to recipients
|
||||
|
||||
expect(mailer.to).to eq(recipients)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.cc' do
|
||||
it 'returns the default value' do
|
||||
describe ".cc" do
|
||||
it "returns the default value" do
|
||||
expect(mailer.cc).to be(nil)
|
||||
end
|
||||
|
||||
it 'sets a single value' do
|
||||
recipient = 'cc@hanami.test'
|
||||
it "sets a single value" do
|
||||
recipient = "cc@hanami.test"
|
||||
mailer.cc recipient
|
||||
|
||||
expect(mailer.cc).to eq(recipient)
|
||||
end
|
||||
|
||||
it 'sets an array of values' do
|
||||
recipients = ['cc@hanami.test']
|
||||
it "sets an array of values" do
|
||||
recipients = ["cc@hanami.test"]
|
||||
mailer.cc recipients
|
||||
|
||||
expect(mailer.cc).to eq(recipients)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.bcc' do
|
||||
it 'returns the default value' do
|
||||
describe ".bcc" do
|
||||
it "returns the default value" do
|
||||
expect(mailer.bcc).to be(nil)
|
||||
end
|
||||
|
||||
it 'sets a single value' do
|
||||
recipient = 'bcc@hanami.test'
|
||||
it "sets a single value" do
|
||||
recipient = "bcc@hanami.test"
|
||||
mailer.bcc recipient
|
||||
|
||||
expect(mailer.bcc).to eq(recipient)
|
||||
end
|
||||
|
||||
it 'sets an array of values' do
|
||||
recipients = ['bcc@hanami.test']
|
||||
it "sets an array of values" do
|
||||
recipients = ["bcc@hanami.test"]
|
||||
mailer.bcc recipients
|
||||
|
||||
expect(mailer.bcc).to eq(recipients)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.subject' do
|
||||
it 'returns the default value' do
|
||||
describe ".subject" do
|
||||
it "returns the default value" do
|
||||
expect(mailer.subject).to be(nil)
|
||||
end
|
||||
|
||||
it 'sets a value' do
|
||||
mail_subject = 'Hello'
|
||||
it "sets a value" do
|
||||
mail_subject = "Hello"
|
||||
mailer.subject mail_subject
|
||||
|
||||
expect(mailer.subject).to eq(mail_subject)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.template' do
|
||||
it 'sets a value' do
|
||||
mailer.template 'file'
|
||||
describe ".template" do
|
||||
it "sets a value" do
|
||||
mailer.template "file"
|
||||
end
|
||||
end
|
||||
|
||||
describe '.template_name' do
|
||||
it 'returns the default value' do
|
||||
describe ".template_name" do
|
||||
it "returns the default value" do
|
||||
expect(mailer.template_name).to be(nil)
|
||||
end
|
||||
|
||||
it 'returns value, if set' do
|
||||
template = 'file'
|
||||
it "returns value, if set" do
|
||||
template = "file"
|
||||
mailer.template template
|
||||
|
||||
expect(mailer.template_name).to eq(template)
|
||||
end
|
||||
end
|
||||
|
||||
describe '.before' do
|
||||
it 'returns the default value' do
|
||||
describe ".before" do
|
||||
it "returns the default value" do
|
||||
expect(mailer.before).to be_kind_of(Proc)
|
||||
end
|
||||
|
||||
it 'sets a value' do
|
||||
it "sets a value" do
|
||||
blk = ->(*) {}
|
||||
mailer.before(&blk)
|
||||
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
RSpec.describe Hanami::Mailer::Finalizer do
|
||||
let(:configuration) do
|
||||
Hanami::Mailer::Configuration.new do |config|
|
||||
config.root = 'spec/support/fixtures'
|
||||
config.root = "spec/support/fixtures"
|
||||
end
|
||||
end
|
||||
|
||||
let(:mailers) { [double('mailer', template_name: "invoice")] }
|
||||
let(:mailers) { [double("mailer", template_name: "invoice")] }
|
||||
|
||||
describe '.finalize' do
|
||||
it 'eager autoloads modules from mail gem' do
|
||||
describe ".finalize" do
|
||||
it "eager autoloads modules from mail gem" do
|
||||
expect(Mail).to receive(:eager_autoload!)
|
||||
described_class.finalize(mailers, configuration)
|
||||
end
|
||||
|
|
|
@ -121,46 +121,46 @@ RSpec.describe Hanami::Mailer do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#render' do
|
||||
describe 'when template is explicitly declared' do
|
||||
describe "#render" do
|
||||
describe "when template is explicitly declared" do
|
||||
let(:mailer) { InvoiceMailer.new(configuration: configuration) }
|
||||
|
||||
it 'renders the given template' do
|
||||
it "renders the given template" do
|
||||
expect(mailer.render(:html, {})).to include(%(<h1>Invoice template</h1>))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when template is implicitly declared' do
|
||||
describe "when template is implicitly declared" do
|
||||
let(:mailer) { LazyMailer.new(configuration: configuration) }
|
||||
|
||||
it 'looks for template with same name with inflected classname and render it' do
|
||||
it "looks for template with same name with inflected classname and render it" do
|
||||
expect(mailer.render(:html, {})).to include(%(Hello World))
|
||||
expect(mailer.render(:txt, {})).to include(%(This is a txt template))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when mailer defines context' do
|
||||
describe "when mailer defines context" do
|
||||
let(:mailer) { WelcomeMailer.new(configuration: configuration) }
|
||||
|
||||
it 'renders template with defined context' do
|
||||
it "renders template with defined context" do
|
||||
expect(mailer.render(:txt, {})).to include(%(Ahoy))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when locals are parsed in' do
|
||||
describe "when locals are parsed in" do
|
||||
let(:mailer) { RenderMailer.new(configuration: configuration) }
|
||||
let(:locals) { { user: User.new('Luca') } }
|
||||
let(:locals) { { user: User.new("Luca") } }
|
||||
|
||||
it 'renders template with parsed locals' do
|
||||
it "renders template with parsed locals" do
|
||||
expect(mailer.render(:html, locals)).to include(locals.fetch(:user).name)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with HAML template engine' do
|
||||
describe "with HAML template engine" do
|
||||
let(:mailer) { TemplateEngineMailer.new(configuration: configuration) }
|
||||
let(:locals) { { user: User.new('MG') } }
|
||||
let(:locals) { { user: User.new("MG") } }
|
||||
|
||||
it 'renders template with parsed locals' do
|
||||
it "renders template with parsed locals" do
|
||||
expect(mailer.render(:html, locals)).to include(%(<h1>\n#{locals.fetch(:user).name}\n</h1>\n))
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue