Skip to content

Commit

Permalink
KBP-141 #time 5m - Conflict fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
esref.viduslu committed Nov 22, 2017
2 parents c1a306a + ad8e286 commit d7e1329
Show file tree
Hide file tree
Showing 30 changed files with 477 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
*.bundle/install.log
Gemfile.lock
tmp/
.DS_Store
.DS_Store
.pronto.yml
3 changes: 2 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ Style/IndentHeredoc:

Naming/HeredocDelimiterNaming:
Exclude:
- 'spec/features/cli_help_spec.rb'
- 'spec/features/cli_help_spec.rb'
- 'spec/features/git_and_git_flow_spec.rb'
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ If you discover any bugs or want to drop a line, feel free to create an issue on

http://github.com/lab2023/cybele/issues

## Development
* Clone project
* Run: brew install cmake
* Run: bundle

## Contributing

Cybele uses [rDoc](http://rubydoc.info/gems/cybele) and [SemVer](http://semver.org/), and takes it seriously.
Expand Down
4 changes: 4 additions & 0 deletions cybele.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ Gem::Specification.new do |spec|

spec.add_dependency 'bundler', '~> 1.5'
spec.add_runtime_dependency 'rails', '~> 5.0', Cybele::RAILS_VERSION
spec.add_development_dependency 'pronto', '~> 0.9.5'
spec.add_development_dependency 'pronto-flay', '~> 0.9.0'
spec.add_development_dependency 'pronto-rubocop', '~> 0.9.0'
spec.add_development_dependency 'rspec', '~> 3.5'
spec.add_development_dependency 'thor', '~> 0.19.4'

spec.extra_rdoc_files = %w[README.md MIT-LICENSE]
end
8 changes: 8 additions & 0 deletions example.pronto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
all:
exclude:
- 'spec/**/*'
bitbucket:
slug: 'lab2023corp/cybele'
username: 'username'
password: 'password'
max_warnings: 150
2 changes: 2 additions & 0 deletions lib/cybele.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
require 'cybele/helpers/mailer'
require 'cybele/helpers/paperclip'
require 'cybele/helpers/devise'
require 'cybele/helpers/docker'
require 'cybele/helpers/error_pages'
require 'cybele/helpers/pronto'
require 'cybele/app_builder'
11 changes: 11 additions & 0 deletions lib/cybele/app_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class AppBuilder < Rails::AppBuilder
include Cybele::Helpers::Paperclip
include Cybele::Helpers::Devise
include Cybele::Helpers::ErrorPages
include Cybele::Helpers::Docker
include Cybele::Helpers::Pronto

def readme
template 'README.md.erb',
Expand All @@ -33,6 +35,15 @@ def add_gems
append_file('Gemfile', template_content('Gemfile.erb'))
end

def force_ssl_setting
gsub_file 'config/environments/production.rb',
/# config.force_ssl = true/, "config.force_ssl = ENV['RAILS_FORCE_SSL'].present?"
gsub_file 'config/environments/staging.rb',
/# config.force_ssl = true/, "config.force_ssl = ENV['RAILS_FORCE_SSL'].present?"
append_file('.env.staging', template_content('ssl/ssl_env_staging.erb'))
append_file('.env.production', template_content('ssl/ssl_env_production.erb'))
end

def add_editor_config
copy_file 'editorconfig', '.editorconfig'
end
Expand Down
28 changes: 26 additions & 2 deletions lib/cybele/generators/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ class AppGenerator < Rails::Generators::AppGenerator
default: false,
group: :cybele,
desc: 'Skip haml and haml-rails integration. Default: don\'t skip'
class_option :skip_docker,
type: :boolean,
aliases: nil,
default: false,
group: :cybele,
desc: 'Skip docker development environment. Default: don\'t skip'

def initialize(*args)
super
Expand All @@ -75,12 +81,14 @@ def initialize(*args)
option_with_ask_yes(:skip_simple_form)
option_with_ask_yes(:skip_show_for)
option_with_ask_yes(:skip_haml)
option_with_ask_yes(:skip_docker)
@options.freeze
end

def customize_gemfile
say 'Customize gem file', :green
build :add_gems
bundle_command 'update thor'
build :add_simple_form_gem unless @options[:skip_simple_form]
build :add_show_for_gem unless @options[:skip_show_for]
build :add_haml_gems unless @options[:skip_haml]
Expand Down Expand Up @@ -187,6 +195,11 @@ def setup_bullet_config
build :configure_bullet
end

def force_ssl
say 'Add ssl control into staging.rb and production.rb', :green
build :force_ssl_setting
end

def setup_paperclip_and_add_aws
say 'Setting up paperclip, editing settings.yml and env files', :green
build :configure_paperclip
Expand Down Expand Up @@ -214,15 +227,26 @@ def gitignore_files_and_folders
end

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

def setup_git_and_git_flow
say 'Initialize git'
say 'Initialize git and git flow'
build :git_and_git_flow_commands
end

def docker_development_env
return if @options[:skip_docker]
say 'Setup docker development environment', :green
build :setup_docker_development_env
end

def setup_pronto_config
say 'Setup pronto config', :green
build :configure_pronto
end

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

module Cybele
module Helpers
module Docker
def setup_docker_development_env
# Create docker files
template 'docker/docker-compose.yml.erb',
'docker-compose.yml',
force: true
template 'docker/Dockerfile.erb',
'Dockerfile',
force: true
template 'docker/start-app.sh.erb',
'bin/start-app.sh',
force: true
template 'docker/start-sidekiq.sh.erb',
'bin/start-sidekiq.sh',
force: true

docker_dotenv_files
end

private

def docker_dotenv_files
append_file('env.sample', template_content('docker/docker_env_sample.erb'))
%w[local staging production].each do |env|
append_file(".env.#{env}", template_content("docker/docker_env_#{env}.erb"))
end
end
end
end
end
27 changes: 27 additions & 0 deletions lib/cybele/helpers/pronto.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module Cybele
module Helpers
module Pronto
def configure_pronto
# Create pronto files
template 'pronto/example.pronto.yml.erb',
'example.pronto.yml',
force: true
template 'pronto/example.pronto.yml.erb',
'.pronto.yml',
force: true
template 'pronto/.rubocop.yml.erb',
'.rubocop.yml',
force: true
template 'pronto/rubo.erb',
'bin/rubo',
force: true
run 'chmod +x bin/rubo'

# Ignore secret information file
append_file('.gitignore', '.pronto.yml')
end
end
end
end
7 changes: 3 additions & 4 deletions spec/features/git_and_git_flow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
setup_app_dependencies
end

let(:git_branch) { cybele_help_run(command: "git branch") }

let(:git_branch) { cybele_help_run(command: 'git branch') }

it 'git branch test' do
expect(git_branch).to include <<~EOH
Expand All @@ -22,8 +21,8 @@
end

it 'git flow test' do
cybele_help_run(command: "git flow feature start test")
git_flow = cybele_help_run(command: "git branch")
cybele_help_run(command: 'git flow feature start test')
git_flow = cybele_help_run(command: 'git branch')
expect(git_flow).to include <<~EOH
develop
* feature/test
Expand Down
35 changes: 34 additions & 1 deletion spec/features/new_default_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
before(:all) do
drop_dummy_database
remove_project_directory
run_cybele
run_cybele('--skip-create-database')
setup_app_dependencies
end

Expand Down Expand Up @@ -215,4 +215,37 @@
it 'uses gitignore' do
git_ignore_test
end

it 'uses ssl_setting' do
force_ssl
end

it 'uses docker development environment' do
expect(File).to exist(file_project_path('docker-compose.yml'))
expect(File).to exist(file_project_path('Dockerfile'))
expect(File).to exist(file_project_path('bin/start-app.sh'))
expect(File).to exist(file_project_path('bin/start-sidekiq.sh'))

env_sample_file = content('env.sample')
expect(env_sample_file).to match('REDISTOGO_URL=redis://redis:6379/0')
expect(env_sample_file).to match('RACK_ENV=development')
expect(env_sample_file).to match('POSTGRESQL_HOST=postgres')
expect(env_sample_file).to match('REDIS_HOST=redis')

env_local_file = content('.env.local')
expect(env_local_file).to match('REDISTOGO_URL=redis://redis:6379/0')
expect(env_local_file).to match('RACK_ENV=development')
expect(env_local_file).to match('POSTGRESQL_HOST=postgres')
expect(env_local_file).to match('REDIS_HOST=redis')

env_staging_file = content('.env.staging')
expect(env_staging_file).to match('REDISTOGO_URL=')

env_production_file = content('.env.production')
expect(env_production_file).to match('REDISTOGO_URL=')
end

it 'uses pronto' do
pronto_test
end
end
29 changes: 28 additions & 1 deletion spec/features/new_not_default_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
drop_dummy_database
remove_project_directory
run_cybele('--database=sqlite3 --skip-create-database --skip-sidekiq --skip-simple-form --skip-show-for'\
' --skip-haml')
' --skip-haml --skip-docker')
setup_app_dependencies
end

