-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from fredwu/pr/39
Pr/39
- Loading branch information
Showing
11 changed files
with
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module ApiTaster | ||
class RouteCollector | ||
cattr_accessor :routes | ||
self.routes = [] | ||
|
||
def self.collect(path) | ||
self.routes = [] | ||
Dir["#{path}/**/*.rb"].each { |file| load(file) } | ||
|
||
Route.mappings = Proc.new do | ||
RouteCollector.routes.each { |route| instance_eval(&route) } | ||
end | ||
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ApiTaster.routes do | ||
post '/dummy_users' | ||
post '/dummy_users', { :hello => 'world' }, { :meta => 'data' } | ||
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ApiTaster.routes do | ||
get '/dummy_users/:id', :id => 1 | ||
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ApiTaster.routes do | ||
get '/dummy_users/:id', :id => 1 | ||
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
ApiTaster.routes do | ||
get '/dummy_route' | ||
desc "Dummy user ID" | ||
get '/dummy_users/:id', :id => 1 | ||
post '/dummy_users' | ||
post '/dummy_users', { :hello => 'world' }, { :meta => 'data' } | ||
put '/dummy_users/:id', :id => 2 | ||
delete '/dummy_users/:id', :id => 3 | ||
patch '/dummy_users/:id', :id => 4 | ||
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ApiTaster.routes do | ||
post '/dummy_users' | ||
post '/dummy_users', { :hello => 'world' }, { :meta => 'data' } | ||
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ApiTaster.routes do | ||
get '/dummy_users/:id', :id => 42 | ||
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'spec_helper' | ||
|
||
module ApiTaster | ||
describe RouteCollector do | ||
before(:all) do | ||
Rails.application.routes.draw do | ||
resources :dummy_users | ||
end | ||
Route.map_routes "#{Rails.root}/app/api_tasters/route_collector" | ||
end | ||
|
||
it "gets users" do | ||
route = Route.find_by_verb_and_path(:get, '/dummy_users/:id') | ||
Route.supplied_params[route[:id]].should == [{ :id => 42 }] | ||
end | ||
|
||
it "posts a new user" do | ||
route = Route.find_by_verb_and_path(:post, '/dummy_users') | ||
Route.supplied_params[route[:id]].should == [{}, { :hello => 'world' }] | ||
end | ||
end | ||
end |