Skip to content

Commit

Permalink
Merge pull request #4567 from portabilis/issue-4469
Browse files Browse the repository at this point in the history
Remove validações não necessárias nas datas de lançamentos do calendário letivo.
  • Loading branch information
AnaPerola authored May 14, 2024
2 parents a47ba79 + adf289d commit 7ec1374
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 60 deletions.
11 changes: 0 additions & 11 deletions app/models/school_calendar_classroom_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class SchoolCalendarClassroomStep < ApplicationRecord
has_many :ieducar_api_exam_postings, dependent: :destroy

validate :start_at_must_be_less_than_end_at
validate :dates_for_posting_less_than_start_date
validate :end_date_less_than_start_date_for_posting

scope :by_school_day, ->(date) { where('? BETWEEN start_at AND end_at', date) }
Expand Down Expand Up @@ -83,16 +82,6 @@ def start_at_must_be_less_than_end_at
errors.add(:start_at, :must_be_less_than_end_at) if start_at.to_date >= end_at.to_date
end

def dates_for_posting_less_than_start_date
return if start_at.blank?

if start_date_for_posting.present? && start_date_for_posting < start_at
errors.add(:start_date_for_posting, :must_be_greater_than_start_at)
elsif end_date_for_posting.present? && end_date_for_posting < start_at
errors.add(:end_date_for_posting, :must_be_greater_than_start_at)
end
end

def end_date_less_than_start_date_for_posting
return if start_date_for_posting.blank? || end_date_for_posting.blank?
return if end_date_for_posting >= start_date_for_posting
Expand Down
11 changes: 0 additions & 11 deletions app/models/school_calendar_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class SchoolCalendarStep < ActiveRecord::Base
validate :start_at_must_not_have_conflicting_date, if: :school_calendar
validate :end_at_must_not_have_conflicting_date, if: :school_calendar
validate :start_at_must_be_less_than_end_at
validate :dates_for_posting_less_than_start_date
validate :end_date_less_than_start_date_for_posting

scope :by_school_calendar_id, ->(school_calendar_id) { where(school_calendar_id: school_calendar_id) }
Expand Down Expand Up @@ -86,16 +85,6 @@ def start_at_must_be_less_than_end_at
errors.add(:start_at, :must_be_less_than_end_at) if start_at.to_date >= end_at.to_date
end

def dates_for_posting_less_than_start_date
return if start_at.blank?

if start_date_for_posting.present? && start_date_for_posting < start_at
errors.add(:start_date_for_posting, :must_be_greater_than_start_at)
elsif end_date_for_posting.present? && end_date_for_posting < start_at
errors.add(:end_date_for_posting, :must_be_greater_than_start_at)
end
end

def end_date_less_than_start_date_for_posting
return if start_date_for_posting.blank? || end_date_for_posting.blank?

Expand Down
3 changes: 0 additions & 3 deletions config/locales/models/school_calendar_classroom_step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,5 @@ pt-BR:
must_be_less_than_end_at: "não pode ser maior ou igual a data final"
end_at:
end_at_must_be_valid: "não pode maior que %{valid_date}"
start_date_for_posting:
must_be_greater_than_start_at: "não pode ser menor que a data inicial"
end_date_for_posting:
must_be_greater_than_start_at: "não pode ser menor que a data inicial"
must_be_greater_than_start_date_for_posting: "não pode ser menor que a data inicial para lançamentos"
3 changes: 0 additions & 3 deletions config/locales/models/school_calendar_step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,5 @@ pt-BR:
end_at:
end_at_must_be_valid: "não pode maior que %{valid_date}"
must_not_have_conflicting_steps: "A data informada não pode ser um dia letivo em outro calendário escolar"
start_date_for_posting:
must_be_greater_than_start_at: "não pode ser menor que a data inicial"
end_date_for_posting:
must_be_greater_than_start_at: "não pode ser menor que a data inicial"
must_be_greater_than_start_date_for_posting: "não pode ser menor que a data inicial para lançamentos"
16 changes: 0 additions & 16 deletions spec/models/school_calendar_classroom_step_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,6 @@
expect(subject.errors.messages[:start_at]).to include('não pode ser maior ou igual a data final')
end

it "validates that start_at is less than start_date_for_posting" do
subject.start_at = "02/01/2020"
subject.start_date_for_posting = "01/01/2020"

expect(subject).to_not be_valid
expect(subject.errors.messages[:start_date_for_posting]).to include("não pode ser menor que a data inicial")
end

it "validates that start_at is less than end_date_for_posting " do
subject.start_at = "02/01/2020"
subject.end_date_for_posting = "01/01/2020"

expect(subject).to_not be_valid
expect(subject.errors.messages[:end_date_for_posting]).to include("não pode ser menor que a data inicial")
end

it "validates that start_date_for_posting is less than end_date_for_posting" do
subject.start_date_for_posting = "02/01/2020"
subject.end_date_for_posting = "01/01/2020"
Expand Down
16 changes: 0 additions & 16 deletions spec/models/school_calendar_step_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,6 @@
expect(subject.errors.messages[:start_at]).to include('não pode ser maior ou igual a data final')
end

it "validates that start_at is less than start_date_for_posting" do
subject.start_at = "02/01/2020"
subject.start_date_for_posting = "01/01/2020"

expect(subject).to_not be_valid
expect(subject.errors.messages[:start_date_for_posting]).to include("não pode ser menor que a data inicial")
end

it "validates that start_at is less than end_date_for_posting " do
subject.start_at = "02/01/2020"
subject.end_date_for_posting = "01/01/2020"

expect(subject).to_not be_valid
expect(subject.errors.messages[:end_date_for_posting]).to include("não pode ser menor que a data inicial")
end

it "validates that start_date_for_posting is less than end_date_for_posting" do
subject.start_date_for_posting = "02/01/2020"
subject.end_date_for_posting = "01/01/2020"
Expand Down

0 comments on commit 7ec1374

Please sign in to comment.