This commit is contained in:
Martin Lensment 2014-09-03 12:48:52 +03:00
parent dfb30dd11a
commit 9b4f0a067e
2 changed files with 26 additions and 54 deletions

View file

@ -248,7 +248,8 @@ describe 'EPP Helper', epp: true do
</epp> </epp>
').to_s.squish ').to_s.squish
generated = Nokogiri::XML(domain_update_xml).to_s.squish xml = domain_update_xml(add: nil)
generated = Nokogiri::XML(xml).to_s.squish
expect(generated).to eq(expected) expect(generated).to eq(expected)
expected = Nokogiri::XML('<?xml version="1.0" encoding="UTF-8" standalone="no"?> expected = Nokogiri::XML('<?xml version="1.0" encoding="UTF-8" standalone="no"?>
@ -271,7 +272,16 @@ describe 'EPP Helper', epp: true do
</epp> </epp>
').to_s.squish ').to_s.squish
xml = domain_update_xml(name: 'one.ee', registrant: 'sh8013', pw: 'b3rafsla') xml = domain_update_xml(
name: { value: 'one.ee' },
add: nil,
chg: [
registrant: { value: 'sh8013' },
authInfo: [
pw: { value: 'b3rafsla' }
]
]
)
generated = Nokogiri::XML(xml).to_s.squish generated = Nokogiri::XML(xml).to_s.squish
expect(generated).to eq(expected) expect(generated).to eq(expected)

View file

@ -161,58 +161,27 @@ module Epp
end end
def domain_update_xml(xml_params = {}) def domain_update_xml(xml_params = {})
# defaults = {
# name: {value: 'example.ee'},
# add: {
# ns: [
# { hostObj: { value: 'ns1.example.com' } },
# { hostObj: { value: 'ns2.example.com' } }
# ],
# contact: [
# {
# attrs: { type: 'tech' },
# value: 'mak21'
# }
# ],
# status: [
# { attrs: {s: 'clientHold', lang: 'en'}, value: 'Payment overdue.'},
# { attrs: {s: 'clientUpdateProhibited' }}
# ]
# }
# }
defaults = { defaults = {
name: { value: 'example.ee' }, name: { value: 'example.ee' },
chg: [ chg: [
{ registrant: { value: 'mak21' } } registrant: { value: 'mak21' },
], authInfo: [
add: { pw: { value: '2BARfoo' }
ns: [
{ hostObj: { value: 'ns1.example.com' } },
{ hostObj: { value: 'ns2.example.com' } }
],
_statuses: [
{ status: { attrs: { s: 'clientHold', lang: 'en' }, value: 'Payment overdue.' } },
{ status: { attrs: { s: 'clientUpdateProhibited' }, value: '' } }
],
_contacts: [
{ contact: { attrs: { type: 'tech' }, value: 'mak21' } }
] ]
} ],
add: [
ns: [
hostObj: { value: 'ns1.example.com' },
hostObj: { value: 'ns2.example.com' }
],
status: { attrs: { s: 'clientHold', lang: 'en' }, value: 'Payment overdue.' },
status: { attrs: { s: 'clientUpdateProhibited' }, value: '' },
contact: { attrs: { type: 'tech' }, value: 'mak21' }
]
} }
xml_params = defaults.deep_merge(xml_params) xml_params = defaults.deep_merge(xml_params)
# xml_params[:name] = xml_params[:name] || 'example.ee'
# xml_params[:add] = xml_params[:add] || {}
# xml_params[:add][:ns] = xml_params[:add][:ns] || {}
# xml_params[:add][:ns][:hostObj] = 'ns1.example.com'
# xml_params[:registrant] = xml_params[:registrant] || 'mak21'
# xml_params[:pw] = xml_params[:pw] || '2BARfoo'
xml = Builder::XmlMarkup.new xml = Builder::XmlMarkup.new
xml.instruct!(:xml, standalone: 'no') xml.instruct!(:xml, standalone: 'no')
@ -240,17 +209,10 @@ module Epp
end end
# Value is an array # Value is an array
elsif v.is_a?(Array) elsif v.is_a?(Array)
# underscore marks "internal" variable, not converted into xml xml.tag!("#{ns}:#{k}") do
if k[0] == '_'
v.each do |x| v.each do |x|
generate_xml_from_hash(x, xml, ns) generate_xml_from_hash(x, xml, ns)
end end
else
xml.tag!("#{ns}:#{k}") do
v.each do |x|
generate_xml_from_hash(x, xml, ns)
end
end
end end
end end
end end