overview
- Railsのアプリに機能を追加したり編集したり削除したりするときの自己流フロー
- 備忘録
- TDDでやりんす(Minitest)
Get staretd
Issue作成
- githubでissueを作る
- チェックボックスでテストメソッドのタイトルを書いておくと良いかも
テストを作る際には以下のルールを設けています
・基本的にModelごとにcreate, read, update, deleteの4ファイルで構成される
・各テストファイルのテスト名はUnable to 〜, Able to 〜と2種類の文頭で始まる
・Unable to 〜でNGなリストを作ることでテストファイルを仕様書として機能させます
# example
- [ ] Create
- Unable to create without Login
- Unable to create with blank
- Able to create
- [ ] Read
- [ ] Update
- [ ] Delete
- Unable to delete without Login
- Unable to delete other users tweet
- Able to delete
作業ブランチ作成
ブランチの運用ルールは以下の通りです
main => 本番環境用のブランチ
dev => 最新の開発用ブランチでここから作業ブランチを作る(mainへのmergeは管理者のみ)
f/xxx => 作業用ブランチで必ずDevブランチから派生する
$ git fetch$ git status$ git branch -a$ git checkout -b f/add-tweet-model origin/dev
テストファイル作成
$ rails t- CRUDで4つのファイルを作成(tweetディレクトリの中で作成することでメンテナンス性up)
$ rails g integration_test tweet/create$ rails g integration_test tweet/read$ rails g integration_test tweet/update$ rails g integration_test tweet/delete
-
$ rails t(greenであればok)
Red, Green, Refactoring
# test/integration/tweet/create_test.rb
def
def setup
@alice = users(:alice)
end
test 'Unable to create without Login' do
sign_in(@alice)
assert_no_difference 'Tweet.count' do
post tweet_path, params: { tweet: {
title: 'hello',
content: 'world!',
} }
end
assert_response :redirect
follow_redirect!
assert_equal tweets_path, request.path
end
end
PR発行
$ git status$ git add .$ git commit -m'Add Test Suite for Tweet'$ git push origin HEAD- ブラウザからPR発行
-
f/add-tweet-model=>dev -
dev=>main
-
Heroku Deploy
$ git checkout main$ git statusgit pullrails tgit push heroku