rails projects workflow

setup your rails vagrant env and add git, by following the instructions in this page

setup your IDE to be connected to your vagrant instance (inside Vagrantfile):

config.vm.synced_folder "./src", "/home/vagrant/your_project"

setup the initial rails app:

rails new myapp

setup the bitbucket repo

config and initialize your git repo:

git config --global user.name "your name"
git config --global user.email your@email.com
git init
git add .
git commit -am "initial commit"
git remote add origin https://youruser@bitbucket.org/youruser/yourrepo.git
git push origin master -u 

setup your testing env:

put the following gems in your Gemfile, in the development:, test: section:

gem "rspec-rails", "~> 3.2.1"

also, add capybara and factory girl:

group :test do
  gem "capybara", "~> 2.4"
  gem "factory_girl_rails", "~>4.5"
end

Update your gems with the additions by running:

bundle update

And install rspec afterwards:

rails g rspec:install

If you get an error message about uglifier being missing, you will have to install nodejs on your system, and run the command again afterwards (there is a js dependency on nodejs)

sudo apt-get install nodejs

make sure you commit your changes at this point:

git add .
git commit -am "setup tests"
git push

database configuration

Install postgresql in your vagrant box:

sudo apt-get update
sudo apt-get install postgresql postgresql-contrib
sudo apt-get install libpq-dev
sudo -i -u postgres psql ALTER USER postgres WITH PASSWORD 'somepassword'

Modify your Gemfile to include the pg gem:

gem ‘pg’

bundle install

Change your config/database.yml file from sqlite3 to postgresql:

default: &default

  adapter: postgresql

  pool: 5

  timeout: 5000

development:

  <<: *default

  database: ticketee_development

  username: vagrant

Also, make sure the test database gets a different name from the development one:

test:
< database: ticketee_test

username: vagrant

Get the vagrant user to be able to run the rails app:

sudo su - postgres
psql
CREATE ROLE vagrant superuser;
alter ROLE vagrant WITH LOGIN;

make sure you tests are running:

setup an rspec test (see the beginning of this post for details)

bundle exec rake db:create
bundle exec rspec

Leave a Reply

Your email address will not be published. Required fields are marked *