Skip to content

Instantly share code, notes, and snippets.

@awkale
Last active October 25, 2018 21:08
Show Gist options
  • Select an option

  • Save awkale/5b1c5b8f63de792b6c86 to your computer and use it in GitHub Desktop.

Select an option

Save awkale/5b1c5b8f63de792b6c86 to your computer and use it in GitHub Desktop.
#rails #cheatsheet
  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.2.1
  $ rvm list
  $ ruby -v
  $ gem install rails
  $ rails -v
  1. Navigate to where you want to create your app.
  $ cd ~/Sites
  1. 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
  1. Navigate into new app
  $ cd ruby_thursday
  1. Set up git
  $ git init
  1. Set up Github and make first commit
  copy/paste from Github to create remote repo
  $ git add .
  $ git commit -m "Initial commit"
  1. Open app in favorite text editor.
  $ subl .
  1. Set Ruby version in Gemfile
  ruby '2.2.1'
  1. Review standard gems change any per preferences #will need to install Postgres on your machine https://wiki.postgresql.org/wiki/Detailed_installation_guides
  gem ‘pg’
  1. Set up preferred test and development gems
  group :development, :test do
    gem 'better_errors'
    #will need to install Qt on your machine https://github.com/thoughtbot/capybara-webkit/wiki/Installing-Qt-and-compiling-capybara-webkit
    gem 'capybara-webkit'
    gem 'factory_girl_rails'
    gem 'ffaker'
    gem 'database_cleaner'
    gem 'letter_opener'
    gem 'rspec-rails'
    gem 'pry'
    gem 'pry-nav'
    gem 'pry-rails', '~> 0.3.2'
    gem 'simple_bdd'
    gem 'shoulda-matchers'
    gem 'spring' 
  end 
  1. Install the gems
  $ bundle
  1. 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
  1. Create database
  $ rake db:create  
  1. Install rspec
  $ rails generate rspec:install
  1. Edit rails_helper.rb
  require 'spec_helper'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'capybara/rspec'
  Capybara.javascript_driver = :webkit
  require 'simple_bdd'
  
  config.include SimpleBdd, type: :feature
  # config.include Devise::TestHelpers, :type => :controller
  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
  1. Commit set up
  $ git add .
  $ git commit -m "Set up app with development gems, rspec, and pg"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment