GithubHelp home page GithubHelp logo

sukusuku's Introduction

Hack k2works/sukusuku on Nitrous.IO Stories in Ready Build Status

すくすくスクラム広島第5回「スクラムやってみる」

目的

デモアプリ

前提

ソフトウェア バージョン 備考
OS X 10.8.5
ruby 2.0.0
rvm 1.24.0
rbricks 2.0.5
heroku-toolbelt 3.6.0

構成

詳細

$ rvm install ruby-2.0.0-p247
$ rvm use ruby-2.0.0
$ rvm gemset create sukusuku
$ rvm use ruby-2.0.0@sukusuku
$ gem install railsbricks
$ gem install rails --version=4.0.4

基本セットアップ

$ git clone https://github.com/LeanEC/mvp_smoke_tester.git
$ bundle
$ rake db:migrate
$ rake db:seed
$ rails s

日本語対応

Gemfile編集

gem 'i18n_generators'

日本語ファイル生成

$ bundle
$ rails g i18n ja

モデルの日本語対応
config/locales/translation_ja.yml

ja:
  activerecord:
    models:
      user: ユーザー

    attributes:
      user:
        admin: 管理者
        email: eメール
        username: ユーザー名
        password: パスワード
        password_confirmation: パスワード再確認
        current_password: 現在のパスワード

RSpec対応

Gemfile編集

group :test, :development do
  gem "rspec-rails", '~> 2.14.1'
  gem "guard-rspec"
  gem "factory_girl_rails"
  gem "spring"
  gem "guard-livereload", require: false
  gem "spring-commands-rspec"
end

FactoryGirlの設定

_spec/spec_helper.rb_の最後に以下を追加

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

Guardの設定

$ guard init rspeclivereload

生成されたGuardfileから以下の行を変更する

変更前

guard :rspec do

変更後

guard :rspec, cmd: 'spring rspec -f doc' do

Cucumber対応

Gemfile編集

group :test do
  gem "cucumber-rails", require: false
  gem "database_cleaner"
  gem "guard-cucumber"
end

Capybaraのsave_and_open_page実行時にブラウザに出力するようにする

group :test do
  gem "capybara", '~> 2.2.1'
  gem "launchy"
end

Cucumberセットアップ

$ bundle
$ rails g cucumber:install
$ rake cucumber

Guardファイル追加

$ guard init cucumber

ドキュメント環境構築

以下のGemを追加してbundle実行

# Yard
group :test, :development do
  gem 'yard', :require => false
  gem 'yard-cucumber', :require => false
  gem 'redcarpet'
  gem 'guard-yard'
  gem 'yard-rails-plugin', :git => 'https://github.com/ogeidix/yard-rails-plugin.git', :tag => 'v0.0.1'
  gem 'guard-ctags-bundler'
end

.yardoptsの追加

--charset UTF-8
"{lib,app,features}/**/*.{rb,feature}" --plugin yard-cucumber

Guardファイル追加

$ guard init yard

Yardの確認

$ guard
$ open http://localhost:8808

WebサーバーをUnicornに変更する

Gemfile編集

gem 'unicorn'

設定ファイル作成

$ bundle
$ touch config/unicorn.rb

config/unicorn.rb

worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 15
preload_app true

before_fork do |server, worker|
  Signal.trap 'TERM' do
    puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
    Process.kill 'QUIT', Process.pid
  end

  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!
end

after_fork do |server, worker|
  Signal.trap 'TERM' do
    puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
  end

  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection
end

Heroku準備

Procfileの作成

Procfile

web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb

.envファイルの追加

$ echo "RACK_ENV=development" >>.env
$ echo "PORT=3000" >> .env
$ echo ".env" >> .gitignore

foreman実行

$ gem install foreman
$ foreman start

Herokuへデプロイ

$ heroku login
$ heroku create --addons heroku-postgresql
$ heroku keys:add
$ git push heroku master

### Herokuデーターベースマイグレーション
```bash
$ heroku run rake db:migrate
$ heroku run rake db:seed

Herokuアプリケーションの確認

$ heroku ps:scale web=1
$ heroku ps
$ heroku open

Herokuアプリケーションの名前変更

$ heroku apps:rename sukusuku-app

サイト確認 http://sukusuku-app.herokuapp.com/

Guardもforemanから呼び出すように変更

Procfile

guard: bundle exec guard

日本語対応

メニューの日本語対応

_app/views/layouts/_navigation_links.html.erb_を編集

Deviseの日本語対応

devise.ja.ymlを_config/locales_に保存する。

_app/views/devise/_以下のファイルを編集する。

  • ログイン画面

    • app/views/devise/sessions/new.html.erb
    • _app/views/devise/shard/links.erb
  • アカウント編集画面

    • app/views/devise/registrations/edit.html.erb
  • 管理者画面

    • app/views/admin/base/index.html.erb
  • ユーザー画面

    • app/views/admin/users/index.html.erb
    • app/views/admin/users/edit.html.erb

Google Analytics対応

トラッキングIDの設定

_app/config/application.yml_を作成してトラッキングIDとトラッキングドメインを明記する

$ rails g figaro:install

application.yml

google_analytics_key: "UA-XXXXXXX-XX"
google_analytics_domain: "herokuapp.com"

事前にトラッキングIDをGoogleAnlyticsで設定しおく。
application.ymlはレポジトリ管理対象にはならないのでローカル環境のみで管理する。

パーシャル追加

_app/views/layouts/_footer.html.erb_に以下のコードを追加

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', '<%= ENV["google_analytics_key"]%>', '<%= ENV["google_analytics_domain"]%>');  
  ga('send', 'pageview');

</script>

Turbolinks対応

_app/assets/javascripts/analytics.js.coffee_を追加する

$(document).on 'page:change', ->
  if window._gaq?
    _gaq.push ['_trackPageview']
  else if window.pageTracker?
    pageTracker._trackPageview()

デプロイ

ここまでの作業をコミットした後Figaroでアプリケーションのキー情報をherokuの環境変数に登録。

$ rake figaro:heroku['sukusuku']

Herokuへデプロイ

$ RAILS_ENV=production rake assets:precompile
$ git add -a
$ git commit -m "assets compiled for Heroku"
$ git push -f heroku master

データベースアノテーション

_Gemfile_に以下を追加

group :development do
  gem 'annotate', '2.5.0'
end

アノテーション実行

$ bundle install
$ bundle exec annotate

※dbスキーマに変更がある度にbundle exec annotateする必要がある

Codeclimate対応

コードチェックの登録

https://codeclimate.com/にログインする。
ダッシュボード画面の_Add Open Source Repo_からレポジトリを追加する。

コードカバレッジの登録

_Gemfile_に追加する。

gem "codeclimate-test-reporter", group: :test, require: nil

_spec/spec_helper_の先頭に以下のコードを追加する。

require "codeclimate-test-reporter"
 CodeClimate::TestReporter.start

_.travis.yml_に以下のコードを追加する。repo_tokenはCodeclimate管理画面の_Settings_メニューのTest Coverageに明記されている。

 addons:
   code_climate:
     repo_token: 1213....

更新を反映

$ bundle
$ git push origin master

参照

sukusuku's People

Contributors

k2works avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.