Skip to content
Open
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
18 changes: 12 additions & 6 deletions app/models/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class Config < ApplicationRecord
[:validate_singleton, :validate_yes_or_no],

budget_bar_max:
[:validate_singleton, :validate_number],
[:validate_singleton, :validate_budget_bar_max],

resources_url:
[:validate_singleton, :validate_url],
Expand Down Expand Up @@ -278,8 +278,8 @@ def clean_config_value
cleaners.each { |cleaner| method(cleaner).call }
end

# parent function. will handle errors; child validators should return true
# if value is valid for key, and false otherwise.
# parent function. will handle errors; child validators should return nil
# if value is valid for key, and the error string otherwise.
def validate_config
# don't try to validate if no key or no value
return if config_key.nil? || options.last.nil?
Expand All @@ -289,7 +289,7 @@ def validate_config
# no validation for this field, ignore
return if validators.blank?

# run the validators and get a boolean, exit if all are true
# run the validators and get a the results, exit if all are nil
# (see comment above in `clean_config_value` for an explainer)
validation_errors = validators.map { |validator| method(validator).call }
return if validation_errors.all? { |validation_error| validation_error.nil? }
Expand Down Expand Up @@ -333,11 +333,11 @@ def validate_url
url = UriService.new(maybe_url).uri

# uriservice returns nil if there's a problem.
return false unless url
return "URL Required" unless url


config_value['options'] = [url]
return true
return
end

### Start of Week
Expand Down Expand Up @@ -408,6 +408,12 @@ def validate_shared_reset_days
end
end

def validate_budget_bar_max
if !validate_number
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I put nah in here it lets me, though it seems to evaluate to zero -- I think this is because validate_number produces a string if something's up. That said it doesn't break anything on the frontend thankfully

"Must be between #{SHARED_MIN_DAYS} and #{SHARED_MAX_DAYS} days."
end
end

def validate_length
total_length = 0
options.each do |option|
Expand Down
Loading