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

Add methods to update model in form #13

Merged
merged 9 commits into from
Apr 30, 2024
Merged

Conversation

afuno
Copy link
Member

@afuno afuno commented Apr 30, 2024

No description provided.

afuno added 2 commits April 30, 2024 22:07
Updated the form model by adding an `update` method that allows attributes to be altered. Exceptions are raised when this method is used with a collection. Accordingly, tests have been added to the user and product specs to ensure correct functionality and error handling. The 'user' references in the product_spec.rb have also been corrected to 'product'.
Updated the Datory exceptions and form modules to handle cases where a collection attribute is being updated. Introduced a new MisuseError exception for inappropriate method use. Introduced a new 'update_by' method that enables selective update of elements in a collection by specifying their index. Updated the user and product specs to reflect these changes.
@afuno afuno added the feature label Apr 30, 2024
@afuno afuno added this to the v1.0.0 milestone Apr 30, 2024
@afuno afuno self-assigned this Apr 30, 2024
@afuno afuno marked this pull request as ready for review April 30, 2024 15:26
afuno added 7 commits April 30, 2024 22:32
The `update_by` method within lib/datory/attributes/form.rb was raising an incorrect error message when invoked without a collection. The error message has been corrected to accurately state that the `update_by` method can't be used "without a collection."
Optimized the variable naming in the form.rb file for better code readability. Changed 'map_index' to 'model_index' to correctly reflect the context and make it more understandable.
This commit extracts common logic for checking if a model is a collection into an individual method named `model_collection?`. The change helps reduce duplication and increases code readability in the `update` and `update_by` methods.
In the methods `update` and `update_by` of 'form.rb', the repetitive task of raising a MisuseError with a specific message has been refactored into a private method called `raise_misuse`. This increases the readability of the code and simplifies the maintenance process.
This update adds a new 'target' method in the 'form' class, and its corresponding tests in the 'user' and 'product' spec files. This method returns the 'context' instance variable for the object, which will enhance the debugging and tracking capabilities.
This commit adds a reader for the model attribute in the Form class of the Datory module. This is followed by updating all calls of @model to the new reader methods inside the Form class. The test cases were also updated to validate the presence of the model attribute.
This commit reorders the model presence checks in user_spec.rb and product_spec.rb test files. The checks for model being present have been moved up so they occur earlier in the test run. This adjustment enhances test readability and troubleshooting.
@afuno afuno merged commit 3ec96cc into main Apr 30, 2024
26 checks passed
@afuno afuno deleted the features/SRV-96/update_model branch April 30, 2024 18:34
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.

1 participant