Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 73 additions and 16 deletions.
  1. +20 −16 lib/wadlgen/merge.rb
  2. +20 −0 test/test_classes.rb
  3. +33 −0 test/test_merge.rb
View
36 lib/wadlgen/merge.rb
@@ -29,7 +29,7 @@ def merge_resources_elem(target, initial, additional)
res = target.add_resources(resources.base)
merge_docs res, resources.docs
if additional.first.parent.has_resources? resources.base
- merge_resources res, resources.resources, additional.first.parent.get_resources(resources.base)
+ merge_resources res, resources.resources, additional.first.parent.get_resources(resources.base).resources
else
merge_resources res, resources.resources
end
@@ -79,13 +79,14 @@ def merge_resource_types(target, initial, additional)
def merge_resources(target, initial, additional = [])
if initial
+ additional ||= []
(initial + additional).each do |init_res|
if target.has_resource? init_res.type, init_res.path
- res = get_resource init_res.type, init_res.path
- merge_docs res, res.docs, add_res.docs
- merge_params res, res.params, add_res.params
- merge_methods res, res.methods, add_res.methods
- merge_resources res, res.resources, add_res.resources
+ res = target.get_resource init_res.type, init_res.path
+ merge_docs res, res.docs, init_res.docs
+ merge_params res, res.params, init_res.params
+ merge_methods res, res.methods, init_res.methods
+ merge_resources res, res.resources, init_res.resources
else
res = target.add_resource init_res.type, init_res.path, init_res.id, init_res.query_type
merge_docs res, init_res.docs
@@ -99,6 +100,7 @@ def merge_resources(target, initial, additional = [])
def merge_methods(target, initial, additional = [])
initial ||= []
+ additional ||= []
(initial + additional).each do |init_meth|
if target.has_method? init_meth.name, init_meth.id
meth = target.get_method init_meth.name, init_meth.id
@@ -115,16 +117,13 @@ def merge_methods(target, initial, additional = [])
end
def merge_request(target, initial, additional = nil)
- if target.request.nil?
- req = target.add_request
- merge_docs req, initial.docs
- merge_params req, initial.params
- merge_representations req, initial.representations
- else
- req = target.request
- merge_docs req, initial.docs
- merge_params req, initial.params
- merge_representations req, initial.representations
+ if initial
+ if target.request.nil?
+ req = target.add_request
+ merge_docs req, initial.docs
+ merge_params req, initial.params
+ merge_representations req, initial.representations
+ end
end
if additional
@@ -137,6 +136,8 @@ def merge_request(target, initial, additional = nil)
end
def merge_responses(target, initial, additional = [])
+ initial ||= []
+ additional ||= [9]
(initial + additional).each do |add_resp|
if target.has_response? add_resp.status
resp = target.get_response add_resp.status
@@ -154,6 +155,7 @@ def merge_responses(target, initial, additional = [])
def merge_representations(target, initial, additional = [])
initial ||= []
+ additional ||= []
(initial + additional).each do |add_repr|
if target.has_representation? add_repr.media_type
repr = target.get_representation add_repr.media_type
@@ -169,6 +171,7 @@ def merge_representations(target, initial, additional = [])
def merge_params(target, initial, additional = [])
initial ||= []
+ additional ||= []
(initial + additional).each do |add_param|
if target.has_param? add_param.name, add_param.style
param = target.get_param add_param.name, add_param.style
@@ -190,6 +193,7 @@ def merge_params(target, initial, additional = [])
def merge_options(target, initial, additional = [])
initial ||= []
+ additional ||= []
(initial + additional).each do |add_opt|
if target.has_option? add_opt.value
opt = target.get_option add_opt.value
View
20 test/test_classes.rb
@@ -8,6 +8,26 @@ def test_application
app = Wadlgen::Application.new
end
+ def test_documentation
+ app = Wadlgen::Application.new
+ doc = app.add_doc "title1", "text1", 'no'
+ assert_equal app, doc.parent
+ assert_equal 'title1', doc.title
+ assert_equal 'text1', doc.text
+ assert_equal 'no', doc.xml_lang
+ assert app.has_doc? 'title1'
+ end
+
+ def test_grammars
+ app = Wadlgen::Application.new
+ grms = app.add_grammars
+ assert_equal app, grms.application
+ incl1 = grms.add_include 'http://some.example.com/'
+ assert_equal grms, incl1.grammars
+ assert grms.has_include?('http://some.example.com/')
+ assert !grms.has_include?('http://some.other.example.com/')
+ end
+
def test_resources
base = "http://www.example.com/"
path = "resources"
View
33 test/test_merge.rb
@@ -10,6 +10,8 @@ def test_merge_application
gram1.add_doc('doc1', 'Doc1')
gram1.add_include("http://example.com/1")
rt1 = app1.add_resource_type("res_type1")
+ rt12 = app1.add_resource_type("res_type2")
+
ress1 = app1.add_resources("http://base1/")
res1 = ress1.add_resource 'GET', '/some/path1', 'id1', 'query'
meth1 = res1.add_method 'GET', 'id1', 'href1'
@@ -18,14 +20,42 @@ def test_merge_application
repr1 = req1.add_representation 'application/json'
resp1 = meth1.add_response '200'
+ # Unique
+ ress11 = app1.add_resources("http://baseX/")
+ res11 = ress11.add_resource 'GET', '/some/pathX', 'idX', 'query'
+ meth11 = res11.add_method 'GET', 'idX', 'hrefX'
+ req11 = meth11.add_request
+ param11 = req11.add_param 'id', 'query'
+ repr11 = req11.add_representation 'application/json'
+ resp11 = meth11.add_response '200'
+
+ param1.add_option('xml', "application/xml")
+ param1.add_option('json', "application/json")
+ param1.add_link 'query', '1.0', '..'
+
app2 = Wadlgen::Application.new
app2.add_doc('app2', "App2")
gram2 = app2.add_grammars
gram2.add_doc('doc2', 'Doc2')
gram2.add_include("http://example.net/2")
rt2 = app2.add_resource_type('res_type2')
+ rt23 = app2.add_resource_type('res_type3')
ress2 = app2.add_resources("http://base2/")
res2 = ress2.add_resource 'GET', '/some/path2', 'id2', 'query'
+ res2.add_doc 'title', 'text'
+
+ # Will collide
+ ress21 = app2.add_resources("http://base1/")
+ res21 = ress21.add_resource 'GET', '/some/path1', 'id1', 'query'
+ res21.add_doc 'doc23', 'text2'
+ res21.add_doc 'doc33', 'text3'
+ meth21 = res21.add_method 'GET', 'id1', 'href1'
+ meth22 = res21.add_method 'GET', 'id22', 'href22'
+ req21 = meth21.add_request
+ req22 = meth22.add_request
+ param21 = req21.add_param 'id', 'query'
+ repr21 = req21.add_representation 'application/json'
+ resp21 = meth21.add_response '200'
assert_equal 'app1', app1.docs.first.title
assert_equal 'app2', app2.docs.first.title
@@ -47,6 +77,9 @@ def test_merge_application
assert_equal '/some/path2', merge.resources.last.resources.first.path
assert_equal '200', merge.resources.first.resources.first.methods.first.responses.first.status
+ assert_equal 'id', merge.resources.first.resources.first.methods.first.request.params.first.name
+ assert_equal 'xml', merge.resources.first.resources.first.methods.first.request.params.first.options.first.value
+ assert_equal 'query', merge.resources.first.resources.first.methods.first.request.params.first.link.resource_type
end
end

No commit comments for this range

Something went wrong with that request. Please try again.