Expand Down Expand Up @@ -195,4 +195,31 @@
it 'uses gitignore' do
git_ignore_test
end

it 'uses ssl_setting' do
force_ssl
end

it "don't use docker development environment" do
expect(File).not_to exist(file_project_path('docker-compose.yml'))
expect(File).not_to exist(file_project_path('Dockerfile'))
expect(File).not_to exist(file_project_path('bin/start-app.sh'))
expect(File).not_to exist(file_project_path('bin/start-sidekiq.sh'))

env_sample_file = content('env.sample')
expect(env_sample_file).not_to match('REDISTOGO_URL=redis://redis:6379/0')

env_local_file = content('.env.local')
expect(env_local_file).not_to match('REDISTOGO_URL=redis://redis:6379/0')

env_staging_file = content('.env.staging')
expect(env_staging_file).not_to match('REDISTOGO_URL=')

env_production_file = content('.env.production')
expect(env_production_file).not_to match('REDISTOGO_URL=')
end

it 'uses pronto' do
pronto_test
end
end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
config.include ErrorPagesTestHelper
config.include GitIgnoreTestHelper
config.include MailTestHelpers
config.include ForceSSLTestHelper
config.include ProntoTestHelpers

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

module ForceSSLTestHelper
def force_ssl
ssl_test
environment_test
end

