Skip to content

Commit be4504e

Browse files
ursmclaudePaul-Bob
authored
chore: ensure remaining specs restore resource items on failure (#4469)
* chore: ensure remaining specs restore resource items on failure Follow-up to #4461. Same pattern: move trailing `Avo::Resources::*.restore_items_from_backup` calls inside `it` blocks into `ensure` clauses so the class-level `temporary_items` state is cleaned up even when an expectation fails mid-test. Failures otherwise leak the temporary block into subsequent tests where it is `instance_eval`d in `detect_fields`, replacing the resource's normal field set. Files audited: every spec that calls `with_temporary_items` or `restore_items_from_backup`. Files already using `before`/`after`/`around` hooks for cleanup are left untouched, as are the two intentionally-leaking tests in `tags_spec.rb` (covered in #4461). Five files have inline restore calls converted to `ensure`. One file (`spec/features/avo/search_has_many_scope_spec.rb`) was missing the restore entirely — added it in `ensure`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * chore: fix flaky format_using tags spec by sharing setup via before/after The two tests in the `format_using (same as deprecated fetch_labels) with fetch_values_from` describe in `tags_spec.rb` had a hidden inter-test dependency: `fetches the labels` set `with_temporary_items`, `keep correct tags on validations error and edit` inherited the leaked state. Under randomised order — or any environment where the leak does not happen to land first — the second test failed because the default Course resource has no `fetch_values_from` configured. This has been observed flaking on main CI (e.g. system_specs job in run 25716241257). Move the `with_temporary_items` setup into a `before` hook and the `restore_items_from_backup` cleanup into an `after` hook. Both tests are now self-contained and independent of execution order. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: Paul Bob <69730720+Paul-Bob@users.noreply.github.com>
1 parent 0c90b43 commit be4504e

7 files changed

Lines changed: 21 additions & 15 deletions

File tree

spec/features/avo/has_many_field_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184

185185
expect(page).to have_css('[data-component-name="avo/filters_component"]')
186186
expect(page).to have_css('[data-search-target="autocomplete"]')
187-
187+
ensure
188188
Avo::Resources::Store.restore_items_from_backup
189189
end
190190
end
@@ -199,7 +199,7 @@
199199

200200
expect(page).not_to have_css('[data-component-name="avo/filters_component"]')
201201
expect(page).not_to have_css('[data-search-target="autocomplete"]')
202-
202+
ensure
203203
Avo::Resources::Store.restore_items_from_backup
204204
end
205205
end

spec/features/avo/number_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
visit "/admin/resources/projects/#{project.id}"
104104

105105
expect(find_field_element(:users_required)).to have_text("10,000")
106-
106+
ensure
107107
Avo::Resources::Project.restore_items_from_backup
108108
end
109109
end
@@ -117,7 +117,7 @@
117117
visit "/admin/resources/projects"
118118

119119
expect(find_field_element(:users_required)).to have_text("10,000")
120-
120+
ensure
121121
Avo::Resources::Project.restore_items_from_backup
122122
end
123123
end
@@ -135,7 +135,7 @@
135135
visit "/admin/resources/projects/#{project.id}"
136136

137137
expect(find_field_element(:users_required)).to have_text("10,000")
138-
138+
ensure
139139
Avo::Resources::Project.restore_items_from_backup
140140
end
141141
end
@@ -149,7 +149,7 @@
149149
visit "/admin/resources/projects/#{project.id}/edit"
150150

151151
expect(page).to have_field("project_users_required", with: "10,000")
152-
152+
ensure
153153
Avo::Resources::Project.restore_items_from_backup
154154
end
155155
end
@@ -163,7 +163,7 @@
163163
visit "/admin/resources/projects/#{project.id}/edit"
164164

165165
expect(page).to have_field("project_users_required", with: "10,000")
166-
166+
ensure
167167
Avo::Resources::Project.restore_items_from_backup
168168
end
169169
end

spec/features/avo/search_has_many_scope_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,7 @@
8282
3.times do |index|
8383
expect(json["course links"]["results"][index]["_id"]).to eq course_with_five_links.links[index].to_param
8484
end
85+
ensure
86+
Avo::Resources::Course.restore_items_from_backup
8587
end
8688
end

spec/system/avo/create_via_belongs_to_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
within field_wrapper(:course) do
196196
expect(page).not_to have_text 'Create new course'
197197
end
198-
198+
ensure
199199
Avo::Resources::CourseLink.restore_items_from_backup
200200
end
201201
end

spec/system/avo/tabs_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@
337337
expect(page).not_to have_text("tab_1")
338338
expect(page).not_to have_text("tab_2")
339339
end
340-
340+
ensure
341341
Avo::Resources::User.restore_items_from_backup
342342
end
343343
end

spec/system/avo/tags_spec.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
let(:field_value_slot) { tags_element(find_field_value_element("skills")) }
182182
let(:tags_input) { field_value_slot.find("span[contenteditable]") }
183183

184-
it "fetches the labels" do
184+
before do
185185
Avo::Resources::Course.with_temporary_items do
186186
field :name
187187
field :skills,
@@ -196,7 +196,13 @@
196196
end
197197
}
198198
end
199+
end
200+
201+
after do
202+
Avo::Resources::Course.restore_items_from_backup
203+
end
199204

205+
it "fetches the labels" do
200206
visit avo.resources_courses_path
201207

202208
expect(page).to have_text "#{users[0].first_name} #{users[0].last_name}"
@@ -230,8 +236,6 @@
230236
save
231237

232238
expect(Course.last.skills.map(&:to_i)).to eql(users.pluck(:id))
233-
ensure
234-
Avo::Resources::Course.restore_items_from_backup
235239
end
236240
end
237241

spec/system/avo/trix_field_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393

9494
expect(page).not_to have_link("More content", href: "javascript:void(0);")
9595
expect(page).not_to have_link("Less content", href: "javascript:void(0);")
96-
96+
ensure
9797
Avo::Resources::Post.restore_items_from_backup
9898
end
9999
end
@@ -142,7 +142,7 @@
142142

143143
expect(page).to have_selector(".trix-content")
144144
expect(page).to have_text(body)
145-
145+
ensure
146146
Avo::Resources::Post.restore_items_from_backup
147147
end
148148
end
@@ -158,7 +158,7 @@
158158

159159
expect(page).to have_selector(".trix-content")
160160
expect(page).to have_text(body)
161-
161+
ensure
162162
Avo::Resources::Post.restore_items_from_backup
163163
end
164164
end

0 commit comments

Comments
 (0)