Skip to content

Commit

Permalink
Subject is required when student saves the thesis
Browse files Browse the repository at this point in the history
  • Loading branch information
amtuannguyen committed Oct 22, 2024
1 parent 1760822 commit 7899dda
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 13 deletions.
1 change: 1 addition & 0 deletions app/models/thesis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def certify_content_correct_present

has_many :thesis_subjectships, dependent: :delete_all
has_many :loc_subjects, through: :thesis_subjectships
validates_presence_of :loc_subjects, if: :updating_by_student?

belongs_to :assigned_to, foreign_key: 'assigned_to_id', class_name: 'User'
belongs_to :embargoed_by, foreign_key: 'embargoed_by_id', class_name: 'User'
Expand Down
2 changes: 1 addition & 1 deletion app/views/student_view/process/review.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<%= simple_form_for([@current_user, @thesis], url: accept_licences_student_thesis_path(@current_user, @thesis), method: :post, html: { class: "p-0" }) do |f| %>
<% if @thesis.errors.any? %>
<div id="error_explanation" class="p-3 bg-warning-subtle">
<h3><%= pluralize(@thesis.errors.count, "error") %> prohibited this thesis from being saved:</h2>
<h4><%= pluralize(@thesis.errors.count, "error") %></h4>
<ul>
<% @thesis.errors.full_messages.each do |message| %>
<li><%= message %></li>
Expand Down
11 changes: 11 additions & 0 deletions app/views/student_view/process/update.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@
</div>

<%= simple_form_for [@student, @thesis], html: { class: "form-horizontal border border-2 bg-light" } do |f| %>
<% if @thesis.errors.any? %>
<div id="error_explanation" class="p-3 bg-warning-subtle">
<h4><%= pluralize(@thesis.errors.count, "error") %></h4>
<ul>
<% @thesis.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<h4 class="text-dark">Please provide the information requested in the following fields. </h4>
<%= render partial: "theses/form_student_editable", locals: { f: f } %>
<input type="submit" name="Save Details" value="" class="d-none" aria-label="Save Details">
Expand Down
5 changes: 4 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@
# available at http://guides.rubyonrails.org/i18n.html.

en:
hello: "Hello world"
activerecord:
attributes:
thesis:
loc_subjects: "Subject"
2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# rails db:seed
LocSubject.load_from_file('lib/loc_subjects.txt') if (Rails.env != 'test') && LocSubject.all.count.zero?
LocSubject.load_from_file('lib/loc_subjects.txt') if LocSubject.all.count.zero?

if (Rails.env != 'test') && User.all.count.zero?
[User::ADMIN, User::MANAGER, User::STAFF].each do |role|
Expand Down
3 changes: 2 additions & 1 deletion test/controllers/theses_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ class ThesesControllerTest < ActionController::TestCase
context 'as a student' do
setup do
@student = create(:student)
@thesis = create(:thesis, student: @student, status: Thesis::OPEN)
@thesis = create(:thesis, student: @student, status: Thesis::OPEN, loc_subjects: create_list(:loc_subject, 1))

log_user_in(@student)
end

Expand Down
4 changes: 2 additions & 2 deletions test/models/thesis_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ThesisTest < ActiveSupport::TestCase

should 'not validate presence of certify_content_correct if updating by student but not submitting for review' do
student_user = create(:student)
thesis = build(:thesis, current_user: student_user, certify_content_correct: nil)
thesis = build(:thesis, current_user: student_user, certify_content_correct: nil, loc_subjects: create_list(:loc_subject, 1))
assert thesis.valid?, 'Should validate thesis if certify_content_correct is missing for students when not submitting for review'
end

Expand Down Expand Up @@ -68,7 +68,7 @@ class ThesisTest < ActiveSupport::TestCase

should 'not validate presence of licence agreements if updating by student but not accepting licences' do
student_user = create(:student)
thesis = build(:thesis, current_user: student_user, lac_licence_agreement: nil, yorkspace_licence_agreement: nil, etd_licence_agreement: nil)
thesis = build(:thesis, current_user: student_user, lac_licence_agreement: nil, yorkspace_licence_agreement: nil, etd_licence_agreement: nil, loc_subjects: create_list(:loc_subject, 1))
assert thesis.valid?, 'Should validate thesis if licence agreements are missing for students when not accepting licences'
end

