Common FactoryBot gotchas

Make sure to include the following in your rails_helper.rb:

config.include FactoryBot::Syntax::Methods

And change use_transactional_fixtures to false so we tell rspec we're using factories instead of fixtures:

config.use_transactional_fixtures = false

If you get the error Factory not registered make sure to include the following in your spec_helper.rb:

config.before(:all) do
   FactoryBot.reload
end

Configure Git

git config --global color.ui true
git config --global user.name "<your_name>"
git config --global user.email "<your_email>"

ssh-keygen -t rsa -b 4096 -C "<your_email>"

cat ~/.ssh/id_rsa.pub

To automatically add to clipboard without viewing:

sudo apt-get install xclip

sudo xclip -sel clip < ~/.ssh/id_rsa.pub

If you need hashed password:

sudo apt-get install whois

sudo mkpasswd -m sha-512

Dedupe a model

def self.get_duplicates(*columns)
    self.order('created_at ASC').select("#{columns.join(',')}, COUNT(*)").group(columns).having("COUNT(*) > 1")
end

def self.dedupe(*columns)
    self.group_by{ |x| columns.map{ |col| x.send(col) } }.each do |duplicates|
      first_one = duplicates.shift
      
      # This will delete all duplicates except one
      duplicates.each{|x| x.destroy}
    end
end
columns = [:name, :description]
Model.get_duplicates(*columns).dedupe(*columns)

Install MySQL

<< Prev - Install Rails

During this process, enter a strong root password.

sudo apt-get update
sudo apt-get install mysql-server mysql-client libmysqlclient-dev

Check if mysql is running:

systemctl status mysql.service

Should see output like:

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2017-12-04 19:33:05 PST; 25s ago
 Main PID: 91383 (mysqld)
   CGroup: /system.slice...

Install PostGIS

<< Prev - Install Postgresql

sudo apt-get install -f
sudo apt-get update
sudo apt-get dist-upgrade

sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update

sudo apt install postgis postgresql-9.4-postgis-2.3

sudo -u postgres psql -c "CREATE EXTENSION postgis; CREATE EXTENSION postgis_topology;" <your_database_name>

Install Postgresql

<< Prev - Install Rails

sudo add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main"
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update

sudo apt-get install postgresql-common postgresql-9.4 postgresql-contrib-9.4 libpq-dev

psql --version

sudo -u postgres createuser -P <your_username>

sudo -u postgres createdb -O <your_username> <name_of_your_database>

psql -h localhost -U <your_username> <name_of_your_database>

If...

Install Rails

<< Prev - Install RVM and Ruby

Make sure nodejs is installed:

node -v

If not, follow commands in Install Rails Dependencies.

// Or, replace with newer version (rails-5.0, for instance)
rvm gemset create rails-4.2.4
rvm gemset use rails-4.2.4

gem install rails -v 4.2.4 (remove -v 4.2.4 for latest)
rails -v

gem install bundler

>> Next - Install Postgresql OR >> Next - Install MySQL

Install Rails Dependencies

sudo apt-get update
sudo apt install curl
sudo apt-get install nodejs

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev nodejs yar...

Install Redis

Install prerequisites:

sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install tcl8.5

Install redis:

wget http://download.redis.io/releases/redis-stable.tar.gz
tar xzf redis-stable.tar.gz
cd redis-stable
make
make test
sudo make install
cd utils
sudo ./install_server.sh
sudo service redis_6379 start

Install RVM and Ruby

<< Prev - Install Rails Dependencies

sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev

sudo apt install gnupg2

// If this fails, try: command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3

curl -sSL https://get.rvm.io | bash -s stable

source ~/.rvm/scripts/rvm

// or 2.3.1, etc. for older version
rvm install 2.4.2
rvm use 2.4.2 --default
ruby -v

If you do not want to install documentation with gems (ot...

Run specific Rspec test

Two ways of doing it:

rspec spec/models/foo_spec.rb:2

or

rake spec SPEC=spec/controllers/foo_controller_spec.rb \
          SPEC_OPTS="-e \"foo_description\""