mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-12-26 12:30:48 +00:00
Added maps api
This commit is contained in:
parent
fc98dd3b65
commit
3ec284b925
4 changed files with 42 additions and 0 deletions
17
app/controllers/api/v1/maps_controller.rb
Normal file
17
app/controllers/api/v1/maps_controller.rb
Normal file
|
@ -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
|
|
@ -7,6 +7,7 @@ Ensl::Application.routes.draw do
|
||||||
namespace :v1 do
|
namespace :v1 do
|
||||||
resources :users, only: [:show, :index]
|
resources :users, only: [:show, :index]
|
||||||
resources :servers, only: [:index]
|
resources :servers, only: [:index]
|
||||||
|
resources :maps, only: [:index]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
19
spec/controllers/api/v1/maps_controller_spec.rb
Normal file
19
spec/controllers/api/v1/maps_controller_spec.rb
Normal file
|
@ -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
|
5
spec/factories/map.rb
Normal file
5
spec/factories/map.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
FactoryGirl.define do
|
||||||
|
factory :map do
|
||||||
|
sequence(:name) { |n| "ns_MapName#{n}" }
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue