Skip to content

Commit

Permalink
Move method from thesis helper to model
Browse files Browse the repository at this point in the history
  • Loading branch information
jazairi committed Sep 18, 2023
1 parent 4490a65 commit fa8f877
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
4 changes: 0 additions & 4 deletions app/helpers/thesis_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion app/models/thesis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
Expand Down
2 changes: 1 addition & 1 deletion app/views/thesis/process_theses.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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?) %>
</li>
<li>
<fieldset>
Expand Down
24 changes: 0 additions & 24 deletions test/helpers/thesis_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 24 additions & 0 deletions test/models/thesis_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fa8f877

Please sign in to comment.