Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ファットモデル対策(サービス層) #157

Open
YutoKashiwagi opened this issue May 8, 2020 · 0 comments
Open

ファットモデル対策(サービス層) #157

YutoKashiwagi opened this issue May 8, 2020 · 0 comments

Comments

@YutoKashiwagi
Copy link
Owner

YutoKashiwagi commented May 8, 2020

Userモデルが太くなってしまっているので、サービス層を利用して細くする

規則

サービス層へ切り出す基準

  • 複数のモデルが絡むメソッドなど
  • バリデーションとアソシエーションは残す

ファイル作成方法

  • app/services/モデル名(単数形)/機能名(単数形)_service.rbというファイルに切り出す

サービス層の単体テスト作成方法

  • spec/services/モデル名(単数形)/機能名(単数形)_service_spec.rbというファイルに書く
  • type: :serviceとする
    • 例: spec/services/user/stock_service_spec.rbの場合
      • RSpec.describe "User::StockService", type: :service do
@YutoKashiwagi YutoKashiwagi changed the title ファットモデル対策 ファットモデル対策(サービス層) May 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant