Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5611190
ISSUE #286: Create the functionality that cancels the class_enrollments
SAASVUUV Jun 6, 2025
f0bb9bd
ISSUE #286: Add some errors when tries to create a class_enrollment. …
SAASVUUV Jun 6, 2025
d0abd17
ISSUE #286: Modify the locales
SAASVUUV Jun 6, 2025
0448632
ISSUE #286: Adjust the specs
SAASVUUV Jun 6, 2025
c823107
ISSUE #286: fix the occurrency of function to cancel enrollment class…
SAASVUUV Jun 18, 2025
045b278
Merge branch 'main' into issue_286
SAASVUUV Jul 30, 2025
c92a9a0
Merge branch 'develop' into issue_286
SAASVUUV Jul 30, 2025
f3dd533
Merge branch 'main' into issue_286
SAASVUUV Aug 7, 2025
e631869
Fix enrollment_factory for tests
SAASVUUV Aug 7, 2025
50dc999
Adding wait for ajax to fix tests
leomurta Aug 7, 2025
bafc588
Waiting for ajax in every link click
leomurta Aug 7, 2025
46e865e
ISSUE #286: Add the function hold_in_date to verify enrollment_holds …
SAASVUUV Aug 22, 2025
56c3bd4
ISSUE #286: Create the function to verify holds in determinated dates…
SAASVUUV Aug 22, 2025
80b2b3c
ISSUE #286: Fix the spec due to the new additions
SAASVUUV Aug 22, 2025
1a991b6
Merge branch 'main' into issue_286
SAASVUUV Aug 22, 2025
0d55603
Merge branch 'develop' into issue_286
JoaoFelipe Aug 23, 2025
4c73b8c
ISSUE #286: Fix class_enroll message, preventing access to class_enro…
SAASVUUV Aug 25, 2025
5ab944e
ISSUE #286: Detailing error in admin's class_enrollment_request screen
SAASVUUV Aug 25, 2025
45069cb
Merge branch 'main' into issue_286
SAASVUUV Aug 25, 2025
a00222c
Fix the research_line view
SAASVUUV Oct 17, 2025
60f614e
ISSUE #584: Testing nem approach for tests, using have_select
SAASVUUV Oct 21, 2025
990b650
ISSUE #584: fix the timeout, aiming to reduce errors related to downl…
SAASVUUV Oct 21, 2025
68015c4
ISSUE #584: Fix download in specs
SAASVUUV Oct 24, 2025
a8a143f
Merge pull request #585 from gems-uff/issue_584
leomurta Nov 14, 2025
e689000
Fix scholarship_duration test issue
SAASVUUV Nov 14, 2025
e0e6f66
Merge branch 'main' into issue_286
SAASVUUV Nov 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/assets/stylesheets/custom/student_enrollment.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
border-color: rgb(1, 104, 1);
}

.background-held{
background-color: #b188b8;
border-color: purple;
}

.show-box summary {
margin-top: 0;
margin-bottom: 10px;
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/class_enrollment_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ def set_status(status, message)
yield record if block_given?
flash[:info] = I18n.t(message, count: 1)
else
flash[:error] = I18n.t(message, count: 0)
flash[:info] = (I18n.t(message, count: 0))
flash[:error] = record.errors.full_messages
end
end
end
Expand Down
1 change: 1 addition & 0 deletions app/controllers/research_lines_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ResearchLinesController < ApplicationController
config.columns = [:name, :research_area, :professor_research_lines, :available]
config.columns[:research_area].form_ui = :record_select
config.list.columns = [:name, :research_area, :available]
config.show.columns = [:name, :research_area, :professors, :courses, :available]

config.actions.exclude :deleted_records
end
Expand Down
7 changes: 7 additions & 0 deletions app/models/class_enrollment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ClassEnrollment < ApplicationRecord
validate :check_multiple_class_enrollment_allowed
validate :professor_changed_only_valid_fields,
if: -> { can?(:post_grades, self) && cannot?(:update_all_fields, self) }
validate :check_enrollment_hold

after_save :notify_student_and_advisor
after_save :class_enrollment_request_cascade
Expand Down Expand Up @@ -129,6 +130,12 @@ def should_send_email_to_professor?
)
end

