ddeveloperr
10/13/2016 - 1:23 PM

Rails-5-cheat-sheet.txt

Rails on Rails Cheat Sheet -- Includes updates from Rails 5.0

1. Open terminal and check versions of Ruby and Rails against production server params or to make sure you are using the most recent stable versions.
  $ ruby -v
  $ rvm list
  $ rvm list known
  $ rvm install ruby 2.3.1
  $ rvm list
  $ ruby -v
  $ gem install rails
  $ rails -v

2. Navigate to where you want to create your app:
  $ cd ~/Sites

3. Create new repo/app without unit tests 
  $ rails new {name} -T  
  example: $ rails new ruby_thursday -T
  or if needing to a specific version of rails: $ rails _4.1.0_ new ruby_thursday -T

4. Navigate into new app
  $ cd ruby_thursday

5. Set up git
  $ git init

6. Set up Github and make first commit
  copy/paste from Github to create remote repo
  $ git add .
  $ git commit -m "Initial commit"

7. Open app in favorite text editor. 
  $ subl .

8. Set Ruby version in Gemfile
  ruby '2.3.1'

9. Review standard gems change any per preferences
	You need to have Postres installed first -- https://wiki.postgresql.org/wiki/Detailed_installation_guides
  gem 'pg'

10. Set up preferred test and development gems

#Option 1: with 'capybara-webkit'  -- you need to have QT installed first https://github.com/thoughtbot/capybara-webkit/wiki/Installing-Qt-and-compiling-capybara-webkit.

	group :development, :test do
		gem 'pry'
    gem 'pry-nav'
    gem 'pry-rails', '~> 0.3.2'
    gem 'rspec-rails'
 		#other option comes with Rails -- gem 'byebug', platform: :mri
	end	

	group :development do
		gem 'better_errors'
    gem 'binding_of_caller'
		gem 'listen', '~> 3.0.5'
		gem 'letter_opener'
		gem 'spring'
		gem 'spring-watcher-listen', '~> 2.0.0'
	end

  group :test do
   	gem 'capybara-email'
    gem 'capybara-webkit'
		gem 'database_cleaner'
    gem 'factory_girl_rails'
    gem 'faker' #some older RubySnacks reference 'ffaker'
    gem 'simple_bdd'
    gem 'shoulda-matchers'
  end 

#Option 2: with 'selenium-webdriver'
	group :development, :test do
		gem 'pry'
    gem 'pry-nav'
    gem 'pry-rails', '~> 0.3.2'
    gem 'rspec-rails'
 		#other option comes with Rails -- gem 'byebug', platform: :mri
	end	

	group :development do
		gem 'better_errors'
    gem 'binding_of_caller'
		gem 'listen', '~> 3.0.5'
		gem 'letter_opener'
		gem 'spring'
		gem 'spring-watcher-listen', '~> 2.0.0'
	end

  group :test do
    gem 'capybara-email'
    gem 'capybara-webkit'
		gem 'database_cleaner'
    gem 'factory_girl_rails'
    gem 'faker' #some older RubySnacks reference 'ffaker'
    gem 'selenium-webdriver'
    gem 'simple_bdd'
    gem 'shoulda-matchers' 
  end

11. Install the gems
  $ bundle

12. Edit config/database.yml with preferred database and database names
  adapter: postgresql
  
  development:
  <<: *default
  database: db/ruby_thursday_development

  test:
    <<: *default
    database: db/ruby_thursday_test

  production:
    <<: *default
    database: db/ruby_thursday_production


13. Create database
  $ rails db:create  #rake db:create still works too

14. Install rspec
  $ rails generate rspec:install

15. Edit or create rails_helper.rb
  #Replace with below for Option 1: with 'capybara-webkit' 
	ENV['RAILS_ENV'] ||= 'test'
	require File.expand_path('../../config/environment', __FILE__)
	# Prevent database truncation if the environment is production
	abort("The Rails environment is running in production mode!") if Rails.env.production?
  require 'spec_helper'
	require 'rspec/rails'
	require 'capybara/rspec'
	require 'simple_bdd'
	require 'shoulda/matchers'
	Capybara.javascript_driver = :webkit

	ActiveRecord::Migration.maintain_test_schema!

	RSpec.configure do |config|
		config.fixture_path = "#{::Rails.root}/spec/fixtures"

		config.use_transactional_fixtures = false
		
    config.before(:suite) do
		  DatabaseCleaner.strategy = :truncation
		  DatabaseCleaner.clean_with(:truncation)
		end	

		config.before(:each) do
		  DatabaseCleaner.start
		end

		config.after(:each) do
		  DatabaseCleaner.clean
		end

    config.include SimpleBdd, type: :feature
		
		Shoulda::Matchers.configure do |config|
		  config.integrate do |with|
		    with.test_framework :rspec
		    with.library :rails
		  end
		end
		
		config.infer_spec_type_from_file_location!

		config.filter_rails_from_backtrace!		

	end

	#Replace with below for Option 2: with 'selenium-webdriver'
		#Note: if selenium-webdriver gem does not update to newest Firefox version fast enough for you
		#you can download a specific version of Firefox and configure to use that version in tests
		#example: 
			#Capybara.register_driver :selenium do |app|
				#require 'selenium/webdriver'
				#Selenium::WebDriver::Firefox::Binary.path = "/home/user/Sites/firefox46/firefox"
				#Capybara::Selenium::Driver.new(app, :browser => :firefox)
			#end
	ENV['RAILS_ENV'] ||= 'test'
	require File.expand_path('../../config/environment', __FILE__)
	# Prevent database truncation if the environment is production
	abort("The Rails environment is running in production mode!") if Rails.env.production?
	require 'spec_helper'
	require 'rspec/rails'
	require 'capybara/rspec'
	require 'simple_bdd'
	require 'shoulda/matchers'

	ActiveRecord::Migration.maintain_test_schema!

	RSpec.configure do |config|

		config.fixture_path = "#{::Rails.root}/spec/fixtures"

		config.use_transactional_fixtures = false

		config.before(:suite) do
		  DatabaseCleaner.clean_with(:truncation)
		end

		config.before(:each) do
		  DatabaseCleaner.strategy = :transaction
		end

		config.before(:each, :js => true) do
		  DatabaseCleaner.strategy = :truncation
		end

		config.before(:each) do
		  DatabaseCleaner.start
		end

		config.after(:each) do
		  DatabaseCleaner.clean
		end
		
		config.include SimpleBdd, type: :feature
		
		Shoulda::Matchers.configure do |config|
		  config.integrate do |with|
		    with.test_framework :rspec
		    with.library :rails
		  end
		end
		
		config.infer_spec_type_from_file_location!

		config.filter_rails_from_backtrace!	

	end
  

16. Commit set up 
  $ git add .
  $ git commit -m "Set up app with development gems, rspec, and pg"