-
Notifications
You must be signed in to change notification settings - Fork 2
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
Chore/ruby 3409 mongoid reference one #1574
Conversation
%w[contact postal registered].each do |address_type| | ||
|
||
define_method(:"#{address_type}_address") do | ||
# handle synonyms | ||
address_type = "postal" if address_type == "contact" | ||
|
||
addresses.where(address_type: address_type.upcase).first | ||
end | ||
|
||
define_method(:"#{address_type}_address=") do |address| | ||
# handle synonyms | ||
address_type = "postal" if address_type == "contact" | ||
|
||
unless address.blank? || address.address_type == address_type.upcase | ||
raise ArgumentError, "Attempted to set #{address_type} address with address of type #{address.address_type}" | ||
end | ||
|
||
# clear any existing address of this type | ||
addresses.where(address_type: address_type.upcase).first&.destroy! | ||
|
||
addresses << address | ||
end | ||
end |
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.
I don't think this matches what was there before.
Previously, we had
contact_address -> address_type: POSTAL
company_address -> address_type: REGISTERED
registered_address -> address_type: REGISTERED
Now we have
contact_address -> address_type: POSTAL
postal_address -> address_type: POSTAL
registered_address -> address_type: REGISTERED
Please double check if code is correct
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.
I agree postal_address is redundant. The rest looks correct - company_address is no more.
bf5807f
to
1454317
Compare
…ute copying - Removed unused parameters `embedded_documents` and `attributes_to_exclude` from the `SafeCopyAttributesService`. - Simplified the logic for copying attributes, focusing on filtering and processing embedded documents directly within the `copy_attributes` method. - Updated related specs to reflect changes in the service, ensuring correct attributes are copied and non-existent attributes are excluded. [RUBY-3387] Implement exclusion of attributes in SafeCopyAttributesService - Updated `SafeCopyAttributesService` to allow exclusion of specified attributes during the copy process. - Modified `can_copy_data_from_registration` to pass `attributes_to_exclude` option. - Enhanced `filter_attributes` method to exclude specified attributes. - Adjusted tests in `safe_copy_attributes_service_spec` to cover new exclusion functionality. - Removed redundant embedded document copying logic from `past_registration` and `registration_completion_service`. [RUBY-3387] Fix duplicate storage of govpay status in `SafeCopyAttributesService` - Updated the service to correctly handle source relation data with both camelCase and snake_case keys. - Adjusted the logic to prevent storing attributes not present on the model, specifically `govpayStatus`. - Enhanced tests to verify that `govpayStatus` is not included in the result while valid attributes like `currency` are correctly processed. [RUBY-3387] Rubocop changes - Corrected the logic to prevent `govpayStatus` from being stored twice by refining the attribute matching process. - Improved code readability by adding parentheses for variable assignments within conditional statements. - Removed redundant code and fixed indentation issues. - Updated tests to reflect changes in attribute presence checks, ensuring `govpayStatus` is not included if not present in the order model. [RUBY-3387] Refactor attribute copying in `SafeCopyAttributesService` - Simplified the `copy_attributes` method to improve readability and maintainability. - Introduced `extract_attributes`, `filter_attributes`, and `process_embedded_relations` helper methods for better structure. - Enhanced handling of embedded relations by adding `find_relation_data` to support different naming conventions. - Improved error handling for unsupported source types. [RUBY-3387] Fix duplicate storage of `govpayStatus` in SafeCopyAttributesService - Updated `SafeCopyAttributesService` to exclude relations specified in `attributes_to_exclude` when copying attributes. - Refactored method to find matching attribute keys based on naming conventions. - Added tests to ensure excluded relations are not copied and that copyable attributes are correctly included. [RUBY-3387] Fix attribute comparison in specs to ignore `_id` field Updated tests in `past_registration_spec.rb` and `registration_completion_service_spec.rb` to compare attributes excluding the `_id` field as new implementation of SafeCopyAttributes does not copy the id field of the embedded documents like the old one did Chore/ruby 3409 mongoid reference one (#1574) https://eaflood.atlassian.net/browse/RUBY-3409 [RUBY-3387] Update spec to reference registered address as company address was removed [RUBY-3387] Add documentation to `SafeCopyAttributesService` in `safe_copy_attributes_service.rb` Enhanced the `SafeCopyAttributesService` with detailed comments explaining its functionality, including how it safely copies attributes between instances and handles embedded relations.
…feCopyAttributesService` - Implement `safe_copy_attributes` method to handle attribute copying more efficiently. - Introduce private helper methods `get_attributes`, `filter_attributes`, and `find_embedded_relation` to modularize logic. - Update specs to cover new functionality, including handling of Hash and BSON::Document sources. - Ensure only valid attributes are copied, and embedded documents are processed correctly. [RUBY-3387] Refactor `SafeCopyAttributesService` to streamline attribute copying - Removed unused parameters `embedded_documents` and `attributes_to_exclude` from the `SafeCopyAttributesService`. - Simplified the logic for copying attributes, focusing on filtering and processing embedded documents directly within the `copy_attributes` method. - Updated related specs to reflect changes in the service, ensuring correct attributes are copied and non-existent attributes are excluded. [RUBY-3387] Implement exclusion of attributes in SafeCopyAttributesService - Updated `SafeCopyAttributesService` to allow exclusion of specified attributes during the copy process. - Modified `can_copy_data_from_registration` to pass `attributes_to_exclude` option. - Enhanced `filter_attributes` method to exclude specified attributes. - Adjusted tests in `safe_copy_attributes_service_spec` to cover new exclusion functionality. - Removed redundant embedded document copying logic from `past_registration` and `registration_completion_service`. [RUBY-3387] Fix duplicate storage of govpay status in `SafeCopyAttributesService` - Updated the service to correctly handle source relation data with both camelCase and snake_case keys. - Adjusted the logic to prevent storing attributes not present on the model, specifically `govpayStatus`. - Enhanced tests to verify that `govpayStatus` is not included in the result while valid attributes like `currency` are correctly processed. [RUBY-3387] Rubocop changes - Corrected the logic to prevent `govpayStatus` from being stored twice by refining the attribute matching process. - Improved code readability by adding parentheses for variable assignments within conditional statements. - Removed redundant code and fixed indentation issues. - Updated tests to reflect changes in attribute presence checks, ensuring `govpayStatus` is not included if not present in the order model. [RUBY-3387] Refactor attribute copying in `SafeCopyAttributesService` - Simplified the `copy_attributes` method to improve readability and maintainability. - Introduced `extract_attributes`, `filter_attributes`, and `process_embedded_relations` helper methods for better structure. - Enhanced handling of embedded relations by adding `find_relation_data` to support different naming conventions. - Improved error handling for unsupported source types. [RUBY-3387] Fix duplicate storage of `govpayStatus` in SafeCopyAttributesService - Updated `SafeCopyAttributesService` to exclude relations specified in `attributes_to_exclude` when copying attributes. - Refactored method to find matching attribute keys based on naming conventions. - Added tests to ensure excluded relations are not copied and that copyable attributes are correctly included. [RUBY-3387] Fix attribute comparison in specs to ignore `_id` field Updated tests in `past_registration_spec.rb` and `registration_completion_service_spec.rb` to compare attributes excluding the `_id` field as new implementation of SafeCopyAttributes does not copy the id field of the embedded documents like the old one did Chore/ruby 3409 mongoid reference one (#1574) https://eaflood.atlassian.net/browse/RUBY-3409 [RUBY-3387] Update spec to reference registered address as company address was removed [RUBY-3387] Add documentation to `SafeCopyAttributesService` in `safe_copy_attributes_service.rb` Enhanced the `SafeCopyAttributesService` with detailed comments explaining its functionality, including how it safely copies attributes between instances and handles embedded relations.
This removes an obsolete custom
can_reference_single_document_in_collection
association workaround in favour of more conventional Rails/mongoid structures.It also retires the use of
company_address
on the Address model, in favour of the existing and preferredregistered_address
. Note that no data changes are required as part of this change.https://eaflood.atlassian.net/browse/RUBY-3409