Skip to content

Commit

Permalink
Merged in feature/integrate_devise_gem (pull request #17)
Browse files Browse the repository at this point in the history
KBP-129 #time 4h - integrate devise gem
  • Loading branch information
FatihAvsan authored and İsmail Akbudak committed Nov 2, 2017
2 parents a510ba6 + 422c0c6 commit 571b1e4
Show file tree
Hide file tree
Showing 12 changed files with 214 additions and 217 deletions.
1 change: 1 addition & 0 deletions lib/cybele.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
require 'cybele/helpers/locale_language'
require 'cybele/helpers/mailer'
require 'cybele/helpers/paperclip'
require 'cybele/helpers/devise'
require 'cybele/app_builder'
1 change: 1 addition & 0 deletions lib/cybele/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class AppBuilder < Rails::AppBuilder
include Cybele::Helpers::LocaleLanguage
include Cybele::Helpers::Mailer
include Cybele::Helpers::Paperclip
include Cybele::Helpers::Devise

def readme
template 'README.md.erb',
Expand Down
9 changes: 9 additions & 0 deletions lib/cybele/generators/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ def setup_paperclip_and_add_aws
build :configure_paperclip
end

def setup_devise
say 'Generate devise'
build :generate_devise_settings
say 'Adding devise user model'
build :generate_devise_user
build :generate_devise_views
say 'Generate devise'
end

def configure_mail_setting
say 'Setup mail settings'
build :configure_action_mailer
Expand Down
27 changes: 27 additions & 0 deletions lib/cybele/helpers/devise.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module Cybele
module Helpers
module Devise
def generate_devise_settings
generate 'devise:install'
gsub_file 'config/initializers/filter_parameter_logging.rb', /:password/,
':password, :password_confirmation'
gsub_file 'config/initializers/devise.rb',
/please-change-me-at-config-initializers-devise@example.com/, "no-reply@#{app_name}.com"
inject_into_file 'config/initializers/devise.rb', after: "# config.mailer = 'Devise::Mailer'\n" do
template_content('devise/devise_mailer.rb.erb')
end
end

def generate_devise_user
generate 'devise User name:string surname:string is_active:boolean time_zone:string'
remove_file 'config/locales/devise.en.yml', force: true
end

def generate_devise_views
generate 'devise:views'
end
end
end
end
118 changes: 10 additions & 108 deletions spec/features/new_default_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
expect(gemfile_file).to match(/^gem 'sidekiq'/)
expect(gemfile_file).to match(/^gem 'sidekiq-cron'/)
expect(gemfile_file).to match(/^gem 'cocaine'/)
expect(gemfile_file).to match(/^gem 'devise-async'/)

sidekiq_file = content('config/sidekiq.yml')
expect(sidekiq_file).to match(/^:concurrency: 25/)
Expand All @@ -49,24 +50,7 @@
end

it 'uses responders' do
gemfile_file = content('Gemfile')
expect(gemfile_file).to match(/^gem 'responders'/)

lib_file = content('lib/application_responder.rb')
expect(lib_file).to match(/^class ApplicationResponder/)

controller_file = content('app/controllers/application_controller.rb')
expect(controller_file).to match("^require 'application_responder'")
expect(controller_file).to match('self.responder = ApplicationResponder')
expect(controller_file).to match('respond_to :html, :js, :json')

expect(File).to exist(file_project_path('config/locales/responders.en.yml'))
expect(File).to exist(file_project_path('config/locales/responders.tr.yml'))
locale_file = content('config/locales/responders.tr.yml')
expect(locale_file).not_to match('# alert:')
expect(locale_file).to match('create:')
expect(locale_file).to match('update:')
expect(locale_file).to match('destroy:')
responder_test_helper
end

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

it 'uses config and staging file' do
gemfile_file = content('Gemfile')
expect(gemfile_file).to match(/^gem 'config'/)

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

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

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

config_test_file = content('config/environments/test.rb')
expect(config_test_file).to match(/^Rails.application.configure/)
config_test_helper
end

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

it 'uses locale_language' do
expect(File).to exist(file_project_path('config/locales/en.yml'))
expect(File).to exist(file_project_path('config/locales/tr.yml'))
locale_file = content('config/locales/tr.yml')
expect(locale_file).to match('phone:')
expect(locale_file).to match('date:')
expect(locale_file).to match('time:')
expect(locale_file).to match('number:')

expect(File).to exist(file_project_path('config/locales/email.en.yml'))
locale_file = content('config/locales/email.en.yml')
expect(locale_file).to match('email:')

expect(File).to exist(file_project_path('config/locales/email.tr.yml'))
locale_file = content('config/locales/email.tr.yml')
expect(locale_file).to match('email:')

expect(File).to exist(file_project_path('config/locales/models.en.yml'))
locale_file = content('config/locales/models.en.yml')
expect(locale_file).to match('activerecord:')

expect(File).to exist(file_project_path('config/locales/models.tr.yml'))
locale_file = content('config/locales/models.tr.yml')
expect(locale_file).to match('activerecord:')

expect(File).to exist(file_project_path('config/locales/view.en.yml'))
locale_file = content('config/locales/view.en.yml')
expect(locale_file).to match('view:')

expect(File).to exist(file_project_path('config/locales/view.tr.yml'))
locale_file = content('config/locales/view.tr.yml')
expect(locale_file).to match('view:')
locale_language_test_helper
end

it 'uses simple_form' do
Expand All @@ -223,54 +164,11 @@
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')
dotenv_test_helper
end

it 'uses paperclip' do
gemfile_file = content('Gemfile')
expect(gemfile_file).to match(/^gem "paperclip"/)
expect(gemfile_file).to match(/^gem 'aws-sdk'/)

env_sample_file = content('env.sample')
expect(env_sample_file).to match('S3_BUCKET_NAME=')
expect(env_sample_file).to match('AWS_RAW_URL=')
expect(env_sample_file).to match('AWS_ACCESS_KEY_ID=')
expect(env_sample_file).to match('AWS_SECRET_ACCESS_KEY=')

env_local_file = content('.env.local')
expect(env_local_file).to match('S3_BUCKET_NAME=dummy_app-development')
expect(env_local_file).to match('AWS_RAW_URL=dummy_app-development.s3.amazonaws.com')
expect(env_local_file).to match('AWS_ACCESS_KEY_ID=')
expect(env_local_file).to match('AWS_SECRET_ACCESS_KEY=')

env_staging_file = content('.env.staging')
expect(env_staging_file).to match('S3_BUCKET_NAME=dummy_app-staging')
expect(env_staging_file).to match('AWS_RAW_URL=dummy_app-staging.s3.amazonaws.com')
expect(env_staging_file).to match('AWS_ACCESS_KEY_ID=')
expect(env_staging_file).to match('AWS_SECRET_ACCESS_KEY=')

env_production_file = content('.env.production')
expect(env_production_file).to match('S3_BUCKET_NAME=dummy_app')
expect(env_production_file).to match('AWS_RAW_URL=dummy_app.s3.amazonaws.com')
expect(env_production_file).to match('AWS_ACCESS_KEY_ID=')
expect(env_production_file).to match('AWS_SECRET_ACCESS_KEY=')
paperclip_test_helper
end

it 'uses mailer' do
Expand Down Expand Up @@ -305,4 +203,8 @@
locale_file = content('config/environments/development.rb')
expect(locale_file).to match('Bullet')
end

it 'uses devise' do
devise_test_helper
end
end
118 changes: 10 additions & 108 deletions spec/features/new_not_default_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
expect(gemfile_file).not_to match(/^gem 'sidekiq'/)
expect(gemfile_file).not_to match(/^gem 'sidekiq-cron'/)
expect(gemfile_file).not_to match(/^gem 'cocaine'/)
expect(gemfile_file).not_to match(/^gem 'devise-async'/)

expect(File).not_to exist(file_project_path('config/sidekiq.yml'))

Expand All @@ -41,24 +42,7 @@
end

it 'uses responders' do
gemfile_file = content('Gemfile')
expect(gemfile_file).to match(/^gem 'responders'/)

lib_file = content('lib/application_responder.rb')
expect(lib_file).to match(/^class ApplicationResponder/)

controller_file = content('app/controllers/application_controller.rb')
expect(controller_file).to match("^require 'application_responder'")
expect(controller_file).to match('self.responder = ApplicationResponder')
expect(controller_file).to match('respond_to :html, :js, :json')

expect(File).to exist(file_project_path('config/locales/responders.en.yml'))
expect(File).to exist(file_project_path('config/locales/responders.tr.yml'))
locale_file = content('config/locales/responders.tr.yml')
expect(locale_file).not_to match('# alert:')
expect(locale_file).to match('create:')
expect(locale_file).to match('update:')
expect(locale_file).to match('destroy:')
responder_test_helper
end

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

it 'uses config and staging file' do
gemfile_file = content('Gemfile')
expect(gemfile_file).to match(/^gem 'config'/)

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

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

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

config_test_file = content('config/environments/test.rb')
expect(config_test_file).to match(/^Rails.application.configure/)
config_test_helper
end

it 'uses locale_language' do
expect(File).to exist(file_project_path('config/locales/en.yml'))
expect(File).to exist(file_project_path('config/locales/tr.yml'))
locale_file = content('config/locales/tr.yml')
expect(locale_file).to match('phone:')
expect(locale_file).to match('date:')
expect(locale_file).to match('time:')
expect(locale_file).to match('number:')

expect(File).to exist(file_project_path('config/locales/email.en.yml'))
locale_file = content('config/locales/email.en.yml')
expect(locale_file).to match('email:')

expect(File).to exist(file_project_path('config/locales/email.tr.yml'))
locale_file = content('config/locales/email.tr.yml')
expect(locale_file).to match('email:')

expect(File).to exist(file_project_path('config/locales/models.en.yml'))
locale_file = content('config/locales/models.en.yml')
expect(locale_file).to match('activerecord:')

expect(File).to exist(file_project_path('config/locales/models.tr.yml'))
locale_file = content('config/locales/models.tr.yml')
expect(locale_file).to match('activerecord:')

expect(File).to exist(file_project_path('config/locales/view.en.yml'))
locale_file = content('config/locales/view.en.yml')
expect(locale_file).to match('view:')

expect(File).to exist(file_project_path('config/locales/view.tr.yml'))
locale_file = content('config/locales/view.tr.yml')
expect(locale_file).to match('view:')
locale_language_test_helper
end

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

it 'uses paperclip' do
gemfile_file = content('Gemfile')
expect(gemfile_file).to match(/^gem "paperclip"/)
expect(gemfile_file).to match(/^gem 'aws-sdk'/)

env_sample_file = content('env.sample')
expect(env_sample_file).to match('S3_BUCKET_NAME=')
expect(env_sample_file).to match('AWS_RAW_URL=')
expect(env_sample_file).to match('AWS_ACCESS_KEY_ID=')
expect(env_sample_file).to match('AWS_SECRET_ACCESS_KEY=')

env_local_file = content('.env.local')
expect(env_local_file).to match('S3_BUCKET_NAME=dummy_app-development')
expect(env_local_file).to match('AWS_RAW_URL=dummy_app-development.s3.amazonaws.com')
expect(env_local_file).to match('AWS_ACCESS_KEY_ID=')
expect(env_local_file).to match('AWS_SECRET_ACCESS_KEY=')

env_staging_file = content('.env.staging')
expect(env_staging_file).to match('S3_BUCKET_NAME=dummy_app-staging')
expect(env_staging_file).to match('AWS_RAW_URL=dummy_app-staging.s3.amazonaws.com')
expect(env_staging_file).to match('AWS_ACCESS_KEY_ID=')
expect(env_staging_file).to match('AWS_SECRET_ACCESS_KEY=')

env_production_file = content('.env.production')
expect(env_production_file).to match('S3_BUCKET_NAME=dummy_app')
expect(env_production_file).to match('AWS_RAW_URL=dummy_app.s3.amazonaws.com')
expect(env_production_file).to match('AWS_ACCESS_KEY_ID=')
expect(env_production_file).to match('AWS_SECRET_ACCESS_KEY=')
paperclip_test_helper
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')
dotenv_test_helper
end

it 'uses mailer' do
Expand All @@ -285,4 +183,8 @@
expect(File).to exist(file_project_path('app/views/layouts/application.html.erb'))
expect(File).not_to exist(file_project_path('app/views/layouts/application.html.haml'))
end

it 'uses devise' do
devise_test_helper
end
end
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 GemTestHelpers
config.include MailTestHelpers

config.before(:all) do
Expand Down
Loading

0 comments on commit 571b1e4

Please sign in to comment.