|
|
Line 29: |
Line 29: |
| We are planning to accomplish the following tasks in this project: | | We are planning to accomplish the following tasks in this project: |
|
| |
|
| === Problem 1: Refactor the create method in assignment_controller.rb file === | | === Problem 1: Add insightful comments to the methods in mail_worker.rb=== |
| * '''Proposed Solution''': Split the whole function into multiple methods performing specific tasks. Change the name of the variables to meaningful names in the method. | | * '''Proposed Solution''': Split the whole function into multiple methods performing specific tasks. Change the name of the variables to meaningful names in the method. |
| * '''Solution Implemented''': Refactored the create method to split tasks into different methods and renamed a variable to correctly reflect its purpose.
| |
| <pre>
| |
| # creates a new assignment via the assignment form
| |
| def create
| |
| @assignment_form = AssignmentForm.new(assignment_form_params)
| |
| if params[:button]
| |
| # first check if assignment name exists, if not then create new, otherwise don't create new assignment
| |
| find_existing_assignment = Assignment.find_by(name: @assignment_form.assignment.name, course_id: @assignment_form.assignment.course_id)
| |
| dir_path = assignment_form_params[:assignment][:directory_path]
| |
| find_existing_directory = Assignment.find_by(directory_path: dir_path, course_id: @assignment_form.assignment.course_id)
| |
| if !find_existing_assignment && !find_existing_directory && @assignment_form.save # No existing names/directories
| |
| assignment_creation_success
| |
| # return
| |
| else
| |
| assignment_creation_failure(find_existing_assignment, dir_path, find_existing_directory)
| |
| end
| |
| else
| |
| render 'new'
| |
| undo_link("Assignment \"#{@assignment_form.assignment.name}\" has been created successfully. ")
| |
| end
| |
| end
| |
| # create a new assignment via the assignment form if the new assignment name and directory doesn't exist
| |
| def assignment_creation_success
| |
| @assignment_form.create_assignment_node
| |
| exist_assignment = Assignment.find(@assignment_form.assignment.id)
| |
| assignment_form_params[:assignment][:id] = exist_assignment.id.to_s
| |
| if assignment_form_params[:assignment][:directory_path].blank? # No existing assignment for assignment form
| |
| assignment_form_params[:assignment][:directory_path] = "assignment_#{assignment_form_params[:assignment][:id]}"
| |
| end
| |
| assignment_form_params[:assignment_questionnaire] = assign_questionnaire_array(exist_assignment)
| |
| assignment_form_params[:due_date] = assign_due_date_array(exist_assignment)
| |
| @assignment_form.update(assignment_form_params, current_user)
| |
| assignment_id = Assignment.find(@assignment_form.assignment.id).id
| |
| ExpertizaLogger.info "Assignment created: #{@assignment_form.as_json}"
| |
| redirect_to edit_assignment_path assignment_id
| |
| undo_link("Assignment \"#{@assignment_form.assignment.name}\" has been created successfully. ")
| |
| end
| |
|
| |
| # raises a flash error message when it fails to create an assignment and redirect to assignment/new page
| |
| def assignment_creation_failure(existing_assignment, dir_path, existing_directory)
| |
| flash[:error] = 'Failed to create assignment.'
| |
| if existing_assignment
| |
| flash[:error] << '<br> ' + @assignment_form.assignment.name + ' already exists as an assignment name'
| |
| end
| |
| if existing_directory
| |
| flash[:error] << '<br> ' + dir_path + ' already exists as a submission directory name'
| |
| end
| |
| redirect_to '/assignments/new?private=1'
| |
| end
| |
|
| |
| </pre>
| |
|
| |
| === Problem 2: Refactor the edit_params_setting method in assignment_controller.rb file ===
| |
| * '''Proposed Solution''': Split the whole function into multiple methods performing specific tasks.
| |
| *'''Solution Implemented''': Refactored edit_params_setting by extracting functionality on setting submissions and review rounds.
| |
| <pre>
| |
| def set_submissions_and_reviews_rounds
| |
| # The submission round i.e. Round 1 (before 1st deadline), Round 2 (after first peer review, before 2nd deadline)
| |
| @num_submissions_round = @assignment.find_due_dates('submission').nil? ? 0 : @assignment.find_due_dates('submission').count
| |
| @num_reviews_round = @assignment.find_due_dates('review').nil? ? 0 : @assignment.find_due_dates('review').count
| |
| end
| |
|
| |
|
| |
| # populates values and settings of the assignment for editing
| |
| def edit_params_setting
| |
| @assignment = Assignment.find(params[:id])
| |
| @topics = SignUpTopic.where(assignment_id: params[:id])
| |
| @assignment_form = AssignmentForm.create_form_object(params[:id])
| |
| @user = current_user
| |
|
| |
| set_submissions_and_reviews_rounds
| |
|
| |
| @assignment_questionnaires = AssignmentQuestionnaire.where(assignment_id: params[:id])
| |
|
| |
| # Set due date
| |
| @due_date_all = AssignmentDueDate.where(parent_id: params[:id])
| |
| @due_date_nameurl_not_empty = false
| |
| @due_date_nameurl_not_empty_checkbox = false
| |
|
| |
| # Set metareview (self-review)
| |
| @metareview_allowed = false
| |
| @metareview_allowed_checkbox = false
| |
|
| |
| # Set up signup and drop topic
| |
| @signup_allowed = false
| |
| @signup_allowed_checkbox = false
| |
| @drop_topic_allowed = false
| |
| @drop_topic_allowed_checkbox = false
| |
|
| |
| # Set up team formation
| |
| @team_formation_allowed = false
| |
| @team_formation_allowed_checkbox = false
| |
|
| |
| # Set up participants and teams counts
| |
| @participants_count = @assignment_form.assignment.participants.size
| |
| @teams_count = @assignment_form.assignment.teams.size
| |
| end
| |
| </pre>
| |
|
| |
|
| === Problem 3: Fix Bugs in sidekiq_mail_worker_spec.rb === | | === Problem 3: Fix Bugs in sidekiq_mail_worker_spec.rb === |
Line 143: |
Line 45: |
| To run the tests, run the following commands from the expertiza directory | | To run the tests, run the following commands from the expertiza directory |
| <pre> | | <pre> |
| rspec ./spec/models/assignment_form_spec.rb
| |
|
| |
| rspec ./spec/workers/sidekiq_mail_worker_spec.rb | | rspec ./spec/workers/sidekiq_mail_worker_spec.rb |
| </pre> | | </pre> |
Line 172: |
Line 72: |
|
| |
|
| #[https://github.com/expertiza/expertiza Expertiza on GitHub] | | #[https://github.com/expertiza/expertiza Expertiza on GitHub] |
| #[https://github.com/MichaelDacanay/expertiza-mailer-refactor/tree/team-E2273 GitHub Project Repository Fork] | | #[https://github.com/MichaelDacanay/expertiza-mailer-refactor/tree/E2273 GitHub Project Repository Fork] |
| #[https://github.com/expertiza/expertiza/pull/2477 E2273 Pull Request] | | #[https://github.com/expertiza/expertiza/pull/2477 E2273 Pull Request] |
| #[http://expertiza.ncsu.edu/ The live Expertiza website] | | #[http://expertiza.ncsu.edu/ The live Expertiza website] |
Background
Expertiza uses Sidekiq gem for asynchronous processing of email tasks. It has a queue system to hold and then process jobs. Sidekiq’s queue replaces DelayedMailer’s queue. The previous team that worked on this also created a method perform() to gather email IDs of all participants in an assignment and send them an email reminder. Some test cases exist for this work.
History: Previous projects
* E2253 [1]
* E2144 [2]
About Assignment Controller
This class is responsible for the creation and implementation of assignment forms. This includes due dates, questionnaires and assigning reviews.
Previous Information can be found here E2144
Files Involved (some changed should not have been changed):
- app/controllers/assignments_controller.rb
- app/mailers/mail_worker.rb
- app/models/assignment_form.rb
- config/sidekiq.yml
- spec/models/assignment_form_spec.rb
- spec/sidekiq_mail_worker_spec.rb
- spec/spec_helper.rb
Problems and planned changes
We are planning to accomplish the following tasks in this project:
* Proposed Solution: Split the whole function into multiple methods performing specific tasks. Change the name of the variables to meaningful names in the method.
Problem 3: Fix Bugs in sidekiq_mail_worker_spec.rb
* Proposed Solution: Comment out or Fix the failing existing tests.
Problem 4: Increase the test coverage for sidekiq_mail_worker_spec.rb
* Proposed Solution: Add more tests to increase test coverage.
Automated Testing using RSPEC
The current version of expertiza included tests for the assignments_form and the mail_worker, but they were far from extensive. Thus we added a few tests of our own.
To run the tests, run the following commands from the expertiza directory
rspec ./spec/workers/sidekiq_mail_worker_spec.rb
Testing from UI
No changes were made to the functionality of the project, however you can access it through the setup below.
To Test via UI
1) Login with the login above
2) Click on Manage...
3) Click on Assignments
4) On the right side click the +
5) Once you've added a name, scroll to the bottom and click create
6) Repeat steps 2 and 3, to view the assignment added to the list
References
- Expertiza on GitHub
- GitHub Project Repository Fork
- E2273 Pull Request
- The live Expertiza website