mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-12-27 04:51:14 +00:00
commit
cf2fcd6e89
11 changed files with 213 additions and 77 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
|
21
app/controllers/api/v1/servers_controller.rb
Normal file
21
app/controllers/api/v1/servers_controller.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
class Api::V1::ServersController < Api::V1::BaseController
|
||||
def index
|
||||
render json: { servers: active_servers }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def active_servers
|
||||
Server.active.map do |s|
|
||||
{
|
||||
id: s.id,
|
||||
description: s.description,
|
||||
dns: s.dns,
|
||||
ip: s.ip,
|
||||
port: s.port,
|
||||
password: s.password,
|
||||
category_id: s.category_id
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
|
@ -17,7 +17,13 @@ class Api::V1::UsersController < Api::V1::BaseController
|
|||
steam: {
|
||||
url: @steam.base_url,
|
||||
nickname: @steam.nickname
|
||||
}
|
||||
},
|
||||
bans: {
|
||||
gather: @user.banned?(Ban::TYPE_GATHER).present?,
|
||||
mute: @user.banned?(Ban::TYPE_MUTE).present?,
|
||||
site: @user.banned?(Ban::TYPE_SITE).present?
|
||||
},
|
||||
team: @user.team.present? ? { id: @user.team.id, name: @user.team.name } : nil
|
||||
}
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
raise ActionController::RoutingError.new('User Not Found')
|
||||
|
|
|
@ -15,7 +15,6 @@ class ShoutmsgsController < ApplicationController
|
|||
|
||||
def create
|
||||
@shoutmsg = Shoutmsg.new params[:shoutmsg]
|
||||
puts @shoutmsg
|
||||
@shoutmsg.user = cuser
|
||||
raise AccessError unless @shoutmsg.can_create? cuser
|
||||
|
||||
|
|
|
@ -6,76 +6,78 @@ Ensl::Application.routes.draw do
|
|||
namespace :api do
|
||||
namespace :v1 do
|
||||
resources :users, only: [:show, :index]
|
||||
resources :servers, only: [:index]
|
||||
resources :maps, only: [:index]
|
||||
end
|
||||
end
|
||||
|
||||
root to: "articles#news_index"
|
||||
root to: "articles#news_index"
|
||||
|
||||
resources :articles do
|
||||
resources :versions
|
||||
end
|
||||
resources :articles do
|
||||
resources :versions
|
||||
end
|
||||
|
||||
match 'contests/del_map'
|
||||
match 'contests/scores'
|
||||
match 'contests/historical', to: "contests#historical"
|
||||
|
||||
resources :contests do
|
||||
get 'current', on: :collection
|
||||
end
|
||||
resources :contests do
|
||||
get 'current', on: :collection
|
||||
end
|
||||
|
||||
resources :log_events
|
||||
resources :categories
|
||||
resources :options
|
||||
resources :polls
|
||||
resources :categories
|
||||
resources :options
|
||||
resources :polls
|
||||
|
||||
match 'comments/quote'
|
||||
|
||||
resources :comments
|
||||
resources :shoutmsgs
|
||||
resources :teamers
|
||||
resources :teams
|
||||
resources :gathers
|
||||
resources :gatherers
|
||||
resources :groups
|
||||
resources :groupers
|
||||
resources :forumers
|
||||
resources :topics
|
||||
resources :comments
|
||||
resources :shoutmsgs
|
||||
resources :teamers
|
||||
resources :teams
|
||||
resources :gathers
|
||||
resources :gatherers
|
||||
resources :groups
|
||||
resources :groupers
|
||||
resources :forumers
|
||||
resources :topics
|
||||
|
||||
match 'forums/up'
|
||||
match 'forums/down'
|
||||
|
||||
resources :forums
|
||||
resources :users
|
||||
resources :locks
|
||||
resources :contesters
|
||||
resources :contests
|
||||
resources :challenges
|
||||
resources :servers
|
||||
resources :predictions
|
||||
resources :rounds
|
||||
resources :matches do |m|
|
||||
resources :forums
|
||||
resources :users
|
||||
resources :locks
|
||||
resources :contesters
|
||||
resources :contests
|
||||
resources :challenges
|
||||
resources :servers
|
||||
resources :predictions
|
||||
resources :rounds
|
||||
resources :matches do |m|
|
||||
get :admin, to: "matches#admin", on: :collection
|
||||
get :ref, to: "matches#ref"
|
||||
end
|
||||
|
||||
resources :maps
|
||||
resources :logs
|
||||
resources :log_files
|
||||
resources :directories
|
||||
resources :maps
|
||||
resources :logs
|
||||
resources :log_files
|
||||
resources :directories
|
||||
resources :data_files
|
||||
resources :predictions
|
||||
resources :weeks
|
||||
resources :movies
|
||||
resources :messages
|
||||
resources :sites
|
||||
resources :bans
|
||||
resources :tweets
|
||||
resources :issues
|
||||
resources :predictions
|
||||
resources :weeks
|
||||
resources :movies
|
||||
resources :messages
|
||||
resources :sites
|
||||
resources :bans
|
||||
resources :tweets
|
||||
resources :issues
|
||||
|
||||
match 'posts/quote'
|
||||
|
||||
resources :posts
|
||||
resources :brackets
|
||||
resources :posts
|
||||
resources :brackets
|
||||
|
||||
match 'about/action'
|
||||
match 'about/staff'
|
||||
|
@ -127,10 +129,10 @@ Ensl::Application.routes.draw do
|
|||
|
||||
match 'votes/create'
|
||||
|
||||
match ':controller/:action', requirements: { action: /A-Za-z/ }
|
||||
match ':controller/:action/:id'
|
||||
match ':controller/:action/:id.:format'
|
||||
match ':controller/:action/:id/:id2'
|
||||
match ':controller/:action', requirements: { action: /A-Za-z/ }
|
||||
match ':controller/:action/:id'
|
||||
match ':controller/:action/:id.:format'
|
||||
match ':controller/:action/:id/:id2'
|
||||
|
||||
match 'teamers/replace', to: 'teamers#replace', as: 'teamers_replace'
|
||||
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
|
20
spec/controllers/api/v1/servers_controller_spec.rb
Normal file
20
spec/controllers/api/v1/servers_controller_spec.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Api::V1::ServersController do
|
||||
before do
|
||||
request.accept = 'application/json'
|
||||
end
|
||||
|
||||
describe '#index' do
|
||||
let!(:server) { create :server, :active }
|
||||
let!(:inactive_server) { create :server, :inactive }
|
||||
|
||||
it 'returns a list of servers' do
|
||||
get :index
|
||||
expect(response).to be_success
|
||||
expect(json['servers'].length).to eq(1)
|
||||
json_server = json['servers'][0]
|
||||
expect(json_server['id']).to eq(server.id)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -6,8 +6,8 @@ describe Api::V1::UsersController do
|
|||
end
|
||||
|
||||
describe '#show' do
|
||||
before do
|
||||
@user = create :user_with_team, :chris
|
||||
before(:each) do
|
||||
@user = create :user, :chris
|
||||
end
|
||||
|
||||
it 'returns user data' do
|
||||
|
@ -22,6 +22,10 @@ describe Api::V1::UsersController do
|
|||
expect(json).to have_key("steam")
|
||||
expect(json['steam']).to have_key("url")
|
||||
expect(json['steam']).to have_key("nickname")
|
||||
expect(json['bans']['mute']).to eq(false)
|
||||
expect(json['bans']['gather']).to eq(false)
|
||||
expect(json['bans']['site']).to eq(false)
|
||||
expect(json['team']).to be_nil
|
||||
end
|
||||
|
||||
it 'returns 404 if user does not exist' do
|
||||
|
@ -29,6 +33,33 @@ describe Api::V1::UsersController do
|
|||
get :show, id: -1
|
||||
}.to raise_error(ActionController::RoutingError)
|
||||
end
|
||||
|
||||
it 'returns correct ban if user muted' do
|
||||
create :ban, :mute, user: @user
|
||||
get :show, id: @user.id
|
||||
expect(response).to be_success
|
||||
expect(json['bans']['mute']).to eq(true)
|
||||
end
|
||||
it 'returns correct ban if user gather banned' do
|
||||
create :ban, :gather, user: @user
|
||||
get :show, id: @user.id
|
||||
expect(response).to be_success
|
||||
expect(json['bans']['gather']).to eq(true)
|
||||
end
|
||||
it 'returns correct ban if user site banned' do
|
||||
create :ban, :site, user: @user
|
||||
get :show, id: @user.id
|
||||
expect(response).to be_success
|
||||
expect(json['bans']['site']).to eq(true)
|
||||
end
|
||||
it 'returns team information' do
|
||||
@user.destroy
|
||||
@user_with_team = create :user_with_team, :chris
|
||||
get :show, id: @user_with_team.id
|
||||
expect(response).to be_success
|
||||
expect(json['team']['id']).to eq(@user_with_team.team.id)
|
||||
expect(json['team']['name']).to eq(@user_with_team.team.name)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#index' do
|
||||
|
|
|
@ -1,23 +1,31 @@
|
|||
FactoryGirl.define do
|
||||
factory :ban do
|
||||
ban_type Ban::TYPE_SITE
|
||||
expiry Date.today + 1
|
||||
# Hack because of the awkward way bans are created (requires user_name)
|
||||
before(:create) do |ban|
|
||||
if ban.user.nil?
|
||||
user = create :user
|
||||
ban.user_name = user.username
|
||||
else
|
||||
ban.user_name = ban.user.username
|
||||
end
|
||||
end
|
||||
end
|
||||
factory :ban do
|
||||
ban_type Ban::TYPE_SITE
|
||||
expiry Date.today + 1
|
||||
# Hack because of the awkward way bans are created (requires user_name)
|
||||
before(:create) do |ban|
|
||||
if ban.user.nil?
|
||||
user = create :user
|
||||
ban.user_name = user.username
|
||||
else
|
||||
ban.user_name = ban.user.username
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
trait :mute do
|
||||
ban_type Ban::TYPE_MUTE
|
||||
end
|
||||
trait :mute do
|
||||
ban_type Ban::TYPE_MUTE
|
||||
end
|
||||
|
||||
trait :expired do
|
||||
expiry Date.yesterday - 1
|
||||
end
|
||||
trait :site do
|
||||
ban_type Ban::TYPE_SITE
|
||||
end
|
||||
|
||||
trait :gather do
|
||||
ban_type Ban::TYPE_GATHER
|
||||
end
|
||||
|
||||
trait :expired do
|
||||
expiry Date.yesterday - 1
|
||||
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
|
|
@ -1,8 +1,16 @@
|
|||
FactoryGirl.define do
|
||||
factory :server do
|
||||
sequence(:name) { |n| "ServerName#{n}" }
|
||||
sequence(:dns) { |n| "DNS#{n}" }
|
||||
sequence(:ip) { |n| "192.168.#{n % 255}.#{n}" }
|
||||
sequence(:port) { |n| "#{1000 + n}" }
|
||||
end
|
||||
factory :server do
|
||||
sequence(:name) { |n| "ServerName#{n}" }
|
||||
sequence(:dns) { |n| "DNS#{n}" }
|
||||
sequence(:ip) { |n| "192.168.#{n % 255}.#{n}" }
|
||||
sequence(:port) { |n| "#{1000 + n}" }
|
||||
|
||||
trait :active do
|
||||
active true
|
||||
end
|
||||
|
||||
trait :inactive do
|
||||
active false
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue