Fix column header lookup fragility, add fetch error handling, add tests

- Replace position-based column header lookup (ths[3]/ths[4]) with
  data-column attribute selectors — immune to column reordering
- Add .catch() error handlers to editMeasurementWide and setDefaultUnit
  fetch calls so failures surface in the console instead of silently
  disappearing
- Add MeasurementsController integration tests covering index auth,
  create with taken_at, empty-readout create, destroy, cross-user
  destroy isolation, and update

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-04 10:24:26 +00:00
parent bfd427c9b2
commit 1bc75f5d40
3 changed files with 69 additions and 11 deletions

View File

@@ -47,10 +47,8 @@ function buildWideTable() {
groupMap.get(key).rows.push(r);
});
// Read column headers from compact thead
var ths = document.querySelectorAll('.measurements-compact thead th');
var takenAtHeader = ths[3] ? ths[3].textContent : '';
var createdAtHeader = ths[4] ? ths[4].textContent : '';
var takenAtHeader = (document.querySelector('[data-column="taken-at"]') || {}).textContent || '';
var createdAtHeader = (document.querySelector('[data-column="created-at"]') || {}).textContent || '';
var table = document.createElement('table');
table.className = 'items-table';
@@ -190,7 +188,8 @@ function editMeasurementWide(url) {
panel.scrollIntoView({behavior: 'smooth', block: 'nearest'});
}
});
});
})
.catch(err => console.error('editMeasurementWide failed:', err));
}
window.editMeasurementWide = editMeasurementWide
@@ -229,7 +228,8 @@ function setDefaultUnit(button) {
}
return response.text();
})
.then(html => Turbo.renderStreamMessage(html));
.then(html => Turbo.renderStreamMessage(html))
.catch(err => console.error('setDefaultUnit failed:', err));
}
window.setDefaultUnit = setDefaultUnit

View File

@@ -21,8 +21,8 @@
<th><%= Quantity.model_name.human %></th>
<th><%= Readout.human_attribute_name(:value) %></th>
<th><%= Unit.model_name.human %></th>
<th><%= Readout.human_attribute_name(:taken_at) %></th>
<th><%= Readout.human_attribute_name(:created_at) %></th>
<th data-column="taken-at"><%= Readout.human_attribute_name(:taken_at) %></th>
<th data-column="created-at"><%= Readout.human_attribute_name(:created_at) %></th>
<% if current_user.at_least(:active) %>
<th></th>
<% end %>