Skip to content

Commit

Permalink
close #49
Browse files Browse the repository at this point in the history
  • Loading branch information
amtuannguyen committed Jul 19, 2024
2 parents 0fca169 + bc8e15e commit b616177
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 31 deletions.
36 changes: 24 additions & 12 deletions app/controllers/theses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def new
@thesis.exam_date = record.examdate
@thesis.program = record.program
@thesis.assign_degree_name_and_level
@thesis.committee_members = record.committee_members

end

def create
Expand All @@ -53,8 +55,18 @@ def create
@thesis.student = @student
@thesis.audit_comment = 'Starting a new thesis. Status: OPEN.'

@thesis.audit_comment = 'Starting a new thesis. Status: OPEN.'

@thesis.status = Thesis::OPEN
if @thesis.save
if params[:committee_member_ids].present?
params[:committee_member_ids].each do |committee_member_id|
if committee_member_id.present?
committee_member = CommitteeMember.find(committee_member_id)
committee_member.update(thesis: @thesis)
end
end
end
redirect_to [@student, @thesis], notice: 'ETD record successfully created.'
else
render action: 'new'
Expand Down Expand Up @@ -149,10 +161,10 @@ def validate_active_thesis(thesis_id)
def submit_for_review
@thesis = @student.theses.find(params[:id])
@thesis.current_user = current_user

# Temporarily assign the attributes for validation
@thesis.assign_attributes(thesis_params)

if @thesis.valid?(:submit_for_review)
if @thesis.update(thesis_params)
if validate_active_thesis(@thesis.id)
Expand All @@ -178,33 +190,33 @@ def validate_licence_uplaod(thesis_id)
def accept_licences
@thesis = @student.theses.find(params[:id])
@thesis.current_user = current_user

# Temporarily assign the attributes for validation
@thesis.assign_attributes(thesis_params)
@thesis.pretty_inspect

if @thesis.valid?(:accept_licences)

if @thesis.update(thesis_params)

if validate_licence_uplaod(@thesis.id)

redirect_to student_view_thesis_process_path(@thesis, Thesis::PROCESS_SUBMIT), notice: "Updated status to #{Thesis::STATUS_ACTIONS[@thesis.status]}"
else

redirect_to student_view_thesis_process_path(@thesis, Thesis::PROCESS_REVIEW), alert: 'Missing Licence Document. Please upload LAC Licence Signed Doc.'
end
else

error_messages = @thesis.errors.full_messages.join(', ')
redirect_to student_view_thesis_process_path(@thesis, Thesis::PROCESS_REVIEW), alert: "There was an error submitting your thesis: #{error_messages}."
end
else

error_messages = @thesis.errors.full_messages.join(', ')
redirect_to student_view_thesis_process_path(@thesis, Thesis::PROCESS_REVIEW), alert: "There was an error submitting your thesis: #{error_messages}."
end

end

