From cf2d237093dce3b230c2a970d9dc36c62e0090c4 Mon Sep 17 00:00:00 2001 From: ildarkayumov Date: Mon, 10 Jun 2013 19:58:03 +0400 Subject: [PATCH] Change default path for load routes --- lib/api_taster/route.rb | 6 ++++-- spec/mapper_spec.rb | 10 ++++++---- spec/route_collector_spec.rb | 3 ++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/api_taster/route.rb b/lib/api_taster/route.rb index 6dde219..9347531 100644 --- a/lib/api_taster/route.rb +++ b/lib/api_taster/route.rb @@ -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 = {} @@ -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 = {} diff --git a/spec/mapper_spec.rb b/spec/mapper_spec.rb index b028a3c..2725ef3 100644 --- a/spec/mapper_spec.rb +++ b/spec/mapper_spec.rb @@ -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 @@ -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 @@ -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 diff --git a/spec/route_collector_spec.rb b/spec/route_collector_spec.rb index 7302bbc..b9034bf 100644 --- a/spec/route_collector_spec.rb +++ b/spec/route_collector_spec.rb @@ -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