Skip to content

Commit

Permalink
KBP-138 #time 10m - fixed code
Browse files Browse the repository at this point in the history
  • Loading branch information
FatihAvsan committed Nov 21, 2017
2 parents 7015df2 + 7769295 commit fb6d99c
Show file tree
Hide file tree
Showing 25 changed files with 409 additions and 179 deletions.
1 change: 1 addition & 0 deletions lib/cybele.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
require 'cybele/helpers/mailer'
require 'cybele/helpers/paperclip'
require 'cybele/helpers/devise'
require 'cybele/helpers/error_pages'
require 'cybele/app_builder'
5 changes: 3 additions & 2 deletions lib/cybele/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class AppBuilder < Rails::AppBuilder
include Cybele::Helpers::Mailer
include Cybele::Helpers::Paperclip
include Cybele::Helpers::Devise
include Cybele::Helpers::ErrorPages

def readme
template 'README.md.erb',
Expand Down Expand Up @@ -82,7 +83,7 @@ def setup_gitignore_files
end

def setup_gitignore_folders
%w(
%w[
app/assets/images
db/migrate
spec/support
Expand All @@ -91,7 +92,7 @@ def setup_gitignore_folders
spec/views
spec/controllers
spec/helpers
).each do |dir|
].each do |dir|
empty_directory_with_keep_file dir
end
end
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 @@ -218,6 +218,11 @@ def gitignore_files_and_folders
build :setup_gitignore_folders
end

def configure_error_pages
say 'Setup custom exception pages and 404 page'
build :configure_error_pages
end

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

module Cybele
module Helpers
module ErrorPages
def configure_error_pages
inject_into_file 'app/controllers/application_controller.rb',
template_content('error_pages/error_control.erb'),
after: 'class ApplicationController < ActionController::Base'

inject_into_file 'app/controllers/application_controller.rb',
template_content('error_pages/error_method.erb'),
after: 'protect_from_forgery with: :exception'

inject_into_file 'config/routes.rb',
template_content('error_pages/error_route.erb'),
before: /^end/

create_error_pages_files
end

private

def create_error_pages_files
# Server Error
template 'error_pages/internal_server_error.html.haml',
'app/views/errors/internal_server_error.html.haml',
force: true

# Not Found Error
template 'error_pages/not_found.html.haml',
'app/views/errors/not_found.html.haml',
force: true
end
end
end
end
22 changes: 15 additions & 7 deletions spec/features/new_default_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
expect(gemfile_file).to match(/^gem 'devise-async'/)

sidekiq_file = content('config/sidekiq.yml')
expect(sidekiq_file).to match(/^:concurrency: 25/)
expect(sidekiq_file).to match('[high_priority, 2]')

sidekiq_schedule_file = content('config/sidekiq_schedule.yml')
expect(sidekiq_schedule_file).to match(/-> Daily at midnight/)
Expand All @@ -50,7 +50,7 @@
end

it 'uses responders' do
responder_test_helper
responder_test
end

it 'uses cybele_version' do
Expand Down Expand Up @@ -126,7 +126,7 @@
end

it 'uses config and staging file' do
config_test_helper
config_test
end

it 'uses recipient_interceptor' do
Expand All @@ -138,7 +138,7 @@
end

it 'uses locale_language' do
locale_language_test_helper
locale_language_test
end

it 'uses simple_form' do
Expand All @@ -164,11 +164,11 @@
end

it 'control env.sample and .env files' do
dotenv_test_helper
dotenv_test
end

it 'uses paperclip' do
paperclip_test_helper
paperclip_test
end

it 'uses mailer' do
Expand Down Expand Up @@ -205,7 +205,15 @@
end

it 'uses devise' do
devise_test_helper
devise_test
end

it 'uses error_pages' do
error_pages_test
end

it 'uses gitignore' do
git_ignore_test
end

it 'uses ssl_setting' do
Expand Down
20 changes: 14 additions & 6 deletions spec/features/new_not_default_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
end

it 'uses responders' do
responder_test_helper
responder_test
end

it 'uses rollbar' do
Expand Down Expand Up @@ -108,11 +108,11 @@
end

it 'uses config and staging file' do
config_test_helper
config_test
end

it 'uses locale_language' do
locale_language_test_helper
locale_language_test
end

it 'uses recipient_interceptor' do
Expand Down Expand Up @@ -152,11 +152,11 @@
end

it 'uses paperclip' do
paperclip_test_helper
paperclip_test
end

it 'control env.sample and .env files' do
dotenv_test_helper
dotenv_test
end

it 'uses mailer' do
Expand Down Expand Up @@ -185,7 +185,15 @@
end

it 'uses devise' do
devise_test_helper
devise_test
end

it 'uses error_pages' do
error_pages_test
end

it 'uses gitignore' do
git_ignore_test
end

it 'uses ssl_setting' do
Expand Down
10 changes: 9 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@

