Шпаргалка по командам при разработке на Ruby on Rails

Git

1.  создать ветку от master (git co -b <ветка>)
2.  часто коммитить
3.  часто делать rebase с master(в ветке feature-branch: git fetch && git rebase origin/master)
4.  обязательно делать rebase с master после окончания работы
5.  прогнать тесты (rspec spec)
6.  закоммитить (git co -m "...")
7.  переключится в master (git co master && git pull)
8.  слить рабочую ветку в master (git merge <ветка>)
9.  обновить локальный репозиторий (git pull --rebase)
10. прогнать тесты (rspec spec)
11. отправить код на сервер (git push)
12. удалить рабочую ветку (git branch -d <ветка>)

Если на 7-м шаге пришли изменения, которых не было на момент рибейза, то:

git co <ветка>
git fetch && git rebase origin/master
и далее

RoR

Новое приложение:

rails new myapp -d postgresql -T
git init
git add .
git commit -m 'Initial commit'

Gems

# User registration & identification
gem 'devise'
gem 'devise-russian'
gem 'omniauth'

# Template
gem 'bootstrap-sass', '~> 3.2.0'
gem 'autoprefixer-rails'
gem 'slim-rails'

# Forms, mails
gem 'mail_form'
gem 'simple_form', '~> 3.1.0.rc2', github: 'plataformatec/simple_form', branch: 'master'
gem 'bootstrap_form'
gem 'nested_form'

gem 'carrierwave'
gem 'remotipart'

# Russ
gem 'russian'

# Pagination
gem 'kaminari'

gem 'rails_config'
gem 'breadcrumbs_on_rails'
gem 'cancancan', '~> 1.9'

# Foundation 5
gem 'foundation-rails'

group :test, :development do
  gem 'rspec-rails'
  gem 'factory_girl_rails'
  gem 'pry'
  gem 'database_cleaner'
  gem 'capybara'
  gem 'capybara-email'
  gem 'launchy'
  gem 'poltergeist'
  gem 'phantomjs', require: 'phantomjs/poltergeist'
end

group :test do
  # Services
  gem 'simplecov', require: false
  gem 'coveralls', require: false
  gem 'shoulda-matchers'
end

group :development do
  gem 'spring'
  gem 'better_errors'
  gem 'binding_of_caller'
  gem 'quiet_assets'
  gem 'capistrano'
  gem 'capistrano-rails'
  gem 'capistrano3-unicorn'
  #Development Guard
  gem 'guard-rails'
  gem 'guard-livereload'
  gem 'rack-livereload'
  gem 'guard-bundler'
  #Preview mail in the browser instead of sending
  gem 'letter_opener'
  gem 'rails_layout'
end

group :production do
# for Heroku deploy
gem 'rails_12factor'
# gem 'rails_serve_static_assets'
end

Настройка гемов

bundle install
brew install phantomjs

rails generate layout:install foundation5 --force
rails generate rspec:install
bundle binstubs rspec-core
rails generate simple_form:install --foundation
rails g cancan:ability

Настройка проекта

.rspec

--color
--require spec_helper
--format doc

.gitignore

/.bundle
/db/*.sqlite3
/db/*.sqlite3-journal
/log/*
/tmp
config/database.yml
.rbenv-gemsets
.ruby-version
coverage
.coveralls.yml
/public/uploads

application.rb

config.i18n.default_locale = :ru

config.generators do |g|
  g.test_framework :rspec,
                   fixtures: true,
                   view_specs: false,
                   helper_specs: false,
                   routing_specs: false,
                   request_specs: false,
                   controller_specs: true
  g.fixture_replacement :factory_girl, dir: 'spec/factories'
end

database.yml

default: &default
  adapter: postgresql
  encoding: unicode
  host: localhost
  port: 5432
  pool: 5
  username: qnauser
  password: pass


development:
  <<: *default
  database: app_development

test:
  <<: *default
  database: app_test

development.rb

config.assets.debug = true
config.assets.raise_runtime_errors = true
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.delivery_method = :letter_opener


spec_helper.rb

require 'simplecov'
require 'coveralls'

SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
    SimpleCov::Formatter::HTMLFormatter,
    Coveralls::SimpleCov::Formatter
]
SimpleCov.start 'rails'


rails_helper.rb

ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'database_cleaner'
require 'shoulda/matchers'
require 'capybara/email/rspec'

Dir[Rails.root.join("spec/support/**/*.rb")].sort.each { |f| require f }

ActiveRecord::Migration.maintain_test_schema!

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

  config.include FactoryGirl::Syntax::Methods
  config.include Devise::TestHelpers, type: :controller
  config.extend ControllerHelpers, type: :controller
end


acceptance_helper.rb

require 'rails_helper'

RSpec.configure do |config|

  Capybara.javascript_driver = :poltergeist
  Capybara.default_wait_time = 15

  config.use_transactional_fixtures = false

  config.include AcceptanceMacros, type: :feature

  #Database Cleaner
  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
    FactoryGirl.reload
  end

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

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

Создание данных

rails generate controller StaticPages home
root :to => 'static_pages#home'
rails g model User name:string surname:string nick:string pic:string


rails generate devise:install
rails generate devise User
rails g devise:views
rails g model Product title:string description:text category_id:integer
rails g model Answer body:text question:reference
rails g controller Products index new create edit destroy
rails g migration AddUserRefToProducts user:reference

Админка:

rails g controller admin::admin
rails g controller admin::application
rails g controller admin::static_pages

Поделиться Комментарии