Skip to content

Commit

Permalink
KBP-129 #time 30m - made DRY code
Browse files Browse the repository at this point in the history
  • Loading branch information
FatihAvsan committed Nov 2, 2017
1 parent 6501562 commit 564f972
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 326 deletions.
25 changes: 0 additions & 25 deletions lib/cybele/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,31 +70,6 @@ def configure_bullet

private

def generate_devise_strong_parameters(model_name)
create_sanitizer_lib(model_name)
create_sanitizer_initializer(model_name)
end

def create_sanitizer_lib(model_name)
create_file "lib/#{model_name.parameterize}_sanitizer.rb", <<-CODE
class #{model_name.classify}::ParameterSanitizer < Devise::ParameterSanitizer
private
def sign_up
default_params.permit(:name, :surname, :email, :password, :password_confirmation, :time_zone) # TODO add other params here
end
end
CODE
end

def create_sanitizer_initializer(model_name)
path = '#'
path += '{Rails.application.root}'
path += "/lib/#{model_name.parameterize}_sanitizer.rb"
initializer 'sanitizers.rb', <<-CODE
require "#{path}"
CODE
end

def configure_environment(rails_env, config)
inject_into_file("config/environments/#{rails_env}.rb", "\n#{config}", before: "\nend")
end
Expand Down
1 change: 0 additions & 1 deletion lib/cybele/helpers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def generate_devise_settings

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

Expand Down
156 changes: 6 additions & 150 deletions spec/features/new_default_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,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 @@ -143,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 @@ -168,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 @@ -224,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 haml' do
Expand All @@ -292,47 +189,6 @@
end

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

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')

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')

devise_user_sanitizer = content('lib/user_sanitizer.rb')
expect(devise_user_sanitizer).to match(':name')
expect(devise_user_sanitizer).to match(':surname')
expect(devise_user_sanitizer).to match(':email')
expect(devise_user_sanitizer).to match(':password')
expect(devise_user_sanitizer).to match(':password_confirmation')
expect(devise_user_sanitizer).to match(':time_zone')

devise_sanitizers = content('config/initializers/sanitizers.rb')
expect(devise_sanitizers).to match('require')

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

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'))
devise_test_helper
end
end
Loading

0 comments on commit 564f972

Please sign in to comment.