-
-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only add /version/ to URLs accessed with /version/
Adds request.version_supplied to detect whether the version was parsed out of the URL. Rewrote some of the URL helpers and serializers to respect this new behaviour. The biggest change is that the DocServerSerializer will no longer add the /prefix to the serialized_path, and it will now ignore the command passed in to the constructor (which is now optional). Instead, DocServerHelper#url_for should be used to generate a URL with a prefix. Closes #426
- Loading branch information
Showing
11 changed files
with
88 additions
and
40 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
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
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,51 @@ | ||
require File.dirname(__FILE__) + "/spec_helper" | ||
|
||
class MyDocServerSerializerRouter | ||
attr_accessor :request | ||
def docs_prefix; 'PREFIX' end | ||
def initialize; @request = mock_request end | ||
end | ||
|
||
class MockDocServerHelper | ||
include YARD::Templates::Helpers::BaseHelper | ||
include YARD::Templates::Helpers::HtmlHelper | ||
include YARD::Server::DocServerHelper | ||
|
||
attr_accessor :adapter | ||
attr_accessor :single_library | ||
attr_accessor :library | ||
|
||
def initialize | ||
@single_library = false | ||
@library = LibraryVersion.new('foo') | ||
@adapter = mock_adapter(:router => MyDocServerSerializerRouter.new) | ||
@serializer = YARD::Server::DocServerSerializer.new | ||
@object = YARD::Registry.root | ||
end | ||
end | ||
|
||
describe YARD::Server::DocServerHelper do | ||
before do | ||
@helper = MockDocServerHelper.new | ||
end | ||
|
||
describe '#url_for' do | ||
it "should not link to /library/ if single_library = true" do | ||
@helper.single_library = true | ||
@helper.url_for(Registry.root).should == "/PREFIX/toplevel" | ||
end | ||
|
||
it "should return /PREFIX/foo/version if foo has a version" do | ||
@helper.library = LibraryVersion.new('foo', 'bar') | ||
@helper.adapter.router.request.version_supplied = true | ||
@helper.url_for(P('A')).should == '/PREFIX/foo/bar/A' | ||
end | ||
end | ||
|
||
describe '#url_for_file' do | ||
it "should properly link file objects using file/ prefix" do | ||
file = CodeObjects::ExtraFileObject.new('a/b/FooBar.md', '') | ||
@helper.url_for_file(file).should == '/PREFIX/foo/file/a/b/FooBar.md' | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,45 @@ | ||
require File.dirname(__FILE__) + '/spec_helper' | ||
|
||
class MyDocServerSerializerRouter | ||
def docs_prefix; 'PREFIX' end | ||
end | ||
|
||
describe YARD::Server::DocServerSerializer do | ||
describe '#serialized_path' do | ||
before do | ||
Registry.clear | ||
@command = mock(:command) | ||
@command.stub!(:single_library).and_return(false) | ||
@command.stub!(:library).and_return(LibraryVersion.new('foo')) | ||
@command.stub!(:adapter).and_return(mock_adapter(:router => MyDocServerSerializerRouter.new)) | ||
@serializer = Server::DocServerSerializer.new(@command) | ||
@serializer = Server::DocServerSerializer.new | ||
end | ||
|
||
after(:all) { Server::Adapter.shutdown } | ||
|
||
it "should return '/PREFIX/library/toplevel' for root" do | ||
@serializer.serialized_path(Registry.root).should == "/PREFIX/foo/toplevel" | ||
@serializer.serialized_path(Registry.root).should == "toplevel" | ||
end | ||
|
||
it "should return /PREFIX/library/Object for Object in a library" do | ||
@serializer.serialized_path(P('A::B::C')).should == '/PREFIX/foo/A/B/C' | ||
@serializer.serialized_path(P('A::B::C')).should == 'A/B/C' | ||
end | ||
|
||
it "should link to instance method as Class:method" do | ||
obj = CodeObjects::MethodObject.new(:root, :method) | ||
@serializer.serialized_path(obj).should == '/PREFIX/foo/toplevel:method' | ||
@serializer.serialized_path(obj).should == 'toplevel:method' | ||
end | ||
|
||
it "should link to class method as Class.method" do | ||
obj = CodeObjects::MethodObject.new(:root, :method, :class) | ||
@serializer.serialized_path(obj).should == '/PREFIX/foo/toplevel.method' | ||
@serializer.serialized_path(obj).should == 'toplevel.method' | ||
end | ||
|
||
it "should link to anchor for constant" do | ||
obj = CodeObjects::ConstantObject.new(:root, :FOO) | ||
@serializer.serialized_path(obj).should == '/PREFIX/foo/toplevel#FOO-constant' | ||
@serializer.serialized_path(obj).should == 'toplevel#FOO-constant' | ||
end | ||
|
||
it "should link to anchor for class variable" do | ||
obj = CodeObjects::ClassVariableObject.new(:root, :@@foo) | ||
@serializer.serialized_path(obj).should == '/PREFIX/foo/toplevel#@@foo-classvariable' | ||
end | ||
|
||
it "should not link to /library/ if single_library = true" do | ||
@command.stub!(:single_library).and_return(true) | ||
@serializer.serialized_path(Registry.root).should == "/PREFIX/toplevel" | ||
@serializer.serialized_path(obj).should == 'toplevel#@@foo-classvariable' | ||
end | ||
|
||
it "should return /PREFIX/foo/version if foo has a version" do | ||
@command.stub!(:library).and_return(LibraryVersion.new('foo', 'bar')) | ||
@serializer.serialized_path(P('A')).should == '/PREFIX/foo/bar/A' | ||
it "should link files using file/ prefix" do | ||
file = CodeObjects::ExtraFileObject.new('a/b/FooBar.md', '') | ||
@serializer.serialized_path(file).should == 'file/FooBar' | ||
end | ||
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