CSC/ECE 517 Fall 2021 - E2121. Refactor suggestion controller.rb

From Expertiza_Wiki
Jump to navigation Jump to search

This page provides a description of the Expertiza based OSS project.


Introduction

About Expertiza

Expertiza is an open-source educational project based on Ruby on Rails framework.

Related Functions

  • Files Involved: suggestion_controller.rb, assignment_team.rb, sign_up_topic.rb, suggestion_controller_spec.rb (create)
  • The following functions are related to E2121:
    • Students could submit suggestions of topic
    • Instructors could approve or reject suggested topics of students
    • Instructors and students could create teams

Tasks Statement

The following tasks were accomplished in this project:

  • Line 76 and 77: use more Ruby-like String concepts
  • Line 94: Refactor create_new_team to assignment_team.rb
  • Line 125: Refactor notification to simplify control logic.
  • Line 160: Refactor approve_suggestion to indicate that notification is being sent.
  • Test functions and increase coverage:
    • Check error in approve
    • Test reject_suggestion
    • Test when topic_id.nil? to make sure the waitlist is cleared.
    • Test the submit, student_view, student_edit, update_suggestion, add_comment function

Procedure to Test Our project Manually

  • Click the link E2121.
  • Test Steps:
 TBD

Refactor Suggestion Controller.rb

Line 76 and 77: use more Ruby-like String concepts

Use Ruby-like string concepts .empty? to replace == " " expression.

Change from:

flash[:success] = 'Thank you for your suggestion!' if @suggestion.unityID != '' "
flash[:success] = 'You have submitted an anonymous suggestion. It will not show in the suggested topic table below.' if @suggestion.unityID == '' "

to:

flash[:success] = 'Thank you for your suggestion!' unless @suggestion.unityID.empty?
flash[:success] = 'You have submitted an anonymous suggestion. It will not show in the suggested topic table below.' if @suggestion.unityID.empty?

Line 94: Refactor create_new_team to assignment_team.rb

Move {create_new_team} function from suggestion controller.rb to assignment_team.rb.

Line 125: Refactor notification to simplify control logic

Line 160: Refactor approve_suggestion to indicate that notification is being sent

Originally, there is an error when the instructor approves a topic:

To fix it, we added new_topic_from_suggestion to app/models/sign_up_topic.rb and used it in approve function of app/controllers/suggestion_controller.rb.

def self.new_topic_from_suggestion(suggestion)
     signuptopic = SignUpTopic.new
     signuptopic.topic_identifier = 'S' + Suggestion.where("assignment_id = ? and id <= ?", suggestion.assignment_id, suggestion.id).size.to_s
     signuptopic.topic_name = suggestion.title
     signuptopic.assignment_id = suggestion.assignment_id
     signuptopic.max_choosers = 1
     #return this model based on these checks
     if signuptopic.save && suggestion.update_attribute('status', 'Approved')
       return signuptopic
     else
       return 'failed'
     end
 end

Then the approving bug is fixed:

Automated Testing using RSPEC

Add factory :suggestion to spec/factories/factories.rb as following:

factory :suggestion, class: Suggestion do
  id 1
  assignment_id 1
  title 'oss topic'
  description 'add oss topic'
  status 'Initiated'
  unityID 'student2065'
  signup_preference 'Y'
end

Check Error in Approve

TBD

Test reject_suggestion

TBD

Test When topic_id.nil? to Make Sure the Waitlist is Cleared

TBD

Test the submit, student_view, student_edit, update_suggestion, add_comment function

  • Test student_view
  describe '#student_view' do
    it 'renders suggestions#student_view' do
       get :student_view, id: 1
       expect(response).to render_template(:student_view)
     end
  end
  • Test student_edit
  describe '#student_edit' do
      it 'renders suggestions#student_edit' do
        get :student_edit, id: 1
        expect(response).to render_template(:student_edit)
      end
  end