### THESIS ASSIGNMENT TO USERS ###
Expand Down Expand Up @@ -241,7 +253,7 @@ def thesis_params
:keywords, :embargo, :language, :degree_name, :degree_level, :program, :published_date,
:exam_date, :student_id, :committee, :abstract, :assigned_to_id, :assigned_to,
:student_accepted_terms_at, :under_review_at, :accepted_at, :published_at, :returned_at,
:committee_members_attributes, :embargoed, :certify_content_correct, :lac_licence_agreement,
:committee_members_attributes, :embargoed, :certify_content_correct, :lac_licence_agreement,
:yorkspace_licence_agreement, :etd_licence_agreement,
committee_members_attributes: %i[first_name last_name role id _destroy],
loc_subject_ids: [])
Expand Down
13 changes: 10 additions & 3 deletions app/views/committee_members/_committee_member.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@
<div class="col"><span class="fw-bold"><%= committee_member.name %></span></div>
<div class="col"><%= committee_member.role %></div>
<div class="col-1">
<% if can?(:destroy, committee_member) && @thesis.status != Thesis::PUBLISHED %>
<%= link_to student_thesis_committee_member_path(@student, @thesis, committee_member),
method: :delete, class: "btn btn-close pull-right", remote: true, data: { confirm: "Are you sure?" } do %>&nbsp;<% end %>
<% if @thesis.id && %>
<% if can?(:destroy, committee_member) && @thesis.status != Thesis::PUBLISHED %>
<%= link_to student_thesis_committee_member_path(@student, @thesis, committee_member),
method: :delete, class: "btn btn-close pull-right", remote: true, data: { confirm: "Are you sure?" } do %>&nbsp;<% end %>
<% end %>
<% else %>
<%= hidden_field_tag "committee_member_ids[]", committee_member.id %>
<a href="#" class="btn btn-close pull-right" onclick="this.closest('.row').remove(); return false;" data-confirm="Are you sure?" rel="nofollow" data-remote="true">
&nbsp;
</a>
<% end %>
</div>
</div>
6 changes: 6 additions & 0 deletions app/views/gem_records/_gem_record.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
<p><%= gem_record.eventtype%></p>
<h6>Program</h6>
<p><%= gem_record.program %></p>
<h6>Committee Members</h6>
<% gem_record.committee_members.each do |committee_member| %>
<div class="row" id="committee_member_<%= committee_member.id %>">
<div class="col"><%= committee_member.name %> - <%= committee_member.role %></div>
</div>
<% end %>
</div>
<div class="col-4">
<h6>Event date</h6>
Expand Down
17 changes: 11 additions & 6 deletions lib/tasks/gem_records_csv.rake
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ namespace :gem_records_csv do
desc 'Loading Gem Records.'
# Usage: cat /file/with/gem_records.txt | rake gem_records:load

task :load, [:filename] => :environment do |t, args|
filename = args[:filename]
if filename.nil? || filename.empty?
puts "Error: Filename is required"
task :load, [:gem_record_file, :commitee_member_file] => :environment do |t, args|
gem_record_filename = Rails.root.join(args[:gem_record_file])
commitee_member_file = Rails.root.join(args[:commitee_member_file])
if gem_record_filename.nil? || gem_record_filename.empty?
puts "Error: Gem Record Filename is required"
exit 1
end
GemRecord.delete_all
#GemRecord.delete_all
gem_load = LoadGemRecordsCSV.new
gem_load.load_csv(filename)
gem_load.load_gem_records(gem_record_filename)
if !commitee_member_file.nil? || !commitee_member_file.empty?
gem_load.load_committee_members(commitee_member_file)
end

end
end
15 changes: 15 additions & 0 deletions test/controllers/gem_records_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,19 @@ class GemRecordsControllerTest < ActionController::TestCase

assert_template 'index', 'Index template should be displayed'
end

should 'committee members included in gem records' do
gem_records = create_list(:gem_record, 5, eventtype: GemRecord::PHD_EXAM)
gem_records.each do |record|
create_list(:committee_member, 2, gem_record: record)
end

get :index, params: { all: true }

records = assigns(:gem_records)

records.each do |record|
assert record.committee_members.count >= 1, 'Each gem record should have at least one committee member'
end
end
end
13 changes: 9 additions & 4 deletions test/controllers/theses_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ class ThesesControllerTest < ActionController::TestCase
thesis = assigns(:thesis)
assert thesis, 'ensure that thesis is assigned'

assert_equal record.committee_members.count, thesis.committee_members.count, 'Number of committee members should match'
record.committee_members.each do |record_member|
thesis_member = thesis.committee_members.find { |tm| tm.first_name == record_member.first_name && tm.last_name == record_member.last_name && tm.role == record_member.role }
assert thesis_member, "Committee member #{record_member.first_name} #{record_member.last_name} should be present in the thesis"
end
assert_equal record.title, thesis.title, 'Title should be prepopulated'
assert_equal record.examdate.beginning_of_day, thesis.exam_date.beginning_of_day,
'Exam date is prepopulate with event date'
Expand Down Expand Up @@ -421,12 +426,12 @@ class ThesesControllerTest < ActionController::TestCase
@thesis.update(certify_content_correct: false)

post :submit_for_review, params: { id: @thesis.id, student_id: @student.id, thesis: { certify_content_correct: false } }

assigns(:thesis)
assert_response :redirect
assert_redirected_to student_view_thesis_process_path(@thesis, Thesis::PROCESS_SUBMIT)
assert_equal "There was an error submitting your thesis: Certify content correct can't be blank.", flash[:alert]

end

## LICENCE UPLOAD CHECK
Expand All @@ -435,8 +440,8 @@ class ThesesControllerTest < ActionController::TestCase
patch :accept_licences, params: { student_id: @student.id, id: @thesis.id, thesis: { lac_licence_agreement: true, yorkspace_licence_agreement: true, etd_licence_agreement: true } }
assert_redirected_to student_view_thesis_process_path(@thesis, Thesis::PROCESS_REVIEW)
assert_equal 'Missing Licence Document. Please upload LAC Licence Signed Doc.', flash[:alert]
end
end

should "should accept licences with a licence document" do
# thesis = create(:thesis, student: @student)
# create(:document, thesis: @thesis, user: @student, usage: 'licence', supplemental: true, deleted: false)
Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/files/gem_records.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
seqgradevent,studentname,sisid,emailaddress,eventtype,eventdate,examresult,title,program,superv,examdate
1,John Doe,123456,[email protected],Exam,2023-06-15,Pass,Thesis Title,Program A,Supervisor X,2023-07-01
2,Jane Smith,654321,[email protected],Defense,2023-06-20,Pass,Thesis Title B,Program B,Supervisor Y,2023-07-02
3,Alice Johnson,789012,[email protected],Exam,2023-06-25,Fail,Thesis Title C,Program C,Supervisor Z,2023-07-03
1,John Doe,123456789,[email protected],Exam,2023-06-15,Pass,Thesis Title,Program A,Supervisor X,2023-07-01
2,Jane Smith,654321476,[email protected],Defense,2023-06-20,Pass,Thesis Title B,Program B,Supervisor Y,2023-07-02
3,Alice Johnson,789012185,[email protected],Exam,2023-06-25,Fail,Thesis Title C,Program C,Supervisor Z,2023-07-03
6 changes: 3 additions & 3 deletions test/lib/load_gem_records_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ class LoadGemRecordsTest < ActiveSupport::TestCase

assert_equal 1, records[0].seqgradevent
assert_equal 'John Doe', records[0].studentname
assert_equal 123456, records[0].sisid
assert_equal 123456789, records[0].sisid
assert_equal '[email protected]', records[0].emailaddress

assert_equal 2, records[1].seqgradevent
assert_equal 'Jane Smith', records[1].studentname
assert_equal 654321, records[1].sisid
assert_equal 654321476, records[1].sisid
assert_equal '[email protected]', records[1].emailaddress

assert_equal 3, records[2].seqgradevent
assert_equal 'Alice Johnson', records[2].studentname
assert_equal 789012, records[2].sisid
assert_equal 789012185, records[2].sisid
assert_equal '[email protected]', records[2].emailaddress

assert_equal 2, records[0].committee_members.count
Expand Down
14 changes: 14 additions & 0 deletions test/system/students_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ class StudentsTest < ApplicationSystemTestCase
click_link('Start this thesis')
end

test 'Gem Record has committee members' do
visit root_url
click_link('Gem Records')
click_link(@gem_record.studentname)

assert_selector "h6", text: "Committee Members"
if @gem_record.committee_members.count > 1
@gem_record.committee_members.each do |committee_member|
assert_selector "p", text: committee_member.full_name
end
end

end

test 'Log in as Student and add a thesis' do
@thesis = FactoryGirl.create(:thesis)
login_as(@thesis.student)
Expand Down

0 comments on commit b616177

Please sign in to comment.