CSC/ECE 517 Fall 2013/oss aoa: Difference between revisions
(78 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
= OSS Project E 819 - Refactoring and Testing - Assignment= | == OSS Project E 819 - Refactoring and Testing - Assignment == | ||
This Wiki page provides a detailed description of the Open Source Software project conducted on Expertiza, as part of the Object Oriented Languages and Systems coursework. | This Wiki page provides a detailed description of the Open Source Software project conducted on Expertiza, as part of the Object Oriented Languages and Systems coursework. | ||
== Introduction to Expertiza== | == Introduction to Expertiza== | ||
[http://expertiza.ncsu.edu/ Expertiza]is an open source project built using the Ruby on Rails platform. It is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities to manage peer reviews in coursework. The source code can be forked from [https://github.com/expertiza/expertiza github] and cloned for performing modifications. The Expertiza environment is already set up in NC State's VCL image "Ruby on Rails". If you have access, this is quickest way to get a development environment running for Expertiza. See the Expertiza | [http://expertiza.ncsu.edu/ Expertiza] is an open source project built using the Ruby on Rails platform. It is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities to manage peer reviews in coursework. The source code can be forked from [https://github.com/expertiza/expertiza github] and cloned for performing modifications. The Expertiza environment is already set up in NC State's VCL image "Ruby on Rails". If you have access, this is quickest way to get a development environment running for Expertiza. See the Expertiza Wiki page on developing Expertiza on VCL. | ||
== Overview of project == | == Overview of project == | ||
Line 33: | Line 33: | ||
==Design Changes (Refactoring) Performed == | ==Design Changes (Refactoring) Performed == | ||
Following are the code snippets of all the files that have been refactored as part of the project: | Following are the code snippets of all the files that have been refactored as part of the project: | ||
=== Refactoring | === Refactoring performed on assignment.rb=== | ||
:1. function candidate_topics_to_review | :1. <b>function candidate_topics_to_review </b> | ||
Code before Refactoring: | Code before Refactoring: | ||
<pre> | <pre> | ||
Line 46: | Line 44: | ||
# Reject contributions of topics whose deadline has passed | # Reject contributions of topics whose deadline has passed | ||
contributor_set.reject! { |contributor| contributor.assignment.get_current_stage(signed_up_topic(contributor).id) == 'Complete' or | contributor_set.reject! { |contributor| contributor.assignment.get_current_stage(signed_up_topic(contributor).id) == 'Complete' or | ||
contributor.assignment.get_current_stage(signed_up_topic(contributor).id) == 'submission' } | |||
</pre> | </pre> | ||
Line 55: | Line 53: | ||
<pre> | <pre> | ||
contributor_set.reject! do |contributor| | contributor_set.reject! do |contributor| | ||
signed_up_topic(contributor).nil? || !contributor.has_submissions? || | |||
contributor.assignment.get_current_stage(signed_up_topic(contributor).id) == 'Complete' || | |||
contributor.assignment.get_current_stage(signed_up_topic(contributor).id) == 'submission' | |||
end | |||
</pre> | |||
:2. <b> Refactoring of self.export method </b> | |||
Code before refactoring: | |||
<pre> | |||
for index in 0 .. @scores[:teams].length - 1 | |||
team = @scores[:teams][index.to_s.to_sym] | |||
for participant in team[:team].get_participants | |||
pscore = @scores[:participants][participant.id.to_s.to_sym] | |||
tcsv = Array.new | |||
tcsv << 'team'+index.to_s | |||
if options['team_score'] == 'true' | |||
if team[:scores] | |||
tcsv.push(team[:scores][:max], team[:scores][:avg], team[:scores][:min], participant.fullname) | |||
else | |||
tcsv.push('---', '---', '---') | |||
end | |||
end | |||
if options['submitted_score'] | |||
if pscore[:review] | |||
tcsv.push(pscore[:review][:scores][:max], pscore[:review][:scores][:min], pscore[:review][:scores][:avg]) | |||
else | |||
tcsv.push('---', '---', '---') | |||
end | |||
end | |||
if options['metareview_score'] | |||
if pscore[:metareview] | |||
tcsv.push(pscore[:metareview][:scores][:max], pscore[:metareview][:scores][:min], pscore[:metareview][:scores][:avg]) | |||
else | |||
tcsv.push('---', '---', '---') | |||
end | |||
end | |||
if options['author_feedback_score'] | |||
if pscore[:feedback] | |||
tcsv.push(pscore[:feedback][:scores][:max], pscore[:feedback][:scores][:min], pscore[:feedback][:scores][:avg]) | |||
else | |||
tcsv.push('---', '---', '---') | |||
end | |||
end | |||
if options['teammate_review_score'] | |||
if pscore[:teammate] | |||
tcsv.push(pscore[:teammate][:scores][:max], pscore[:teammate][:scores][:min], pscore[:teammate][:scores][:avg]) | |||
else | |||
tcsv.push('---', '---', '---') | |||
end | |||
end | |||
tcsv.push(pscore[:total_score]) | |||
csv << tcsv | |||
end | |||
end | |||
</pre> | |||
Code after refactoring (merging the if-else statements and replacing them with ternary operator): | |||
<pre> | |||
for index in 0 .. @scores[:teams].length - 1 | |||
team = @scores[:teams][index.to_s.to_sym] | |||
for participant in team[:team].get_participants | |||
pscore = @scores[:participants][participant.id.to_s.to_sym] | |||
tcsv = Array.new | |||
tcsv << 'team'+index.to_s | |||
team[:scores] ? | |||
tcsv.push(team[:scores][:max], team[:scores][:avg], team[:scores][:min], participant.fullname) : | |||
tcsv.push('---', '---', '---') if options['team_score'] == 'true' | |||
pscore[:review] ? | |||
tcsv.push(pscore[:review][:scores][:max], pscore[:review][:scores][:min], pscore[:review][:scores][:avg]) : | |||
tcsv.push('---', '---', '---') if options['submitted_score'] | |||
pscore[:metareview] ? | |||
tcsv.push(pscore[:metareview][:scores][:max], pscore[:metareview][:scores][:min], pscore[:metareview][:scores][:avg]) : | |||
tcsv.push('---', '---', '---') if options['metareview_score'] | |||
pscore[:feedback] ? | |||
tcsv.push(pscore[:feedback][:scores][:max], pscore[:feedback][:scores][:min], pscore[:feedback][:scores][:avg]) : | |||
tcsv.push('---', '---', '---') if options['author_feedback_score'] | |||
pscore[:teammate] ? | |||
tcsv.push(pscore[:teammate][:scores][:max], pscore[:teammate][:scores][:min], pscore[:teammate][:scores][:avg]) : | |||
tcsv.push('---', '---', '---') if options['teammate_review_score'] | |||
tcsv.push(pscore[:total_score]) | |||
csv << tcsv | |||
end | |||
end | |||
</pre> | </pre> | ||
:3. <b> Replaced all occurrences of if statements with one-line if statements </b> | |||
Code before refactoring: | |||
<pre> | |||
if min_reviews > 0 | |||
contributor_set.sort! { |a, b| a.review_mappings.last.id <=> b.review_mappings.last.id } | |||
end | |||
</pre> | |||
Code after refactoring: | |||
<pre> | |||
contributor_set.sort! { |a, b| a.review_mappings.last.id <=> b.review_mappings.last.id } if min_reviews > 0 | |||
</pre> | |||
:4. <b> Replaced all occurrences of if-else-end with ternary operator </b> | |||
Code before refactoring: | |||
<pre> | |||
def is_using_dynamic_reviewer_assignment? | |||
if self.review_assignment_strategy == RS_AUTO_SELECTED or self.review_assignment_strategy == RS_STUDENT_SELECTED | |||
true | |||
else | |||
false | |||
end | |||
end | |||
</pre> | |||
Code after refactoring: | |||
<pre> | |||
def dynamic_reviewer_assignment? | |||
(self.review_assignment_strategy == RS_AUTO_SELECTED || self.review_assignment_strategy == RS_STUDENT_SELECTED) ? true : false | |||
end | |||
</pre> | |||
:5. <b> Replaced all occurrences of for loops with an each iterator </b> | |||
Code before refactoring: | |||
<pre> | |||
for rm in reviewer_mappings | |||
if rm.reviewee.id != mapping.reviewee.id | |||
review_num += 1 | |||
else | |||
break | |||
end | |||
end | |||
</pre> | |||
Code after refactoring: | |||
<pre> | |||
reviewer_mappings.each do |rm| | |||
(rm.reviewee.id != mapping.reviewee.id) ? review_num += 1 : break | |||
end | |||
</pre> | |||
:6. <b> Replaced all occurrences of "AND" and "OR" with logical && and || </b> | |||
Code before refactoring: | Code before refactoring: | ||
<pre> | <pre> | ||
Line 77: | Line 213: | ||
raise 'This assignment does not have topics' if !has_topics? and topic | raise 'This assignment does not have topics' if !has_topics? and topic | ||
</pre> | </pre> | ||
Code after refactoring: | Code after refactoring: | ||
<pre> | <pre> | ||
Line 82: | Line 219: | ||
raise 'This assignment does not have topics' if !has_topics? && topic | raise 'This assignment does not have topics' if !has_topics? && topic | ||
</pre> | </pre> | ||
=== Refactoring performed on assignment_participant.rb === | |||
:1. <b> Refactoring get_hyperlinks method </b> | |||
Code after refactoring: | |||
<pre> | |||
def get_hyperlinks | |||
team.try :get_hyperlinks | |||
end | |||
def get_hyperlinks_array | |||
self.submitted_hyperlinks.nil? ? [] : YAML::load(self.submitted_hyperlinks) | |||
end | |||
</pre> | |||
:2. <b> Discarded all unnecessary return statements at the end of functions and eliminated parantheses </b> | |||
Code before refactoring: | |||
<pre> | |||
def get_submitted_files() | |||
files = Array.new | |||
if(self.directory_num) | |||
files = get_files(self.get_path) | |||
end | |||
return files | |||
end | |||
</pre> | |||
Code after refactoring: | |||
<pre> | |||
def get_submitted_files | |||
files = Array.new | |||
files = get_files(self.get_path) if self.directory_num | |||
files | |||
end | |||
</pre> | |||
=== Refactoring performed on assignment_team.rb === | |||
:1. <b> Refactoring done on method has_submissions? </b> | |||
Before refactoring: | |||
<pre> | |||
def has_submissions? | |||
participants.each do |participant| | |||
return true if participant.has_submissions? | |||
end | |||
return false | |||
end | |||
</pre> | |||
After refactoring (Replacing do block with single line {} block and discarding return statement): | |||
<pre> | |||
def has_submissions? | |||
participants.each { |participant| return true if participant.has_submissions? } | |||
false | |||
end | |||
</pre> | |||
==List of classes and corresponding methods refactored== | |||
# <b> assignment.rb </b> | |||
## candidate_topics_to_review | |||
## contributor_to_review(reviewer, topic) | |||
## response_map_to_metareview(metareviewer) | |||
## is_using_dynamic_reviewer_assignment? | |||
## get_contributor(contrib_id) | |||
## get_path | |||
## check_condition(column, topic_id = nil) | |||
## submission_allowed(topic_id = nil) | |||
## review_allowed(topic_id = nil) | |||
## metareview_allowed(topic_id=nil) | |||
## email(author_id) | |||
## get_review_number(mapping) | |||
## is_wiki_assignment | |||
## is_microtask? | |||
## create_node | |||
## get_current_stage(topic_id = nil) | |||
## get_stage_deadline(topic_id = nil) | |||
## get_review_rounds | |||
## get_review_questionnaire_id | |||
## get_next_due_date | |||
## find_next_stage() | |||
## get_total_reviews_assigned_by_type(type) | |||
## get_total_reviews_completed_by_type_and_date(type, date) | |||
## compute_total_score(scores) | |||
# <b> assignment_participant.rb </b> | |||
## includes?(participant) | |||
## reviewed_by?(reviewer) | |||
## has_submissions? | |||
## get_reviewees | |||
## get_reviewers | |||
## get_cycle_similarity_score(cycle) | |||
## get_cycle_deviation_score(cycle) | |||
## copy(course_id) | |||
## get_submitted_files | |||
## get_wiki_submissions | |||
## self.import(row,session,id) | |||
## self.get_export_fields(options) | |||
## set_handle() | |||
## set_student_directory_num | |||
## get_topic_string | |||
# <b> assignment_team.rb </b> | |||
## includes?(participant) | |||
## reviewed_by?(reviewer) | |||
## has_submissions? | |||
## reviewed_contributor?(contributor) | |||
## get_hyperlinks | |||
## get_review_map_type | |||
## self.handle_duplicate(team, name, assignment_id, handle_duplicates) | |||
## self.import(row,session,assignment_id,options) | |||
## get_participants | |||
## add_participant | |||
## get_scores(questions) | |||
## self.get_team(participant) | |||
## self.get_export_fields(options) | |||
## self.create_team_and_node(assignment_id) | |||
=== Common refactoring performed on all three files=== | |||
:1. Merged all if-else-end statements and replaced them with ternary operator. | |||
:2. Replaced all occurrences of if statements with one-line if statements. | |||
:3. Replaced all occurrences of for loops with an each iterator. | |||
:4. Replaced all occurrences of "AND" and "OR" with logical && and ||. | |||
:5. Discarded all unnecessary return statements at the end of functions and eliminated parentheses. | |||
== Testing == | == Testing == | ||
The files containing unit test cases related to the files we refactored are listed below: | |||
:1. assignment_test.rb | |||
:2. assignment_participant_test.rb | |||
:3. assignment_team_test | |||
All these files were tested to ensure proper functioning of all test cases. | |||
== Future Work == | == Future Work == | ||
The following tasks can be performed as future work in this project: | |||
:1. Adding more functional tests for newly added methods. | |||
:2. Verifying whether the existing functional tests need revamping or improvement. | |||
:3. Running tools like CodeClimate to identify hotspots, evaluate new approaches, and improve code quality. | |||
:4. Adding more unit tests for better code coverage. | |||
== References == | == References == | ||
:1. [http://guides.rubyonrails.org/ Rails Guide] | |||
:2. [https://github.com/bbatsov/ruby-style-guide Ruby Style Guide] | |||
:3. [http://refactoring.com/ refactoring.com] | |||
:4. [http://ghendry.net/refactor.html Refactoring Notes] | |||
== External Links == | == External Links == | ||
: 1.[http://rubymonk.com/learning/books/4-ruby-primer-ascent RubyMonk] | |||
: 2.[http://www.refactoringinruby.info/ Refactoring in Ruby] | |||
: 3. [https://github.com/okdalvi/Expertiza-E819 Expertiza Repo] | |||
: 4. [http://152.46.17.175:3000/ VCL Link to E 819] | |||
: 5. [https://docs.google.com/a/ncsu.edu/document/d/1Z0xjFZu-Zy-xm73YyUVUgFCtfWgRwhN1rZuThoyF-U0/edit Steps for setting up Expertiza] |
Latest revision as of 23:16, 30 October 2013
OSS Project E 819 - Refactoring and Testing - Assignment
This Wiki page provides a detailed description of the Open Source Software project conducted on Expertiza, as part of the Object Oriented Languages and Systems coursework.
Introduction to Expertiza
Expertiza is an open source project built using the Ruby on Rails platform. It is a web application where students can submit and peer-review learning objects (articles, code, web sites, etc). It is used in select courses at NC State and by professors at several other colleges and universities to manage peer reviews in coursework. The source code can be forked from github and cloned for performing modifications. The Expertiza environment is already set up in NC State's VCL image "Ruby on Rails". If you have access, this is quickest way to get a development environment running for Expertiza. See the Expertiza Wiki page on developing Expertiza on VCL.
Overview of project
The main objective of the project was to refactor three Ruby files:
- • assignment.rb (925 lines)
- • assignment_participant.rb (385 lines)
- • assignment_team.rb (254 lines)
These three files are responsible for creation and management of assignments in Expertiza. They perform operations relating to a user participating in an assignment. AssignmentParticipant is a subclass of class Participant. CourseParticipant is Participant’s only other subclass. If a course has CourseParticipants, then an assignment can take its participants from the CourseParticipants.
Project Requirements
- 1. Do methods 'get_percentage_reviews_completed' and 'get_total_reviews_completed_by_type_and_date' belong to this class? The assignment.rb file should only contain those methods that pertain to the creation and maintenance of assignments in Expertiza.
- 2. The self.export method contains a lot of statements that have been repeated. Refactor this method to avoid duplication.
- 3. Look for other methods in the assignment.rb file that shouldn't belong to this file but to some other model/controller.
- 4. The 'get_scores' method in the 'assignment', 'assignment_participant' and 'assignment_team' files contain lines of code that appear to be repeated. Can this be refactored so that only one method implements the common functionality?
- 5. Refactor 'get_hyperlinks' to replace the conditional statement with polymorphism.
- 6. Refactor the 'get_reviews' method by replacing the conditional statement with polymorphism.
- 7. Look for any unused methods or variables in these files.
- 8. Also apply other refactorings such as Rename variable, Rename method to give the variables and methods more meaningful names.
Design Changes (Refactoring) Performed
Following are the code snippets of all the files that have been refactored as part of the project:
Refactoring performed on assignment.rb
- 1. function candidate_topics_to_review
Code before Refactoring:
contributor_set.reject! { |contributor| signed_up_topic(contributor).nil? or !contributor.has_submissions? } # Reject contributions of topics whose deadline has passed contributor_set.reject! { |contributor| contributor.assignment.get_current_stage(signed_up_topic(contributor).id) == 'Complete' or contributor.assignment.get_current_stage(signed_up_topic(contributor).id) == 'submission' }
Code after refactoring (merging reject statements)
contributor_set.reject! do |contributor| signed_up_topic(contributor).nil? || !contributor.has_submissions? || contributor.assignment.get_current_stage(signed_up_topic(contributor).id) == 'Complete' || contributor.assignment.get_current_stage(signed_up_topic(contributor).id) == 'submission' end
- 2. Refactoring of self.export method
Code before refactoring:
for index in 0 .. @scores[:teams].length - 1 team = @scores[:teams][index.to_s.to_sym] for participant in team[:team].get_participants pscore = @scores[:participants][participant.id.to_s.to_sym] tcsv = Array.new tcsv << 'team'+index.to_s if options['team_score'] == 'true' if team[:scores] tcsv.push(team[:scores][:max], team[:scores][:avg], team[:scores][:min], participant.fullname) else tcsv.push('---', '---', '---') end end if options['submitted_score'] if pscore[:review] tcsv.push(pscore[:review][:scores][:max], pscore[:review][:scores][:min], pscore[:review][:scores][:avg]) else tcsv.push('---', '---', '---') end end if options['metareview_score'] if pscore[:metareview] tcsv.push(pscore[:metareview][:scores][:max], pscore[:metareview][:scores][:min], pscore[:metareview][:scores][:avg]) else tcsv.push('---', '---', '---') end end if options['author_feedback_score'] if pscore[:feedback] tcsv.push(pscore[:feedback][:scores][:max], pscore[:feedback][:scores][:min], pscore[:feedback][:scores][:avg]) else tcsv.push('---', '---', '---') end end if options['teammate_review_score'] if pscore[:teammate] tcsv.push(pscore[:teammate][:scores][:max], pscore[:teammate][:scores][:min], pscore[:teammate][:scores][:avg]) else tcsv.push('---', '---', '---') end end tcsv.push(pscore[:total_score]) csv << tcsv end end
Code after refactoring (merging the if-else statements and replacing them with ternary operator):
for index in 0 .. @scores[:teams].length - 1 team = @scores[:teams][index.to_s.to_sym] for participant in team[:team].get_participants pscore = @scores[:participants][participant.id.to_s.to_sym] tcsv = Array.new tcsv << 'team'+index.to_s team[:scores] ? tcsv.push(team[:scores][:max], team[:scores][:avg], team[:scores][:min], participant.fullname) : tcsv.push('---', '---', '---') if options['team_score'] == 'true' pscore[:review] ? tcsv.push(pscore[:review][:scores][:max], pscore[:review][:scores][:min], pscore[:review][:scores][:avg]) : tcsv.push('---', '---', '---') if options['submitted_score'] pscore[:metareview] ? tcsv.push(pscore[:metareview][:scores][:max], pscore[:metareview][:scores][:min], pscore[:metareview][:scores][:avg]) : tcsv.push('---', '---', '---') if options['metareview_score'] pscore[:feedback] ? tcsv.push(pscore[:feedback][:scores][:max], pscore[:feedback][:scores][:min], pscore[:feedback][:scores][:avg]) : tcsv.push('---', '---', '---') if options['author_feedback_score'] pscore[:teammate] ? tcsv.push(pscore[:teammate][:scores][:max], pscore[:teammate][:scores][:min], pscore[:teammate][:scores][:avg]) : tcsv.push('---', '---', '---') if options['teammate_review_score'] tcsv.push(pscore[:total_score]) csv << tcsv end end
- 3. Replaced all occurrences of if statements with one-line if statements
Code before refactoring:
if min_reviews > 0 contributor_set.sort! { |a, b| a.review_mappings.last.id <=> b.review_mappings.last.id } end
Code after refactoring:
contributor_set.sort! { |a, b| a.review_mappings.last.id <=> b.review_mappings.last.id } if min_reviews > 0
- 4. Replaced all occurrences of if-else-end with ternary operator
Code before refactoring:
def is_using_dynamic_reviewer_assignment? if self.review_assignment_strategy == RS_AUTO_SELECTED or self.review_assignment_strategy == RS_STUDENT_SELECTED true else false end end
Code after refactoring:
def dynamic_reviewer_assignment? (self.review_assignment_strategy == RS_AUTO_SELECTED || self.review_assignment_strategy == RS_STUDENT_SELECTED) ? true : false end
- 5. Replaced all occurrences of for loops with an each iterator
Code before refactoring:
for rm in reviewer_mappings if rm.reviewee.id != mapping.reviewee.id review_num += 1 else break end end
Code after refactoring:
reviewer_mappings.each do |rm| (rm.reviewee.id != mapping.reviewee.id) ? review_num += 1 : break end
- 6. Replaced all occurrences of "AND" and "OR" with logical && and ||
Code before refactoring:
raise 'Please select a topic' if has_topics? and topic.nil? raise 'This assignment does not have topics' if !has_topics? and topic
Code after refactoring:
raise 'Please select a topic' if has_topics? && topic.nil? raise 'This assignment does not have topics' if !has_topics? && topic
Refactoring performed on assignment_participant.rb
- 1. Refactoring get_hyperlinks method
Code after refactoring:
def get_hyperlinks team.try :get_hyperlinks end def get_hyperlinks_array self.submitted_hyperlinks.nil? ? [] : YAML::load(self.submitted_hyperlinks) end
- 2. Discarded all unnecessary return statements at the end of functions and eliminated parantheses
Code before refactoring:
def get_submitted_files() files = Array.new if(self.directory_num) files = get_files(self.get_path) end return files end
Code after refactoring:
def get_submitted_files files = Array.new files = get_files(self.get_path) if self.directory_num files end
Refactoring performed on assignment_team.rb
- 1. Refactoring done on method has_submissions?
Before refactoring:
def has_submissions? participants.each do |participant| return true if participant.has_submissions? end return false end
After refactoring (Replacing do block with single line {} block and discarding return statement):
def has_submissions? participants.each { |participant| return true if participant.has_submissions? } false end
List of classes and corresponding methods refactored
- assignment.rb
- candidate_topics_to_review
- contributor_to_review(reviewer, topic)
- response_map_to_metareview(metareviewer)
- is_using_dynamic_reviewer_assignment?
- get_contributor(contrib_id)
- get_path
- check_condition(column, topic_id = nil)
- submission_allowed(topic_id = nil)
- review_allowed(topic_id = nil)
- metareview_allowed(topic_id=nil)
- email(author_id)
- get_review_number(mapping)
- is_wiki_assignment
- is_microtask?
- create_node
- get_current_stage(topic_id = nil)
- get_stage_deadline(topic_id = nil)
- get_review_rounds
- get_review_questionnaire_id
- get_next_due_date
- find_next_stage()
- get_total_reviews_assigned_by_type(type)
- get_total_reviews_completed_by_type_and_date(type, date)
- compute_total_score(scores)
- assignment_participant.rb
- includes?(participant)
- reviewed_by?(reviewer)
- has_submissions?
- get_reviewees
- get_reviewers
- get_cycle_similarity_score(cycle)
- get_cycle_deviation_score(cycle)
- copy(course_id)
- get_submitted_files
- get_wiki_submissions
- self.import(row,session,id)
- self.get_export_fields(options)
- set_handle()
- set_student_directory_num
- get_topic_string
- assignment_team.rb
- includes?(participant)
- reviewed_by?(reviewer)
- has_submissions?
- reviewed_contributor?(contributor)
- get_hyperlinks
- get_review_map_type
- self.handle_duplicate(team, name, assignment_id, handle_duplicates)
- self.import(row,session,assignment_id,options)
- get_participants
- add_participant
- get_scores(questions)
- self.get_team(participant)
- self.get_export_fields(options)
- self.create_team_and_node(assignment_id)
Common refactoring performed on all three files
- 1. Merged all if-else-end statements and replaced them with ternary operator.
- 2. Replaced all occurrences of if statements with one-line if statements.
- 3. Replaced all occurrences of for loops with an each iterator.
- 4. Replaced all occurrences of "AND" and "OR" with logical && and ||.
- 5. Discarded all unnecessary return statements at the end of functions and eliminated parentheses.
Testing
The files containing unit test cases related to the files we refactored are listed below:
- 1. assignment_test.rb
- 2. assignment_participant_test.rb
- 3. assignment_team_test
All these files were tested to ensure proper functioning of all test cases.
Future Work
The following tasks can be performed as future work in this project:
- 1. Adding more functional tests for newly added methods.
- 2. Verifying whether the existing functional tests need revamping or improvement.
- 3. Running tools like CodeClimate to identify hotspots, evaluate new approaches, and improve code quality.
- 4. Adding more unit tests for better code coverage.
References
- 1. Rails Guide
External Links
- 1.RubyMonk