private

def ssl_test
config_staging_file = content('config/environments/staging.rb')
expect(config_staging_file).to match('config.force_ssl')

config_production_file = content('config/environments/staging.rb')
expect(config_production_file).to match('config.force_ssl')
end

def environment_test
env_staging_file = content('.env.staging')
expect(env_staging_file).to match('RAILS_FORCE_SSL=')

env_production_file = content('.env.production')
expect(env_production_file).to match('RAILS_FORCE_SSL=')
end
end
30 changes: 30 additions & 0 deletions spec/support/pronto_test_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

module ProntoTestHelpers
def pronto_test
file_exist_test
file_content_test
gitignore_test
end

private

def file_exist_test
gemfile_file = content('Gemfile')
expect(gemfile_file).to match("gem 'pronto'")
expect(gemfile_file).to match("gem 'pronto-flay'")
expect(gemfile_file).to match("gem 'pronto-rubocop'")
end

def file_content_test # rubocop:disable Metrics/AbcSize
expect(File).to exist(file_project_path('example.pronto.yml'))
expect(File).to exist(file_project_path('.pronto.yml'))
expect(File).to exist(file_project_path('.rubocop.yml'))
expect(File).to exist(file_project_path('bin/rubo'))
end

def gitignore_test
gemfile_file = content('.gitignore')
expect(gemfile_file).to match('.pronto.yml')
end
end
Loading

0 comments on commit d7e1329

Please sign in to comment.