Skip to content

Commit

Permalink
KBP-131 #time 30m - code fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
FatihAvsan committed Oct 31, 2017
2 parents 90d4558 + e10314b commit cdf9e6a
Show file tree
Hide file tree
Showing 15 changed files with 122 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lib/cybele.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
require 'cybele/helpers/recipient_interceptor'
require 'cybele/helpers/haml'
require 'cybele/helpers/locale_language'
require 'cybele/helpers/bullet'
require 'cybele/helpers/dotenv'
require 'cybele/app_builder'
6 changes: 5 additions & 1 deletion lib/cybele/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AppBuilder < Rails::AppBuilder
include Cybele::Helpers::ShowFor
include Cybele::Helpers::Haml
include Cybele::Helpers::LocaleLanguage
include Cybele::Helpers::Bullet
include Cybele::Helpers::Dotenv

def readme
template 'README.md.erb',
Expand Down Expand Up @@ -62,6 +62,10 @@ def generate_rollbar
generate 'rollbar'
end

def configure_bullet
configure_environment 'development', template_content('bullet/bullet_settings.rb')
end

private

def configure_environment(rails_env, config)
Expand Down
5 changes: 5 additions & 0 deletions lib/cybele/generators/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ def setup_bullet_config
build :configure_bullet
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
Expand Down
22 changes: 0 additions & 22 deletions lib/cybele/helpers/bullet.rb

This file was deleted.

28 changes: 28 additions & 0 deletions lib/cybele/helpers/dotenv.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

module Cybele
module Helpers
module Dotenv
def configure_dotenv
# Add dotenv gem
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
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
29 changes: 26 additions & 3 deletions spec/features/new_default_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,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'/)
Expand Down Expand Up @@ -217,6 +222,27 @@
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

it 'uses haml' do
gemfile_file = content('Gemfile')
expect(gemfile_file).to match(/^gem 'haml'/)
Expand All @@ -232,8 +258,5 @@

locale_file = content('config/environments/development.rb')
expect(locale_file).to match('Bullet')

locale_file = content('config/environments/test.rb')
expect(locale_file).not_to match('Bullet')
end
end
29 changes: 26 additions & 3 deletions spec/features/new_not_default_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,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'/)
Expand Down Expand Up @@ -188,9 +193,6 @@

locale_file = content('config/environments/development.rb')
expect(locale_file).to match('Bullet')

locale_file = content('config/environments/test.rb')
expect(locale_file).not_to match('Bullet')
end

it 'do not use simple_form' do
Expand All @@ -208,6 +210,27 @@
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

it 'do not use haml' do
gemfile_file = content('Gemfile')
expect(gemfile_file).not_to match(/^gem 'haml'/)
Expand Down
3 changes: 3 additions & 0 deletions templates/Gemfile.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ group :development, :test do
gem 'better_errors', '~> 2.4'
gem 'bullet', '~> 5.6', '>= 5.6.1'
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'
8 changes: 8 additions & 0 deletions templates/bullet/bullet_settings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
config.after_initialize do
Bullet.enable = true
Bullet.alert = true
Bullet.bullet_logger = true
Bullet.console = true
Bullet.rails_logger = true
Bullet.add_footer = false
end
3 changes: 3 additions & 0 deletions templates/dotenv/.env.local.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ROOT_PATH=http://localhost:3000

ROLLBAR_ACCESS_TOKEN=
5 changes: 5 additions & 0 deletions templates/dotenv/.env.production.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ROOT_PATH=https://<%= app_name %>.herokuapp.com

ROLLBAR_ACCESS_TOKEN=

SECRET_KEY_BASE=
5 changes: 5 additions & 0 deletions templates/dotenv/.env.staging.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ROOT_PATH=https://staging-<%= app_name %>.herokuapp.com

ROLLBAR_ACCESS_TOKEN=

SECRET_KEY_BASE=
2 changes: 2 additions & 0 deletions templates/dotenv/dotenv_Gemfile.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Dot-Env
gem 'dotenv-rails', require: 'dotenv/rails-now'
3 changes: 3 additions & 0 deletions templates/dotenv/env.sample.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ROOT_PATH=http://localhost:3000

ROLLBAR_ACCESS_TOKEN=
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Mail.register_interceptor RecipientInterceptor.new(Settings.email.sandbox, subject_prefix: '[STAGING]')

Mail.register_interceptor RecipientInterceptor.new(Settings.email.sandbox, subject_prefix: '[STAGING]')

0 comments on commit cdf9e6a

Please sign in to comment.