RSpec.configure do |config|
config.include CybeleTestHelpers
config.include GemTestHelpers
config.include DotenvTestHelper
config.include ConfigTestHelper
config.include DeviseTestHelper
config.include PaperclipTestHelper
config.include LocaleLanguageTestHelper
config.include ResponderTestHelper
config.include ErrorPagesTestHelper
config.include GitIgnoreTestHelper
config.include MailTestHelpers
config.include SSLTestHelper

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

module ConfigTestHelper
def config_test
gemfile_file = content('Gemfile')
expect(gemfile_file).to match(/^gem 'config'/)

config_development_file_test
config_staging_file_test
config_production_file_test
config_test_file_test
end

private

def config_development_file_test
config_development_file = content('config/environments/development.rb')
expect(config_development_file).to match(/^Rails.application.configure/)
end

def config_staging_file_test
config_staging_file = content('config/environments/staging.rb')
expect(config_staging_file).to match(/^Rails.application.configure/)
end

def config_production_file_test
config_production_file = content('config/environments/production.rb')
expect(config_production_file).to match(/^Rails.application.configure/)
end

def config_test_file_test
config_test_file = content('config/environments/test.rb')
expect(config_test_file).to match(/^Rails.application.configure/)
end
end
52 changes: 52 additions & 0 deletions spec/support/devise_test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# frozen_string_literal: true

module DeviseTestHelper
def devise_test
gemfile_file = content('Gemfile')
expect(gemfile_file).to match(/^gem 'devise'/)

devise_initializers_test
devise_route_file_test
devise_model_file_test
file_control_test
end

private

def devise_initializers_test
initializers_devise = content('config/initializers/devise.rb')
expect(initializers_devise).to match('mailer')
expect(initializers_devise).to match('mailer_sender')

filter_parameter_logging = content('config/initializers/filter_parameter_logging.rb')
expect(filter_parameter_logging).to match(':password')
expect(filter_parameter_logging).to match(':password_confirmation')
end

def devise_route_file_test
devise_route = content('config/routes.rb')
expect(devise_route).to match('devise_for :users')
end

def devise_model_file_test # rubocop:disable Metrics/AbcSize
devise_model_file = content('app/models/user.rb')
expect(devise_model_file).to match(':database_authenticatable')
expect(devise_model_file).to match(':registerable')
expect(devise_model_file).to match(':recoverable')
expect(devise_model_file).to match(':rememberable')
expect(devise_model_file).to match(':trackable')
expect(devise_model_file).to match(':validatable')
end

def file_control_test # rubocop:disable Metrics/AbcSize
expect(File).to exist(file_project_path('app/views/devise/confirmations'))
expect(File).to exist(file_project_path('app/views/devise/mailer'))
expect(File).to exist(file_project_path('app/views/devise/passwords'))
expect(File).to exist(file_project_path('app/views/devise/registrations'))
expect(File).to exist(file_project_path('app/views/devise/sessions'))
expect(File).to exist(file_project_path('app/views/devise/shared'))
expect(File).to exist(file_project_path('app/views/devise/unlocks'))

expect(File).not_to exist(file_project_path('config/locales/devise.en.yml'))
end
end
35 changes: 35 additions & 0 deletions spec/support/dotenv_test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

module DotenvTestHelper
def dotenv_test
gemfile_file = content('Gemfile')
expect(gemfile_file).to match(/^gem 'dotenv-rails'/)

env_sample_file_test
env_local_file_test
env_staging_file_test
env_production_file_test
end

private

def env_sample_file_test
env_sample_file = content('env.sample')
expect(env_sample_file).to match('ROOT_PATH=http://localhost:3000')
end

def env_local_file_test
env_local_file = content('.env.local')
expect(env_local_file).to match('ROOT_PATH=http://localhost:3000')
end

def env_staging_file_test
env_staging_file = content('.env.staging')
expect(env_staging_file).to match('ROOT_PATH=https://staging-dummy_app.herokuapp.com')
end

def env_production_file_test
env_production_file = content('.env.production')
expect(env_production_file).to match('ROOT_PATH=https://dummy_app.herokuapp.com')
end
end
24 changes: 24 additions & 0 deletions spec/support/error_pages_test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

module ErrorPagesTestHelper
def error_pages_test
controller_file_test
routes_file_test
end

private

def controller_file_test # rubocop:disable Metrics/AbcSize
application_controller_file = content('app/controllers/application_controller.rb')
expect(application_controller_file).to match('rescue_from Exception')
expect(application_controller_file).to match('rescue_from ActiveRecord::RecordNotFound')
expect(application_controller_file).to match('rescue_from ActionController::RoutingError')
expect(application_controller_file).to match('server_error')
expect(application_controller_file).to match('page_not_found')
end

def routes_file_test
route_file = content('config/routes.rb')
expect(route_file).to match('unmatched_route')
end
end
Loading

0 comments on commit fb6d99c

Please sign in to comment.