Correct a few bugs

This commit is contained in:
Eric Schultz 2021-02-25 13:33:06 -06:00 committed by Eric Schultz
parent 6865b6e22f
commit 914b06dc84
2 changed files with 17 additions and 21 deletions

View file

@ -664,6 +664,7 @@ AllCops:
- 'spec/controllers/recurring_donations_spec.rb'
- 'spec/controllers/events_spec.rb'
- 'spec/support/contexts.rb'
- 'spec/support/expect.rb'
- 'spec/support/factory_bot.rb'
- 'spec/support/mock_helpers.rb'
- 'spec/support/contexts/shared_rd_donation_value_context.rb'

View file

@ -3,28 +3,23 @@
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
module Expect
def expect_validation_errors(list_of_errors, validators, error_validator_length_should_match: true) # rubocop:disable Metrics/AbcSize
list_of_errors = get_list_of_errors(list_of_errors)
validators = [validators] if validators.is_a?(Hash)
expect(list_of_errors.length).to eq(validators.length) if error_validator_length_should_match
def expect_validation_errors(list_of_errors, validators, error_validator_length_should_match = true)
if list_of_errors.is_a?(ParamValidation::ValidationError)
validators.each do |i|
expect(list_of_errors.any? do |e|
e[:key].to_s == i[:key].to_s && e[:name].to_s == i[:name].to_s
end).to eq(true), "#{i[:key]} should have existed for #{i[:name]}"
end
end
list_of_errors = list_of_errors.data
end
list_of_errors = [list_of_errors] if list_of_errors.is_a?(Hash)
validators = [validators] if validators.is_a?(Hash)
if error_validator_length_should_match
expect(list_of_errors.length).to eq(validators.length)
end
def match_houid(prefix)
match(/#{prefix}_[a-zA-Z0-9]{22}/)
end
validators.each do |i|
expect(list_of_errors.any? { |e| e[:key].to_s == i[:key].to_s && e[:name].to_s == i[:name].to_s }).to eq(true), "#{i[:key]} should have existed for #{i[:name]}"
end
end
private
def get_list_of_errors(list_of_errors)
return list_of_errors.data if list_of_errors.is_a?(ParamValidation::ValidationError)
return [list_of_errors] if list_of_errors.is_a?(Hash)
list_of_errors
end
def match_houid(prefix)
match(/#{prefix}_[a-zA-Z0-9]{22}/)
end
end