-
Notifications
You must be signed in to change notification settings - Fork 118
Refactor AnswersController#create_or_update
#3519
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
Open
aaronskiba
wants to merge
10
commits into
conditional-question-fix-for-removing-questions-bug-rails7
Choose a base branch
from
aaron/conditional-question-fix-for-removing-questions-bug-rails7
base: conditional-question-fix-for-removing-questions-bug-rails7
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.
Open
Refactor AnswersController#create_or_update
#3519
aaronskiba
wants to merge
10
commits into
conditional-question-fix-for-removing-questions-bug-rails7
from
aaron/conditional-question-fix-for-removing-questions-bug-rails7
Conversation
This file contains hidden or 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 refactor addresses the Style/GuardClause offense. It also makes the code easier to read by replacing the large `if @answer.present?` block with the early `return unless @answer.present?` - The code comment has also been updated to correspond with the refactor.
Generated by 🚫 Danger |
- This refactor simply applies DRY principles to some of the plan fetching code in `AnswersController#create_or_update`.
- Cut and pasted existing answer transaction logic to new `handle_answer_transaction` helper method. - This refactor is intended to isolate the complex logic for the `Answer.transaction` block and to make the underlying `create_or_update` action easier to read and maintain.
These changes refactor the `Answer.transaction do` block into separate `create_answer`, `update_answer`, and `handle_stale_answer_error` methods. The changes are almost entirely a direct cut/paste from the original block into the corresponding methods. The only alteration is the prior `if q.question_format.rda_metadata?` check to `return unless q.question_format.rda_metadata?`. This early return check was auto-applied by rubocop.
- This change addresses the following rubocop offences: ``` app/controllers/answers_controller.rb:125:43: C: Naming/MethodParameterName: Method parameter must be at least 3 characters long. def handle_answer_transaction(p_params, q) ^ app/controllers/answers_controller.rb:144:27: C: Naming/MethodParameterName: Method parameter must be at least 3 characters long. def create_answer(args, q, standards) ^ app/controllers/answers_controller.rb:156:27: C: Naming/MethodParameterName: Method parameter must be at least 3 characters long. def update_answer(args, q, standards) ```
-This change maintains the functional logic of the deletion of answers (based on questions to be removed) while also optimising its efficiency.
- This change updates/corrects the commented locals in `app/views/answers/_new_edit.html.erb`. - Prior to this change, there were conflicting comments listing the available locals. `plan` does not appear to be one of them. Also, `app/controllers/answers_controller.rb` reveals that `base_template_org` is one of them.
436df3a
to
b025dfe
Compare
AnswersController#create_or_update
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Changes proposed in this PR:
AnswerController#create_or_update
create_or_update
action into separate private helper methods (commits 609d5df, efecb33, and a840abb).destroy_all
rather than iterating through each individual answer.app/javascript/src/utils/sectionUpdate.js
locals
variables available withinapp/views/answers/_new_edit.html.erb
.