Browse Source

lint fixes

pull/683/head
Dushan Despotovic 3 years ago
parent
commit
33db47d6f4
  1. 4
      app/models/case_log.rb
  2. 12
      app/models/validations/date_validations.rb
  3. 10
      spec/models/validations/date_validations_spec.rb

4
app/models/case_log.rb

@ -35,8 +35,8 @@ class CaseLog < ApplicationRecord
belongs_to :owning_organisation, class_name: "Organisation", optional: true belongs_to :owning_organisation, class_name: "Organisation", optional: true
belongs_to :managing_organisation, class_name: "Organisation", optional: true belongs_to :managing_organisation, class_name: "Organisation", optional: true
belongs_to :created_by, class_name: "User", optional: true belongs_to :created_by, class_name: "User", optional: true
belongs_to :scheme, required: false belongs_to :scheme, optional: true
scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) } scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) }
scope :filter_by_status, ->(status, _user = nil) { where status: } scope :filter_by_status, ->(status, _user = nil) { where status: }
scope :filter_by_years, lambda { |years, _user = nil| scope :filter_by_years, lambda { |years, _user = nil|

12
app/models/validations/date_validations.rb

@ -34,19 +34,17 @@ module Validations::DateValidations
if record.startdate < first_collection_start_date || record.startdate > second_collection_end_date if record.startdate < first_collection_start_date || record.startdate > second_collection_end_date
record.errors.add :startdate, I18n.t("validations.date.outside_collection_window") record.errors.add :startdate, I18n.t("validations.date.outside_collection_window")
end end
# if record.voiddate.present? # if record.voiddate.present?
# if (record.startdate.to_date - record.voiddate.to_date).to_i.abs > 730 # if (record.startdate.to_date - record.voiddate.to_date).to_i.abs > 730
# record.errors.add :startdate, I18n.t("validations.setup.startdate.voiddate_difference") # record.errors.add :startdate, I18n.t("validations.setup.startdate.voiddate_difference")
# end # end
# end # end
if record.scheme_id.present? if record.scheme_id.present?
scheme_end_date = Scheme.find(record.scheme_id).end_date scheme_end_date = Scheme.find(record.scheme_id).end_date
if scheme_end_date.present? if scheme_end_date.present? && (record.startdate > scheme_end_date)
if record.startdate > scheme_end_date record.errors.add :startdate, I18n.t("validations.setup.startdate.before_scheme_end_date")
record.errors.add :startdate, I18n.t("validations.setup.startdate.before_scheme_end_date")
end
end end
end end
end end

10
spec/models/validations/date_validations_spec.rb

@ -5,8 +5,8 @@ RSpec.describe Validations::DateValidations do
let(:validator_class) { Class.new { include Validations::DateValidations } } let(:validator_class) { Class.new { include Validations::DateValidations } }
let(:record) { FactoryBot.create(:case_log) } let(:record) { FactoryBot.create(:case_log) }
let(:scheme) { FactoryBot.create(:scheme, end_date: Time.zone.today - 5.days)} let(:scheme) { FactoryBot.create(:scheme, end_date: Time.zone.today - 5.days) }
let(:scheme_no_end_date) { FactoryBot.create(:scheme, end_date: nil)} let(:scheme_no_end_date) { FactoryBot.create(:scheme, end_date: nil) }
describe "tenancy start date" do describe "tenancy start date" do
it "cannot be before the first collection window start date" do it "cannot be before the first collection window start date" do
@ -39,21 +39,21 @@ RSpec.describe Validations::DateValidations do
setup_validator.validate_startdate(record) setup_validator.validate_startdate(record)
expect(record.errors["startdate"]) expect(record.errors["startdate"])
.to include(match I18n.t("validations.setup.startdate.before_scheme_end_date")) .to include(match I18n.t("validations.setup.startdate.before_scheme_end_date"))
end end
it "produces no error when the tenancy start date is before the end date of the chosen scheme if it has an end date" do it "produces no error when the tenancy start date is before the end date of the chosen scheme if it has an end date" do
record.startdate = Time.zone.today - 30.days record.startdate = Time.zone.today - 30.days
record.scheme = scheme record.scheme = scheme
setup_validator.validate_startdate(record) setup_validator.validate_startdate(record)
expect(record.errors["startdate"]).to be_empty expect(record.errors["startdate"]).to be_empty
end end
it "produces no startdate error for scheme end dates when the chosen scheme does not have an end date" do it "produces no startdate error for scheme end dates when the chosen scheme does not have an end date" do
record.startdate = Time.zone.today record.startdate = Time.zone.today
record.scheme = scheme_no_end_date record.scheme = scheme_no_end_date
setup_validator.validate_startdate(record) setup_validator.validate_startdate(record)
expect(record.errors["startdate"]).to be_empty expect(record.errors["startdate"]).to be_empty
end end
# it "validates that tenancy start date is less than 730 days away from the void date" do # it "validates that tenancy start date is less than 730 days away from the void date" do
# record.startdate = Time.zone.today # record.startdate = Time.zone.today

Loading…
Cancel
Save