Skip to content

Commit 578db70

Browse files
committed
fix(cli): keep generate controller no-actions path from writing an index view
Review finding on #3131: the unconditional `actions = result.actions` in Module.cfc adopted CodeGen's defaulted ["index"] list when the user passed no actions, so `wheels generate controller Users` started writing app/views/users/index.cfm — contradicting the documented "passing no actions creates an empty controller with no view files" behavior retained in the same code-generation.mdx paragraph. Surface the caller-requested (post-normalization, pre-default) action list as result.actions instead: empty input stays empty, so the view loop writes nothing, while comma-joined tokens still expand to one view per real action. The controller body keeps its default index() stub as before. Covered by a new CodeGenSpec case asserting result.actions is empty (and the stub present) for the no-actions path. Signed-off-by: Peter Amiri <peter@alurium.com>
1 parent d967a9c commit 578db70

3 files changed

Lines changed: 32 additions & 7 deletions

File tree

cli/lucli/Module.cfc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,9 +3190,11 @@ component extends="modules.BaseModule" {
31903190
return "";
31913191
}
31923192

3193-
// Use the normalized action list the generator actually wrote (comma-joined
3194-
// tokens like "index,show" are split into discrete actions) so view files
3195-
// match the controller methods instead of being named "index,show.cfm" (#3112).
3193+
// Use the normalized action list from the generator (comma-joined tokens like
3194+
// "index,show" are split into discrete actions) so view files match the
3195+
// controller methods instead of being named "index,show.cfm" (#3112). When no
3196+
// actions were passed result.actions is empty — documented behavior is an
3197+
// empty controller with no view files, so the view loop below writes nothing.
31963198
actions = result.actions;
31973199

31983200
// Create view files for non-mutation actions

cli/lucli/services/CodeGen.cfc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ component {
149149
// each token on commas, trim, and de-duplicate so both forms behave identically.
150150
arguments.actions = normalizeActions(arguments.actions);
151151

152+
// Capture the caller-requested list BEFORE the defaulting below. result.actions
153+
// drives the caller's view loop, and the documented contract is "passing no
154+
// actions creates an empty controller with no view files" — the index/CRUD
155+
// defaults applied next shape the controller body only, never the view files.
156+
var requestedActions = arguments.actions;
157+
152158
// Default actions based on type
153159
if (arrayLen(arguments.actions) == 0) {
154160
arguments.actions = arguments.crud ? crudActions : ["index"];
@@ -184,10 +190,12 @@ component {
184190
context = context
185191
);
186192

187-
// Surface the normalized action list so callers (e.g. Module.cfc's view loop)
188-
// render one view file per real action instead of one named after the raw
189-
// comma-joined token (#3112).
190-
result.actions = arguments.actions;
193+
// Surface the normalized caller-requested action list so callers (e.g.
194+
// Module.cfc's view loop) render one view file per real action instead of one
195+
// named after the raw comma-joined token (#3112). Deliberately the pre-default
196+
// list: when no actions were passed this stays empty, so callers write no view
197+
// files even though the controller body gets a default index() stub.
198+
result.actions = requestedActions;
191199
return result;
192200
}
193201

cli/lucli/tests/specs/services/CodeGenSpec.cfc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,21 @@ component extends="wheels.wheelstest.system.BaseSpec" {
250250
expect(result.actions).toBe(["index", "show"]);
251251
});
252252

253+
it("returns an empty action list when no actions are passed so callers write no views", () => {
254+
var result = codegen.generateController(
255+
name = "Stubs",
256+
actions = [],
257+
force = true
258+
);
259+
var content = fileRead(tempRoot & "/app/controllers/Stubs.cfc");
260+
// The controller body still gets the default index() stub...
261+
expect(content).toInclude("function index()");
262+
// ...but result.actions stays empty so the caller writes no view
263+
// files, preserving the documented "no actions => empty controller
264+
// with no view files" behavior (PR ##3131 review).
265+
expect(result.actions).toBeEmpty();
266+
});
267+
253268
});
254269

255270
describe("validateName()", () => {

0 commit comments

Comments
 (0)