From 34398f459ede9f9f2fbef368baaf914622276811 Mon Sep 17 00:00:00 2001 From: dennis Date: Mon, 22 Jul 2024 17:10:49 -0400 Subject: [PATCH] first commit --- app/controllers/theses_controller.rb | 9 ++++++-- app/models/thesis.rb | 1 + test/system/students_test.rb | 34 ++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/app/controllers/theses_controller.rb b/app/controllers/theses_controller.rb index 8bd6871..9125d5b 100644 --- a/app/controllers/theses_controller.rb +++ b/app/controllers/theses_controller.rb @@ -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| diff --git a/app/models/thesis.rb b/app/models/thesis.rb index 97ba70b..d809181 100644 --- a/app/models/thesis.rb +++ b/app/models/thesis.rb @@ -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 ###### diff --git a/test/system/students_test.rb b/test/system/students_test.rb index dd66210..9709599 100644 --- a/test/system/students_test.rb +++ b/test/system/students_test.rb @@ -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)