def check_enrollment_hold
if self.course_class && EnrollmentHold.hold_in_date(enrollment, self.course_class.start_date, self.course_class.end_date)
errors.add(:enrollment, :enrollment_is_held)
end
end

private
def grade_for_situation
if course_has_grade
Expand Down
7 changes: 7 additions & 0 deletions app/models/class_enrollment_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class ClassEnrollmentRequest < ApplicationRecord
if: -> { !student_saving && !marked_for_destruction? }
validate :that_course_class_does_not_exist_in_a_class_enrollment,
if: -> { !marked_for_destruction? }
validate :check_enrollment_hold

before_validation :create_or_destroy_class_enrollment, on: %i[create update]
after_save :destroy_or_create_class_enrollment
Expand Down Expand Up @@ -126,6 +127,12 @@ def remove_not_effected?
self.status != ClassEnrollmentRequest::EFFECTED
end

def check_enrollment_hold
if self.course_class && EnrollmentHold.hold_in_date(enrollment, self.course_class.start_date, self.course_class.end_date)
errors.add(:enrollment, :enrollment_is_held)
end
end

protected
def that_class_enrollment_matches_course_and_enrollment
ce = self.class_enrollment
Expand Down
10 changes: 10 additions & 0 deletions app/models/course_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ def label_with_course
"#{self.course.name}#{name_l} - #{year}/#{semester}"
end

def start_date
ys = YearSemester.new(year: year, semester: semester)
ys.semester_begin
end

def end_date
ys = YearSemester.new(year: year, semester: semester)
ys.semester_end
end

def class_enrollments_count
self.class_enrollments.count
end
Expand Down
22 changes: 22 additions & 0 deletions app/models/enrollment_hold.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class EnrollmentHold < ApplicationRecord

validate :validate_dates

validate :verify_class_enrollments

after_commit :create_phase_completions

def to_label
Expand Down Expand Up @@ -61,4 +63,24 @@ def end_date
def create_phase_completions
enrollment.create_phase_completions
end

def verify_class_enrollments
class_enrollments = ClassEnrollment.where(enrollment: self.enrollment)
class_enrollments.each do |class_enrollment|
course_class = class_enrollment.course_class
unless course_class.end_date < self.start_date || course_class.start_date > self.end_date
errors.add(:base, :class_enrollments_exist)
end
end
end

