-
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.
Add ability to collect routes from several files.
- Loading branch information
ildarkayumov
committed
Apr 6, 2013
1 parent
2c0909e
commit 49b61a5
Showing
11 changed files
with
89 additions
and
37 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,18 @@ | ||
module ApiTaster | ||
class RouteCollector | ||
cattr_accessor :routes | ||
self.routes = [] | ||
|
||
class << self | ||
def collect!(path) | ||
self.routes = [] | ||
Dir["#{path}/**/*.rb"].each { |file| load(file) } | ||
Route.mappings = Proc.new do | ||
for route in RouteCollector.routes | ||
instance_eval(&route) | ||
end | ||
end | ||
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 => 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
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 => 1 }] | ||
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 |