Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default path for load routes #43

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/api_taster/route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ class Route
cattr_accessor :obsolete_definitions
cattr_accessor :comments
cattr_accessor :metadata
cattr_accessor :path

class << self
def map_routes(path = "#{Rails.root}/app/api_tasters")
def map_routes
self.route_set = Rails.application.routes
self.path ||= "#{Rails.root}/lib/api_tasters"
self.supplied_params = {}
self.obsolete_definitions = []
self.comments = {}
Expand All @@ -19,7 +21,7 @@ def map_routes(path = "#{Rails.root}/app/api_tasters")
normalise_routes!

begin
ApiTaster::RouteCollector.collect(path)
ApiTaster::RouteCollector.collect(self.path)
Mapper.instance_eval(&self.mappings)
rescue
Route.mappings = {}
Expand Down
10 changes: 6 additions & 4 deletions spec/mapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module ApiTaster
context "#global_params" do
before(:all) do
ApiTaster.global_params = { :foo => 'bar' }

Route.map_routes "#{Rails.root}/app/api_tasters/global_params"
Route.path = "#{Rails.root}/app/api_tasters/global_params"
Route.map_routes
end

it "merges params" do
Expand All @@ -25,7 +25,8 @@ module ApiTaster
end

Route.route_set = routes
Route.map_routes "#{Rails.root}/app/api_tasters/mapper"
Route.path = "#{Rails.root}/app/api_tasters/mapper"
Route.map_routes
end

it "records obsolete definitions" do
Expand All @@ -40,7 +41,8 @@ module ApiTaster
end
end

Route.map_routes "#{Rails.root}/app/api_tasters/mapper"
Route.path = "#{Rails.root}/app/api_tasters/mapper"
Route.map_routes
end

it "gets users" do
Expand Down
3 changes: 2 additions & 1 deletion spec/route_collector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module ApiTaster
Rails.application.routes.draw do
resources :dummy_users
end
Route.map_routes "#{Rails.root}/app/api_tasters/route_collector"
Route.path = "#{Rails.root}/app/api_tasters/route_collector"
Route.map_routes
end

it "gets users" do
Expand Down