From dabbefd50e79a45b1831237f02ce9949c419b2a6 Mon Sep 17 00:00:00 2001 From: "esref.viduslu" Date: Mon, 30 Oct 2017 16:43:41 +0300 Subject: [PATCH 1/4] KBP-123 #time 3h - Dotenv gem added in gemfile and env.sample, .env.local, .env.staging, .env.production files created. --- lib/cybele.rb | 1 + lib/cybele/app_builder.rb | 1 + lib/cybele/generators/app_generator.rb | 5 ++++ lib/cybele/helpers/dotenv.rb | 27 +++++++++++++++++++ spec/features/new_default_project_spec.rb | 21 +++++++++++++++ spec/features/new_not_default_project_spec.rb | 21 +++++++++++++++ templates/dotenv/.env.local.erb | 3 +++ templates/dotenv/.env.production.erb | 5 ++++ templates/dotenv/.env.staging.erb | 5 ++++ templates/dotenv/dotenv_Gemfile.erb | 2 ++ templates/dotenv/env.sample.erb | 3 +++ .../recipient_interceptor_staging.rb.erb | 3 ++- 12 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 lib/cybele/helpers/dotenv.rb create mode 100644 templates/dotenv/.env.local.erb create mode 100644 templates/dotenv/.env.production.erb create mode 100644 templates/dotenv/.env.staging.erb create mode 100644 templates/dotenv/dotenv_Gemfile.erb create mode 100644 templates/dotenv/env.sample.erb diff --git a/lib/cybele.rb b/lib/cybele.rb index 58c5249..e7fc600 100644 --- a/lib/cybele.rb +++ b/lib/cybele.rb @@ -10,4 +10,5 @@ require 'cybele/helpers/show_for' require 'cybele/helpers/recipient_interceptor' require 'cybele/helpers/locale_language' +require 'cybele/helpers/dotenv' require 'cybele/app_builder' diff --git a/lib/cybele/app_builder.rb b/lib/cybele/app_builder.rb index 9f0b5e1..4c8f1d5 100644 --- a/lib/cybele/app_builder.rb +++ b/lib/cybele/app_builder.rb @@ -10,6 +10,7 @@ class AppBuilder < Rails::AppBuilder include Cybele::Helpers::RecipientInterceptor include Cybele::Helpers::ShowFor include Cybele::Helpers::LocaleLanguage + include Cybele::Helpers::Dotenv def readme template 'README.md.erb', diff --git a/lib/cybele/generators/app_generator.rb b/lib/cybele/generators/app_generator.rb index e19ae78..bb1f481 100644 --- a/lib/cybele/generators/app_generator.rb +++ b/lib/cybele/generators/app_generator.rb @@ -158,6 +158,11 @@ def add_staging_secret_key build :add_staging_secret_key_to_secrets_yml end + def setup_dotenv + say 'Generate env.sample and .env files', :green + build :configure_dotenv + end + def goodbye say 'Congratulations! That\'s all...', :green end diff --git a/lib/cybele/helpers/dotenv.rb b/lib/cybele/helpers/dotenv.rb new file mode 100644 index 0000000..4c08a70 --- /dev/null +++ b/lib/cybele/helpers/dotenv.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +module Cybele + module Helpers + module Dotenv + def configure_dotenv + # Add dotenv gem + append_file('Gemfile', template_content('dotenv/dotenv_Gemfile.erb')) + run_bundle + + # Create dotenv files + template 'dotenv/env.sample.erb', + 'env.sample', + force: true + template 'dotenv/.env.local.erb', + '.env.local', + force: true + template 'dotenv/.env.staging.erb', + '.env.staging', + force: true + template 'dotenv/.env.production.erb', + '.env.production', + force: true + end + end + end +end \ No newline at end of file diff --git a/spec/features/new_default_project_spec.rb b/spec/features/new_default_project_spec.rb index 9ec88c3..1bcca34 100644 --- a/spec/features/new_default_project_spec.rb +++ b/spec/features/new_default_project_spec.rb @@ -211,4 +211,25 @@ secret_file = content('config/secrets.yml') expect(secret_file).to match('staging') end + + it 'control env.sample and .env files' do + gemfile_file = content('Gemfile') + expect(gemfile_file).to match(/^gem 'dotenv-rails'/) + + expect(File).to exist(file_project_path('env.sample')) + env_sample_file = content('env.sample') + expect(env_sample_file).to match('ROOT_PATH=http://localhost:3000') + + expect(File).to exist(file_project_path('.env.local')) + env_local_file = content('.env.local') + expect(env_local_file).to match('ROOT_PATH=http://localhost:3000') + + expect(File).to exist(file_project_path('.env.staging')) + env_staging_file = content('.env.staging') + expect(env_staging_file).to match('ROOT_PATH=https://staging-dummy_app.herokuapp.com') + + expect(File).to exist(file_project_path('.env.production')) + env_production_file = content('.env.production') + expect(env_production_file).to match('ROOT_PATH=https://dummy_app.herokuapp.com') + end end diff --git a/spec/features/new_not_default_project_spec.rb b/spec/features/new_not_default_project_spec.rb index 5cda8ef..1e16358 100644 --- a/spec/features/new_not_default_project_spec.rb +++ b/spec/features/new_not_default_project_spec.rb @@ -191,4 +191,25 @@ secret_file = content('config/secrets.yml') expect(secret_file).to match('staging') end + + it 'control env.sample and .env files' do + gemfile_file = content('Gemfile') + expect(gemfile_file).to match(/^gem 'dotenv-rails'/) + + expect(File).to exist(file_project_path('env.sample')) + env_sample_file = content('env.sample') + expect(env_sample_file).to match('ROOT_PATH=http://localhost:3000') + + expect(File).to exist(file_project_path('.env.local')) + env_local_file = content('.env.local') + expect(env_local_file).to match('ROOT_PATH=http://localhost:3000') + + expect(File).to exist(file_project_path('.env.staging')) + env_staging_file = content('.env.staging') + expect(env_staging_file).to match('ROOT_PATH=https://staging-dummy_app.herokuapp.com') + + expect(File).to exist(file_project_path('.env.production')) + env_production_file = content('.env.production') + expect(env_production_file).to match('ROOT_PATH=https://dummy_app.herokuapp.com') + end end diff --git a/templates/dotenv/.env.local.erb b/templates/dotenv/.env.local.erb new file mode 100644 index 0000000..e817432 --- /dev/null +++ b/templates/dotenv/.env.local.erb @@ -0,0 +1,3 @@ +ROOT_PATH=http://localhost:3000 + +ROLLBAR_ACCESS_TOKEN= \ No newline at end of file diff --git a/templates/dotenv/.env.production.erb b/templates/dotenv/.env.production.erb new file mode 100644 index 0000000..7d728f2 --- /dev/null +++ b/templates/dotenv/.env.production.erb @@ -0,0 +1,5 @@ +ROOT_PATH=https://<%= app_name %>.herokuapp.com + +ROLLBAR_ACCESS_TOKEN= + +SECRET_KEY_BASE= \ No newline at end of file diff --git a/templates/dotenv/.env.staging.erb b/templates/dotenv/.env.staging.erb new file mode 100644 index 0000000..a262956 --- /dev/null +++ b/templates/dotenv/.env.staging.erb @@ -0,0 +1,5 @@ +ROOT_PATH=https://staging-<%= app_name %>.herokuapp.com + +ROLLBAR_ACCESS_TOKEN= + +SECRET_KEY_BASE= \ No newline at end of file diff --git a/templates/dotenv/dotenv_Gemfile.erb b/templates/dotenv/dotenv_Gemfile.erb new file mode 100644 index 0000000..6f87128 --- /dev/null +++ b/templates/dotenv/dotenv_Gemfile.erb @@ -0,0 +1,2 @@ +#Dot-Env +gem 'dotenv-rails', require: 'dotenv/rails-now' \ No newline at end of file diff --git a/templates/dotenv/env.sample.erb b/templates/dotenv/env.sample.erb new file mode 100644 index 0000000..e817432 --- /dev/null +++ b/templates/dotenv/env.sample.erb @@ -0,0 +1,3 @@ +ROOT_PATH=http://localhost:3000 + +ROLLBAR_ACCESS_TOKEN= \ No newline at end of file diff --git a/templates/recipient_interceptor/recipient_interceptor_staging.rb.erb b/templates/recipient_interceptor/recipient_interceptor_staging.rb.erb index c54fc8c..583d69e 100644 --- a/templates/recipient_interceptor/recipient_interceptor_staging.rb.erb +++ b/templates/recipient_interceptor/recipient_interceptor_staging.rb.erb @@ -1 +1,2 @@ -Mail.register_interceptor RecipientInterceptor.new(Settings.email.sandbox, subject_prefix: '[STAGING]') \ No newline at end of file + + Mail.register_interceptor RecipientInterceptor.new(Settings.email.sandbox, subject_prefix: '[STAGING]') \ No newline at end of file From 2d428dc77cd1a2fcbafd017790af395c0150a899 Mon Sep 17 00:00:00 2001 From: "esref.viduslu" Date: Mon, 30 Oct 2017 16:51:02 +0300 Subject: [PATCH 2/4] KBP-123 #time 5m - Rubocop offenses fixed --- lib/cybele/helpers/dotenv.rb | 2 +- spec/features/new_not_default_project_spec.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/cybele/helpers/dotenv.rb b/lib/cybele/helpers/dotenv.rb index 4c08a70..ac267d9 100644 --- a/lib/cybele/helpers/dotenv.rb +++ b/lib/cybele/helpers/dotenv.rb @@ -24,4 +24,4 @@ def configure_dotenv end end end -end \ No newline at end of file +end diff --git a/spec/features/new_not_default_project_spec.rb b/spec/features/new_not_default_project_spec.rb index 1e16358..08bebe6 100644 --- a/spec/features/new_not_default_project_spec.rb +++ b/spec/features/new_not_default_project_spec.rb @@ -168,7 +168,6 @@ expect(locale_file).to match('view:') end - it 'uses recipient_interceptor' do gemfile_file = content('Gemfile') expect(gemfile_file).to match(/^gem 'recipient_interceptor'/) From 51efdd76127327fc6c6e35ba02c36dcc8eb34a52 Mon Sep 17 00:00:00 2001 From: FatihAvsan Date: Tue, 31 Oct 2017 11:51:50 +0300 Subject: [PATCH 3/4] KBP-130 #time 30m - integrate rails-i18n gem --- spec/features/new_default_project_spec.rb | 5 +++++ spec/features/new_not_default_project_spec.rb | 6 +++++- templates/Gemfile.erb | 5 ++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/spec/features/new_default_project_spec.rb b/spec/features/new_default_project_spec.rb index 9ec88c3..ac435f2 100644 --- a/spec/features/new_default_project_spec.rb +++ b/spec/features/new_default_project_spec.rb @@ -117,6 +117,11 @@ expect(gemfile_file).to match("gem 'better_errors'") end + it 'uses rails-i18n' do + gemfile_file = content('Gemfile') + expect(gemfile_file).to match(/^gem 'rails-i18n'/) + end + it 'uses show_for' do gemfile_file = content('Gemfile') expect(gemfile_file).to match(/^gem 'show_for'/) diff --git a/spec/features/new_not_default_project_spec.rb b/spec/features/new_not_default_project_spec.rb index 5cda8ef..4f85c74 100644 --- a/spec/features/new_not_default_project_spec.rb +++ b/spec/features/new_not_default_project_spec.rb @@ -108,6 +108,11 @@ expect(gemfile_file).to match("gem 'better_errors'") end + it 'uses rails-i18n' do + gemfile_file = content('Gemfile') + expect(gemfile_file).to match(/^gem 'rails-i18n'/) + end + it 'do not use show_for' do gemfile_file = content('Gemfile') expect(gemfile_file).not_to match(/^gem 'show_for'/) @@ -168,7 +173,6 @@ expect(locale_file).to match('view:') end - it 'uses recipient_interceptor' do gemfile_file = content('Gemfile') expect(gemfile_file).to match(/^gem 'recipient_interceptor'/) diff --git a/templates/Gemfile.erb b/templates/Gemfile.erb index b733e14..00ebecc 100644 --- a/templates/Gemfile.erb +++ b/templates/Gemfile.erb @@ -26,4 +26,7 @@ gem 'roo', '~> 2.7', '>= 2.7.1' group :development, :test do gem 'colorize', '~> 0.8.1' gem 'better_errors', '~> 2.4' -end \ No newline at end of file +end + +# A set of common locale data and translations to internationalize and/or localize your Rails applications. +gem 'rails-i18n', '~> 5.0', '>= 5.0.4' \ No newline at end of file From c9bde7f7b55b4fe539eb16ec08ce878c22be4414 Mon Sep 17 00:00:00 2001 From: "esref.viduslu" Date: Tue, 31 Oct 2017 12:32:04 +0300 Subject: [PATCH 4/4] KBP-123 #time 30m - dotenv gem added to the top of the Gemfile list --- lib/cybele/helpers/dotenv.rb | 3 ++- templates/dotenv/dotenv_Gemfile.erb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/cybele/helpers/dotenv.rb b/lib/cybele/helpers/dotenv.rb index ac267d9..9cc06cd 100644 --- a/lib/cybele/helpers/dotenv.rb +++ b/lib/cybele/helpers/dotenv.rb @@ -5,7 +5,8 @@ module Helpers module Dotenv def configure_dotenv # Add dotenv gem - append_file('Gemfile', template_content('dotenv/dotenv_Gemfile.erb')) + inject_into_file 'Gemfile', template_content('dotenv/dotenv_Gemfile.erb'), + before: "# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'" run_bundle # Create dotenv files diff --git a/templates/dotenv/dotenv_Gemfile.erb b/templates/dotenv/dotenv_Gemfile.erb index 6f87128..0846b3c 100644 --- a/templates/dotenv/dotenv_Gemfile.erb +++ b/templates/dotenv/dotenv_Gemfile.erb @@ -1,2 +1,2 @@ -#Dot-Env -gem 'dotenv-rails', require: 'dotenv/rails-now' \ No newline at end of file +# Dot-Env +gem 'dotenv-rails', require: 'dotenv/rails-now'