Skip to content

Commit

Permalink
Rename util class, add first usage
Browse files Browse the repository at this point in the history
  • Loading branch information
yulgolem committed May 21, 2021
1 parent 45dfa57 commit a0d0ce3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
2 changes: 1 addition & 1 deletion config/initializers/xsd.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
require 'application_service'
require 'xsd/util'
require 'xsd/schema'
10 changes: 8 additions & 2 deletions lib/xsd/util.rb → lib/xsd/schema.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Xsd
class Util < ApplicationService
class Schema < ApplicationService
SCHEMA_PATH = 'lib/schemas/'.freeze
BASE_URL = 'https://epp.tld.ee/schema/'.freeze

attr_reader :xsd_schemas, :for_prefix

Expand All @@ -10,8 +11,13 @@ def initialize(params)
@xsd_schemas = Dir.entries(schema_path).select { |f| File.file? File.join(schema_path, f) }
end

def self.filename(*args, &block)
new(*args, &block).call
end

def call
latest(for_prefix)
filename = latest(for_prefix)
BASE_URL + filename
end

private
Expand Down
6 changes: 3 additions & 3 deletions test/integration/epp/domain/create/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def test_illegal_chars_in_dns_key

request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="https://epp.tld.ee/schema/epp-ee-1.0.xsd">
<epp xmlns="#{Xsd::Schema.filename(for_prefix: 'epp-ee')}">
<command>
<create>
<domain:create xmlns:domain="https://epp.tld.ee/schema/domain-eis-1.0.xsd">
<domain:create xmlns:domain="#{Xsd::Schema.filename(for_prefix: 'domain-eis')}">
<domain:name>#{name}</domain:name>
<domain:registrant>#{registrant.code}</domain:registrant>
</domain:create>
Expand All @@ -31,7 +31,7 @@ def test_illegal_chars_in_dns_key
<secDNS:pubKey>#{pub_key}</secDNS:pubKey>
</secDNS:keyData>
</secDNS:create>
<eis:extdata xmlns:eis="https://epp.tld.ee/schema/eis-1.0.xsd">
<eis:extdata xmlns:eis="#{Xsd::Schema.filename(for_prefix: 'eis')}">
<eis:legalDocument type="pdf">#{'test' * 2000}</eis:legalDocument>
</eis:extdata>
</extension>
Expand Down
21 changes: 21 additions & 0 deletions test/lib/xsd_schema/xsd_schema_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'test_helper'
require 'xsd/schema'

class XsdSchemaTest < ActiveSupport::TestCase
def setup
@schema_path = 'test/fixtures/files/schemas'
super
end

def test_single_part_name
filename = Xsd::Schema.filename(schema_path: @schema_path, for_prefix: 'abcde')

assert_equal Xsd::Schema::BASE_URL + 'abcde-1.2.xsd', filename
end

def test_double_part_name
filename = Xsd::Schema.filename(schema_path: @schema_path, for_prefix: 'abcde-fghij')

assert_equal Xsd::Schema::BASE_URL + 'abcde-fghij-1.3.xsd', filename
end
end
16 changes: 0 additions & 16 deletions test/lib/xsd_util/xsd_util_test.rb

This file was deleted.

0 comments on commit a0d0ce3

Please sign in to comment.