def self.hold_in_date(enrollment, course_start, course_end)
enrollment_holds = EnrollmentHold.where(enrollment: enrollment)
unless enrollment_holds.empty?
enrollment_holds.each do |hold|
return true unless course_end < hold.start_date || course_start > hold.end_date
end
end
false
end
end
43 changes: 26 additions & 17 deletions app/views/student_enrollment/_show_enroll.html.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
<div class="enrollment-show-box show-box <%= "background-#{enrollment_request.persisted? ? ClassEnrollmentRequest::STATUSES_MAP[enrollment_request.status] : 'not-persisted'}"%>">
<h3>
<% if semester.main_enroll_open? %>
<%= t "student_enrollment.show_enroll.title_main", semester: semester.to_label %>
<% is_held = EnrollmentHold.hold_in_date(@enrollment, semester.period_start, semester.period_end)%>
<% unless is_held%>
<div class="enrollment-show-box show-box <%= "background-#{enrollment_request.persisted? ? ClassEnrollmentRequest::STATUSES_MAP[enrollment_request.status] : 'not-persisted'}"%>">
<% else %>
<div class="enrollment-show-box show-box background-held">
<% end %>
<h3>
<% if semester.main_enroll_open? %>
<%= t "student_enrollment.show_enroll.title_main", semester: semester.to_label %>
<% else %>
<%= t "student_enrollment.show_enroll.title_adjust", semester: semester.to_label %>
<% end %>
</h3>
<% unless is_held%>
<% linkpath = student_enroll_path(id: @enrollment.id, year: semester.year, semester: semester.semester) %>
<% if enrollment_request.persisted? %>
<% unread = enrollment_request.student_unread_messages %>
<%= link_to t("student_enrollment.show_enroll.enroll_link_edit_#{ClassEnrollmentRequest::STATUSES_MAP[enrollment_request.status]}"), linkpath %>
<% if unread > 0 %>
<%= t("student_enrollment.show_enroll.unread", count: unread) %>
<% end %>
<% else %>
<%= link_to t("student_enrollment.show_enroll.enroll_link_new"), linkpath %>
<% end %>
<% else %>
<%= t "student_enrollment.show_enroll.title_adjust", semester: semester.to_label %>
<p><%= t "student_enrollment.show_enroll.enrollment_is_held" %></p>
<% end %>
</h3>
<% linkpath = student_enroll_path(id: @enrollment.id, year: semester.year, semester: semester.semester) %>
<% if enrollment_request.persisted? %>
<% unread = enrollment_request.student_unread_messages %>
<%= link_to t("student_enrollment.show_enroll.enroll_link_edit_#{ClassEnrollmentRequest::STATUSES_MAP[enrollment_request.status]}"), linkpath %>
<% if unread > 0 %>
<%= t("student_enrollment.show_enroll.unread", count: unread) %>
<% end %>
<% else %>
<%= link_to t("student_enrollment.show_enroll.enroll_link_new"), linkpath %>
<% end %>
</div>
</div>
2 changes: 2 additions & 0 deletions config/locales/class_enrollment.pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pt-BR:
student: "Aluno"
enrollment_level: "Nível"
enrollment_status: "Tipo de Matrícula"
enrollment_hold: "Matrícula Trancada"
admission_date: "Data de Admissão"
scholarship_durations_active: "Possui bolsa?"
advisor: "Orientador"
Expand All @@ -51,6 +52,7 @@ pt-BR:
grade_gt_100: "deve ser menor ou igual a 10.0"
grade_lt_0: "deve ser maior ou igual a 0.0"
changes_to_disallowed_fields: "houve modificação de campos não válidos"
enrollment_is_held: "está trancada no período da turma"

models:
class_enrollment:
Expand Down
3 changes: 3 additions & 0 deletions config/locales/class_enrollment_request.pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pt-BR:
remove: "Remoção"
class_enrollment_requests:
course_class: Turma
enrollment: Matrícula

errors:
models:
Expand All @@ -43,6 +44,8 @@ pt-BR:
course_class:
previously_approved: "já foi cursada anteriormente com aprovação"
taken: "duplicada"
enrollment:
enrollment_is_held: "está trancada no período"

models:
class_enrollment_request:
Expand Down
1 change: 1 addition & 0 deletions config/locales/enrollment_hold.pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pt-BR:
enrollment_hold:
before_admission_date: "anterior a Data de Admissão"
after_dismissal_date: "posterior a Data de Desligamento"
class_enrollments_exist: "existem inscrições no período trancado"

models:
enrollment_hold:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/research_line.pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pt-BR:
activerecord:
attributes:
research_line:
code: "Código"
courses: "Disciplinas"
name: "Nome"
research_area: "Área de Pesquisa"
professor_research_lines: "Professores"
Expand Down
1 change: 1 addition & 0 deletions config/locales/student_enrollment.pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pt-BR:
show_enroll:
title_main: Inscrições em disciplinas do semestre %{semester} estão abertas!
title_adjust: Período de ajustes do semestre %{semester} está aberto!
enrollment_is_held: Sua matrícula está trancada. Entre em contato com a secretaria caso queira destrancar para esta inscrição.
enroll_link_new: Clique aqui para fazer um pedido de inscrição.
enroll_link_edit_valid: Seu pedido de inscrição foi marcado como válido. Clique aqui para editar
enroll_link_edit_requested: Clique aqui para editar seu pedido de inscrição.
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/factory_enrollment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
sequence :enrollment_number do |number|
"M#{number}"
end
admission_date { 5.days.ago.to_date }
admission_date { 10.days.ago.to_date }
end
end
10 changes: 8 additions & 2 deletions spec/features/enrollments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,15 @@

