Skip to content

Commit

Permalink
Merged in feature/configure_mailer_settings (pull request #16)
Browse files Browse the repository at this point in the history
KBP-137 Feature/configure mailer settings

Approved-by: Eşref VİDUŞLU <esref.viduslu@lab2023.com>
Approved-by: İsmail Akbudak <ismail.akbudak@lab2023.com>
  • Loading branch information
FatihAvsan authored and İsmail Akbudak committed Nov 2, 2017
2 parents d3014c7 + b88705e commit a510ba6
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/cybele.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
require 'cybele/helpers/recipient_interceptor'
require 'cybele/helpers/haml'
require 'cybele/helpers/locale_language'
require 'cybele/helpers/mailer'
require 'cybele/helpers/paperclip'
require 'cybele/app_builder'
5 changes: 5 additions & 0 deletions lib/cybele/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class AppBuilder < Rails::AppBuilder
include Cybele::Helpers::ShowFor
include Cybele::Helpers::Haml
include Cybele::Helpers::LocaleLanguage
include Cybele::Helpers::Mailer
include Cybele::Helpers::Paperclip

def readme
Expand Down Expand Up @@ -72,5 +73,9 @@ def configure_bullet
def configure_environment(rails_env, config)
inject_into_file("config/environments/#{rails_env}.rb", "\n#{config}", before: "\nend")
end

def action_mailer_host(rails_env)
configure_environment(rails_env, template_content('mailer/host.rb.erb'))
end
end
end
7 changes: 7 additions & 0 deletions lib/cybele/generators/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ def setup_paperclip_and_add_aws
build :configure_paperclip
end

def configure_mail_setting
say 'Setup mail settings'
build :configure_action_mailer
build :configure_smtp
build :setup_letter_opener
end

def goodbye
say 'Congratulations! That\'s all...', :green
end
Expand Down
25 changes: 25 additions & 0 deletions lib/cybele/helpers/mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module Cybele
module Helpers
module Mailer
def configure_action_mailer
action_mailer_host 'development'
action_mailer_host 'staging'
action_mailer_host 'production'
end

def configure_smtp
configure_environment 'staging',
template_content('recipient_interceptor/recipient_interceptor_staging.rb.erb')
configure_environment 'production', template_content('mailer/smtp.rb.erb')
configure_environment 'staging', template_content('mailer/smtp.rb.erb')
append_file 'config/settings.yml', template_content('mailer/mailer_settings.yml.erb')
end

def setup_letter_opener
configure_environment 'development', template_content('mailer/letter_opener.rb.erb')
end
end
end
end
16 changes: 16 additions & 0 deletions spec/features/new_default_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,22 @@
expect(env_production_file).to match('AWS_SECRET_ACCESS_KEY=')
end

it 'uses mailer' do
gemfile_file = content('Gemfile')
expect(gemfile_file).to match("gem 'letter_opener'")

expect(File).to exist(file_project_path('config/settings/production.yml'))
expect(File).to exist(file_project_path('config/settings/staging.yml'))

mail_test_helper('config/settings.yml')
mail_test_helper('config/environments/production.rb')
mail_test_helper('config/environments/staging.rb')

development_file = content('config/environments/development.rb')
expect(development_file).to match('host:')
expect(development_file).to match(':letter_opener')
end

it 'uses haml' do
gemfile_file = content('Gemfile')
expect(gemfile_file).to match(/^gem 'haml'/)
Expand Down
16 changes: 16 additions & 0 deletions spec/features/new_not_default_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,22 @@
expect(env_production_file).to match('ROOT_PATH=https://dummy_app.herokuapp.com')
end

it 'uses mailer' do
gemfile_file = content('Gemfile')
expect(gemfile_file).to match("gem 'letter_opener'")

expect(File).to exist(file_project_path('config/settings/production.yml'))
expect(File).to exist(file_project_path('config/settings/staging.yml'))

mail_test_helper('config/settings.yml')
mail_test_helper('config/environments/production.rb')
mail_test_helper('config/environments/staging.rb')

development_file = content('config/environments/development.rb')
expect(development_file).to match('host:')
expect(development_file).to match(':letter_opener')
end

it 'do not use haml' do
gemfile_file = content('Gemfile')
expect(gemfile_file).not_to match(/^gem 'haml'/)
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

RSpec.configure do |config|
config.include CybeleTestHelpers
config.include MailTestHelpers

config.before(:all) do
create_tmp_directory
Expand Down
17 changes: 17 additions & 0 deletions spec/support/mail_test_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module MailTestHelpers
def mail_test_helper(path)
file = content(path)
expect(file).to match('smtp')
expect(file).to match('address:')
expect(file).to match('port:')
expect(file).to match('enable_starttls_auto:')
expect(file).to match('user_name:')
expect(file).to match('password:')
expect(file).to match('authentication:')
unless content('config/settings.yml').present?
expect(file).to match('host:')
end
end
end
1 change: 1 addition & 0 deletions templates/Gemfile.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ group :development, :test do
gem 'colorize', '~> 0.8.1'
gem 'better_errors', '~> 2.4'
gem 'bullet', '~> 5.6', '>= 5.6.1'
gem 'letter_opener', '~> 1.4', '>= 1.4.1'
end

# A set of common locale data and translations to internationalize and/or localize your Rails applications.
Expand Down
2 changes: 2 additions & 0 deletions templates/mailer/host.rb.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Mail Setting
config.action_mailer.default_url_options = { host: ENV['ROOT_PATH'] }
1 change: 1 addition & 0 deletions templates/mailer/letter_opener.rb.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config.action_mailer.delivery_method = :letter_opener
9 changes: 9 additions & 0 deletions templates/mailer/mailer_settings.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root_path: <%= ENV['ROOT_PATH'] %>

smtp:
address: <%= ENV['SMTP_ADDRESS'] %>
port: 587
enable_starttls_auto: true
user_name: <%= ENV['SMTP_USER_NAME'] %>
password: <%= ENV['SMTP_PASSWORD'] %>
authentication: 'plain'
10 changes: 10 additions & 0 deletions templates/mailer/smtp.rb.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = false
config.action_mailer.smtp_settings = {
address: Settings.smtp.address,
port: Settings.smtp.port,
enable_starttls_auto: Settings.smtp.enable_starttls_auto,
user_name: Settings.smtp.user_name,
password: Settings.smtp.password,
authentication: Settings.smtp.authentication
}

0 comments on commit a510ba6

Please sign in to comment.