diff --git a/lib/api_taster/route.rb b/lib/api_taster/route.rb index f273ed4..2ff8ed1 100644 --- a/lib/api_taster/route.rb +++ b/lib/api_taster/route.rb @@ -9,7 +9,6 @@ class Route cattr_accessor :metadata class << self - def map_routes(path = "#{Rails.root}/app/api_tasters") self.route_set = Rails.application.routes self.supplied_params = {} @@ -20,7 +19,7 @@ def map_routes(path = "#{Rails.root}/app/api_tasters") normalise_routes! begin - ApiTaster::RouteCollector.collect!(path) + ApiTaster::RouteCollector.collect(path) Mapper.instance_eval(&self.mappings) rescue Route.mappings = {} diff --git a/lib/api_taster/route_collector.rb b/lib/api_taster/route_collector.rb index ac6d927..0993d7f 100644 --- a/lib/api_taster/route_collector.rb +++ b/lib/api_taster/route_collector.rb @@ -3,15 +3,12 @@ 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 + 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 diff --git a/spec/dummy/app/api_tasters/route_collector/test2.rb b/spec/dummy/app/api_tasters/route_collector/test2.rb index b00daf6..a1b2d5f 100644 --- a/spec/dummy/app/api_tasters/route_collector/test2.rb +++ b/spec/dummy/app/api_tasters/route_collector/test2.rb @@ -1,3 +1,3 @@ ApiTaster.routes do - get '/dummy_users/:id', :id => 1 + get '/dummy_users/:id', :id => 42 end diff --git a/spec/mapper_spec.rb b/spec/mapper_spec.rb index 518f91e..b028a3c 100644 --- a/spec/mapper_spec.rb +++ b/spec/mapper_spec.rb @@ -39,9 +39,7 @@ module ApiTaster member { map_method :patch, :update } end end - end - before(:all) do Route.map_routes "#{Rails.root}/app/api_tasters/mapper" end diff --git a/spec/route_collector_spec.rb b/spec/route_collector_spec.rb index c1609e2..7302bbc 100644 --- a/spec/route_collector_spec.rb +++ b/spec/route_collector_spec.rb @@ -11,7 +11,7 @@ module ApiTaster it "gets users" do route = Route.find_by_verb_and_path(:get, '/dummy_users/:id') - Route.supplied_params[route[:id]].should == [{ :id => 1 }] + Route.supplied_params[route[:id]].should == [{ :id => 42 }] end it "posts a new user" do