Added maps api

This commit is contained in:
Chris Blanchard 2015-08-01 16:34:01 +01:00
parent fc98dd3b65
commit 3ec284b925
4 changed files with 42 additions and 0 deletions

View 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

View file

@ -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

View 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
View file

@ -0,0 +1,5 @@
FactoryGirl.define do
factory :map do
sequence(:name) { |n| "ns_MapName#{n}" }
end
end