APIエンドポイントとリクエストバリデーションを実装#12
Merged
Merged
Conversation
Closed
a640b2c to
8169e8d
Compare
6b21fba to
d0dde37
Compare
8169e8d to
64807d7
Compare
d0dde37 to
118f057
Compare
64807d7 to
ba0c72a
Compare
118f057 to
df370f2
Compare
ba0c72a to
8a9a3cd
Compare
df370f2 to
12ed79a
Compare
8a9a3cd to
ce9f7d0
Compare
12ed79a to
8270ee7
Compare
Base automatically changed from
feature/2605/en-Barry/electricity-bill-simulator
to
develop
May 12, 2026 10:29
AMPERE_VALUES (Form) と VALID_AMPERES (Service) が同値の別名で重複しており 片方だけ変更したときに不整合が生じるリスクがあったため、 app/models/concerns/electricity_bill_constants.rb に一元化し両クラスで include する。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
8270ee7 to
6f996eb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
要約
Issue #7(
GET /api/v1/electricity_bill_simulationsエンドポイントの TDD 実装)を解決する。ElectricityBillSimulationParams(Form Object)でリクエストパラメータの検証と JSON:API エラー配列生成を担い、コントローラは薄く保つactivemodel.errors.models.*)でja.ymlに一元管理Closes #7
実装してみて発生した追加判断
ActiveModel::Attributesを使わずattr_writer+ reader override を採用:attribute :kwh, :integerを使うと"100.5"→100に黙示切り捨てされ「小数を弾く」テストが失敗する。cast_to_integerがInteger("100.5")でArgumentErrorを捕捉し生値を返すことで、numericalityが:not_an_integerを立てる設計にしたVALID_AMPERES/MAX_KWHをElectricityBillConstantsモジュールに切り出し: 同じ定数がElectricityBillSimulationParamsとElectricityBillSimulatorに重複・名称不統一で定義されており、片方だけ変更したときの不整合を防ぐためapp/models/concerns/electricity_bill_constants.rbに一元化したテストケース一覧
spec/forms/electricity_bill_simulation_params_spec.rb(14 examples)spec/requests/api/v1/electricity_bill_simulations_spec.rb(3 examples)