Expand Down
6 changes: 6 additions & 0 deletions test/system/app_settings_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class AppSettingsTest < ApplicationSystemTestCase
fill_in 'student_email_external', with: '[email protected]'
click_button('Continue')
fill_in 'thesis_abstract', with: 'Abstract Text Test'
find('#select_subjects_11_chosen a.chosen-default').click
first('#select_subjects_11_chosen .active-result').click
click_link('Continue')
assert_text "Upload Files Text Test"
click_link_or_button('Upload Supplementary Thesis Files')
Expand Down Expand Up @@ -141,6 +143,8 @@ class AppSettingsTest < ApplicationSystemTestCase
fill_in 'student_email_external', with: '[email protected]'
click_button('Continue')
fill_in 'thesis_abstract', with: 'Abstract Text Test'
find('#select_subjects_11_chosen a.chosen-default').click
first('#select_subjects_11_chosen .active-result').click
click_link('Continue')
click_link_or_button('Upload Primary Thesis File')
attach_file('document_file', Rails.root.join('test/fixtures/files/pdf-document.pdf'))
Expand Down Expand Up @@ -175,6 +179,8 @@ class AppSettingsTest < ApplicationSystemTestCase
fill_in 'student_email_external', with: '[email protected]'
click_button('Continue')
fill_in 'thesis_abstract', with: 'Abstract Text Test'
find('#select_subjects_11_chosen a.chosen-default').click
first('#select_subjects_11_chosen .active-result').click
click_link('Continue')
click_link_or_button('Upload Primary Thesis File')
attach_file('document_file', Rails.root.join('test/fixtures/files/pdf-document.pdf'))
Expand Down
15 changes: 8 additions & 7 deletions test/system/students_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class StudentsTest < ApplicationSystemTestCase
visit root_url
fill_in('Non-YorkU Email Address', with: Faker::Internet.email)
click_button('Continue')
find('#select_subjects_11_chosen a.chosen-default').click
first('#select_subjects_11_chosen .active-result').click
click_link('Continue') #update
click_link('Continue') #upload
click_link('Continue') #review
Expand Down Expand Up @@ -226,10 +228,6 @@ class StudentsTest < ApplicationSystemTestCase
## Page 2 and 3 tests
should "upload primary file" do
@thesis = FactoryGirl.create(:thesis)
create(:loc_subject, name: "Accounting", category: "BUSINESS")
create(:loc_subject, name: "Management", category: "BUSINESS")
create(:loc_subject, name: "Finance", category: "BUSINESS")

login_as(@thesis.student)
visit root_url

Expand Down Expand Up @@ -271,6 +269,8 @@ class StudentsTest < ApplicationSystemTestCase
select "Management", from: 'select_subjects_12'
select "Finance", from: 'select_subjects_13'

save_screenshot

fill_in "thesis_keywords", with: "accounting-kw, management-kw"
click_on("Continue")

Expand Down Expand Up @@ -352,9 +352,6 @@ class StudentsTest < ApplicationSystemTestCase
## Supplementary Info displays on edit/error
should "Supplementary Info displays on edit/error" do
@thesis = FactoryGirl.create(:thesis)
create(:loc_subject, name: "Accounting", category: "BUSINESS")
create(:loc_subject, name: "Management", category: "BUSINESS")
create(:loc_subject, name: "Finance", category: "BUSINESS")

login_as(@thesis.student)
visit root_url
Expand All @@ -368,6 +365,10 @@ class StudentsTest < ApplicationSystemTestCase
## Page 2: Thesis Details
select "English", from: "thesis_language"
fill_in "thesis_abstract", with: Faker::Lorem.paragraph

find('#select_subjects_11_chosen a.chosen-default').click
first('#select_subjects_11_chosen .active-result').click

click_on("Continue")

## Page 3: Upload Supplementary
Expand Down
4 changes: 4 additions & 0 deletions test/system/theses_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ class ThesesTest < ApplicationSystemTestCase
click_on("Continue")

fill_in("Abstract", with: "Abstract Test")

find('#select_subjects_11_chosen a.chosen-default').click
first('#select_subjects_11_chosen .active-result').click

click_on("Continue")

click_on("Upload Supplementary Thesis Files")
Expand Down

0 comments on commit 7899dda

Please sign in to comment.