Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Follow up to bbe7fe4 to fix enum leakage across classes.
The original attempt didn't really fix the problem and wasn't testing the problematic area. This commit corrected those issues in the original commit. Also removed the private `enum_mapping_for` method. As `defined_enums` is now a method, this method doesn't provide much value anymore.
- Loading branch information
1 parent
3f5eb59
commit a5664fe
Showing
3 changed files
with
35 additions
and
11 deletions.
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,3 +1,5 @@ | |||
require 'active_support/core_ext/object/deep_dup' | |||
|
|||
module ActiveRecord | module ActiveRecord | ||
# Declare an enum attribute where the values map to integers in the database, | # Declare an enum attribute where the values map to integers in the database, | ||
# but can be queried by name. Example: | # but can be queried by name. Example: | ||
|
@@ -70,8 +72,9 @@ def self.extended(base) | ||
base.defined_enums = {} | base.defined_enums = {} | ||
end | end | ||
|
|
||
def enum_mapping_for(attr_name) # :nodoc: | def inherited(base) | ||
defined_enums[attr_name.to_s] | base.defined_enums = defined_enums.deep_dup | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
chancancode
via email
Author
Member
|
|||
super | |||
end | end | ||
|
|
||
def enum(definitions) | def enum(definitions) | ||
|
@@ -136,7 +139,7 @@ def _enum_methods_module | ||
mod = Module.new do | mod = Module.new do | ||
private | private | ||
def save_changed_attribute(attr_name, value) | def save_changed_attribute(attr_name, value) | ||
if (mapping = self.class.enum_mapping_for(attr_name)) | if (mapping = self.class.defined_enums[attr_name]) | ||
if attribute_changed?(attr_name) | if attribute_changed?(attr_name) | ||
old = changed_attributes[attr_name] | old = changed_attributes[attr_name] | ||
|
|
||
|
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
1 comment
on commit a5664fe
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.
Why do we have an inherited and an extended callbacks?