Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix upper check in application progress date validation #300

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion app/validators/application_progress_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def invalid_date_range(date_param, field_date)
end

def date_out_range?(field_date)
field_date < 12.months.ago || 12.months.from_now > field_date
field_date < 12.months.ago || 12.months.from_now < field_date
end

def parse_date(year, month, day)
Expand Down
28 changes: 27 additions & 1 deletion spec/validators/application_progress_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

it_behaves_like "requires a rejection reason"

context "date really out of range" do
context "date really out of range on the lower side" do
let(:date_param) { ApplicationProgressValidator::DATE_PARAMS.first }
let(:params) { { "#{date_param}(3i)" => "31", "#{date_param}(2i)" => "1", "#{date_param}(1i)" => "23" } }

Expand All @@ -54,4 +54,30 @@
expect(progress.errors.details[date_param]).to include(error: "out of range")
end
end

context "date really out of range on the higher side" do
let(:date_param) { ApplicationProgressValidator::DATE_PARAMS.first }
let(:params) { { "#{date_param}(3i)" => "31", "#{date_param}(2i)" => "1", "#{date_param}(1i)" => "2003" } }

it "adds an error for the invalid date" do
validator = described_class.new(progress, params)

expect(validator.valid?).to be false
expect(progress.errors.details[date_param]).to include(error: "out of range")
end
end

context "dates valid" do
let(:date_param) { ApplicationProgressValidator::DATE_PARAMS.first }
let(:year) { Date.current.year.to_s }
let(:params) do
{ "#{date_param}(3i)" => "31", "#{date_param}(2i)" => "1", "#{date_param}(1i)" => year }
end

it "adds an error for the invalid date" do
validator = described_class.new(progress, params)

expect(validator.valid?).to be true
end
end
end