forked from austvik/wadlgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test parsing routes for much better test coverage
- Loading branch information
Showing
6 changed files
with
191 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
require 'test/unit' | ||
require 'rails' | ||
require 'active_support/core_ext/hash' | ||
require "action_controller/railtie" | ||
require 'wadlgen' | ||
|
||
# | ||
# Test Rails application | ||
# | ||
class WadlgenTestApp < Rails::Application | ||
routes.draw do | ||
resources :foos | ||
match "/bar" => "foos#bar" | ||
end | ||
end | ||
|
||
class FoosController < ActionController::Base | ||
respond_to :json, :xml, :html | ||
def bar | ||
self.response_body = "Hello World" | ||
end | ||
end | ||
|
||
class TestRouteParser < Test::Unit::TestCase | ||
|
||
def test_parse_routes | ||
|
||
app = Wadlgen::Wadl.parse_route(WadlgenTestApp, 'https://example.com/app') | ||
|
||
ress = app.resources | ||
assert_equal 'https://example.com/app', ress.base | ||
assert_equal 4, ress.resources.count | ||
res = ress.resources.first | ||
meth = res.methods.first | ||
assert_equal "GET", meth.name | ||
assert_equal "index", meth.id | ||
end | ||
|
||
def test_generate | ||
expected = <<HERE | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<application xmlns="http://wadl.dev.java.net/2009/02" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://wadl.dev.java.net/2009/02 wadl.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | ||
<resources base="https://example.com/app"> | ||
<resource path="/foos(.:format)"> | ||
<method id="index" name="GET"> | ||
<request> | ||
<param name="format" style="query"> | ||
<option mediaType="application/json" value="json"/> | ||
<option mediaType="application/xml" value="xml"/> | ||
<option mediaType="application/html" value="html"/> | ||
</param> | ||
</request> | ||
<response status="200"> | ||
<representation element="json" mediaType="application/json"/> | ||
<representation element="xml" mediaType="application/xml"/> | ||
<representation element="html" mediaType="application/html"/> | ||
</response> | ||
</method> | ||
<method id="create" name="POST"> | ||
<request> | ||
<param name="format" style="query"> | ||
<option mediaType="application/json" value="json"/> | ||
<option mediaType="application/xml" value="xml"/> | ||
<option mediaType="application/html" value="html"/> | ||
</param> | ||
<param name="id" style="query"> | ||
</param> | ||
</request> | ||
<response status="200"> | ||
<representation element="json" mediaType="application/json"/> | ||
<representation element="xml" mediaType="application/xml"/> | ||
<representation element="html" mediaType="application/html"/> | ||
</response> | ||
</method> | ||
</resource> | ||
<resource path="/foos/new(.:format)"> | ||
<method id="new" name="GET"> | ||
<request> | ||
<param name="format" style="query"> | ||
<option mediaType="application/json" value="json"/> | ||
<option mediaType="application/xml" value="xml"/> | ||
<option mediaType="application/html" value="html"/> | ||
</param> | ||
<param name="id" style="query"> | ||
</param> | ||
</request> | ||
<response status="200"> | ||
<representation element="json" mediaType="application/json"/> | ||
<representation element="xml" mediaType="application/xml"/> | ||
<representation element="html" mediaType="application/html"/> | ||
</response> | ||
</method> | ||
</resource> | ||
<resource path="/foos/:id(.:format)"> | ||
<method id="show" name="GET"> | ||
<request> | ||
<param name="format" style="query"> | ||
<option mediaType="application/json" value="json"/> | ||
<option mediaType="application/xml" value="xml"/> | ||
<option mediaType="application/html" value="html"/> | ||
</param> | ||
<param name="id" style="query"> | ||
</param> | ||
</request> | ||
<response status="200"> | ||
<representation element="json" mediaType="application/json"/> | ||
<representation element="xml" mediaType="application/xml"/> | ||
<representation element="html" mediaType="application/html"/> | ||
</response> | ||
</method> | ||
<method id="update" name="PUT"> | ||
<request> | ||
<param name="format" style="query"> | ||
<option mediaType="application/json" value="json"/> | ||
<option mediaType="application/xml" value="xml"/> | ||
<option mediaType="application/html" value="html"/> | ||
</param> | ||
<param name="id" style="query"> | ||
</param> | ||
</request> | ||
<response status="200"> | ||
<representation element="json" mediaType="application/json"/> | ||
<representation element="xml" mediaType="application/xml"/> | ||
<representation element="html" mediaType="application/html"/> | ||
</response> | ||
</method> | ||
<method id="destroy" name="DELETE"> | ||
<request> | ||
<param name="format" style="query"> | ||
<option mediaType="application/json" value="json"/> | ||
<option mediaType="application/xml" value="xml"/> | ||
<option mediaType="application/html" value="html"/> | ||
</param> | ||
<param name="id" style="query"> | ||
</param> | ||
</request> | ||
<response status="200"> | ||
<representation element="json" mediaType="application/json"/> | ||
<representation element="xml" mediaType="application/xml"/> | ||
<representation element="html" mediaType="application/html"/> | ||
</response> | ||
</method> | ||
</resource> | ||
<resource path="/bar(.:format)"> | ||
<method id="bar"> | ||
<request> | ||
<param name="format" style="query"> | ||
<option mediaType="application/json" value="json"/> | ||
<option mediaType="application/xml" value="xml"/> | ||
<option mediaType="application/html" value="html"/> | ||
</param> | ||
</request> | ||
<response status="200"> | ||
<representation element="json" mediaType="application/json"/> | ||
<representation element="xml" mediaType="application/xml"/> | ||
<representation element="html" mediaType="application/html"/> | ||
</response> | ||
</method> | ||
</resource> | ||
</resources> | ||
</application> | ||
HERE | ||
|
||
res = Wadlgen::Wadl.generate(WadlgenTestApp, 'https://example.com/app') | ||
assert_equal expected, res | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,15 +9,15 @@ Gem::Specification.new do |s| | |
s.date = %q{2011-02-16} | ||
s.description = %q{Generate WADL from rails routes} | ||
s.email = %q{[email protected]} | ||
s.extra_rdoc_files = ["README", "lib/rake/wadlgen.rb", "lib/wadlgen.rb", "lib/wadlgen/classes.rb", "lib/wadlgen/railtie.rb"] | ||
s.files = ["Gemfile", "Gemfile.lock", "MIT-LICENSE", "README", "Rakefile", "lib/rake/wadlgen.rb", "lib/wadlgen.rb", "lib/wadlgen/classes.rb", "lib/wadlgen/railtie.rb", "test/test_classes.rb", "test/test_generate.rb", "test/test_parser.rb", "wadlgen.gemspec", "Manifest"] | ||
s.extra_rdoc_files = ["README", "lib/rake/wadlgen.rb", "lib/wadlgen.rb", "lib/wadlgen/classes.rb", "lib/wadlgen/railtie.rb", "lib/wadlgen/route_parser.rb", "lib/wadlgen/xml_generator.rb", "lib/wadlgen/xml_parser.rb"] | ||
s.files = ["Gemfile", "Gemfile.lock", "MIT-LICENSE", "README", "Rakefile", "lib/rake/wadlgen.rb", "lib/wadlgen.rb", "lib/wadlgen/classes.rb", "lib/wadlgen/railtie.rb", "lib/wadlgen/route_parser.rb", "lib/wadlgen/xml_generator.rb", "lib/wadlgen/xml_parser.rb", "test/test_classes.rb", "test/test_generate.rb", "test/test_route_parser.rb", "test/test_xml_parser.rb", "wadlgen.gemspec", "Manifest"] | ||
s.homepage = %q{https://github.com/austvik/wadlgen} | ||
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Wadlgen", "--main", "README"] | ||
s.require_paths = ["lib"] | ||
s.rubyforge_project = %q{wadlgen} | ||
s.rubygems_version = %q{1.5.0} | ||
s.summary = %q{Generate WADL from rails routes} | ||
s.test_files = ["test/test_classes.rb", "test/test_parser.rb", "test/test_generate.rb"] | ||
s.test_files = ["test/test_route_parser.rb", "test/test_classes.rb", "test/test_generate.rb", "test/test_xml_parser.rb"] | ||
|
||
if s.respond_to? :specification_version then | ||
s.specification_version = 3 | ||
|