Last active
October 13, 2015 04:17
-
-
Save erichmachado/4138106 to your computer and use it in GitHub Desktop.
Ruby on Rails 4.x application template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def commit(message) | |
git add: '-A' | |
git commit: "-qm \"#{message}\"" | |
end | |
# Initializing Git | |
git :init | |
commit 'Initial commit' | |
# Configuring Ruby version in Bundler | |
insert_into_file 'Gemfile', "\nruby '2.2.2'\n", after: "source 'https://rubygems.org'\n" | |
commit 'Configured Bundler for Ruby 2.2.2' | |
# Prevent logging of password_confirmation | |
gsub_file 'config/initializers/filter_parameter_logging.rb', '[:password]', '[:password, :password_confirmation]' | |
commit 'Preventing password_confirmation parameter logging along with the password one' | |
# Configuring application to read i18n catalogs | |
gsub_file 'config/application.rb', "# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]", "config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]" | |
commit 'Configuring the application i18n catalogs location' | |
# Configuring production environment log lines tags | |
gsub_file 'config/environments/production.rb', "# config.log_tags = [ :subdomain, :uuid ]", "config.log_tags = [:subdomain, :uuid]" | |
commit 'Configuring the application production environment log lines tags' | |
# Banning all spiders from site | |
gsub_file 'public/robots.txt', '# User-Agent: *', 'User-Agent: *' | |
gsub_file 'public/robots.txt', '# Disallow: /', 'Disallow: /' | |
commit 'Configured robots.txt to ban all spiders from site' | |
# Adding pry support | |
gem_group(:development) do | |
gem('pry') | |
end | |
run('bundle install') | |
commit 'Added pry to development environment' | |
# Deployment support for cloud-computing environments (e.g. Heroku) | |
gem_group(:production) do | |
gem('rails_12factor') | |
end | |
run('bundle install') | |
commit 'Production environment is 12 factor friendly' | |
# Installing Mongoid | |
gem('mongoid', '~> 4.0.0') | |
run('bundle install') | |
generate('mongoid:config') | |
commit 'Added Mongoid 4.0.x to the project' | |
# MongoDB support rake tasks | |
rakefile('mongodb.rake') do | |
%Q{namespace :db do | |
desc 'Stops the MongoDB daemon' | |
task :stop do | |
sh %{launchctl stop homebrew.mxcl.mongodb} | |
end | |
desc 'Starts the MongoDB daemon' | |
task :start do | |
sh %{launchctl start homebrew.mxcl.mongodb} | |
end | |
desc 'Repairs and unlocks MongoDB after an incorrect database shutdown' | |
task :repair do | |
sh %{mongod --repair} | |
end | |
end if Rails.env.development? | |
} | |
end | |
commit 'Added MongoDB support rake tasks' | |
# Configuring test tools | |
gem_group(:test, :development) do | |
gem('rspec-rails', '~> 3.0.0') | |
gem('mongoid-rspec') | |
gem('database_cleaner') | |
gem('fabrication') | |
gem('faker') | |
end | |
run('bundle install') | |
generate('rspec:install') | |
#gsub_file 'spec/spec_helper.rb', 'config.fixture_path = "#{::Rails.root}/spec/fixtures"', '# config.fixture_path = "#{::Rails.root}/spec/fixtures"' | |
#gsub_file 'spec/spec_helper.rb', 'config.use_transactional_fixtures = true', '# config.use_transactional_fixtures = true' | |
#gsub_file 'spec/spec_helper.rb', 'config.infer_base_class_for_anonymous_controllers = false', 'config.infer_base_class_for_anonymous_controllers = true' | |
create_file 'spec/support/mongoid.rb' do | |
%Q{RSpec.configure do |config| | |
config.include Mongoid::Matchers | |
end | |
} | |
end | |
create_file 'spec/support/database_cleaner.rb' do | |
%Q{RSpec.configure do |config| | |
config.before(:suite) do | |
DatabaseCleaner.strategy = :truncation | |
end | |
config.before(:each) do | |
DatabaseCleaner.start | |
end | |
config.after(:each) do | |
DatabaseCleaner.clean | |
end | |
end | |
} | |
end | |
inject_into_file 'config/application.rb', after: "Rails::Application\n" do | |
%Q{ | |
config.generators do |g| | |
g.test_framework :rspec, fixture: true | |
g.fixture_replacement :fabrication | |
end | |
} | |
end | |
commit 'Added RSpec, RSpec Mongoid matchers, Database Cleaner, Fabrication and Faker' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment