Skip to content

勤怠管理、タスク管理アプリケーション[サーバ]

Notifications You must be signed in to change notification settings

RailsCorp/xtreme_alpha

Repository files navigation

Xtreme

codecov

  • Docker内に入るコマンド
$ docker exec -it xtreme_server bash
  • Devise Token Auth認証について
  • controllerの生成
bundle exec rails g controller <...>
  • Modelの生成
bundle exec rails g mdoel <...>
  • migrationファイルの生成
bundle exec rails g migration <...>
  • dbをmigrate
bundle exec rails db:migrate
  • migrateなどで失敗した時の対処法

1つのテーブルに1つのmigrationファイルにすること! (無駄にファイル数を増やしたくない)

bundle exec rails db:migrate:reset
  • RSpec実行
bundle exec rspec <ディレクトリ>
  • Rubocopの実行(自動修正モード)
bundle exec rubocop -a

appディレクトリ構成

app/
 ┣━ assets/
 ┣━ channels/
 ┣━ controllers/
 ┣━ decorators/ gem `draper`を使用
 ┣━ helpers/ 未使用
 ┣━ jobs/ 今の所使う予定なし
 ┣━ mailers/ action mailerとして使う可能性あり
 ┣━ models/ fatモデルにならないように気をつける
 ┣━ usecases/ service層 controllerやmodelのdelegateモジュール
 ┣━ queries/ controllerでの処理のフィルタリングに使用
 ┗━ views/ json.jbuilderで書く。

DeviseTokenAuthを用いた認証周りに関する知識

認証は DeviseTokenAuthを用いて

api/auth/registrations_controller.rbDeviseTokenAuth::RegistrationsControllerを継承!

createsメソッドDeviseTokenAuth::RegistrationsControllerを用いて、sign_up_paramsはオーバーライドしている。

app/controllers/application_controllerDeviseTokenAuth::Concerns::SetUserByTokenモジュールをincludeしているため、どのcontrollerでもいちいちaccess-tokenなどを定義する必要なし。

csrf対策はまだ未定。今後に導入。

devise_token_auth

devise_token_authは、headerに"access-token""client"uidを乗せてリクエスト送る。

{
  "access-token": "lhG-DTB64dyOlv1e-6BAiQ",
  "client": "RqCpylnDWcDUQVntAbpyDw",
  "uid": "[email protected]"
}

使えるメソッド

1. api_user_signed_in?
2. before_action :authenticate_api_user!
3. current_api_user

PostmanからUserオブジェクトを作るときに

{
	"name": "hogehoge1",
	"email": "[email protected]",
	"password": "hogehoge1",
	"password_confirmation": "hogehoge1",
	"reset_password_token": "hoegehoge1",
	"uid": "[email protected]"
}

mongodbを使用していないrspec

$ bin/rspec-test-queue.rb --exclude-pattern "spec/mongo/**/*_spec.rb" spec/
$ bundle exec rspec spec/mongo/.

About

勤怠管理、タスク管理アプリケーション[サーバ]

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages