From d19728bce2a22ff7e643164fd33133ebe51ae268 Mon Sep 17 00:00:00 2001 From: fadimezhan Date: Thu, 7 Dec 2017 17:29:55 +0300 Subject: [PATCH 1/4] KBP-171 #time 2h - integrate mailtrap instead of letter_opener --- lib/cybele/generators/app_generator.rb | 2 +- lib/cybele/helpers/mailer.rb | 5 +++-- spec/features/new_default_project_spec.rb | 5 +++-- spec/features/new_not_default_project_spec.rb | 5 +++-- templates/Gemfile.erb | 2 +- templates/mailer/.env.local.erb | 4 ++++ templates/mailer/letter_opener.rb.erb | 1 - 7 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 templates/mailer/.env.local.erb delete mode 100644 templates/mailer/letter_opener.rb.erb diff --git a/lib/cybele/generators/app_generator.rb b/lib/cybele/generators/app_generator.rb index 7df5bba..4d16c83 100644 --- a/lib/cybele/generators/app_generator.rb +++ b/lib/cybele/generators/app_generator.rb @@ -225,7 +225,7 @@ def configure_mail_setting say 'Setup mail settings' build :configure_action_mailer build :configure_smtp - build :setup_letter_opener + build :setup_mailtrap end def gitignore_files_and_folders diff --git a/lib/cybele/helpers/mailer.rb b/lib/cybele/helpers/mailer.rb index 01aeff4..50dcc8f 100644 --- a/lib/cybele/helpers/mailer.rb +++ b/lib/cybele/helpers/mailer.rb @@ -17,8 +17,9 @@ def configure_smtp 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') + def setup_mailtrap + configure_environment 'development', template_content('mailer/smtp.rb.erb') + append_file('.env.local', "\n\n#{template_content('mailer/.env.local.erb')}") end end end diff --git a/spec/features/new_default_project_spec.rb b/spec/features/new_default_project_spec.rb index 699c267..c031312 100644 --- a/spec/features/new_default_project_spec.rb +++ b/spec/features/new_default_project_spec.rb @@ -174,7 +174,7 @@ it 'uses mailer' do gemfile_file = content('Gemfile') - expect(gemfile_file).to match("gem 'letter_opener'") + expect(gemfile_file).to match("gem 'mailtrap'") expect(File).to exist(file_project_path('config/settings/production.yml')) expect(File).to exist(file_project_path('config/settings/staging.yml')) @@ -182,10 +182,11 @@ mail_test_helper('config/settings.yml') mail_test_helper('config/environments/production.rb') mail_test_helper('config/environments/staging.rb') + mail_test_helper('config/environments/development.rb') development_file = content('config/environments/development.rb') expect(development_file).to match('host:') - expect(development_file).to match(':letter_opener') + expect(development_file).to match(':smtp') end it 'uses haml' do diff --git a/spec/features/new_not_default_project_spec.rb b/spec/features/new_not_default_project_spec.rb index 3ced797..59250f5 100644 --- a/spec/features/new_not_default_project_spec.rb +++ b/spec/features/new_not_default_project_spec.rb @@ -162,7 +162,7 @@ it 'uses mailer' do gemfile_file = content('Gemfile') - expect(gemfile_file).to match("gem 'letter_opener'") + expect(gemfile_file).to match("gem 'mailtrap'") expect(File).to exist(file_project_path('config/settings/production.yml')) expect(File).to exist(file_project_path('config/settings/staging.yml')) @@ -170,10 +170,11 @@ mail_test_helper('config/settings.yml') mail_test_helper('config/environments/production.rb') mail_test_helper('config/environments/staging.rb') + mail_test_helper('config/environments/development.rb') development_file = content('config/environments/development.rb') expect(development_file).to match('host:') - expect(development_file).to match(':letter_opener') + expect(development_file).to match(':smtp') end it 'do not use haml' do diff --git a/templates/Gemfile.erb b/templates/Gemfile.erb index cbe1809..38f64f4 100644 --- a/templates/Gemfile.erb +++ b/templates/Gemfile.erb @@ -31,7 +31,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' + gem 'mailtrap', '~> 0.2.1' gem 'pronto', '~> 0.9.5' gem 'pronto-flay', '~> 0.9.0', require: false gem 'pronto-rubocop', '~> 0.9.0', require: false diff --git a/templates/mailer/.env.local.erb b/templates/mailer/.env.local.erb new file mode 100644 index 0000000..dee3305 --- /dev/null +++ b/templates/mailer/.env.local.erb @@ -0,0 +1,4 @@ +# SMTP Get username and password from https://mailtrap.io +SMTP_USER_NAME= +SMTP_PASSWORD= +SMTP_ADDRESS=smtp.mailtrap.io \ No newline at end of file diff --git a/templates/mailer/letter_opener.rb.erb b/templates/mailer/letter_opener.rb.erb deleted file mode 100644 index 81115a3..0000000 --- a/templates/mailer/letter_opener.rb.erb +++ /dev/null @@ -1 +0,0 @@ -config.action_mailer.delivery_method = :letter_opener \ No newline at end of file From e34e314f8c6b09f97c485962a6f9a95b1e949e07 Mon Sep 17 00:00:00 2001 From: fadimezhan Date: Thu, 7 Dec 2017 17:33:13 +0300 Subject: [PATCH 2/4] KBP-171 #time 5m - refactor on test for mailer --- spec/features/new_default_project_spec.rb | 4 ---- spec/features/new_not_default_project_spec.rb | 4 ---- 2 files changed, 8 deletions(-) diff --git a/spec/features/new_default_project_spec.rb b/spec/features/new_default_project_spec.rb index c031312..22db8e8 100644 --- a/spec/features/new_default_project_spec.rb +++ b/spec/features/new_default_project_spec.rb @@ -183,10 +183,6 @@ mail_test_helper('config/environments/production.rb') mail_test_helper('config/environments/staging.rb') mail_test_helper('config/environments/development.rb') - - development_file = content('config/environments/development.rb') - expect(development_file).to match('host:') - expect(development_file).to match(':smtp') end it 'uses haml' do diff --git a/spec/features/new_not_default_project_spec.rb b/spec/features/new_not_default_project_spec.rb index 59250f5..fabcff0 100644 --- a/spec/features/new_not_default_project_spec.rb +++ b/spec/features/new_not_default_project_spec.rb @@ -171,10 +171,6 @@ mail_test_helper('config/environments/production.rb') mail_test_helper('config/environments/staging.rb') mail_test_helper('config/environments/development.rb') - - development_file = content('config/environments/development.rb') - expect(development_file).to match('host:') - expect(development_file).to match(':smtp') end it 'do not use haml' do From 66c4895ce4b0a7ab4d38c3a0113d0b50b314cf8e Mon Sep 17 00:00:00 2001 From: fadimezhan Date: Sat, 9 Dec 2017 10:19:21 +0300 Subject: [PATCH 3/4] KBP-171 #time 1h - add missing environment variables --- lib/cybele/helpers/mailer.rb | 2 +- templates/mailer/.env.local.erb | 4 +++- templates/mailer/mailer_settings.yml.erb | 3 +++ templates/mailer/mailtrap.rb.erb | 10 ++++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 templates/mailer/mailtrap.rb.erb diff --git a/lib/cybele/helpers/mailer.rb b/lib/cybele/helpers/mailer.rb index 50dcc8f..b8ebce1 100644 --- a/lib/cybele/helpers/mailer.rb +++ b/lib/cybele/helpers/mailer.rb @@ -18,7 +18,7 @@ def configure_smtp end def setup_mailtrap - configure_environment 'development', template_content('mailer/smtp.rb.erb') + configure_environment 'development', template_content('mailer/mailtrap.rb.erb') append_file('.env.local', "\n\n#{template_content('mailer/.env.local.erb')}") end end diff --git a/templates/mailer/.env.local.erb b/templates/mailer/.env.local.erb index dee3305..c99f13e 100644 --- a/templates/mailer/.env.local.erb +++ b/templates/mailer/.env.local.erb @@ -1,4 +1,6 @@ # SMTP Get username and password from https://mailtrap.io SMTP_USER_NAME= SMTP_PASSWORD= -SMTP_ADDRESS=smtp.mailtrap.io \ No newline at end of file +SMTP_PORT=2525 +SMTP_ADDRESS=smtp.mailtrap.io +SMTP_AUTHENTICATION=cram_md5 \ No newline at end of file diff --git a/templates/mailer/mailer_settings.yml.erb b/templates/mailer/mailer_settings.yml.erb index 684f195..e3f518f 100644 --- a/templates/mailer/mailer_settings.yml.erb +++ b/templates/mailer/mailer_settings.yml.erb @@ -6,3 +6,6 @@ smtp: user_name: <%= ENV['SMTP_USER_NAME'] %> password: <%= ENV['SMTP_PASSWORD'] %> authentication: 'plain' + mailtrap: + port: <%= ENV['SMTP_PORT'] %> + authentication: <%= ENV['SMTP_AUTHENTICATION'] %> diff --git a/templates/mailer/mailtrap.rb.erb b/templates/mailer/mailtrap.rb.erb new file mode 100644 index 0000000..26e52cd --- /dev/null +++ b/templates/mailer/mailtrap.rb.erb @@ -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.mailtrap.port, + enable_starttls_auto: Settings.smtp.enable_starttls_auto, + user_name: Settings.smtp.user_name, + password: Settings.smtp.password, + authentication: Settings.smtp.mailtrap.authentication + } \ No newline at end of file From b7014b29f622fa80dd062062c2d5cb291246e7b7 Mon Sep 17 00:00:00 2001 From: fadimezhan Date: Tue, 12 Dec 2017 14:17:14 +0300 Subject: [PATCH 4/4] KBP-171 #time 10m - join mailtrap settings with smtp --- lib/cybele/helpers/mailer.rb | 2 +- templates/mailer/mailer_settings.yml.erb | 3 --- templates/mailer/mailtrap.rb.erb | 10 ---------- 3 files changed, 1 insertion(+), 14 deletions(-) delete mode 100644 templates/mailer/mailtrap.rb.erb diff --git a/lib/cybele/helpers/mailer.rb b/lib/cybele/helpers/mailer.rb index b8ebce1..50dcc8f 100644 --- a/lib/cybele/helpers/mailer.rb +++ b/lib/cybele/helpers/mailer.rb @@ -18,7 +18,7 @@ def configure_smtp end def setup_mailtrap - configure_environment 'development', template_content('mailer/mailtrap.rb.erb') + configure_environment 'development', template_content('mailer/smtp.rb.erb') append_file('.env.local', "\n\n#{template_content('mailer/.env.local.erb')}") end end diff --git a/templates/mailer/mailer_settings.yml.erb b/templates/mailer/mailer_settings.yml.erb index e3f518f..684f195 100644 --- a/templates/mailer/mailer_settings.yml.erb +++ b/templates/mailer/mailer_settings.yml.erb @@ -6,6 +6,3 @@ smtp: user_name: <%= ENV['SMTP_USER_NAME'] %> password: <%= ENV['SMTP_PASSWORD'] %> authentication: 'plain' - mailtrap: - port: <%= ENV['SMTP_PORT'] %> - authentication: <%= ENV['SMTP_AUTHENTICATION'] %> diff --git a/templates/mailer/mailtrap.rb.erb b/templates/mailer/mailtrap.rb.erb deleted file mode 100644 index 26e52cd..0000000 --- a/templates/mailer/mailtrap.rb.erb +++ /dev/null @@ -1,10 +0,0 @@ - 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.mailtrap.port, - enable_starttls_auto: Settings.smtp.enable_starttls_auto, - user_name: Settings.smtp.user_name, - password: Settings.smtp.password, - authentication: Settings.smtp.mailtrap.authentication - } \ No newline at end of file