it "should update research_line columns when research_area is chosen" do
within("#as_#{plural_name}-create--form") do
expect(page.all("select#record_research_line_ option").map(&:text)).to eq ["Selecione uma opção", "Machine Learning", "Versionamento"]
expect(page).to have_select(
"record_research_line_",
options: ["Selecione uma opção", "Machine Learning", "Versionamento"]
)
find(:select, "record_research_area_").find(:option, text: @research_area1.name).select_option
expect(page.all("select#record_research_line_ option").map(&:text)).to eq ["Selecione uma opção", "Machine Learning"]
expect(page).to have_select(
"record_research_line_",
options: ["Selecione uma opção", "Machine Learning"]
)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/features/scholarship_durations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
start_month = I18n.l(2.months.ago, format: "%B")
find(:select, "suspended_start_month").find(:option, text: start_month).select_option

end_year = 0.years.ago.year
end_year = 1.year.from_now.year
find(:select, "suspended_end_year").find(:option, text: end_year.to_s).select_option

end_month = I18n.l(2.months.from_now, format: "%B")
Expand Down
16 changes: 8 additions & 8 deletions spec/features/student_enrollment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@
@destroy_all << @enrollment3 = FactoryBot.create(:enrollment, enrollment_number: "D01", student: @student1, level: @level1, enrollment_status: @enrollment_status1)
@destroy_all << @enrollment4 = FactoryBot.create(:enrollment, enrollment_number: "D02", student: @student1, level: @level1, enrollment_status: @enrollment_status1)

@destroy_all << @course_class1 = FactoryBot.create(:course_class, name: "Algebra", course: @course1, professor: @professor1, year: 2022, semester: 1)
@destroy_all << @course_class2 = FactoryBot.create(:course_class, name: "Algebra", course: @course1, professor: @professor1, year: 2022, semester: 2)
@destroy_all << @course_class3 = FactoryBot.create(:course_class, name: "Algebra", course: @course2, professor: @professor1, year: 2021, semester: 1)
@destroy_all << @course_class4 = FactoryBot.create(:course_class, name: "Versionamento", course: @course3, professor: @professor2, year: 2022, semester: 2)
@destroy_all << @course_class5 = FactoryBot.create(:course_class, name: "Defesa", course: @course4, professor: @professor3, year: 2022, semester: 2)
@destroy_all << @course_class6 = FactoryBot.create(:course_class, name: "Mineração de Repositórios", course: @course5, professor: @professor2, year: 2022, semester: 2)
@destroy_all << @course_class7 = FactoryBot.create(:course_class, name: "Pesquisa", course: @course6, professor: @professor3, year: 2022, semester: 2)
@destroy_all << @course_class8 = FactoryBot.create(:course_class, name: "Programação", course: @course7, professor: @professor1, year: 2022, semester: 2)
@destroy_all << @course_class1 = FactoryBot.create(:course_class, name: "Algebra", course: @course1, professor: @professor1, year: 3.years.ago.year, semester: 1)
@destroy_all << @course_class2 = FactoryBot.create(:course_class, name: "Algebra", course: @course1, professor: @professor1, year: 3.years.ago.year, semester: 2)
@destroy_all << @course_class3 = FactoryBot.create(:course_class, name: "Algebra", course: @course2, professor: @professor1, year: 4.years.ago.year, semester: 1)
@destroy_all << @course_class4 = FactoryBot.create(:course_class, name: "Versionamento", course: @course3, professor: @professor2, year: 3.years.ago.year, semester: 2)
@destroy_all << @course_class5 = FactoryBot.create(:course_class, name: "Defesa", course: @course4, professor: @professor3, year: 3.years.ago.year, semester: 2)
@destroy_all << @course_class6 = FactoryBot.create(:course_class, name: "Mineração de Repositórios", course: @course5, professor: @professor2, year: 3.years.ago.year, semester: 2)
@destroy_all << @course_class7 = FactoryBot.create(:course_class, name: "Pesquisa", course: @course6, professor: @professor3, year: 3.years.ago.year, semester: 2)
@destroy_all << @course_class8 = FactoryBot.create(:course_class, name: "Programação", course: @course7, professor: @professor1, year: 3.years.ago.year, semester: 2)

