diff --git a/app/helpers/thesis_helper.rb b/app/helpers/thesis_helper.rb index ec2bd6a6..4988800b 100644 --- a/app/helpers/thesis_helper.rb +++ b/app/helpers/thesis_helper.rb @@ -93,8 +93,4 @@ def proquest_status_counts(theses) end result end - - def look_up_degree_period(thesis) - DegreePeriod.find_by(grad_year: thesis.graduation_year, grad_month: thesis.graduation_month) - end end diff --git a/app/models/thesis.rb b/app/models/thesis.rb index 52498db3..ecd64ea7 100644 --- a/app/models/thesis.rb +++ b/app/models/thesis.rb @@ -148,13 +148,17 @@ class Thesis < ApplicationRecord # Looks up the thesis' accession number based on its degree period. def accession_number - degree_period = DegreePeriod.find_by(grad_year: graduation_year, grad_month: graduation_month) + degree_period = look_up_degree_period return if degree_period.nil? return if degree_period.archivematica_accession.nil? degree_period.archivematica_accession.accession_number end + def look_up_degree_period + DegreePeriod.find_by(grad_year: graduation_year, grad_month: graduation_month) + end + # Returns a true/false value (rendered as "yes" or "no") if there are any # holds with a status of either 'active' or 'expired'. A false/"No" is # only returned if all holds are 'released'. diff --git a/app/views/thesis/process_theses.html.erb b/app/views/thesis/process_theses.html.erb index 1c647cf8..d4cc6482 100644 --- a/app/views/thesis/process_theses.html.erb +++ b/app/views/thesis/process_theses.html.erb @@ -53,7 +53,7 @@ label_html: { style: 'width: 50%' }, input_html: { class: 'disabled', style: 'width: 40%', value: f.object.accession_number.present?? 'Yes' : 'No' }, hint_html: { style: 'display: block' }, - hint: (link_to('Create new accession number', new_admin_archivematica_accession_path(degree_period_id: look_up_degree_period(f.object)), target: :_blank) if f.object.accession_number.nil?) %> + hint: (link_to('Create new accession number', new_admin_archivematica_accession_path(degree_period_id: f.object.look_up_degree_period), target: :_blank) if f.object.accession_number.nil?) %>
  • diff --git a/test/helpers/thesis_helper_test.rb b/test/helpers/thesis_helper_test.rb index c388252b..9f5234ca 100644 --- a/test/helpers/thesis_helper_test.rb +++ b/test/helpers/thesis_helper_test.rb @@ -222,28 +222,4 @@ class ThesisHelperTest < ActionView::TestCase assert_equal({ opted_in: 1, opted_out: 1, no_decision: 1, conflict: 1 }, proquest_status_counts([true_thesis, false_thesis, nil_thesis, conflict_thesis])) end - - test 'can look up degree period' do - thesis = theses(:one) - - # Ensure the thesis has a degree period - assert_not_nil DegreePeriod.find_by(grad_year: thesis.graduation_year, grad_month: thesis.graduation_month) - - # Ensure that degree period lookup returns the appropriate record - degree_period = look_up_degree_period(thesis) - assert_equal thesis.graduation_year, degree_period.grad_year - assert_equal thesis.graduation_month, degree_period.grad_month - end - - test 'returns nil on degree period lookup if no degree period exists' do - thesis = theses(:one) - - # Ensure the thesis has no degree period - thesis.graduation_year = '3000' - thesis.save - assert_nil DegreePeriod.find_by(grad_year: thesis.graduation_year, grad_month: thesis.graduation_month) - - # Ensure that degree period lookup also returns nil - assert_nil look_up_degree_period(thesis) - end end diff --git a/test/models/thesis_test.rb b/test/models/thesis_test.rb index 9e148e79..2987dbc5 100644 --- a/test/models/thesis_test.rb +++ b/test/models/thesis_test.rb @@ -1457,6 +1457,30 @@ def attach_file_with_purpose_to(thesis, purpose = 'thesis_pdf') assert t.accession_number.starts_with? t.graduation_year end + test 'can look up degree period' do + thesis = theses(:one) + + # Ensure the thesis has a degree period + assert_not_nil DegreePeriod.find_by(grad_year: thesis.graduation_year, grad_month: thesis.graduation_month) + + # Ensure that degree period lookup returns the appropriate record + degree_period = thesis.look_up_degree_period + assert_equal thesis.graduation_year, degree_period.grad_year + assert_equal thesis.graduation_month, degree_period.grad_month + end + + test 'returns nil on degree period lookup if no degree period exists' do + thesis = theses(:one) + + # Ensure the thesis has no degree period + thesis.graduation_year = '3000' + thesis.save + assert_nil DegreePeriod.find_by(grad_year: thesis.graduation_year, grad_month: thesis.graduation_month) + + # Ensure that degree period lookup also returns nil + assert_nil thesis.look_up_degree_period + end + test 'bachelor theses cannot be put into publication review without accession number' do t = theses(:bachelor) t.save