Skip to content
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

[DON'T MERGE] Add failing tests for association with abort on destroy #522

Merged
merged 2 commits into from
Mar 23, 2022

Conversation

tricknotes
Copy link
Contributor

paranoia destroys associations even if the destruction is aborted.
My expectation is what associations are not destroyed as the same as ActiveRecord's default.

@radar
How do you think about this behavior?


I added reproduction code as failing tests.
Here is the result of this test cases.

$ RAILS='~> 6.1' bundle exec rake
Run options: --seed 21553

# Running:

...............F

Failure:
ParanoiaTest#test_destroy_behavior_for_association_with_abort [test/paranoia_test.rb:146]:
Expected: 0
  Actual: 1


rails test test/paranoia_test.rb:135

....................................F

Failure:
ParanoiaTest#test_destroy_bang_behavior_for_association_with_abort [test/paranoia_test.rb:161]:
Expected: 0
  Actual: 1


rails test test/paranoia_test.rb:149

..............................

Finished in 0.542657s, 152.9511 runs/s, 475.4384 assertions/s.
83 runs, 258 assertions, 2 failures, 0 errors, 0 skips

@tricknotes
Copy link
Contributor Author

I don't have an idea to fix this tests yet.
However, I know using prepend: true avoids that.

diff --git a/test/paranoia_test.rb b/test/paranoia_test.rb
index 81f80c6..482abdd 100644
--- a/test/paranoia_test.rb
+++ b/test/paranoia_test.rb
@@ -1169,7 +1169,7 @@ end
 class AssociationWithAbortModel < ActiveRecord::Base
   acts_as_paranoid
   has_many :related_models, class_name: 'RelatedModel', foreign_key: :parent_model_id, dependent: :destroy
-  before_destroy { |_|
+  before_destroy(prepend: true) { |_|
     if ActiveRecord::VERSION::MAJOR < 5
       false
     else

@mathieujobin
Copy link
Collaborator

is this related to #513 ?

@mathieujobin mathieujobin merged commit 2af6700 into rubysherpas:core Mar 23, 2022
@tricknotes tricknotes deleted the failing-tests branch March 23, 2022 17:04
karunkumar1ly pushed a commit to edcast/paranoia that referenced this pull request Feb 6, 2024
)

Co-authored-by: Mathieu Jobin <mathieujobin@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants