Merge branch 'develop'

This commit is contained in:
Luke Barratt 2015-08-23 10:44:43 +01:00
commit f54ed83673
38 changed files with 947 additions and 409 deletions

View file

@ -1,9 +1,9 @@
source 'http://rubygems.org' source 'http://rubygems.org'
ruby '2.1.5' ruby '2.2.2'
gem 'dotenv-rails', '~> 0.10.0' gem 'dotenv-rails', '~> 0.10.0'
gem 'rails', '~> 3.2.19' gem 'rails', '~> 3.2.22'
gem 'mysql2', '~> 0.3.15' gem 'mysql2', '~> 0.3.15'
gem 'dalli', '~> 2.7.0' gem 'dalli', '~> 2.7.0'
gem 'puma', '~> 2.11.1' gem 'puma', '~> 2.11.1'
@ -23,6 +23,7 @@ gem 'country_code_select', '~> 1.0.1'
gem 'active_link_to', '~> 1.0.2' gem 'active_link_to', '~> 1.0.2'
gem 'rmagick', '~> 2.13.4', require: false gem 'rmagick', '~> 2.13.4', require: false
gem 'steam-condenser', github: 'koraktor/steam-condenser-ruby' gem 'steam-condenser', github: 'koraktor/steam-condenser-ruby'
gem 'test-unit', '~> 3.1.3'
# Please install nodejs locally. # Please install nodejs locally.
gem 'therubyracer', '~> 0.12.1' if RUBY_PLATFORM == 'x86_64-linux' gem 'therubyracer', '~> 0.12.1' if RUBY_PLATFORM == 'x86_64-linux'
@ -59,8 +60,8 @@ group :test do
gem 'simplecov', '~> 0.7.1', require: false gem 'simplecov', '~> 0.7.1', require: false
gem 'codeclimate-test-reporter', '~> 0.3.0', require: nil gem 'codeclimate-test-reporter', '~> 0.3.0', require: nil
gem 'database_cleaner', '~> 1.2.0' gem 'database_cleaner', '~> 1.2.0'
gem 'rspec-rails', '~> 2.14.1' gem 'rspec-rails', '~> 3.3.3'
gem 'capybara', '~> 2.2.1' gem 'capybara', '~> 2.4.4'
gem 'poltergeist', '~> 1.6.0' gem 'poltergeist', '~> 1.6.0'
gem 'selenium-webdriver', '~> 2.41.0' gem 'selenium-webdriver', '~> 2.41.0'
gem 'factory_girl_rails', '~> 4.4.1' gem 'factory_girl_rails', '~> 4.4.1'

View file

