CSC/ECE 517 Spring 2016/Refactor and write unit tests for question type.rb: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 37: Line 37:


==Refactor==
==Refactor==
* Criterion.rb
===Criterion.rb===
** Method has too many lines: Line 35 - 158 [106/30]
* Method has too many lines: Line 35 - 158 [106/30]
** Cyclomatic complexity for complete is too high: Line 35 - 158 [28/6]
* Cyclomatic complexity for complete is too high: Line 35 - 158 [28/6]
** Identical code found in 1 other location: Line 20 - 32 (mass = 89)
* Identical code found in 1 other location: Line 20 - 32 (mass = 89)
** Identical code found in 1 other location: Line 135 - 139 (mass = 50)
* Identical code found in 1 other location: Line 135 - 139 (mass = 50)
** Identical code found in 1 other location Line 13 - 14 (mass = 40)
* Identical code found in 1 other location Line 13 - 14 (mass = 40)
** Similar code found in 1 other location Line 103 - 105 (mass = 26)
* Similar code found in 1 other location Line 103 - 105 (mass = 26)
** Similar code found in 2 other locations Line 152 - 153 (mass = 22)
* Similar code found in 2 other locations Line 152 - 153 (mass = 22)
** Similar code found in 3 other locations: Line 130 - 134 (mass = 18)
* Similar code found in 3 other locations: Line 130 - 134 (mass = 18)
* Scale.rb
===Scale.rb===
** Cyclomatic complexity for complete is too high. Method has too many lines
* Cyclomatic complexity for complete is too high. Method has too many lines
** Identical code found in 1 other location: line 17-28
* Identical code found in 1 other location: line 17-28
** Identical code  found in 1 other location: line 50-54
* Identical code  found in 1 other location: line 50-54
** Identical code found in 1 other location: line 10-11
* Identical code found in 1 other location: line 10-11
** Similar code found in 3 other locations: line 60-64
* Similar code found in 3 other locations: line 60-64
* Checkbox.rb
===Checkbox.rb===
** Method has too many lines.
* Method has too many lines.
** Cyclomatic complexity for complete is too high.
* Cyclomatic complexity for complete is too high.
** Similar codes in edit method are found in 2 other locations.
* Similar codes in edit method are found in 2 other locations.
** Similar codes in view_question_text method are found in 4 other locations.
* Similar codes in view_question_text method are found in 4 other locations.
* Questionnaire_header.rb
===Questionnaire_header.rb===
* Upload_file.rb
===Upload_file.rb===
==Unit-test==
==Unit-test==
* Criterion.rb
===Criterion.rb===
* Scale.rb
===Scale.rb===
* Checkbox.rb
===Checkbox.rb===
* Upload_file.rb
===Upload_file.rb===

Revision as of 21:17, 21 March 2016

This wiki page is for the description of changes made under E1608 OSS assignment for Spring 2016, CSC/ECE 517. The assignment task is to refactor & write unit tests for [question_type].rb (eg. criterion.rb).


Problem Statement

Files related

Four models is related: criterion.rb, scale.rb, checkbox.rb, questionnaire_header.rb, upload_file.rb. There are 4 methods “edit”, “view_question_text”, “complete” and “view_completed_question” correspond to different views.

  • edit ~> when instructor add/edit new questions
  • view ~> when instructor view existed questions
  • complete ~> when students do peer reviews
  • view_completed_question ~> when student view existed peer reviews

Expertiza question types inheritance hierarchy

  • Choice question
    • Scored question
      • Scale
      • Criterion
    • Unscored question
      • Dropdown
      • CheckBox
  • TextResponse
    • TextArea
    • TextField
  • UploadFile

Files problem

There are some issues in each file, such as security, complexity, duplication, etc. And currently there is no unit tests for [question_type].rb.

Our contribution

  • Refactor these [question_type].rb files and fix issues.
  • Keep the inputs and outputs of these methods (edit, view, complete, view_completed_question) the same as before.
  • Write unit tests for [question_type].rb listed above.
  • Create RSpec files for each question type in /spec/models/ folder
  • Create multiple tests to check valid and invalid cases, such as input including special character double quote (“”).

Refactor

Criterion.rb

  • Method has too many lines: Line 35 - 158 [106/30]
  • Cyclomatic complexity for complete is too high: Line 35 - 158 [28/6]
  • Identical code found in 1 other location: Line 20 - 32 (mass = 89)
  • Identical code found in 1 other location: Line 135 - 139 (mass = 50)
  • Identical code found in 1 other location Line 13 - 14 (mass = 40)
  • Similar code found in 1 other location Line 103 - 105 (mass = 26)
  • Similar code found in 2 other locations Line 152 - 153 (mass = 22)
  • Similar code found in 3 other locations: Line 130 - 134 (mass = 18)

Scale.rb

  • Cyclomatic complexity for complete is too high. Method has too many lines
  • Identical code found in 1 other location: line 17-28
  • Identical code found in 1 other location: line 50-54
  • Identical code found in 1 other location: line 10-11
  • Similar code found in 3 other locations: line 60-64

Checkbox.rb

  • Method has too many lines.
  • Cyclomatic complexity for complete is too high.
  • Similar codes in edit method are found in 2 other locations.
  • Similar codes in view_question_text method are found in 4 other locations.

Questionnaire_header.rb

Upload_file.rb

Unit-test

Criterion.rb

Scale.rb

Checkbox.rb

Upload_file.rb