-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set a @versions
ivar and pass to helpers to avoid duplicate slow lookups of obj.versions
#1777
Conversation
show_authors_and_editors names, locations, glossary terms, descriptions x2
glossary_term, name, location, description x2 versions_controller of all these
@JoeCohen - This test is failing, and I believe it should not. As far as I understand, setting However, if the What do you think is going on here? def test_destroy_fails
term = glossary_terms(:no_images_glossary_term)
login
make_admin
term.stub(:destroy, false) do
GlossaryTerm.stub(:safe_find, term) do
delete(:destroy, params: { id: term.id })
end
end
assert_redirected_to(glossary_term_path(term.id),
"It should redisplay a Term it fails to destroy")
end |
@nimmolo: I'll have a look at |
@nimmolo: Does |
@JoeCohen Yes, fails both for me locally and on CI. Check to be sure you're on this branch and running this test: I can make the test pass by swapping the commented lines for the current lines in def find_glossary_term!
# @glossary_term = find_or_goto_index(GlossaryTerm,
# params[:id].to_s)
@glossary_term = GlossaryTerm.includes(show_includes).strict_loading.
find_by(id: params[:id]) ||
flash_error_and_goto_index(GlossaryTerm, params[:id])
end |
It's passing locally for me: joe@Josephs-MacBook-Pro ~/mushroom-observer (nimmo-panels-show-name)$ git status
On branch nimmo-panels-show-name
Your branch is up to date with 'origin/nimmo-panels-show-name'.
nothing to commit, working tree clean
joe@Josephs-MacBook-Pro ~/mushroom-observer (nimmo-panels-show-name)$ rails t test/controllers/glossary_terms_controller_test.rb -n test_destroy_fails
Started with run options -n test_destroy_fails --seed 1755
...
1 tests, 5 assertions, 0 failures, 0 errors, 0 skips
...
joe@Josephs-MacBook-Pro ~/mushroom-observer (nimmo-panels-show-name)$ rails t
Started with run options --seed 50929
...
2327 tests, 27078 assertions, 0 failures, 0 errors, 0 skips |
Sorry. Never moind. I'm in the wrong branch. Will keep looking. |
Looks to me like the stub works correctly. If I put a breakpoint in the test at the failing assertion, then ask if the term is destroyed, it returns joe@Josephs-MacBook-Pro ~/mushroom-observer (nimmo-versions-ivar)$ rails t test/controllers/glossary_terms_controller_test.rb -n test_destroy_fails
...
449| GlossaryTerm.stub(:safe_find, term) do
450| delete(:destroy, params: { id: term.id })
451| end
452| end
453|
=> 454| debugger
455| assert_redirected_to(glossary_term_path(term.id),
456| "It should redisplay a Term it fails to destroy")
457| end
458| # ---------- helpers ---------------------------------------------------------
=>#0 GlossaryTermsControllerTest#test_destroy_fails at ~/mushroom-observer/test/controllers/glossary_terms_controller_test.rb:454
#1 block in run (3 levels) at ~/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/minitest-5.20.0/lib/minitest/test.rb:94
# and 25 frames (use `bt' command for all frames)
(ruby) term.destroyed?
false The implication is that the test is working and there's an issue in the controller. |
Versions not possible
The test's inner stub
Bottom line: |
@JoeCohen - Thanks - this is great info! I had no idea about |
Easy peasy. I just swapped |
The PR currently deletes a lookup of the user instance when building a
user_link
for the latest version's user, just taking theversion.user_id
without confirming the user still exists.There's a chance this could give a dead link, but it seems remote. To me page slow loads are the bigger issue.
versions
should be eager-loaded, so this PR also setsstrict_loading
on the mainshow
query for all the controllers here.strict_loading
suggested eager-loading many more associations, added here.