@destroy_all << FactoryBot.create(:allocation, course_class: @course_class2, day: "Segunda", start_time: 11, end_time: 13)
@destroy_all << FactoryBot.create(:allocation, course_class: @course_class2, day: "Segunda", start_time: 14, end_time: 16)
Expand Down
12 changes: 12 additions & 0 deletions spec/models/class_enrollment_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ def prepare_course_class(allocations, to_destroy, attributes = {})
:must_represent_the_same_enrollment_and_class).on :class_enrollment
end
end
context "should have error enrollment_is_held when" do
it "enrollment has an enrollment hold conflicting the date of course_class" do
@destroy_later << e = FactoryBot.create(:enrollment, admission_date: 3.years.ago.at_beginning_of_month.to_date)
@destroy_later << cc = FactoryBot.create(:course_class, year: 1.year.ago.year, semester: 1)
@destroy_later << FactoryBot.create(:enrollment_hold, enrollment: e,
year: 2.years.ago.year, number_of_semesters: 4)
@destroy_later << cer = FactoryBot.create(:enrollment_request, enrollment: e)
class_enrollment_request.enrollment_request = cer
class_enrollment_request.course_class = cc
expect(class_enrollment_request).to have_error(:enrollment_is_held).on :enrollment
end
end
end
end
describe "Methods" do
Expand Down
11 changes: 11 additions & 0 deletions spec/models/class_enrollment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@
expect(class_enrollment).to have_error(:disapproved_by_absence_for_situation_aproved).on :disapproved_by_absence
end
end
context "should have error enrollment_is_held when" do
it "enrollment has an enrollment hold conflicting the date of course_class" do
@destroy_later << e = FactoryBot.create(:enrollment, admission_date: 3.years.ago.at_beginning_of_month.to_date)
@destroy_later << cc = FactoryBot.create(:course_class, year: 1.year.ago.year, semester: 1)
@destroy_later << FactoryBot.create(:enrollment_hold, enrollment: e,
year: 2.years.ago.year, number_of_semesters: 4)
class_enrollment.enrollment = e
class_enrollment.course_class = cc
expect(class_enrollment).to have_error(:enrollment_is_held).on :enrollment
end
end
end
end
describe "Methods" do
Expand Down
11 changes: 11 additions & 0 deletions spec/models/enrollment_hold_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@
enrollment_hold.number_of_semesters = 20
expect(enrollment_hold).to have_error(:after_dismissal_date).on :base
end

it "exist class enrollment in enrollment hold period" do
@destroy_later << e = FactoryBot.create(:enrollment)
@destroy_later << cc = FactoryBot.create(:course_class, year: e.admission_date.year + 2)
@destroy_later << FactoryBot.create(:class_enrollment, enrollment: e, course_class: cc)
enrollment_hold.enrollment = e
enrollment_hold.year = e.admission_date.year + 1
enrollment_hold.semester = 2
enrollment_hold.number_of_semesters = 6
expect(enrollment_hold).to have_error(:class_enrollments_exist).on :base
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/support/download_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# frozen_string_literal: true

module DownloadHelpers
TIMEOUT = 1
TIMEOUT = 5
PATH = Rails.root.join("tmp/test_downloads")

extend self
Expand Down Expand Up @@ -31,7 +31,7 @@ def downloaded?
end

def downloading?
downloads.grep(/\.part$/).any?
downloads.any? { |f| f.end_with?(".part", ".crdownload") }
end

def clear_downloads
Expand Down
Loading