From d787237a95de559531a9e4d7b31bd43f69fe8c1c Mon Sep 17 00:00:00 2001 From: Phil Ayres Date: Thu, 18 Jun 2026 18:57:50 +0100 Subject: [PATCH 1/4] Added versioned embed template config fix and system specs - fixes #1238 --- .../_search_results_template.html.erb | 15 +- ...embedded_versioned_template_config_spec.rb | 264 +++++++++++++ .../embedded_versioned_show_mode_spec.rb | 359 ++++++++++++++++++ 3 files changed, 635 insertions(+), 3 deletions(-) create mode 100644 spec/requests/activity_log/embedded_versioned_template_config_spec.rb create mode 100644 spec/system/activity_log/embedded_versioned_show_mode_spec.rb diff --git a/app/views/common_templates/_search_results_template.html.erb b/app/views/common_templates/_search_results_template.html.erb index deb9f250cf..e227c59355 100644 --- a/app/views/common_templates/_search_results_template.html.erb +++ b/app/views/common_templates/_search_results_template.html.erb @@ -387,9 +387,18 @@ <% if full_name.to_s.start_with?('dynamic_model__') && option_type_config_name.to_s == default_option_type_name.to_s %> _fpa.state.caption_before.<%=name.underscore%> = _fpa.state.caption_before.<%=name_with_option_type.underscore%>; _fpa.state.labels_<%=name.underscore%> = _fpa.state.labels_<%=name_with_option_type.underscore%>; - _fpa.state.template_config.<%=resource_name%> = _fpa.state.template_config.<%=resource_name%> || _fpa.state.template_config.<%=name.underscore%>; - _fpa.state.template_config.<%=name.underscore.pluralize%> = _fpa.state.template_config.<%=name.underscore.pluralize%> || _fpa.state.template_config.<%=name.underscore%>; - _fpa.state.template_config.<%=name.underscore.sub('dynamic_model__', '')%> = _fpa.state.template_config.<%=name.underscore.sub('dynamic_model__', '')%> || _fpa.state.template_config.<%=name.underscore%> + <%# Alias the dynamic model's template config under its alternative resource + names (plural resource_name, pluralized name, and short name). The current + version's template object is aliased as before, but we must ALSO alias the + specific def_version key. Without this, when the base object already exists + from the initial page load (the current version), an older version's + template (loaded on demand via the template_config endpoint) is never linked + onto these alternative names, so versioned embedded items fail to render in + show mode (issue #1238). %> + <% [resource_name, name.underscore.pluralize, name.underscore.sub('dynamic_model__', '')].uniq.each do |alias_name| %> + _fpa.state.template_config.<%=alias_name%> = _fpa.state.template_config.<%=alias_name%> || _fpa.state.template_config.<%=name.underscore%>; + _fpa.state.template_config.<%=alias_name%>.v<%=def_version%> = _fpa.state.template_config.<%=alias_name%>.v<%=def_version%> || _fpa.state.template_config.<%=name.underscore%>.v<%=def_version%>; + <% end %> <% end %> <% end %> diff --git a/spec/requests/activity_log/embedded_versioned_template_config_spec.rb b/spec/requests/activity_log/embedded_versioned_template_config_spec.rb new file mode 100644 index 0000000000..14a3535a21 --- /dev/null +++ b/spec/requests/activity_log/embedded_versioned_template_config_spec.rb @@ -0,0 +1,264 @@ +# frozen_string_literal: true + +# Request specs for issue #1238 — activity log embedded dynamic models fail to +# render in show (read-only) mode when the embedded dynamic model uses +# "definition versioning: version at record creation". +# +# User-facing symptom: after saving an activity log embedded form, the +# read-only (show) form does not appear, and the browser console logs: +# fpa_state_item: could not find template_config dynamic_model__... v123 +# Editing the activity correctly shows the edit form, but on save/cancel the +# read-only form is missing. +# +# Root cause exercised here: the activity log `template_config` endpoint builds +# the Handlebars template-config