diff --git a/app/controllers/api/v1/maps_controller.rb b/app/controllers/api/v1/maps_controller.rb new file mode 100644 index 0000000..da7ffbb --- /dev/null +++ b/app/controllers/api/v1/maps_controller.rb @@ -0,0 +1,17 @@ +class Api::V1::MapsController < Api::V1::BaseController + def index + render json: { maps: gather_maps } + end + + private + + def gather_maps + Map.classic.basic.map do |m| + { + id: m.id, + name: m.name, + category_id: m.category_id + } + end + end +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 0cf0a48..1442471 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,6 +7,7 @@ Ensl::Application.routes.draw do namespace :v1 do resources :users, only: [:show, :index] resources :servers, only: [:index] + resources :maps, only: [:index] end end diff --git a/spec/controllers/api/v1/maps_controller_spec.rb b/spec/controllers/api/v1/maps_controller_spec.rb new file mode 100644 index 0000000..8d1d4ba --- /dev/null +++ b/spec/controllers/api/v1/maps_controller_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +describe Api::V1::MapsController do + before do + request.accept = 'application/json' + end + + describe '#index' do + let!(:map) { create :map } + + it 'returns a list of maps' do + get :index + expect(response).to be_success + expect(json['maps'].length).to eq(1) + json_map = json['maps'][0] + expect(json_map['id']).to eq(map.id) + end + end +end \ No newline at end of file diff --git a/spec/factories/map.rb b/spec/factories/map.rb new file mode 100644 index 0000000..36ce198 --- /dev/null +++ b/spec/factories/map.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :map do + sequence(:name) { |n| "ns_MapName#{n}" } + end +end