Skip to content

Starting rails with Travis and Heroku

Frolin edited this page May 21, 2015 · 8 revisions

##Quick install Rails project

 rvm use 2.1.1  
 gem i rails  
 rails new appname -­d postgresql ­­--skip­bundle`  
 git init  

###Install and config Postgresql

Install Postgre packages:

sudo apt-get install postgresql postgresql-client libpq-dev

Edit postgre configuration file:

sudo gedit /etc/postgresql/POSTGRE_VERSION/main/pg_hba.conf

Change all configuration access to:

# Database administrative login by Unix domain socket
local   all             all                                     trust
# TYPE  DATABASE        USER            ADDRESS                 METHOD
# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust

Restart postgre server

sudo /etc/init.d/postgresql restart

Enjoy :)

####config/database.yml Делаем локальный доступ -- без пароля

local: &local
 adapter: postgresql
 username: postgres
 password:
 host: localhost
development:
 <<: *local
 database: %name_dev
test:
 <<: *local
 database: %name_test
production:
 <<: *local
 database: %name_production

##Add to Gemfile

group :development, :test do
 gem 'pry­rails'
 gem 'pry'
 gem 'pry­nav'
 gem 'pry­remote'
 gem 'factory_girl_rails'
 gem 'faker', '~> 1.2.0'
end  
group :test do
 gem 'rspec­rails'
 gem 'spork'
 gem 'database_cleaner'
 gem 'shoulda­matchers'
 gem 'webmock'
end
 bundle install

Configure generators:

config.generators do |g|
 g.test_framework  :rspec, :view_specs => false, 
                :fixture => true, 
                :fixture_replacement => "factory_girl"
  g.assets = false
  g.helper = false
  g.fixture_replacement :factory_girl, :dir => 'spec/factories'
end

##Configure RSpec

rails generate rspec:install

##connect heroku: https://devcenter.heroku.com/articles/getting-started-with-rails4


##Travis

create a file /.travis.yml

language: ruby
 rvm:
 - 2.1.0
 cache: -apt -bundler
 env: -DB=postgresql
 script:
 - RAILS_ENV=test bundle exec rake db:migrate --trace
 - bundle exec rake
 before_script:
 - cp config/database.yml.travis config/database.yml
 - psql -c 'create database travis_YOURapp_test;' -U postgres      
 deploy:
 provider: heroku
 api_key:
  secure: %_api_key_% 
 app:
  dev: dev.YourAppName   
  master: YourAppName

Генерируем ключ. ''%api_key%''

gem install travis 
generate_key:
 travis encrypt $(heroku auth:token) --add deploy.api_key
or:
 travis setup heroku


config/database.yml.travis
 test:
 adapter: postgresql
 database: travis_YourAppName_test
 username: postgres

Теперь Travis после успешного выполнения всех тестов будет автоматом деплоить на heroku. В зависимости от ветки:

branch dev -> dev.YourAppName.heroku.com
branch master -> YourAppName.heroku.com


Clone this wiki locally