Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis committed Jul 22, 2024
1 parent a7218e4 commit 34398f4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/controllers/theses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,14 @@ 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.exists?(title: @thesis.title, student: @student, degree_name: @thesis.degree_name, degree_level: @thesis.degree_level)
flash[:alert] = 'You cannot save the same thesis.'
render action: 'new'
return
end

if @thesis.save
if params[:committee_member_ids].present?
params[:committee_member_ids].each do |committee_member_id|
Expand Down
1 change: 1 addition & 0 deletions app/models/thesis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Thesis < ApplicationRecord

validates :published_date, timeliness: { allow_blank: true }
validates :exam_date, timeliness: { type: :date }
validates :title, uniqueness: { scope: [:student_id, :degree_name, :degree_level]}

##### RELATIONS ######

Expand Down
34 changes: 34 additions & 0 deletions test/system/students_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,40 @@ class StudentsTest < ApplicationSystemTestCase
assert_selector "p", text: "#{@thesis.student.email}", visible: :all
end


test 'Creating a thesis, pressing back and attempting to save again' do
visit root_url
click_link('Gem Records')
click_link(@gem_record.studentname)
click_link('Create ETD Student Record')
page.accept_alert
click_link('Start this thesis')
select "EMBA", from: "thesis_degree_name"
select "Master's", from: "thesis_degree_level"
click_button('Create Thesis')
page.go_back
click_button('Create Thesis')
visit root_url

thesis_elements = all('a')

thesis_titles = thesis_elements.map(&:text)

# Use a set to track seen titles and duplicates
seen_titles = Set.new
duplicates = []

thesis_titles.each do |title|
if seen_titles.include?(title)
duplicates << title
else
seen_titles.add(title)
end
end

assert_empty duplicates, "Duplicate thesis titles found: #{duplicates.join(', ')}"
end

should "display full name instead of first, middle and last name" do
@thesis = FactoryGirl.create(:thesis)
login_as(@thesis.student)
Expand Down

0 comments on commit 34398f4

Please sign in to comment.