CSC/ECE 517 Fall 2019 - E1971. OSS project Finklestein: Instructors & Institutions: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 127: Line 127:


====Test for Task2====
====Test for Task2====
   <font color="green">'''''233''''' it 'save successfully with a new institution' do
   '''Changed files:''' <font color="blue">spec/controllers/users_controller_spec.rb</font>
   '''''234'''''   driver = Selenium::WebDriver.for :firefox
   
   '''''235'''''   driver.get("http://localhost:3000/")
   <font color="green">'''''234''''' session = {user: admin}
   '''''236'''''    driver.find_element(:id, "login_name").send_keys("super_administrator2")
   '''''235''''' params = {
   '''''237'''''   driver.find_element(:id, "login_password").send_keys("password")
   '''''236'''''    user: {name: 'instructor6',
   '''''238'''''   driver.find_element(:name, "commit").click()
   '''''237'''''           crypted_password: 'password',
   '''''239'''''   driver.get("http://localhost:3000/users/new?utf8=%E2%9C%93&role=Instructor&commit=New+Instructor")
   '''''238'''''           role_id: 2,
   '''''240'''''   driver.find_element(:id, "user_name").send_keys("yzhu48")
   '''''239'''''           password_salt: 1,
   '''''241'''''   driver.find_element(:id, "user_fullname").send_keys("yzhu48")
   '''''240'''''           fullname: '6, instructor',
   '''''242'''''   driver.find_element(:id, "user_email").send_keys("yzhu48@ncsu.com")
   '''''241'''''           email: 'yzhu48@ncsu.edu',
   '''''243'''''   driver.find_element(:id, "user_password").send_keys("111111")
   '''''242'''''           parent_id: 1,
   '''''244'''''   driver.find_element(:id, "user_password_confirmation").send_keys("111111")
   '''''243'''''           private_by_default: false,
   '''''245'''''      
   '''''244'''''           mru_directory_path: nil,
   '''''246'''''   institutionMenu = driver.find_element(:id, 'user_institution_id')
   '''''245'''''           email_on_review: true,
   '''''247'''''   option = Selenium::WebDriver::Support::Select.new(institutionMenu)
   '''''246'''''           email_on_submission: true,
   '''''248'''''   option.select_by(:text, 'Other')
  '''''247'''''          email_on_review_of_review: true,
   '''''249'''''  
   '''''248'''''           is_new_user: false,
   '''''250'''''   driver.find_element(:id, "institution_name").send_keys("yzhu48")
  '''''249'''''          master_permission_granted: 0,
   '''''251'''''
  '''''250'''''          handle: 'handle',
   '''''252'''''   driver.find_element(:name, "commit").click()
  '''''251'''''          digital_certificate: nil,
   '''''253'''''   expect(response.status).to eq(200)
  '''''252'''''          timezonepref: 'Eastern Time (US & Canada)',
   '''''254'''''  end</font>
   '''''253'''''          public_key: nil,
  '''''254'''''           copy_of_emails: nil,
  '''''255'''''          institution_id: 666,
   '''''256'''''           institution: {
   '''''257'''''               name: 'yzhu48'
  '''''258'''''          }
  '''''259'''''    }
  '''''260'''''  } 
   '''''261''''' post :create, params, session
   '''''262''''' allow_any_instance_of(User).to receive(:undo_link).with('The user "instructor6" has been successfully created. ').and_return(true)
   '''''263''''' expect(flash[:success]).to eq "A new password has been sent to new user's e-mail address."
   '''''264'''''  expect(response).to redirect_to('http://test.host/users/list')
 
====Test for Task3====
====Test for Task3====
   <font color="green">'''''17'''''  describe "View users" do
   <font color="green">'''''17'''''  describe "View users" do

Revision as of 03:26, 29 October 2019

E1971. OSS project Finklestein: Instructors & Institutions

Expertiza is an open-source project based on Ruby on Rails framework. Expertiza allows instructors to manager courses and assignments for students. Students can form up teams in Expertiza to work on different projects and assignments and do peer review about other students' submissions.

Introduction

  • E1971 Project aims to fix the associations problems between the Institution and Instructor class.

Problem Statement

The following tasks were accomplished in E1971 project:

  • Task1: The institution list should be sorted alphabetically.
    • Details: When creating a course, the drop-down list for selecting the institution does not show in alphabetical order.
 
  • Task2: Adding a new institution during creation of an instructor profile.
    • Details: The admin can attempt to create a new institution when creating a new instructor. But, after one types in the name of the institution & clicks create, it crashes.
 
  • Task3: Listing of instructors should show their institutions on the same line as their new feature.
    • Details: When listing users, there is currently no column to display the user’s associated institution.
 

Task1

As the issue is the Institution drop-down list is not alphabetically sorted. We simply added a step of sort when the Institution list was retrieved from the Database.

Changed files: _course.html.erb

line3 <%= select("course", "institutions_id", Institution.all.order(:name).collect{ |c| [ c.name, c.id] }) %>

Task2

The issue occurs when the admin trying to create a new instructor with a new institution name. To fix this problem, we added a function to create a new institution and a confirmation prompt to alert the admin.

Changed files: app/controllers/users_controller.rb

116  # if the user name already exists, register the user by email address
117  check = User.find_by(name: params[:user][:name])
118  params[:user][:name] = params[:user][:email] unless check.nil?
119  if params[:user][:institution_id].empty?
120    institution = Institution.find_or_create_by(name: params[:institution][:name])
121    params[:user][:institution_id] = institution.id
122  end
123  @user = User.new(user_params)
124  @user.institution_id = params[:user][:institution_id]
-------------------------------------------------------------------------------------------------
142  else
143    foreign
144    render action: 'new'
144    flash[:error] = "Create Instructor Error!"
145    redirect_to '/admin/list_instructors'
146  end
Changed files: app/views/users/new.html.erb

