inline_forms 8.1.15 → 8.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58e6670831f8bce627752b9797371fb20d2f3b14f571a4bc8c879478b71f5ff6
4
- data.tar.gz: 32fd5f2f3503126e9113d10a3bea9ba23468667f11cc4db8252d78078b101af8
3
+ metadata.gz: a523b9082f8bf1ada004984c1d3cc66e745cae0e525e36acbf66df97b7015e98
4
+ data.tar.gz: d82f9950bde7f293ea70ef2e63162bcb304a0fac44eb6c8f645f88bbefe947da
5
5
  SHA512:
6
- metadata.gz: d9e59af7820b05e5ef046c1771a85f37ee1d7dd4ab9affbe0f8e2dfda03fe49db57d9452972406a889f699732165b8117bb56ecdee6c6a5edf9c05b0d14642f8
7
- data.tar.gz: 55be4d675321e511079de4a362688b664e65dce704dd56ef5929c8db2a286f0fef034312a2572016138808155a18e4f7150472a26aa904adb65e926d762da949
6
+ metadata.gz: 275bec7794f426e5131ae69843dfcb9bd2cec55ae9124075bc59ae0e171fc6df3d406ae776d78526a918a12dbc87aa41b0b12ade138fd4f520d75254570e6b01
7
+ data.tar.gz: 33bb93de6e2f017d664b610e07105afea73708b5ee67a269b48bd68de6b3d0fa8b9688eab4c21882ea408a8fc7ab68fcf6e2a18ff733d56fad29110e5863790e
data/CHANGELOG.md CHANGED
@@ -4,6 +4,16 @@ All notable changes to this project are documented in this file.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [8.1.16] - 2026-05-28
8
+
9
+ ### Fixed
10
+
11
+ - **`RecordNotUnique` on `action_text_rich_texts.id` when undoing a delete more than once.** Restoring rich text after parent undo used `reify.save!`, which INSERTs the old primary key. A second delete/undo cycle (or an already-restored row) hit SQLite's unique constraint. Restoration now upserts by `(record_type, record_id, name)` and copies `body` only, and only the latest PaperTrail `destroy` version per attribute is applied.
12
+
13
+ ### Added
14
+
15
+ - **Regression test:** nested Photo delete → undo → delete → undo.
16
+
7
17
  ## [8.1.15] - 2026-05-28
8
18
 
9
19
  ### Fixed
@@ -331,23 +331,49 @@ class InlineFormsController < ApplicationController
331
331
  # Undoing a parent +destroy+ reifies the Apartment/Photo row only. ActionText
332
332
  # bodies live in +action_text_rich_texts+ and get their own PaperTrail
333
333
  # +destroy+ versions; those rows are gone after +parent.destroy+, so we also
334
- # reify and save each matching +ActionText::RichText+ destroy snapshot.
334
+ # reify each matching +ActionText::RichText+ destroy snapshot.
335
+ #
336
+ # Use +find_or_initialize_by(record_type, record_id, name)+ and copy +body+
337
+ # only. Reified rows carry the old PK; +save!+ on a new record would INSERT
338
+ # that id and raise +RecordNotUnique+ on a second delete/undo cycle when the
339
+ # row already exists. Only the newest destroy version per attribute name is
340
+ # applied (repeat delete/undo leaves multiple RT destroy versions in the table).
335
341
  def restore_rich_texts_for_reverted_parent!(parent)
336
342
  return unless defined?(ActionText::RichText)
337
343
 
338
344
  record_type = parent.class.base_class.name
339
345
  record_id = parent.id
346
+ versions_by_name = {}
347
+
348
+ PaperTrail::Version
349
+ .where(item_type: "ActionText::RichText", event: "destroy")
350
+ .order(id: :desc)
351
+ .each do |version|
352
+ attrs = version.object_deserialized
353
+ next unless attrs.is_a?(Hash)
340
354
 
341
- PaperTrail::Version.where(item_type: "ActionText::RichText", event: "destroy").find_each do |version|
342
- attrs = version.object_deserialized
343
- next unless attrs.is_a?(Hash)
355
+ type = attrs["record_type"] || attrs[:record_type]
356
+ rid = attrs["record_id"] || attrs[:record_id]
357
+ next unless type == record_type && rid.to_i == record_id
344
358
 
345
- type = attrs["record_type"] || attrs[:record_type]
346
- rid = attrs["record_id"] || attrs[:record_id]
347
- next unless type == record_type && rid.to_i == record_id
359
+ name = (attrs["name"] || attrs[:name]).to_s
360
+ next if name.empty?
361
+
362
+ versions_by_name[name] ||= version
363
+ end
348
364
 
349
- rich_text = version.reify
350
- rich_text&.save!
365
+ versions_by_name.each_value do |version|
366
+ reified = version.reify
367
+ next unless reified
368
+
369
+ name = reified.name.to_s
370
+ record = ActionText::RichText.find_or_initialize_by(
371
+ record_type: record_type,
372
+ record_id: record_id,
373
+ name: name
374
+ )
375
+ record.body = reified.body if reified.respond_to?(:body)
376
+ record.save!
351
377
  end
352
378
  end
353
379
 
@@ -1,4 +1,4 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module InlineForms
3
- VERSION = "8.1.15"
3
+ VERSION = "8.1.16"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inline_forms
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.15
4
+ version: 8.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ace Suares