From b275840a815bb98d7807446ce52ac76e222b874e Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Cabral da Cunha Date: Thu, 23 May 2019 14:11:41 -0300 Subject: [PATCH 1/9] #289 updating ruby from ~> 2.4.0 to ~>2.6.3 --- Gemfile | 3 ++- Gemfile.lock | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index a742d7a7..c072fc04 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,8 @@ source 'https://rubygems.org' # The following line is necessary to allow RVM choosing the correct ruby version. RVM 2.0 will probably be able to interpret the "~>" symbol and we will be able to safely remove the "#ruby=2.4" line. #ruby=2.4 -ruby '~> 2.4.0' +ruby '~>2.6.3' +gem 'irb', require: false #necessario a partir do ruby 2.6.0, para que o rake funcione com o irb # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '5.1.6.2' diff --git a/Gemfile.lock b/Gemfile.lock index 47519405..259a09e1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -133,6 +133,7 @@ GEM i18n (1.6.0) concurrent-ruby (~> 1.0) ice_nine (0.11.2) + irb (1.0.0) jbuilder (2.7.0) activesupport (>= 4.2.0) multi_json (>= 1.2) @@ -330,6 +331,7 @@ DEPENDENCIES factory_girl_rails ffi (>= 1.9.24) font-awesome-rails + irb jbuilder jquery-rails (>= 4.0.4) jquery-ui-rails @@ -365,7 +367,7 @@ DEPENDENCIES webrick RUBY VERSION - ruby 2.4.1p111 + ruby 2.6.3p62 BUNDLED WITH 1.16.0 From 5b2d203ec17f40e923f15d8814614cfdd3724b4e Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Cabral da Cunha Date: Fri, 24 May 2019 10:37:54 -0300 Subject: [PATCH 2/9] #289 changing line #ruby=2.4 to #ruby=2.6 to avoid RVM incompatibility --- Gemfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index c072fc04..3d6a8580 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' -# The following line is necessary to allow RVM choosing the correct ruby version. RVM 2.0 will probably be able to interpret the "~>" symbol and we will be able to safely remove the "#ruby=2.4" line. -#ruby=2.4 +# The following line is necessary to allow RVM choosing the correct ruby version. RVM 2.0 will probably be able to interpret the "~>" symbol and we will be able to safely remove the "#ruby=2.6" line. +#ruby=2.6 ruby '~>2.6.3' gem 'irb', require: false #necessario a partir do ruby 2.6.0, para que o rake funcione com o irb From 28a04944ce85e78dae34d82d51356fe904ad5a0a Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Cabral da Cunha Date: Fri, 24 May 2019 11:50:08 -0300 Subject: [PATCH 3/9] #293 adding one test to spec of scholarship_duration to validate cancel_date --- spec/models/scholarship_duration_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/models/scholarship_duration_spec.rb b/spec/models/scholarship_duration_spec.rb index d57d5589..e7b1d22a 100644 --- a/spec/models/scholarship_duration_spec.rb +++ b/spec/models/scholarship_duration_spec.rb @@ -63,6 +63,20 @@ end end end + describe "end_date" do + context "is valid and greater than scholarship.end_date" do + it "there must be a cancel_date less than or equal scholarship.end_date" do + enrollment = FactoryGirl.create(:enrollment) + scholarship = FactoryGirl.create(:scholarship, :start_date => start_date, :end_date => end_date) + scholarship_duration.enrollment = enrollment + scholarship_duration.scholarship = scholarship + scholarship_duration.start_date = scholarship.start_date + scholarship_duration.end_date = scholarship.end_date + 1.day + scholarship_duration.cancel_date = scholarship.end_date + scholarship_duration.should have(0).errors_on :end_date + end + end + end describe "if_scholarship_is_not_with_another_student" do context "should return the expected error when" do it "has an old scholarship that ends after the new scholarship starts" do From 6cc6b8e0f4abff438c1b00eed5732f49cb92fe87 Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Cabral da Cunha Date: Fri, 24 May 2019 18:36:54 -0300 Subject: [PATCH 4/9] #293 fixing cancel_date validation in scholarship_duration model and adding warning message --- app/models/scholarship_duration.rb | 5 +++-- config/locales/pt-BR.yml | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/scholarship_duration.rb b/app/models/scholarship_duration.rb index 54503932..638e4d1e 100644 --- a/app/models/scholarship_duration.rb +++ b/app/models/scholarship_duration.rb @@ -25,10 +25,11 @@ class ScholarshipDuration < ApplicationRecord validates_date :start_date, :on_or_after => :scholarship_start_date, :on_or_after_message => I18n.t("activerecord.errors.models.scholarship_duration.start_date_before_scholarship_start_date") validates_date :start_date, :on_or_before => :scholarship_end_date, :on_or_before_message => I18n.t("activerecord.errors.models.scholarship_duration.start_date_after_scholarship_end_date") validates_date :end_date, :on_or_after => :scholarship_start_date, :on_or_after_message => I18n.t("activerecord.errors.models.scholarship_duration.end_date_before_scholarship_start_date") - validates_date :end_date, :on_or_before => :scholarship_end_date, :on_or_before_message => I18n.t("activerecord.errors.models.scholarship_duration.end_date_after_scholarship_end_date") + validates_date :end_date, :on_or_before => :scholarship_end_date, :on_or_before_message => I18n.t("activerecord.errors.models.scholarship_duration.end_date_after_scholarship_end_date"), :if => Proc.new{cancel_date.nil?} + validates_date :cancel_date, :on_or_before => :scholarship_end_date, :on_or_before_message => I18n.t("activerecord.errors.models.scholarship_duration.end_date_after_scholarship_end_date"), :allow_nil => true # # #validates if a cancel date of an scholarship duration is valid - validates_date :cancel_date, :on_or_before => :end_date, :allow_nil => true + validates_date :cancel_date, :on_or_before => :end_date, :allow_nil => true, :on_or_before_message => I18n.t("activerecord.errors.models.scholarship_duration.cancel_date_after_end_date") validates_date :cancel_date, :on_or_after => :start_date, :allow_nil => true before_save :update_end_and_cancel_dates diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index bf75a8b9..274a0caf 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -534,6 +534,7 @@ pt-BR: the_levels_of_scholarship_and_enrollment_are_different: "não pode ser alocado a esta Matrícula porque eles são de níveis diferentes" end_date_after_scholarship_end_date: "posterior a Data de Fim de Bolsa" end_date_before_scholarship_start_date: "anterior a Data de Início de Bolsa" + cancel_date_after_end_date: "posterior a Data Limite de Concessão" enrollment_and_scholarship_uniqueness: "já possui uma Bolsa alocada nesse período" scholarship_start_date_after_end_or_cancel_date: "posterior a Data de Início de outra alocação de bolsa" start_date_after_scholarship_end_date: "da alocação de bolsa deve ser posterior a data de limite de concessão de uma alocação que não tem data de encerramento" @@ -545,7 +546,6 @@ pt-BR: start_date_after_end_date: "posterior a Data de Limite de Concessão" cancel_date: on_or_after: "anterior a Data de Início" - on_or_before: "posterior a Data Limite de Concessão" scholarship_suspension: suspension_start_date_after_end_date: "posterior a Data de Fim" suspension_start_date_before_scholarship_start_date: "anterior a Data de Início da Alocação" From e7a53305df24d15bf3443c129d3b3ebb497c216f Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Cabral da Cunha Date: Fri, 31 May 2019 21:22:48 -0300 Subject: [PATCH 5/9] #293 adding tests to spec of scholarship to validate scholarship_duration date boundaries --- config/locales/pt-BR.yml | 1 + spec/models/scholarship_spec.rb | 35 ++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 274a0caf..f4b930d4 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -533,6 +533,7 @@ pt-BR: scholarship_duration: the_levels_of_scholarship_and_enrollment_are_different: "não pode ser alocado a esta Matrícula porque eles são de níveis diferentes" end_date_after_scholarship_end_date: "posterior a Data de Fim de Bolsa" + cancel_date_after_scholarship_end_date: "posterior a Data de Fim de Bolsa" end_date_before_scholarship_start_date: "anterior a Data de Início de Bolsa" cancel_date_after_end_date: "posterior a Data Limite de Concessão" enrollment_and_scholarship_uniqueness: "já possui uma Bolsa alocada nesse período" diff --git a/spec/models/scholarship_spec.rb b/spec/models/scholarship_spec.rb index bd789740..f2c525b6 100644 --- a/spec/models/scholarship_spec.rb +++ b/spec/models/scholarship_spec.rb @@ -38,7 +38,40 @@ end end end + describe "start_date" do + context "is after scholarship_duration.start_date" do + scholarship_duration = ScholarshipDuration.new + it "should return an error message" do + scholarship.start_date = Date.today + scholarship_duration.scholarship = scholarship + scholarship_duration.start_date = scholarship.start_date - 1.day + scholarship.validate + expect(scholarship_duration).to have_error(:start_date_before_scholarship_start_date).on :start_date + end + end + end describe "end_date" do + context "is before scholarship_duration.end_date and scholarship.cancel_date is nil" do + scholarship_duration = ScholarshipDuration.new + it "should return an error message" do + scholarship.end_date = Date.today + scholarship_duration.scholarship = scholarship + scholarship_duration.end_date = scholarship.end_date + 1.day + scholarship_duration.cancel_date = nil + scholarship.validate + expect(scholarship_duration).to have_error(:end_date_after_scholarship_end_date).on :end_date + end + end + context "is before scholarship_duration.cancel_date" do + scholarship_duration = ScholarshipDuration.new + it "should return an error message" do + scholarship.end_date = Date.today + scholarship_duration.scholarship = scholarship + scholarship_duration.cancel_date = scholarship.end_date + 1.day + scholarship.validate + expect(scholarship_duration).to have_error(:cancel_date_after_scholarship_end_date).on :cancel_date + end + end context "should be valid when" do it "end_date is greater than start_date" do scholarship.end_date = Date.today @@ -100,4 +133,4 @@ end end end -end \ No newline at end of file +end From 8a6fa0aa757d79c61c4b5a07652b77018d971482 Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Cabral da Cunha Date: Fri, 31 May 2019 21:27:13 -0300 Subject: [PATCH 6/9] #293 fixing scholarship_duration boundaries validation in scholarships page --- app/models/scholarship_duration.rb | 33 +++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/app/models/scholarship_duration.rb b/app/models/scholarship_duration.rb index 638e4d1e..67f096fd 100644 --- a/app/models/scholarship_duration.rb +++ b/app/models/scholarship_duration.rb @@ -21,19 +21,38 @@ class ScholarshipDuration < ApplicationRecord # #validates if a scholarship duration start date isn't before it's end date validates_date :start_date, :on_or_before => :end_date, :on_or_before_message => I18n.t("activerecord.errors.models.scholarship_duration.attributes.start_date_after_end_date") # -# #validates if a scholarship duration isn't invalid according to the selected scholarship - validates_date :start_date, :on_or_after => :scholarship_start_date, :on_or_after_message => I18n.t("activerecord.errors.models.scholarship_duration.start_date_before_scholarship_start_date") - validates_date :start_date, :on_or_before => :scholarship_end_date, :on_or_before_message => I18n.t("activerecord.errors.models.scholarship_duration.start_date_after_scholarship_end_date") - validates_date :end_date, :on_or_after => :scholarship_start_date, :on_or_after_message => I18n.t("activerecord.errors.models.scholarship_duration.end_date_before_scholarship_start_date") - validates_date :end_date, :on_or_before => :scholarship_end_date, :on_or_before_message => I18n.t("activerecord.errors.models.scholarship_duration.end_date_after_scholarship_end_date"), :if => Proc.new{cancel_date.nil?} - validates_date :cancel_date, :on_or_before => :scholarship_end_date, :on_or_before_message => I18n.t("activerecord.errors.models.scholarship_duration.end_date_after_scholarship_end_date"), :allow_nil => true -# # #validates if a cancel date of an scholarship duration is valid validates_date :cancel_date, :on_or_before => :end_date, :allow_nil => true, :on_or_before_message => I18n.t("activerecord.errors.models.scholarship_duration.cancel_date_after_end_date") validates_date :cancel_date, :on_or_after => :start_date, :allow_nil => true + validate :check_date_boundaries_of_scholarship + before_save :update_end_and_cancel_dates + def day_of(date) + date.strftime("%Y%m%d").to_i + end + + def check_date_boundaries_of_scholarship + #return if start_date.nil? || end_date.nil? || scholarship.start_date.nil? || scholarship.end_date.nil? + + if (not start_date.nil?) && (not scholarship.start_date.nil?) + if day_of(start_date) < day_of(scholarship.start_date) + errors.add(:start_date, I18n.t("activerecord.errors.models.scholarship_duration.start_date_before_scholarship_start_date")) + end + end + + if not scholarship.end_date.nil? + if not cancel_date.nil? + if day_of(cancel_date) > day_of(scholarship.end_date) + errors.add(:cancel_date, I18n.t("activerecord.errors.models.scholarship_duration.cancel_date_after_scholarship_end_date")) + end + elsif (not end_date.nil?) && (day_of(end_date) > day_of(scholarship.end_date)) + errors.add(:end_date, I18n.t("activerecord.errors.models.scholarship_duration.end_date_after_scholarship_end_date")) + end + end + end + def init self.start_date = Date.today.beginning_of_month + 1.month if self.start_date.nil? self.update_end_date From 83bb2570fabf704062c34e091a66ea73aba7755c Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Cabral da Cunha Date: Fri, 31 May 2019 21:30:43 -0300 Subject: [PATCH 7/9] #293 fixing scholarship_duration boundaries validation in scholarships page --- app/models/scholarship_duration.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/models/scholarship_duration.rb b/app/models/scholarship_duration.rb index 67f096fd..3d768327 100644 --- a/app/models/scholarship_duration.rb +++ b/app/models/scholarship_duration.rb @@ -34,8 +34,6 @@ def day_of(date) end def check_date_boundaries_of_scholarship - #return if start_date.nil? || end_date.nil? || scholarship.start_date.nil? || scholarship.end_date.nil? - if (not start_date.nil?) && (not scholarship.start_date.nil?) if day_of(start_date) < day_of(scholarship.start_date) errors.add(:start_date, I18n.t("activerecord.errors.models.scholarship_duration.start_date_before_scholarship_start_date")) From 945c9c1fe2b5addf4c8d36670adad6211e949181 Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Cabral da Cunha Date: Mon, 3 Jun 2019 21:27:55 -0300 Subject: [PATCH 8/9] Revert "#289 changing line #ruby=2.4 to #ruby=2.6 to avoid RVM incompatibility" This reverts commit 5b2d203ec17f40e923f15d8814614cfdd3724b4e. --- Gemfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 3d6a8580..c072fc04 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' -# The following line is necessary to allow RVM choosing the correct ruby version. RVM 2.0 will probably be able to interpret the "~>" symbol and we will be able to safely remove the "#ruby=2.6" line. -#ruby=2.6 +# The following line is necessary to allow RVM choosing the correct ruby version. RVM 2.0 will probably be able to interpret the "~>" symbol and we will be able to safely remove the "#ruby=2.4" line. +#ruby=2.4 ruby '~>2.6.3' gem 'irb', require: false #necessario a partir do ruby 2.6.0, para que o rake funcione com o irb From deba3dd7324875b78f9a1792b3677b72d4893b6f Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Cabral da Cunha Date: Mon, 3 Jun 2019 21:33:11 -0300 Subject: [PATCH 9/9] Revert "#289 updating ruby from ~> 2.4.0 to ~>2.6.3" This reverts commit b275840a815bb98d7807446ce52ac76e222b874e. --- Gemfile | 3 +-- Gemfile.lock | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index c072fc04..a742d7a7 100644 --- a/Gemfile +++ b/Gemfile @@ -2,8 +2,7 @@ source 'https://rubygems.org' # The following line is necessary to allow RVM choosing the correct ruby version. RVM 2.0 will probably be able to interpret the "~>" symbol and we will be able to safely remove the "#ruby=2.4" line. #ruby=2.4 -ruby '~>2.6.3' -gem 'irb', require: false #necessario a partir do ruby 2.6.0, para que o rake funcione com o irb +ruby '~> 2.4.0' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '5.1.6.2' diff --git a/Gemfile.lock b/Gemfile.lock index 259a09e1..47519405 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -133,7 +133,6 @@ GEM i18n (1.6.0) concurrent-ruby (~> 1.0) ice_nine (0.11.2) - irb (1.0.0) jbuilder (2.7.0) activesupport (>= 4.2.0) multi_json (>= 1.2) @@ -331,7 +330,6 @@ DEPENDENCIES factory_girl_rails ffi (>= 1.9.24) font-awesome-rails - irb jbuilder jquery-rails (>= 4.0.4) jquery-ui-rails @@ -367,7 +365,7 @@ DEPENDENCIES webrick RUBY VERSION - ruby 2.6.3p62 + ruby 2.4.1p111 BUNDLED WITH 1.16.0