@ -9,12 +9,12 @@ GIT
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
actionmailer (3.2.19) actionmailer (3.2.22)
actionpack (= 3.2.19) actionpack (= 3.2.22)
mail (~> 2.5.4) mail (~> 2.5.4)
actionpack (3.2.19) actionpack (3.2.22)
activemodel (= 3.2.19) activemodel (= 3.2.22)
activesupport (= 3.2.19) activesupport (= 3.2.22)
builder (~> 3.0.0) builder (~> 3.0.0)
erubis (~> 2.7.0) erubis (~> 2.7.0)
journey (~> 1.0.4) journey (~> 1.0.4)
@ -24,18 +24,18 @@ GEM
sprockets (~> 2.2.1) sprockets (~> 2.2.1)
active_link_to (1.0.2) active_link_to (1.0.2)
actionpack actionpack
activemodel (3.2.19) activemodel (3.2.22)
activesupport (= 3.2.19) activesupport (= 3.2.22)
builder (~> 3.0.0) builder (~> 3.0.0)
activerecord (3.2.19) activerecord (3.2.22)
activemodel (= 3.2.19) activemodel (= 3.2.22)
activesupport (= 3.2.19) activesupport (= 3.2.22)
arel (~> 3.0.2) arel (~> 3.0.2)
tzinfo (~> 0.3.29) tzinfo (~> 0.3.29)
activeresource (3.2.19) activeresource (3.2.22)
activemodel (= 3.2.19) activemodel (= 3.2.22)
activesupport (= 3.2.19) activesupport (= 3.2.22)
activesupport (3.2.19) activesupport (3.2.22)
i18n (~> 0.6, >= 0.6.4) i18n (~> 0.6, >= 0.6.4)
multi_json (~> 1.0) multi_json (~> 1.0)
annotate (2.6.3) annotate (2.6.3)
@ -69,7 +69,7 @@ GEM
capistrano-rbenv (2.0.2) capistrano-rbenv (2.0.2)
capistrano (~> 3.1) capistrano (~> 3.1)
sshkit (~> 1.3) sshkit (~> 1.3)
capybara (2.2.1) capybara (2.4.4)
mime-types (>= 1.16) mime-types (>= 1.16)
nokogiri (>= 1.3.3) nokogiri (>= 1.3.3)
rack (>= 1.0.0) rack (>= 1.0.0)
@ -122,19 +122,19 @@ GEM
haml (4.0.5) haml (4.0.5)
tilt tilt
hike (1.2.3) hike (1.2.3)
i18n (0.6.11) i18n (0.7.0)
journey (1.0.4) journey (1.0.4)
jquery-rails (2.0.3) jquery-rails (2.0.3)
railties (>= 3.1.0, < 5.0) railties (>= 3.1.0, < 5.0)
thor (~> 0.14) thor (~> 0.14)
json (1.8.1) json (1.8.3)
mail (2.5.4) mail (2.5.4)
mime-types (~> 1.16) mime-types (~> 1.16)
treetop (~> 1.4.8) treetop (~> 1.4.8)
method_source (0.8.2) method_source (0.8.2)
mime-types (1.25.1) mime-types (1.25.1)
mini_portile (0.5.3) mini_portile (0.6.2)
multi_json (1.10.1) multi_json (1.11.2)
multi_xml (0.5.5) multi_xml (0.5.5)
multipart-post (2.0.0) multipart-post (2.0.0)
mysql2 (0.3.15) mysql2 (0.3.15)
@ -145,8 +145,8 @@ GEM
net-ssh (>= 2.6.5) net-ssh (>= 2.6.5)
net-ssh (2.9.0) net-ssh (2.9.0)
newrelic_rpm (3.7.2.195) newrelic_rpm (3.7.2.195)
nokogiri (1.6.1) nokogiri (1.6.6.2)
mini_portile (~> 0.5.0) mini_portile (~> 0.6.0)
oj (2.5.5) oj (2.5.5)
poltergeist (1.6.0) poltergeist (1.6.0)
capybara (~> 2.1) capybara (~> 2.1)
@ -154,6 +154,7 @@ GEM
multi_json (~> 1.0) multi_json (~> 1.0)
websocket-driver (>= 0.2.0) websocket-driver (>= 0.2.0)
polyglot (0.3.5) polyglot (0.3.5)
power_assert (0.2.4)
pry (0.9.12.6) pry (0.9.12.6)
coderay (~> 1.0) coderay (~> 1.0)
method_source (~> 0.8) method_source (~> 0.8)
@ -165,46 +166,51 @@ GEM
rack (>= 1.1, < 2.0) rack (>= 1.1, < 2.0)
quiet_assets (1.0.2) quiet_assets (1.0.2)
railties (>= 3.1, < 5.0) railties (>= 3.1, < 5.0)
rack (1.4.5) rack (1.4.7)
rack-cache (1.2) rack-cache (1.2)
rack (>= 0.4) rack (>= 0.4)
rack-ssl (1.3.4) rack-ssl (1.3.4)
rack rack
rack-test (0.6.2) rack-test (0.6.3)
rack (>= 1.0) rack (>= 1.0)
rails (3.2.19) rails (3.2.22)
actionmailer (= 3.2.19) actionmailer (= 3.2.22)
actionpack (= 3.2.19) actionpack (= 3.2.22)
activerecord (= 3.2.19) activerecord (= 3.2.22)
activeresource (= 3.2.19) activeresource (= 3.2.22)
activesupport (= 3.2.19) activesupport (= 3.2.22)
bundler (~> 1.0) bundler (~> 1.0)
railties (= 3.2.19) railties (= 3.2.22)
rails_autolink (1.1.5) rails_autolink (1.1.5)
rails (> 3.1) rails (> 3.1)
railties (3.2.19) railties (3.2.22)
actionpack (= 3.2.19) actionpack (= 3.2.22)
activesupport (= 3.2.19) activesupport (= 3.2.22)
rack-ssl (~> 1.3.2) rack-ssl (~> 1.3.2)
rake (>= 0.8.7) rake (>= 0.8.7)
rdoc (~> 3.4) rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0) thor (>= 0.14.6, < 2.0)
rake (10.3.2) rake (10.4.2)
rdoc (3.12.2) rdoc (3.12.2)
json (~> 1.4) json (~> 1.4)
rmagick (2.13.4) rmagick (2.13.4)
rspec-core (2.14.8) rspec-core (3.3.2)
rspec-expectations (2.14.5) rspec-support (~> 3.3.0)
diff-lcs (>= 1.1.3, < 2.0) rspec-expectations (3.3.1)
rspec-mocks (2.14.6) diff-lcs (>= 1.2.0, < 2.0)
rspec-rails (2.14.2) rspec-support (~> 3.3.0)
actionpack (>= 3.0) rspec-mocks (3.3.2)
activemodel (>= 3.0) diff-lcs (>= 1.2.0, < 2.0)
activesupport (>= 3.0) rspec-support (~> 3.3.0)
railties (>= 3.0) rspec-rails (3.3.3)
rspec-core (~> 2.14.0) actionpack (>= 3.0, < 4.3)
rspec-expectations (~> 2.14.0) activesupport (>= 3.0, < 4.3)
rspec-mocks (~> 2.14.0) railties (>= 3.0, < 4.3)
rspec-core (~> 3.3.0)
rspec-expectations (~> 3.3.0)
rspec-mocks (~> 3.3.0)
rspec-support (~> 3.3.0)
rspec-support (3.3.0)
rubyzip (1.1.3) rubyzip (1.1.3)
sanitize (2.1.0) sanitize (2.1.0)
nokogiri (>= 1.4.4) nokogiri (>= 1.4.4)
@ -223,7 +229,7 @@ GEM
simplecov-html (~> 0.7.1) simplecov-html (~> 0.7.1)
simplecov-html (0.7.1) simplecov-html (0.7.1)
slop (3.5.0) slop (3.5.0)
sprockets (2.2.2) sprockets (2.2.3)
hike (~> 1.2) hike (~> 1.2)
multi_json (~> 1.0) multi_json (~> 1.0)
rack (~> 1.0) rack (~> 1.0)
@ -234,6 +240,8 @@ GEM
term-ansicolor term-ansicolor
term-ansicolor (1.3.0) term-ansicolor (1.3.0)
tins (~> 1.0) tins (~> 1.0)
test-unit (3.1.3)
power_assert
thor (0.19.1) thor (0.19.1)
tilt (1.4.1) tilt (1.4.1)
timecop (0.7.1) timecop (0.7.1)
@ -243,7 +251,7 @@ GEM
treetop (1.4.15) treetop (1.4.15)
polyglot polyglot
polyglot (>= 0.3.1) polyglot (>= 0.3.1)
tzinfo (0.3.41) tzinfo (0.3.44)
uglifier (2.5.0) uglifier (2.5.0)
execjs (>= 0.3.0) execjs (>= 0.3.0)
json (>= 1.8.0) json (>= 1.8.0)
@ -270,7 +278,7 @@ DEPENDENCIES
capistrano-bundler (~> 1.1.2) capistrano-bundler (~> 1.1.2)
capistrano-rails (~> 1.1) capistrano-rails (~> 1.1)
capistrano-rbenv (~> 2.0.2) capistrano-rbenv (~> 2.0.2)
capybara (~> 2.2.1) capybara (~> 2.4.4)
carrierwave (~> 0.10.0) carrierwave (~> 0.10.0)
codeclimate-test-reporter (~> 0.3.0) codeclimate-test-reporter (~> 0.3.0)
coffee-rails (~> 3.2.2) coffee-rails (~> 3.2.2)
@ -294,10 +302,10 @@ DEPENDENCIES
pry-byebug (~> 1.3.2) pry-byebug (~> 1.3.2)
puma (~> 2.11.1) puma (~> 2.11.1)
quiet_assets (~> 1.0.2) quiet_assets (~> 1.0.2)
rails (~> 3.2.19) rails (~> 3.2.22)
rails_autolink (~> 1.1.5) rails_autolink (~> 1.1.5)
rmagick (~> 2.13.4) rmagick (~> 2.13.4)
rspec-rails (~> 2.14.1) rspec-rails (~> 3.3.3)
sanitize (~> 2.1.0) sanitize (~> 2.1.0)
sass (~> 3.3.4) sass (~> 3.3.4)
sass-rails (~> 3.2.6) sass-rails (~> 3.2.6)
@ -305,7 +313,11 @@ DEPENDENCIES
simplecov (~> 0.7.1) simplecov (~> 0.7.1)
sprockets (~> 2.2.1) sprockets (~> 2.2.1)
steam-condenser! steam-condenser!
test-unit (~> 3.1.3)
timecop (~> 0.7.1) timecop (~> 0.7.1)
tinymce-rails (~> 3.5.9) tinymce-rails (~> 3.5.9)
uglifier (~> 2.5.0) uglifier (~> 2.5.0)
will_paginate (~> 3.0.5) will_paginate (~> 3.0.5)
BUNDLED WITH
1.10.5

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

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