8  <ρ style="color: red; font-weight: bold">* Please Make Sure All Information is Correct</ρ>
9  <%= submit_tag "Create" %>

Task3

The issue is that the user page is not displaying the user's associated institution. To fix this issue, we added an 'institution' column in the HTML file retrieving the institution names of each user.

Changed files: app/models/user.rb

111  def institution(ip_address = nil)
112    if User.anonymized_view?(ip_address)
113      self.role.name + ', ' + self.id.to_s
114    else
115      if self[:role_id] == 2
116        self[:institution_id].nil? ? "" : Institution.find(self[:institution_id]).name
117      end
118    end
119  end
Changed files: app/views/users/list.html.erb
 

20 21 Name 22 Full Name 23 Institution 24 Email Address 25 Role 26 Parent 27 Review 28 Submission 29 Metareview 30 31 <% for user in @users %> 32 <% if ((params[:show] != 'true' && !user.name(session[:ip]).include?("_hidden")) || params[:show] == 'true')%> 33 34 <%= link_to user.name(session[:ip]), impersonate_impersonate_path(:user => {:name => user.name(session[:ip])}), :method => :post %> 35 <%= link_to user.fullname(session[:ip]), :controller=> 'users', :action => 'show', :id => user.id %> 36 <%= user.institution(session[:ip]) %> 37 <%= user.email(session[:ip]) %> 38 <%= link_to user.role.name, :controller => 'roles', :action => 'show', :id => user.role.id %> 39 <%= user.parent.try :name %> 40 <%= User.yesorno(user.email_on_review) %> 41 <%= User.yesorno(user.email_on_submission) %> 42 <%= User.yesorno(user.email_on_review_of_review) %> 43 44 <% end %> 45 <% end -%>

Task Demonstration

Task1


Task2



Task3


Test

Test for Task1

 Changed files: spec/features/course_creation_spec.rb

 13  it "check if the courses are sorted alphabetically" do
 14    create(:superadmin, name: 'super_administrator2')
 15    login_as('super_administrator2')
 16    visit "/course/new?private=1"
 17    expect(page.find(:xpath, "//*[@id=\"course_institutions_id\"]/option[1]").text).to eq("A")
 18    expect(page.find(:xpath, "//*[@id=\"course_institutions_id\"]/option[2]").text).to eq("B")
 19    expect(page.find(:xpath, "//*[@id=\"course_institutions_id\"]/option[3]").text).to eq("C")
 20    expect(page.find(:xpath, "//*[@id=\"course_institutions_id\"]/option[4]").text).to eq("D")
 21  end

Test for Task2

 Changed files: spec/controllers/users_controller_spec.rb

 234  session = {user: admin}
 235  params = {
 236    user: {name: 'instructor6',
 237           crypted_password: 'password',
 238           role_id: 2,
 239           password_salt: 1,
 240           fullname: '6, instructor',
 241           email: 'yzhu48@ncsu.edu',
 242           parent_id: 1,
 243           private_by_default: false,
 244           mru_directory_path: nil,
 245           email_on_review: true,
 246           email_on_submission: true,
 247           email_on_review_of_review: true,
 248           is_new_user: false,
 249           master_permission_granted: 0,
 250           handle: 'handle',
 251           digital_certificate: nil,
 252           timezonepref: 'Eastern Time (US & Canada)',
 253           public_key: nil,
 254           copy_of_emails: nil,
 255           institution_id: 666,
 256           institution: {
 257               name: 'yzhu48'
 258           }
 259     }
 260  }  
 261  post :create, params, session
 262  allow_any_instance_of(User).to receive(:undo_link).with('The user "instructor6" has been successfully created. ').and_return(true)
 263  expect(flash[:success]).to eq "A new password has been sent to new user's e-mail address."
 264  expect(response).to redirect_to('http://test.host/users/list')

Test for Task3

 17  describe "View users" do
 18    it "check if instructors show their institutions on the same line as their new feature" do
 19      require 'pp'
 20      driver = Selenium::WebDriver.for :firefox
 21      driver.get("http://localhost:3000/")
 22      driver.find_element(:id, "login_name").send_keys("instructor6")
 23      driver.find_element(:id, "login_password").send_keys("password")
 24      driver.find_element(:name, "commit").click()
 25      driver.get("http://localhost:3000/users/list")
 26
 27      has_institution = false
 28      if driver.find_element(xpath: "/html/body/div[1]/div[1]/div/div/div/div/table/tbody/tr[2]/th[3]").text == "Institution"
 29        has_institution = true
 30        expect(has_institution).to be(true)
 31      end
 32      expect(has_institution).to be(true)
 33    end
 34  end

Process Video

Video Demonstration for Testing Task1: Task1-Video
Video Demonstration for Testing Task2: Task2-Video
Video Demonstration for Testing Task3: Task3-Video

Project Deployment

Expertiza_Team_4430

Team Information

 Team_4430:
 Ruiwen Wu (rwu5@ncsu.edu)
 Yongjian Zhu (yzhu48@ncsu.edu)
 Ling Li (lli46@ncsu.edu)
 Mentor: Carmen Bentley (cnaiken@ncsu.edu)

References

Expertiza on GitHub

Expertiza website

Expertiza project documentation wiki

GitHub Project Repository Fork

Rspec Documentation