Permalink
Browse files

Tweaked Route#comment_for to accept route instead

  • Loading branch information...
1 parent c0a22fb commit 1ab36c5c577a045e9b4ec81a1a952c56a5eed0b6 @fredwu committed Aug 2, 2012
@@ -9,9 +9,9 @@ def index
end
def show
- @route = Route.find(params[:id])
- @params = Route.params_for(@route)
- @comment = Route.comment_for(params[:id])
+ @route = Route.find(params[:id])
+ @params = Route.params_for(@route)
+ @comment = Route.comment_for(@route)
end
def missing_definitions
View
@@ -10,10 +10,10 @@ class Route
class << self
def map_routes
- self.route_set = Rails.application.routes
- self.supplied_params = {}
- self.obsolete_definitions = []
- self.comments = []
+ self.route_set = Rails.application.routes
+ self.supplied_params = {}
+ self.obsolete_definitions = []
+ self.comments = {}
normalise_routes!
@@ -74,8 +74,11 @@ def params_for(route)
supplied_params[route[:id]].collect { |input| split_input(input, route) }
end
- def comment_for(id)
- self.comments[id.to_i]
+ def comment_for(route)
+ unless undefined_route?(route)
+ self.comments[route[:id].to_i]
+ end
+ end
end
def defined_definitions
@@ -21,11 +21,13 @@ module ApiTaster
it "#show" do
Route.stub(:find).and_return(Route.new)
Route.stub(:params_for).and_return([])
+ Route.stub(:comment_for).and_return([])
get :show, :id => 1, :use_route => :api_taster
assigns(:route).should be_kind_of(Route)
assigns(:params).should be_kind_of(Array)
+ assigns(:comment).should be_kind_of(Array)
end
it "#missing_definitions" do
@@ -14,6 +14,7 @@
:hello => 'world'
}
+ desc 'Get a __list__ of users.'
get '/users'
post '/users', {
@@ -0,0 +1,9 @@
+require 'spec_helper'
+
+module ApiTaster
+ describe ApplicationHelper do
+ it "#markdown" do
+ helper.markdown('__bold__').should == "<p><strong>bold</strong></p>\n"
+ end
+ end
+end
View
@@ -84,13 +84,13 @@ module ApiTaster
it "describes a route" do
route = Route.find_by_verb_and_path(:get, '/dummy_users/:id')
- Route.comment_for(route[:id]).should == "Dummy user ID"
+ Route.comment_for(route).should == "Dummy user ID"
end
it "don't describe a route" do
route = Route.find_by_verb_and_path(:post, '/dummy_users')
- Route.comment_for(route[:id]).should be_nil
+ Route.comment_for(route).should be_nil
end
end
end
View
@@ -97,9 +97,16 @@ module ApiTaster
end
it "#comment_for" do
+ Route.stub(:routes).and_return([{
+ :id => 42,
+ :path => '/dummy/:dummy_id'
+ }])
+ Route.supplied_params[42] = {}
+
markdown_comment = "Heading\n=======\n * List item 1\n * List item 2"
Route.comments[42] = markdown_comment
- Route.comment_for(42).should eq(markdown_comment)
+
+ Route.comment_for(Route.find(42)).should eq(markdown_comment)
end
it "#missing_definitions and #defined_definitions" do

0 comments on commit 1ab36c5

Please sign in to comment.