CSC/ECE 517 Fall 2017/E1756 TLD Refactor response.rb: Difference between revisions
No edit summary |
No edit summary |
||
Line 107: | Line 107: | ||
Solution: | Solution: | ||
The method has been broken in to smaller and simpler parts and have been given the reasonable names | |||
[[File:E1756pic2.png]] | [[File:E1756pic2.png]] | ||
[[File:E1756pic3.png]] | |||
Problem 2: | Problem 2: | ||
The method has repeated lines of code. | The method has repeated lines of code. | ||
[[File:E1756pic4.png]] | |||
Solution: | Solution: | ||
Line 126: | Line 124: | ||
The loop has been included in the method instead of writing the same lines of code. | The loop has been included in the method instead of writing the same lines of code. | ||
[[File:E1756pic5.png]] | |||
Problem 3: | Problem 3: | ||
Line 132: | Line 130: | ||
Changing the method names | Changing the method names | ||
[[File:E1756pic6.png]] | |||
Solution: | Solution: | ||
[[File:E1756pic7.png]] | |||
Problem 4: | Problem 4: | ||
Use sort_by(&:seq) instead of sort { |a, b| a.seq <=> b.seq } | Use sort_by(&:seq) instead of sort { |a, b| a.seq <=> b.seq } | ||
[[File:E1756pic8.png]] | |||
Solution: | Solution: | ||
[[File:E1756pic9.png]] | |||
Problem 5: | Problem 5: | ||
find_by instead of where.first | find_by instead of where.first | ||
[[File:E1756pic10.png]] | |||
Solution: | Solution: | ||
[[File:E1756pic11.png]] | |||
Revision as of 03:03, 28 October 2017
About Expertiza
Expertiza is a Ruby on Rails based Open Source project. It is a collaboration tool which lets users with different roles (student, instructor, teaching assistant) to collaborate on a course in an institution. A collaboration could be for an assignment where students teams up for an assignment and instructors grades them on the basis of their submission. Students could review other's works and give feedbacks as well.
Github link
https://github.com/expertiza/expertiza
Wiki link
http://wiki.expertiza.ncsu.edu/index.php/Expertiza_documentation
Problem Statement
Background
response.rb is the default class to interact with the responses table, which stores all answers of each questionnaire.
What’s wrong with it?
response.rb is a fairly complex file. It contains a lot of methods that are long and hard to understand. These methods need to be broken down into simpler and more specific methods that are easier to read/understand. Also, the few instances of code duplication that exist should be -removed.
Problems
Problem 1:Refactor display_as_html method
Write failing tests first
Split into several simpler methods and assign reasonable names
Extract duplicated code into separate methods
Problem 2:Refactor self.get_volume_of_review_comments method
Write failing tests first
Convert duplicated code into loop
Problem 3:Rename method and change all other places it is used
Write failing tests first
get_total_score → total_score
get_average_score → average_score
get_maximum_score → maximum_score
Problem 4:Use sort_by(&:seq) instead of sort { |a, b| a.seq <=> b.seq }
Write failing tests first
Problem 5:Use find_by instead of where.first
Write failing tests first
Problem 6:Complete the pending tests in grades_controller_spec.rb, and write integration tests for newly-created methods. Refactor corresponding methods, and only then finish pending tests.
Issue links (external)
https://github.com/expertiza/expertiza/issues/720 https://github.com/expertiza/expertiza/issues/732
Files Modified
For Problem 1:
app/models/response.rb
For Problem 2:
app/models/response.rb
For Problem 3:
app/controllers/assessment360_controller.rb
app/controllers/popup_controller.rb
app/helpers/review_mapping_helper.rb
app/models/collusion_cycle.rb
spec/models/response_spec.rb
For Problem 4:
app/models/response.rb
For Problem 5:
app/models/response.rb
Issue and Solution
Problem 1:
The method display_as_html is complex. Many functions are embedded in to a single method.
Solution:
The method has been broken in to smaller and simpler parts and have been given the reasonable names
Problem 2:
The method has repeated lines of code.
Solution:
The loop has been included in the method instead of writing the same lines of code.
Problem 3:
Changing the method names
Problem 4:
Use sort_by(&:seq) instead of sort { |a, b| a.seq <=> b.seq } Solution:
Problem 5:
find_by instead of where.first