-
Notifications
You must be signed in to change notification settings - Fork 427
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
Support ActiveRecord 5.2 #337
Open
seanabrahams
wants to merge
1
commit into
attr-encrypted:master
Choose a base branch
from
Countable-us:active-record-5.2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+52
−4
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,7 +126,6 @@ class Address < ActiveRecord::Base | |
end | ||
|
||
class ActiveRecordTest < Minitest::Test | ||
|
||
def setup | ||
drop_all_tables | ||
create_tables | ||
|
@@ -221,6 +220,32 @@ def test_attribute_was_works_when_options_for_old_encrypted_value_are_different_ | |
assert_equal pw.reverse, account.password | ||
end | ||
|
||
# ActiveRecord 5.2 specific methods | ||
if ::ActiveRecord::VERSION::STRING >= "5.2" | ||
def test_should_create_will_save_change_to_predicate | ||
person = Person.create!(email: '[email protected]') | ||
refute person.will_save_change_to_email? | ||
person.email = '[email protected]' | ||
refute person.will_save_change_to_email? | ||
person.email = '[email protected]' | ||
assert person.will_save_change_to_email? | ||
end | ||
|
||
def test_should_create_saved_change_to_predicate | ||
person = Person.create!(email: '[email protected]') | ||
assert person.saved_change_to_email? | ||
person.reload | ||
person.email = '[email protected]' | ||
refute person.saved_change_to_email? | ||
person.email = nil | ||
refute person.saved_change_to_email? | ||
person.email = '[email protected]' | ||
refute person.saved_change_to_email? | ||
person.save | ||
assert person.saved_change_to_email? | ||
end | ||
end | ||
|
||
if ::ActiveRecord::VERSION::STRING > "4.0" | ||
def test_should_assign_attributes | ||
@user = UserWithProtectedAttribute.new(login: 'login', is_admin: false) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works well with ActiveRecord 5.2.
However, in ActiveRecord 6.0.0, private method
set_attribute_was
was removed. rails/rails@6b0a9deThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how we should proceed with a fix that only works in a single release. My first thought was to allow this to merge, and for Rails 6 we create a new major release. That will also give us the opportunity to finally deprecate some old code and potentially do some major cleanup of the test suite.
Any thoughts on how we can move forward? Is my suggestion the best course or are there better ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just update the pull request with the code snippet bellow
#337 (comment)