More full paths in error messages

This commit is contained in:
Martin Lensment 2015-01-28 16:22:18 +02:00
parent 01fb195104
commit 7c69783091
3 changed files with 13 additions and 6 deletions

View file

@ -119,24 +119,27 @@ class EppController < ApplicationController
end end
def exactly_one_of(*selectors) def exactly_one_of(*selectors)
full_selectors = create_full_selectors(*selectors)
return if element_count(*selectors) == 1 return if element_count(*selectors) == 1
epp_errors << { epp_errors << {
code: '2306', code: '2306',
msg: I18n.t(:exactly_one_parameter_required, params: selectors.join(' or ')) msg: I18n.t(:exactly_one_parameter_required, params: full_selectors.join(' OR '))
} }
end end
def mutually_exclusive(*selectors) def mutually_exclusive(*selectors)
full_selectors = create_full_selectors(*selectors)
return if element_count(*selectors) <= 1 return if element_count(*selectors) <= 1
epp_errors << { epp_errors << {
code: '2306', code: '2306',
msg: I18n.t(:mutally_exclusive_params, params: selectors.join(', ')) msg: I18n.t(:mutally_exclusive_params, params: full_selectors.join(', '))
} }
end end
def optional(selector, *validations) def optional(selector, *validations)
full_selector = [@prefix, selector].join(' ') full_selector = [@prefix, selector].compact.join(' ')
el = params[:parsed_frame].css(full_selector).first el = params[:parsed_frame].css(full_selector).first
return unless el && el.text.present? return unless el && el.text.present?
value = el.text value = el.text
@ -151,13 +154,17 @@ class EppController < ApplicationController
def element_count(*selectors) def element_count(*selectors)
present_count = 0 present_count = 0
selectors.each do |selector| selectors.each do |selector|
full_selector = [@prefix, selector].join(' ') full_selector = [@prefix, selector].compact.join(' ')
el = params[:parsed_frame].css(full_selector).first el = params[:parsed_frame].css(full_selector).first
present_count += 1 if el && el.text.present? present_count += 1 if el && el.text.present?
end end
present_count present_count
end end
def create_full_selectors(*selectors)
selectors.map { |x| [@prefix, x].compact.join(' ') }
end
def xml_attrs_present?(ph, attributes) # TODO: THIS IS DEPRECATED AND WILL BE REMOVED IN FUTURE def xml_attrs_present?(ph, attributes) # TODO: THIS IS DEPRECATED AND WILL BE REMOVED IN FUTURE
attributes.each do |x| attributes.each do |x|
epp_errors << { epp_errors << {

View file

@ -629,7 +629,7 @@ describe 'EPP Domain', epp: true do
}) })
response = epp_plain_request(xml, :xml) response = epp_plain_request(xml, :xml)
response[:msg].should == 'Mutually exclusive parameters: keyData, dsData' response[:msg].should == 'Mutually exclusive parameters: extension > create > keyData, extension > create > dsData'
response[:result_code].should == '2306' response[:result_code].should == '2306'
end end
end end

View file

@ -163,7 +163,7 @@ describe 'EPP Keyrelay', epp: true do
}) })
response = epp_request(xml, :xml, :elkdata) response = epp_request(xml, :xml, :elkdata)
response[:msg].should == 'Exactly one parameter required: expiry > relative or expiry > absolute' response[:msg].should == 'Exactly one parameter required: keyrelay > expiry > relative OR keyrelay > expiry > absolute'
@zone.messages.queued.count.should == msg_count @zone.messages.queued.count.should == msg_count
end end