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

Allow subclasses to redefine autosave callbacks for associated records #33378

Merged

Conversation

@numbata
Copy link
Contributor

@numbata numbata commented Jul 17, 2018

Summary

This addresses this issue #33305

AutosaveAssociation skip creation of callback method if it's already defined (even in parent class).

@rails-bot
Copy link

@rails-bot rails-bot commented Jul 17, 2018

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @rafaelfranca (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

Copy link
Contributor

@bogdanvlviv bogdanvlviv left a comment

Thanks.
Could you please fix rubocop issues in https://codeclimate.com/github/rails/rails/pull/33378?

activerecord/CHANGELOG.md Outdated
@@ -1,3 +1,9 @@
* Allow subclasses to redefine autosave callbacks for associated records.

Fixes #33305

This comment has been minimized.

@bogdanvlviv

bogdanvlviv Jul 17, 2018
Contributor

Missing dot after #33305

activerecord/test/cases/autosave_association_test.rb Outdated
@@ -1774,3 +1775,29 @@ def test_after_save_callback_with_autosave
assert_equal 1, comment.post_comments_count
end
end


This comment has been minimized.

@bogdanvlviv

bogdanvlviv Jul 17, 2018
Contributor

Extra empty line

activerecord/test/cases/autosave_association_test.rb Outdated
@@ -1774,3 +1775,29 @@ def test_after_save_callback_with_autosave
assert_equal 1, comment.post_comments_count
end
end


class TestAutosaveAssociationOnAHasManyAssociationDefinedINSubclass < ActiveRecord::TestCase

This comment has been minimized.

@bogdanvlviv

bogdanvlviv Jul 17, 2018
Contributor

IN => In. I would also add suffix WithAcceptsNestedAttributes.

activerecord/test/cases/autosave_association_test.rb Outdated

valid_project.reload

assert_equal valid_project.name, 'Updated'

This comment has been minimized.

@bogdanvlviv

bogdanvlviv Jul 17, 2018
Contributor

Could you change order of arguments since assert_equal receive expected value as first argument and actual values as the second.
It would improve error message:

Expected: "Initial"
  Actual: "Updated"
activerecord/test/cases/autosave_association_test.rb Outdated

valid_project.reload

assert_equal valid_project.name, "Updated"

This comment has been minimized.

@bogdanvlviv

bogdanvlviv Jul 17, 2018
Contributor

Could you change the order of arguments since assert_equal receive an expected value as the first argument and an actual values as the second.
It would improve error message:

Expected: "Initial"
  Actual: "Updated"

This comment has been minimized.

@numbata

numbata Jul 17, 2018
Author Contributor

@bogdanvlviv Sure. Can i squash commits into one after?

@bogdanvlviv
Copy link
Contributor

@bogdanvlviv bogdanvlviv commented Jul 17, 2018

Could you squash commits into one?

@numbata numbata force-pushed the numbata:subclass-redefine-autosave-callbacks branch Jul 17, 2018
activerecord/test/cases/autosave_association_test.rb Outdated
has_many :projects, foreign_key: :firm_id

accepts_nested_attributes_for :projects
end

This comment has been minimized.

@bogdanvlviv

bogdanvlviv Jul 17, 2018
Contributor

Not sure, but maybe it would be better to move this class definition to activerecord/test/models/company.rb

This comment has been minimized.

@numbata

numbata Jul 17, 2018
Author Contributor

Actually, I'm not sure too. This specific class used in this specific place only. It should be useless in other cases. Especially when activerecord/test/models/company.rb full of other classes.

Also maybe i should move this spec to activerecord/test/cases/nested_attributes_test.rb?

@numbata numbata force-pushed the numbata:subclass-redefine-autosave-callbacks branch Jul 26, 2018
@numbata numbata force-pushed the numbata:subclass-redefine-autosave-callbacks branch to 35ee756 Jul 26, 2018
@rafaelfranca rafaelfranca merged commit 35ee756 into rails:master Sep 13, 2018
2 checks passed
2 checks passed
codeclimate All good!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
rafaelfranca added a commit that referenced this pull request Sep 13, 2018
…lbacks

Allow subclasses to redefine autosave callbacks for associated records
suketa added a commit to suketa/rails_sandbox that referenced this pull request Jun 1, 2019
Allow subclasses to redefine autosave callbacks for associated records
rails/rails#33378
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.