View file

@ -17,7 +17,15 @@ class Api::V1::UsersController < Api::V1::BaseController
steam: { steam: {
url: @steam.base_url, url: @steam.base_url,
nickname: @steam.nickname 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')
end end
end end

View file

@ -2,7 +2,6 @@ class PluginController < ApplicationController
def user def user
buffer = [] buffer = []
out = [] out = []
if ban = Ban.first(:conditions => ["expiry > UTC_TIMESTAMP() AND steamid = ? AND ban_type = ?", params[:id], Ban::TYPE_SERVER]) if ban = Ban.first(:conditions => ["expiry > UTC_TIMESTAMP() AND steamid = ? AND ban_type = ?", params[:id], Ban::TYPE_SERVER])
out << "#USER#" out << "#USER#"
out << "BANNED" out << "BANNED"
@ -31,7 +30,7 @@ class PluginController < ApplicationController
buffer << user.steamid buffer << user.steamid
buffer << user.username buffer << user.username
buffer << user.lastip buffer << '0.0.0.0'
buffer << (user.team ? Verification.uncrap(user.team.to_s) : "No Team") buffer << (user.team ? Verification.uncrap(user.team.to_s) : "No Team")
buffer << user.id buffer << user.id
buffer << user.team_id buffer << user.team_id

View file

@ -15,7 +15,6 @@ class ShoutmsgsController < ApplicationController
def create def create
@shoutmsg = Shoutmsg.new params[:shoutmsg] @shoutmsg = Shoutmsg.new params[:shoutmsg]
puts @shoutmsg
@shoutmsg.user = cuser @shoutmsg.user = cuser
raise AccessError unless @shoutmsg.can_create? cuser raise AccessError unless @shoutmsg.can_create? cuser

View file

@ -32,12 +32,6 @@ class Topic < ActiveRecord::Base
scope :basic, :include => [:latest, { forum: :forumer }, :user] scope :basic, :include => [:latest, { forum: :forumer }, :user]
scope :ordered, :order => "state DESC, posts.id DESC" scope :ordered, :order => "state DESC, posts.id DESC"
scope :recent,
:conditions => "forumers.id IS NULL AND posts.id = (SELECT id FROM posts AS P WHERE P.topic_id = topics.id ORDER BY id DESC LIMIT 1)",
:order => "posts.id DESC",
:group => "topics.id"
scope :latest_page,
lambda { |page| {:limit => "#{(page-1)*LATEST_PER_PAGE}, #{(page-1)*LATEST_PER_PAGE+LATEST_PER_PAGE}"} }
validates_presence_of :user_id, :forum_id validates_presence_of :user_id, :forum_id
validates_length_of :title, :in => 1..50 validates_length_of :title, :in => 1..50
@ -47,6 +41,24 @@ class Topic < ActiveRecord::Base
acts_as_readable acts_as_readable
def self.recent_topics
find_by_sql %q{
SELECT DISTINCT topics.*
FROM (SELECT id, topic_id
FROM posts
ORDER BY id DESC
LIMIT 20) AS T
INNER JOIN topics
ON T.topic_id = topics.id
INNER JOIN forums
ON forums.id = topics.forum_id
LEFT OUTER JOIN forumers
ON forumers.forum_id = forums.id
WHERE forumers.id IS NULL
LIMIT 5
}
end
def to_s def to_s
title title
end end

View file

@ -1,5 +1,5 @@
<ol> <ol>
<% Topic.basic.recent.latest_page(page).each do |topic| %> <% Topic.recent_topics.each do |topic| %>
<li class="bold"> <li class="bold">
<%= link_to (h topic), lastpost(topic) %> <%= link_to (h topic), lastpost(topic) %>
</li> </li>

View file

@ -4,7 +4,7 @@
<div class="widget-content-wrapper"> <div class="widget-content-wrapper">
<div class="separator">Latest forum posts</div> <div class="separator">Latest forum posts</div>
<ol> <ol>
<% Topic.basic.recent.latest_page(1).each do |topic| %> <% Topic.recent_topics.each do |topic| %>
<li> <li>
<%= link_to shorten(topic, 28), lastpost(topic) %> <%= link_to shorten(topic, 28), lastpost(topic) %>
</li> </li>

View file

@ -9,7 +9,7 @@ set :repo_url, 'https://github.com/ENSL/ensl.org.git'
set :keep_releases, 10 set :keep_releases, 10
set :rbenv_type, :user set :rbenv_type, :user
set :rbenv_ruby, '2.1.5' set :rbenv_ruby, '2.2.2'
set :bundle_flags, '--quiet' set :bundle_flags, '--quiet'
set :dotenv_role, [:app, :web] set :dotenv_role, [:app, :web]

View file

@ -61,4 +61,7 @@ Ensl::Application.configure do
# Send deprecation notices to registered listeners # Send deprecation notices to registered listeners
config.active_support.deprecation = :notify config.active_support.deprecation = :notify
# Custom Session Store config to allow gathers.staging.ensl.org
# config.session_store :cookie_store, key: '_ENSL_session_key', expire_after: 30.days.to_i, domain: "gathers.ensl.org"
end end

View file

@ -61,4 +61,7 @@ Ensl::Application.configure do
# Send deprecation notices to registered listeners # Send deprecation notices to registered listeners
config.active_support.deprecation = :notify config.active_support.deprecation = :notify
# Custom Session Store config to allow gathers.staging.ensl.org
config.session_store :cookie_store, key: "_ENSL_session_key_staging", expire_after: 30.days.to_i, domain: ".staging.ensl.org"
end end

View file

@ -6,6 +6,8 @@ Ensl::Application.routes.draw do
namespace :api do namespace :api do
namespace :v1 do namespace :v1 do
resources :users, only: [:show, :index] resources :users, only: [:show, :index]
resources :servers, only: [:index]
resources :maps, only: [:index]
end end
end end

View file

@ -0,0 +1,6 @@
class AddIndexToForumers < ActiveRecord::Migration
def change
add_index :forumers, :forum_id
add_index :forumers, :group_id
end
end

View file

@ -11,7 +11,21 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20150701233306) do ActiveRecord::Schema.define(:version => 20150820223313) do
create_table "admin_requests", :force => true do |t|
t.string "addr"
t.string "pwd"
t.integer "server_id"
t.string "player"
t.integer "user_id"
t.string "msg"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "admin_requests", ["server_id"], :name => "index_admin_requests_on_server_id"
add_index "admin_requests", ["user_id"], :name => "index_admin_requests_on_user_id"
create_table "article_versions", :force => true do |t| create_table "article_versions", :force => true do |t|
t.integer "article_id" t.integer "article_id"
@ -200,6 +214,16 @@ ActiveRecord::Schema.define(:version => 20150701233306) do
add_index "data_files", ["directory_id"], :name => "index_data_files_on_directory_id" add_index "data_files", ["directory_id"], :name => "index_data_files_on_directory_id"
add_index "data_files", ["related_id"], :name => "index_data_files_on_related_id" add_index "data_files", ["related_id"], :name => "index_data_files_on_related_id"
create_table "deleteds", :force => true do |t|
t.integer "deletable_id"
t.string "deletable_type"
t.integer "user_id"
t.text "reason"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "related_id"
end
create_table "directories", :force => true do |t| create_table "directories", :force => true do |t|
t.string "name" t.string "name"
t.string "description" t.string "description"
@ -212,6 +236,21 @@ ActiveRecord::Schema.define(:version => 20150701233306) do
add_index "directories", ["parent_id"], :name => "index_directories_on_parent_id" add_index "directories", ["parent_id"], :name => "index_directories_on_parent_id"
create_table "firms", :force => true do |t|
t.string "name"
t.string "y_code"
t.string "email"
t.string "website"
t.string "phone"
t.string "address"
t.integer "zipcode"
t.string "town"
t.integer "owner"
t.string "opentime"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "forumers", :force => true do |t| create_table "forumers", :force => true do |t|
t.integer "forum_id" t.integer "forum_id"
t.integer "group_id" t.integer "group_id"
@ -220,6 +259,9 @@ ActiveRecord::Schema.define(:version => 20150701233306) do
t.datetime "updated_at" t.datetime "updated_at"
end end
add_index "forumers", ["forum_id"], :name => "index_forumers_on_forum_id"
add_index "forumers", ["group_id"], :name => "index_forumers_on_group_id"
create_table "forums", :force => true do |t| create_table "forums", :force => true do |t|
t.string "title" t.string "title"
t.string "description" t.string "description"
@ -340,6 +382,44 @@ ActiveRecord::Schema.define(:version => 20150701233306) do
add_index "locks", ["lockable_id", "lockable_type"], :name => "index_locks_on_lockable_id_and_lockable_type" add_index "locks", ["lockable_id", "lockable_type"], :name => "index_locks_on_lockable_id_and_lockable_type"
create_table "log_events", :force => true do |t|
t.string "name"
t.string "description"
t.integer "team"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "log_files", :force => true do |t|
t.string "name"
t.string "md5"
t.integer "size"
t.integer "server_id"
t.datetime "updated_at"
end
add_index "log_files", ["server_id"], :name => "index_log_files_on_server_id"
create_table "logs", :force => true do |t|
t.integer "server_id"
t.text "text"
t.integer "domain"
t.datetime "created_at"
t.integer "round_id"
t.string "details"
t.integer "actor_id"
t.integer "target_id"
t.string "specifics1"
t.string "specifics2"
t.integer "log_file_id"
end
add_index "logs", ["actor_id"], :name => "index_logs_on_actor_id"
add_index "logs", ["log_file_id"], :name => "index_logs_on_log_file_id"
add_index "logs", ["round_id"], :name => "index_logs_on_round_id"
add_index "logs", ["server_id"], :name => "index_logs_on_server_id"
add_index "logs", ["target_id"], :name => "index_logs_on_target_id"
create_table "maps", :force => true do |t| create_table "maps", :force => true do |t|
t.string "name" t.string "name"
t.string "download" t.string "download"
@ -441,6 +521,13 @@ ActiveRecord::Schema.define(:version => 20150701233306) do
add_index "movies", ["status"], :name => "index_movies_on_status" add_index "movies", ["status"], :name => "index_movies_on_status"
add_index "movies", ["user_id"], :name => "index_movies_on_user_id" add_index "movies", ["user_id"], :name => "index_movies_on_user_id"
create_table "nodes", :force => true do |t|
t.string "name"
t.integer "foreign_key"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "options", :force => true do |t| create_table "options", :force => true do |t|
t.string "option" t.string "option"
t.integer "poll_id" t.integer "poll_id"
@ -583,6 +670,42 @@ ActiveRecord::Schema.define(:version => 20150701233306) do
add_index "readings", ["user_id", "readable_id", "readable_type"], :name => "index_readings_on_user_id_and_readable_id_and_readable_type" add_index "readings", ["user_id", "readable_id", "readable_type"], :name => "index_readings_on_user_id_and_readable_id_and_readable_type"
add_index "readings", ["user_id"], :name => "index_readings_on_user_id" add_index "readings", ["user_id"], :name => "index_readings_on_user_id"
create_table "rounders", :force => true do |t|
t.integer "round_id"
t.integer "user_id"
t.integer "team"
t.string "roles"
t.integer "kills"
t.integer "deaths"
t.string "name"
t.string "steamid"
t.integer "team_id"
end
add_index "rounders", ["round_id"], :name => "index_rounders_on_round_id"
add_index "rounders", ["team_id"], :name => "index_rounders_on_team_id"
add_index "rounders", ["user_id"], :name => "index_rounders_on_user_id"
create_table "rounds", :force => true do |t|
t.integer "server_id"
t.datetime "start"
t.datetime "end"
t.integer "winner"
t.integer "match_id"
t.integer "commander_id"
t.integer "team1_id"
t.integer "team2_id"
t.string "map_name"
t.integer "map_id"
end
add_index "rounds", ["commander_id"], :name => "index_rounds_on_commander_id"
add_index "rounds", ["map_id"], :name => "index_rounds_on_map_id"
add_index "rounds", ["match_id"], :name => "index_rounds_on_match_id"
add_index "rounds", ["server_id"], :name => "index_rounds_on_server_id"
add_index "rounds", ["team1_id"], :name => "index_rounds_on_team1_id"
add_index "rounds", ["team2_id"], :name => "index_rounds_on_team2_id"
create_table "server_versions", :force => true do |t| create_table "server_versions", :force => true do |t|
t.integer "server_id" t.integer "server_id"
t.integer "version" t.integer "version"
@ -638,18 +761,6 @@ ActiveRecord::Schema.define(:version => 20150701233306) do
add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id" add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at" add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
create_table "shoutmsg_archive", :force => true do |t|
t.integer "user_id"
t.string "text"
t.datetime "created_at"
t.datetime "updated_at"
t.string "shoutable_type"
t.integer "shoutable_id"
end
add_index "shoutmsg_archive", ["shoutable_type", "shoutable_id"], :name => "index_shoutmsgs_on_shoutable_type_and_shoutable_id"
add_index "shoutmsg_archive", ["user_id"], :name => "index_shoutmsgs_on_user_id"
create_table "shoutmsgs", :force => true do |t| create_table "shoutmsgs", :force => true do |t|
t.integer "user_id" t.integer "user_id"
t.string "text" t.string "text"
@ -744,9 +855,13 @@ ActiveRecord::Schema.define(:version => 20150701233306) do
t.string "time_zone" t.string "time_zone"
t.integer "version" t.integer "version"
t.boolean "public_email", :default => false, :null => false t.boolean "public_email", :default => false, :null => false
t.string "salt"
end end
add_index "users", ["email"], :name => "index_users_on_email"
add_index "users", ["password"], :name => "index_users_on_password"
add_index "users", ["team_id"], :name => "index_users_on_team_id" add_index "users", ["team_id"], :name => "index_users_on_team_id"
add_index "users", ["username"], :name => "index_users_on_username"
create_table "versions", :force => true do |t| create_table "versions", :force => true do |t|
t.string "item_type", :null => false t.string "item_type", :null => false

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

View 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

View file

@ -6,8 +6,8 @@ describe Api::V1::UsersController do
end end
describe '#show' do describe '#show' do
before do before(:each) do
@user = create :user_with_team, :chris @user = create :user, :chris
end end
it 'returns user data' do it 'returns user data' do
@ -22,6 +22,46 @@ describe Api::V1::UsersController do
expect(json).to have_key("steam") expect(json).to have_key("steam")
expect(json['steam']).to have_key("url") expect(json['steam']).to have_key("url")
expect(json['steam']).to have_key("nickname") 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
expect {
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
end end

View file

@ -0,0 +1,29 @@
require 'spec_helper'
describe PluginController do
render_views
describe '#user' do
before do
create :group, :donors
create :group, :champions
end
let!(:user) { create :user_with_team }
it 'returns user data' do
get :user, id: user.steamid
expect(response).to be_success
expect(response.body).to include(user.username)
end
it 'definitely does not return IP address' do
last_ip = '127.0.0.1'
user.lastip = last_ip
user.save!
get :user, id: user.steamid
expect(response).to be_success
expect(response).to_not include(last_ip)
end
end
end

View file

@ -17,6 +17,14 @@ FactoryGirl.define do
ban_type Ban::TYPE_MUTE ban_type Ban::TYPE_MUTE
end end
trait :site do
ban_type Ban::TYPE_SITE
end
trait :gather do
ban_type Ban::TYPE_GATHER
end
trait :expired do trait :expired do
expiry Date.yesterday - 1 expiry Date.yesterday - 1
end end

6
spec/factories/forum.rb Normal file
View file

@ -0,0 +1,6 @@
FactoryGirl.define do
factory :forum do
sequence(:title) { |n| "Forum Title #{n}" }
sequence(:description) { |n| "Forum Description #{n}" }
end
end

View file

@ -0,0 +1,7 @@
FactoryGirl.define do
factory :forumer do
forum
group
access Forumer::ACCESS_TOPIC
end
end

View file

@ -9,4 +9,14 @@ FactoryGirl.define do
name "Admins" name "Admins"
id Group::ADMINS id Group::ADMINS
end end
trait :champions do
name "Champions"
id Group::CHAMPIONS
end
trait :donors do
name "Donors"
id Group::DONORS
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

7
spec/factories/post.rb Normal file
View file

@ -0,0 +1,7 @@
FactoryGirl.define do
factory :post do
sequence(:text) { |n| "Post Body #{n}" }
topic
user
end
end

View file

@ -4,5 +4,13 @@ FactoryGirl.define do
sequence(:dns) { |n| "DNS#{n}" } sequence(:dns) { |n| "DNS#{n}" }
sequence(:ip) { |n| "192.168.#{n % 255}.#{n}" } sequence(:ip) { |n| "192.168.#{n % 255}.#{n}" }
sequence(:port) { |n| "#{1000 + n}" } sequence(:port) { |n| "#{1000 + n}" }
trait :active do
active true
end
trait :inactive do
active false
end
end end
end end

10
spec/factories/topic.rb Normal file
View file

@ -0,0 +1,10 @@
FactoryGirl.define do
factory :topic do
sequence(:title) { |n| "Topic Title #{n}" }
forum
user
before(:create) do |topic|
topic.first_post = "My first post on the topic"
end
end
end

View file

@ -15,58 +15,64 @@
# ip :string(255) # ip :string(255)
# #
require 'spec_helper' require "spec_helper"
describe Ban do describe Ban do
let!(:user) { create :user } let!(:user) { create :user }
let(:ban) { Ban.new } let(:ban) { Ban.new }
let!(:server) { create :server } let!(:server) { create :server }
describe '#check_user' do describe "#check_user" do
it "assigns user by user_name" do it "assigns user by user_name" do
ban.user_name = user.username ban.user_name = user.username
ban.check_user ban.check_user
expect(ban.user).to eq(user) expect(ban.user).to eq(user)
end end
it "assigns user and server if user_name not present" do it "assigns user and server if user_name not present" do
ban.steamid = user.steamid ban.steamid = user.steamid
ban.addr = server.addr ban.addr = server.addr
ban.check_user ban.check_user
expect(ban.user).to eq(user) expect(ban.user).to eq(user)
expect(ban.server).to eq(server) expect(ban.server).to eq(server)
end end
end end
describe 'Permissions' do describe "Permissions" do
let!(:user) { create :user } let!(:user) { create :user }
let!(:admin) { create :user, :admin } let!(:admin) { create :user, :admin }
let!(:server_user) { create :user } let!(:server_user) { create :user }
let(:ban) { Ban.new } let(:ban) { Ban.new }
describe 'can_create?' do describe "can_create?" do
it 'returns true for admins' do it "returns true for admins" do
expect(ban.can_create? admin).to be_true expect(ban.can_create? admin).to be_truthy
end end
it 'returns false for non-admins' do
expect(ban.can_create? user).to be_false it "returns false for non-admins" do
expect(ban.can_create? user).to be_falsey
end end
end end
describe 'can_destroy?' do describe "can_destroy?" do
it 'returns true for admin' do it "returns true for admin" do
expect(ban.can_destroy? admin).to be_true expect(ban.can_destroy? admin).to be_truthy
end end
it 'returns false for non-admins' do
expect(ban.can_destroy? user).to be_false it "returns false for non-admins" do
expect(ban.can_destroy? user).to be_falsey
end end
end end
describe 'can_update?' do describe "can_update?" do
it 'returns true for admin' do it "returns true for admin" do
expect(ban.can_update? admin).to be_true expect(ban.can_update? admin).to be_truthy
end end
it 'returns false for non-admins' do
expect(ban.can_update? user).to be_false it "returns false for non-admins" do
expect(ban.can_update? user).to be_falsey
end end
end end
end end

29
spec/models/forum_spec.rb Normal file
View file

@ -0,0 +1,29 @@
# == Schema Information
#
# Table name: forums
#
# id :integer not null, primary key
# title :string(255)
# description :string(255)
# category_id :integer
# created_at :datetime
# updated_at :datetime
# position :integer
#
require "spec_helper"
describe Forum do
let!(:user) { create :user }
describe "create" do
let(:forum) { build :forum }
it "creates a new forum" do
expect(forum.valid?).to eq(true)
expect do
forum.save!
end.to change(Forum, :count).by(1)
end
end
end

View file

@ -0,0 +1,26 @@
# == Schema Information
#
# Table name: forumers
#
# id :integer not null, primary key
# forum_id :integer
# group_id :integer
# access :integer
# created_at :datetime
# updated_at :datetime
#
require "spec_helper"
describe Forumer do
describe "create" do
let(:forumer) { build :forumer }
it "creates a new forumer" do
expect(forumer.valid?).to eq(true)
expect do
forumer.save!
end.to change(Forumer, :count).by(1)
end
end
end

View file

@ -15,45 +15,52 @@
# text_parsed :text # text_parsed :text
# #
require 'spec_helper' require "spec_helper"
describe 'User' do describe "User" do
describe 'Permissions' do describe "Permissions" do
let!(:user) { create :user } let!(:user) { create :user }
let!(:admin) { create :user, :admin } let!(:admin) { create :user, :admin }
let(:issue) { Issue.new } let(:issue) { Issue.new }
describe 'can_show?' do describe "can_show?" do
it 'returns true for author' do it "returns true for author" do
issue.author = user issue.author = user
expect(issue.can_show? user).to be_true expect(issue.can_show? user).to be_truthy
end end
it 'returns true for admin' do
expect(issue.can_show? admin).to be_true it "returns true for admin" do
expect(issue.can_show? admin).to be_truthy
end end
it 'returns false if neither admin nor author' do
expect(issue.can_show? user).to be_false it "returns false if neither admin nor author" do
expect(issue.can_show? user).to be_falsey
end end
end end
describe 'can_create?' do
describe "can_create?" do
it "returns true" do it "returns true" do
expect(issue.can_create? nil).to be_true expect(issue.can_create? nil).to be_truthy
end end
end end
describe 'can_update?' do
it 'returns true for admin' do describe "can_update?" do
expect(issue.can_update? admin).to be_true it "returns true for admin" do
expect(issue.can_update? admin).to be_truthy
end end
it 'returns false for non-admin' do
expect(issue.can_update? user).to be_false it "returns false for non-admin" do
expect(issue.can_update? user).to be_falsey
end end
end end
describe 'can_destroy?' do
it 'returns true for admin' do describe "can_destroy?" do
expect(issue.can_destroy? admin).to be_true it "returns true for admin" do
expect(issue.can_destroy? admin).to be_truthy
end end
it 'returns false for non-admin' do
expect(issue.can_destroy? user).to be_false it "returns false for non-admin" do
expect(issue.can_destroy? user).to be_falsey
end end
end end
end end

View file

@ -14,43 +14,49 @@
# text_parsed :text # text_parsed :text
# #
require 'spec_helper' require "spec_helper"
describe Message do describe Message do
let!(:user) { create :user } let!(:user) { create :user }
describe 'create' do describe "create" do
let(:message) { build :message } let(:message) { build :message }
it 'creates a new message' do
expect(message.valid?).to be_true it "creates a new message" do
expect(message.valid?).to eq(true)
expect do expect do
message.save! message.save!
end.to change(Message, :count).by(1) end.to change(Message, :count).by(1)
end end
end end
describe 'Permissions' do describe "Permissions" do
let(:message) { Message.new } let(:message) { Message.new }
describe 'can_create?' do
it 'returns true for user' do describe "can_create?" do
expect(message.can_create?(user)).to be_true it "returns true for user" do
expect(message.can_create?(user)).to be_truthy
end end
it 'returns false if user is banned' do
it "returns false if user is banned" do
create :ban, :mute, user: user create :ban, :mute, user: user
expect(message.can_create?(user)).to be_false expect(message.can_create?(user)).to be_falsey
end end
end end
describe 'can_show?' do describe "can_show?" do
let!(:message) { create :message } let!(:message) { create :message }
it 'returns true if sender' do
expect(message.can_show?(message.sender)).to be_true it "returns true if sender" do
expect(message.can_show?(message.sender)).to be_truthy
end end
it 'returns true if receiver' do
expect(message.can_show?(message.recipient)).to be_true it "returns true if receiver" do
expect(message.can_show?(message.recipient)).to be_truthy
end end
it 'returns false if neither sender nor receiver' do
expect(message.can_show?(user)).to be_false it "returns false if neither sender nor receiver" do
expect(message.can_show?(user)).to be_falsey
end end
end end
end end

30
spec/models/post_spec.rb Normal file
View file

@ -0,0 +1,30 @@
# == Schema Information
#
# Table name: posts
#
# id :integer not null, primary key
# text :text
# topic_id :integer
# user_id :integer
# created_at :datetime
# updated_at :datetime
# text_parsed :text
#
require "spec_helper"
describe Post do
let!(:user) { create :user }
describe "create" do
let(:post) { build :post }
it "creates a new post" do
# expect(post.valid?).to eq(true)
post.topic = create :topic
expect do
post.save!
end.to change(Post, :count).by(1)
end
end
end

View file

@ -30,67 +30,75 @@
# category_id :integer # category_id :integer
# #
require 'spec_helper' require "spec_helper"
describe Server do describe Server do
describe 'create' do describe "create" do
it 'sets category to 45 if domain is NS2' do it "sets category to 45 if domain is NS2" do
server = create :server, domain: Server::DOMAIN_NS2 server = create :server, domain: Server::DOMAIN_NS2
expect(server.category_id).to eq(45) expect(server.category_id).to eq(45)
end end
it 'sets category to 44 if domain is not NS2' do
it "sets category to 44 if domain is not NS2" do
server = create :server, domain: Server::DOMAIN_HLDS server = create :server, domain: Server::DOMAIN_HLDS
expect(server.category_id).to eq(44) expect(server.category_id).to eq(44)
end end
end end
describe 'addr' do describe "addr" do
it 'returns properly formatted IP and port number' do it "returns properly formatted IP and port number" do
ip = '1.1.1.1' ip = "1.1.1.1"
port = '8000' port = "8000"
server = create :server, ip: ip, port: port server = create :server, ip: ip, port: port
expect(server.addr).to eq('1.1.1.1:8000')
expect(server.addr).to eq("1.1.1.1:8000")
end end
end end
describe 'to_s' do describe "to_s" do
it 'returns server name' do it "returns server name" do
server_name = "Foo" server_name = "Foo"
server = create :server, name: server_name server = create :server, name: server_name
expect(server.to_s).to eq(server_name) expect(server.to_s).to eq(server_name)
end end
end end
describe 'Permissions' do describe "Permissions" do
let!(:user) { create :user } let!(:user) { create :user }
let!(:admin) { create :user, :admin } let!(:admin) { create :user, :admin }
let!(:server_user) {create :user } let!(:server_user) { create :user }
let!(:server) { create :server, user: server_user } let!(:server) { create :server, user: server_user }
describe 'can_create?' do describe "can_create?" do
it 'returns true for non-admins' do it "returns true for non-admins" do
expect(server.can_create? user).to be_true expect(server.can_create? user).to be_truthy
end end
end end
describe 'can_destroy?' do describe "can_destroy?" do
it 'returns true for admin' do it "returns true for admin" do
expect(server.can_destroy? admin).to be_true expect(server.can_destroy? admin).to eq(true)
end end
it 'returns false for non-admins' do
expect(server.can_destroy? user).to be_false it "returns false for non-admins" do
expect(server.can_destroy? user).to eq(false)
end end
end end
describe 'can_update?' do describe "can_update?" do
it 'returns true for admin' do it "returns true for admin" do
expect(server.can_update? admin).to be_true expect(server.can_update? admin).to eq(true)
end end
it 'returns true if server belongs to user' do
expect(server.can_update? server_user).to be_true it "returns true if server belongs to user" do
expect(server.can_update? server_user).to eq(true)
end end
it 'returns false for non-admins' do
expect(server.can_update? user).to be_false it "returns false for non-admins" do
expect(server.can_update? user).to eq(false)
end end
end end
end end

51
spec/models/topic_spec.rb Normal file
View file

@ -0,0 +1,51 @@
# == Schema Information
#
# Table name: topics
#
# id :integer not null, primary key
# title :string(255)
# user_id :integer
# forum_id :integer
# created_at :datetime
# updated_at :datetime
# state :integer default(0), not null
#
require "spec_helper"
describe Topic do
let!(:user) { create :user }
let!(:forum) { create :forum }
describe "create" do
let(:topic) { build :topic, user: user, forum: forum }
it "creates a new topic" do
topic.first_post = "Foo"
expect do
topic.save!
end.to change(Topic, :count).by(1)
end
end
describe ".recent_topics" do
it "returns 5 unique, most recently posted topics" do
topics = []
6.times do
topic = create :topic
topics << topic
3.times { create :post, topic: topic }
end
recent_topics = Topic.recent_topics
topics.last(5).each do |topic|
expect(recent_topics).to include(topic)
end
end
it "does not return posts from restricted forums" do
restricted_topic = create :topic, title: "Restricted"
create :forumer, forum: restricted_topic.forum
create :post, topic: restricted_topic
expect(Topic.recent_topics).to_not include(restricted_topic)
end
end
end

View file

@ -19,6 +19,7 @@
# time_zone :string(255) # time_zone :string(255)
# version :integer # version :integer
# public_email :boolean default(FALSE), not null # public_email :boolean default(FALSE), not null
# salt :string(255)
# #
require 'spec_helper' require 'spec_helper'
@ -28,17 +29,23 @@ describe User do
describe "#banned?" do describe "#banned?" do
it "returns false if user is not banned" do it "returns false if user is not banned" do
expect(user.banned?).to be_false expect(user.banned?).to be_falsey
end end
it "returns true if user is banned" do it "returns true if user is banned" do
ban = Ban.create! ban_type: Ban::TYPE_SITE, expiry: Time.now + 10.days, user_name: user.username Ban.create!(ban_type: Ban::TYPE_SITE,
expect(user.banned?).to be_true expiry: Time.now + 10.days,
user_name: user.username)
expect(user.banned?).to be_truthy
end end
it "returns true for specific bans" do it "returns true for specific bans" do
ban = Ban.create! ban_type: Ban::TYPE_MUTE, expiry: Time.now + 10.days, user_name: user.username Ban.create!(ban_type: Ban::TYPE_MUTE,
expect(user.banned? Ban::TYPE_MUTE).to be_true expiry: Time.now + 10.days,
user_name: user.username)
expect(user.banned? Ban::TYPE_MUTE).to be_truthy
end end
end end
end end

View file

@ -10,7 +10,7 @@ require 'rspec/rails'
require 'capybara/rspec' require 'capybara/rspec'
require 'capybara/poltergeist' require 'capybara/poltergeist'
Capybara.default_wait_time = 30 Capybara.default_wait_time = 5
Capybara.register_driver :poltergeist do |app| Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, Capybara::Poltergeist::Driver.new(app,
timeout: 30, timeout: 30,
@ -34,6 +34,7 @@ RSpec.configure do |config|
config.use_transactional_fixtures = false config.use_transactional_fixtures = false
config.color = true config.color = true
config.formatter = :documentation config.formatter = :documentation
config.infer_spec_type_from_file_location!
config.before(:each) do config.before(:each) do
events_list_json = JSON.parse(File.read(Rails.root.join('spec/fixtures/google_calendar.json'))) events_list_json = JSON.parse(File.read(Rails.root.join('spec/fixtures/google_calendar.json')))