Files
fizzy/app/controllers/cards/steps_controller.rb
T
Jeremy Daer a52b6f1c87 Add explicit wrap_parameters to all controllers (#2680)
* Add explicit wrap_parameters to controllers for flat JSON API support

Virtual attributes (has_rich_text, has_one_attached, delegated setters,
ActiveModel attrs) are not in Model.attribute_names, so wrap_parameters
auto-detection silently drops them from flat JSON requests. Add explicit
include: lists matching each controller's permitted params.

* Convert short-form wrap_parameters to explicit include: lists

Defense-in-depth: these controllers only have real-column params today,
so auto-detection works, but explicit lists prevent future regressions
if virtual attributes are added.

* Add flat JSON param tests for all wrap_parameters controllers

17 new tests covering every controller with wrap_parameters, verifying
that flat (unwrapped) JSON payloads are correctly wrapped and processed.
Focuses on virtual attributes that would be silently dropped without
explicit include: lists.
2026-03-09 21:47:05 -07:00

54 lines
975 B
Ruby

class Cards::StepsController < ApplicationController
wrap_parameters :step, include: %i[ content completed ]
include CardScoped
before_action :set_step, only: %i[ show edit update destroy ]
def index
fresh_when etag: @card.steps
end
def create
@step = @card.steps.create!(step_params)
respond_to do |format|
format.turbo_stream
format.json { render :show, status: :created, location: card_step_path(@card, @step, format: :json) }
end
end
def show
end
def edit
end
def update
@step.update!(step_params)
respond_to do |format|
format.turbo_stream
format.json { render :show }
end
end
def destroy
@step.destroy!
respond_to do |format|
format.turbo_stream
format.json { head :no_content }
end
end
private
def set_step
@step = @card.steps.find(params[:id])
end
def step_params
params.expect(step: [ :content, :completed ])
end
end