From 7a18fd2ec2ad5c6781df959aa1987d37c568dc8d Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Wed, 22 Jul 2015 17:22:38 +0100 Subject: [PATCH 01/30] Return 404 if user not found --- app/controllers/api/v1/users_controller.rb | 2 ++ spec/controllers/api/v1/users_controller_spec.rb | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index 2762f2c..9a22225 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -19,5 +19,7 @@ class Api::V1::UsersController < Api::V1::BaseController nickname: @steam.nickname } } + rescue ActiveRecord::RecordNotFound + raise ActionController::RoutingError.new('User Not Found') end end diff --git a/spec/controllers/api/v1/users_controller_spec.rb b/spec/controllers/api/v1/users_controller_spec.rb index 0fa31b2..73f1740 100644 --- a/spec/controllers/api/v1/users_controller_spec.rb +++ b/spec/controllers/api/v1/users_controller_spec.rb @@ -23,6 +23,12 @@ describe Api::V1::UsersController do expect(json['steam']).to have_key("url") expect(json['steam']).to have_key("nickname") end + + it 'returns 404 if user does not exist' do + expect { + get :show, id: -1 + }.to raise_error(ActionController::RoutingError) + end end describe '#index' do From 9736ca4d102a3bf5b251907e1173254aab17934a Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Sat, 1 Aug 2015 16:20:49 +0100 Subject: [PATCH 02/30] Added server api --- app/controllers/api/v1/servers_controller.rb | 21 ++++ config/routes.rb | 97 ++++++++++--------- .../api/v1/servers_controller_spec.rb | 20 ++++ spec/factories/server.rb | 20 ++-- 4 files changed, 104 insertions(+), 54 deletions(-) create mode 100644 app/controllers/api/v1/servers_controller.rb create mode 100644 spec/controllers/api/v1/servers_controller_spec.rb diff --git a/app/controllers/api/v1/servers_controller.rb b/app/controllers/api/v1/servers_controller.rb new file mode 100644 index 0000000..fe5a6cf --- /dev/null +++ b/app/controllers/api/v1/servers_controller.rb @@ -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 \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 483f9d2..0cf0a48 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,76 +6,77 @@ Ensl::Application.routes.draw do namespace :api do namespace :v1 do resources :users, only: [:show, :index] + resources :servers, 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 +128,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 diff --git a/spec/controllers/api/v1/servers_controller_spec.rb b/spec/controllers/api/v1/servers_controller_spec.rb new file mode 100644 index 0000000..8b55eec --- /dev/null +++ b/spec/controllers/api/v1/servers_controller_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/factories/server.rb b/spec/factories/server.rb index 837c9ad..e5cb877 100644 --- a/spec/factories/server.rb +++ b/spec/factories/server.rb @@ -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 \ No newline at end of file From 5fae2c46eddc4c27784ab65d684ceb7fc33c7134 Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Sat, 1 Aug 2015 16:33:40 +0100 Subject: [PATCH 03/30] Ooops --- app/controllers/shoutmsgs_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/shoutmsgs_controller.rb b/app/controllers/shoutmsgs_controller.rb index 395328a..041116c 100644 --- a/app/controllers/shoutmsgs_controller.rb +++ b/app/controllers/shoutmsgs_controller.rb @@ -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 From cdfea24a87ff77556e84ecfd6219c27d24fa97f0 Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Sat, 1 Aug 2015 16:34:01 +0100 Subject: [PATCH 04/30] Added maps api --- app/controllers/api/v1/maps_controller.rb | 17 +++++++++++++++++ config/routes.rb | 1 + .../api/v1/maps_controller_spec.rb | 19 +++++++++++++++++++ spec/factories/map.rb | 5 +++++ 4 files changed, 42 insertions(+) create mode 100644 app/controllers/api/v1/maps_controller.rb create mode 100644 spec/controllers/api/v1/maps_controller_spec.rb create mode 100644 spec/factories/map.rb 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 From beb3470bb9160c25821c596ad6dce7b8f43aae9a Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Sat, 1 Aug 2015 16:44:39 +0100 Subject: [PATCH 05/30] Added ban information to user api --- app/controllers/api/v1/users_controller.rb | 5 ++ .../api/v1/users_controller_spec.rb | 19 ++++++++ spec/factories/ban.rb | 46 +++++++++++-------- 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index 9a22225..af2f5ff 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -17,6 +17,11 @@ 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? } } rescue ActiveRecord::RecordNotFound diff --git a/spec/controllers/api/v1/users_controller_spec.rb b/spec/controllers/api/v1/users_controller_spec.rb index 73f1740..4cc19e6 100644 --- a/spec/controllers/api/v1/users_controller_spec.rb +++ b/spec/controllers/api/v1/users_controller_spec.rb @@ -29,6 +29,25 @@ 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 end describe '#index' do diff --git a/spec/factories/ban.rb b/spec/factories/ban.rb index 81a5c7b..0f998be 100644 --- a/spec/factories/ban.rb +++ b/spec/factories/ban.rb @@ -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 \ No newline at end of file From 4a3634601b3fd95df5ec634997a2d7eb95b75ed7 Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Sat, 1 Aug 2015 17:05:17 +0100 Subject: [PATCH 06/30] Added team information to usre --- app/controllers/api/v1/users_controller.rb | 3 ++- spec/controllers/api/v1/users_controller_spec.rb | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb index af2f5ff..ea0f56b 100644 --- a/app/controllers/api/v1/users_controller.rb +++ b/app/controllers/api/v1/users_controller.rb @@ -22,7 +22,8 @@ class Api::V1::UsersController < Api::V1::BaseController 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') diff --git a/spec/controllers/api/v1/users_controller_spec.rb b/spec/controllers/api/v1/users_controller_spec.rb index 4cc19e6..534b939 100644 --- a/spec/controllers/api/v1/users_controller_spec.rb +++ b/spec/controllers/api/v1/users_controller_spec.rb @@ -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 @@ -48,6 +52,14 @@ describe Api::V1::UsersController do 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 From c16903213defe0f73df1841ac83bc2f05fd85225 Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Wed, 12 Aug 2015 01:54:41 +0100 Subject: [PATCH 07/30] Enable session store across gather domains --- config/environments/production.rb | 3 +++ config/environments/staging.rb | 3 +++ 2 files changed, 6 insertions(+) diff --git a/config/environments/production.rb b/config/environments/production.rb index f607881..efb76b4 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -61,4 +61,7 @@ Ensl::Application.configure do # Send deprecation notices to registered listeners 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 \ No newline at end of file diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 797adaa..745ce9f 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -61,4 +61,7 @@ Ensl::Application.configure do # Send deprecation notices to registered listeners 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.staging.ensl.org" end From 159388b0604df07e1a21aecfe87ae3c9ef998aec Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Sat, 15 Aug 2015 11:48:55 +0100 Subject: [PATCH 08/30] Revert session cookie changes in production --- config/environments/production.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index efb76b4..c646579 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -63,5 +63,5 @@ Ensl::Application.configure do 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" + # config.session_store :cookie_store, key: '_ENSL_session_key', expire_after: 30.days.to_i, domain: "gathers.ensl.org" end \ No newline at end of file From 944c55a86945ad5bbf51278a4e2b216f9ca70cf1 Mon Sep 17 00:00:00 2001 From: Luke Barratt Date: Sat, 15 Aug 2015 12:50:28 +0100 Subject: [PATCH 09/30] Upgrade ruby to 2.2.2. Bump rails to 3.2.22 - Upgrade RSpec to 3.3 - Auto formatted existing specs - Fixes broken test assertions - Update capistrano rbenv_ruby to target 2.2.2 - Added test-unit as test dependency as it has been removed form ruby 2.2 --- Gemfile | 9 +- Gemfile.lock | 114 ++++++++++-------- config/deploy.rb | 8 +- .../api/v1/maps_controller_spec.rb | 5 +- .../api/v1/servers_controller_spec.rb | 5 +- .../api/v1/users_controller_spec.rb | 6 +- spec/models/ban_spec.rb | 101 ++++++++-------- spec/models/issue_spec.rb | 85 +++++++------ spec/models/message_spec.rb | 77 ++++++------ spec/models/server_spec.rb | 111 ++++++++--------- spec/models/user_spec.rb | 32 ++--- spec/spec_helper.rb | 3 +- 12 files changed, 298 insertions(+), 258 deletions(-) diff --git a/Gemfile b/Gemfile index 9bb95ef..3c71a7c 100644 --- a/Gemfile +++ b/Gemfile @@ -1,9 +1,9 @@ source 'http://rubygems.org' -ruby '2.1.5' +ruby '2.2.2' gem 'dotenv-rails', '~> 0.10.0' -gem 'rails', '~> 3.2.19' +gem 'rails', '~> 3.2.22' gem 'mysql2', '~> 0.3.15' gem 'dalli', '~> 2.7.0' gem 'puma', '~> 2.11.1' @@ -59,12 +59,13 @@ group :test do gem 'simplecov', '~> 0.7.1', require: false gem 'codeclimate-test-reporter', '~> 0.3.0', require: nil gem 'database_cleaner', '~> 1.2.0' - gem 'rspec-rails', '~> 2.14.1' - gem 'capybara', '~> 2.2.1' + gem 'rspec-rails', '~> 3.3.3' + gem 'capybara', '~> 2.4.4' gem 'poltergeist', '~> 1.6.0' gem 'selenium-webdriver', '~> 2.41.0' gem 'factory_girl_rails', '~> 4.4.1' gem 'timecop', '~> 0.7.1' + gem 'test-unit', '~> 3.1.3' end group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index b02d36d..99f2468 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,12 +9,12 @@ GIT GEM remote: http://rubygems.org/ specs: - actionmailer (3.2.19) - actionpack (= 3.2.19) + actionmailer (3.2.22) + actionpack (= 3.2.22) mail (~> 2.5.4) - actionpack (3.2.19) - activemodel (= 3.2.19) - activesupport (= 3.2.19) + actionpack (3.2.22) + activemodel (= 3.2.22) + activesupport (= 3.2.22) builder (~> 3.0.0) erubis (~> 2.7.0) journey (~> 1.0.4) @@ -24,18 +24,18 @@ GEM sprockets (~> 2.2.1) active_link_to (1.0.2) actionpack - activemodel (3.2.19) - activesupport (= 3.2.19) + activemodel (3.2.22) + activesupport (= 3.2.22) builder (~> 3.0.0) - activerecord (3.2.19) - activemodel (= 3.2.19) - activesupport (= 3.2.19) + activerecord (3.2.22) + activemodel (= 3.2.22) + activesupport (= 3.2.22) arel (~> 3.0.2) tzinfo (~> 0.3.29) - activeresource (3.2.19) - activemodel (= 3.2.19) - activesupport (= 3.2.19) - activesupport (3.2.19) + activeresource (3.2.22) + activemodel (= 3.2.22) + activesupport (= 3.2.22) + activesupport (3.2.22) i18n (~> 0.6, >= 0.6.4) multi_json (~> 1.0) annotate (2.6.3) @@ -69,7 +69,7 @@ GEM capistrano-rbenv (2.0.2) capistrano (~> 3.1) sshkit (~> 1.3) - capybara (2.2.1) + capybara (2.4.4) mime-types (>= 1.16) nokogiri (>= 1.3.3) rack (>= 1.0.0) @@ -122,19 +122,19 @@ GEM haml (4.0.5) tilt hike (1.2.3) - i18n (0.6.11) + i18n (0.7.0) journey (1.0.4) jquery-rails (2.0.3) railties (>= 3.1.0, < 5.0) thor (~> 0.14) - json (1.8.1) + json (1.8.3) mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) method_source (0.8.2) mime-types (1.25.1) - mini_portile (0.5.3) - multi_json (1.10.1) + mini_portile (0.6.2) + multi_json (1.11.2) multi_xml (0.5.5) multipart-post (2.0.0) mysql2 (0.3.15) @@ -145,8 +145,8 @@ GEM net-ssh (>= 2.6.5) net-ssh (2.9.0) newrelic_rpm (3.7.2.195) - nokogiri (1.6.1) - mini_portile (~> 0.5.0) + nokogiri (1.6.6.2) + mini_portile (~> 0.6.0) oj (2.5.5) poltergeist (1.6.0) capybara (~> 2.1) @@ -154,6 +154,7 @@ GEM multi_json (~> 1.0) websocket-driver (>= 0.2.0) polyglot (0.3.5) + power_assert (0.2.4) pry (0.9.12.6) coderay (~> 1.0) method_source (~> 0.8) @@ -165,46 +166,51 @@ GEM rack (>= 1.1, < 2.0) quiet_assets (1.0.2) railties (>= 3.1, < 5.0) - rack (1.4.5) + rack (1.4.7) rack-cache (1.2) rack (>= 0.4) rack-ssl (1.3.4) rack - rack-test (0.6.2) + rack-test (0.6.3) rack (>= 1.0) - rails (3.2.19) - actionmailer (= 3.2.19) - actionpack (= 3.2.19) - activerecord (= 3.2.19) - activeresource (= 3.2.19) - activesupport (= 3.2.19) + rails (3.2.22) + actionmailer (= 3.2.22) + actionpack (= 3.2.22) + activerecord (= 3.2.22) + activeresource (= 3.2.22) + activesupport (= 3.2.22) bundler (~> 1.0) - railties (= 3.2.19) + railties (= 3.2.22) rails_autolink (1.1.5) rails (> 3.1) - railties (3.2.19) - actionpack (= 3.2.19) - activesupport (= 3.2.19) + railties (3.2.22) + actionpack (= 3.2.22) + activesupport (= 3.2.22) rack-ssl (~> 1.3.2) rake (>= 0.8.7) rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) - rake (10.3.2) + rake (10.4.2) rdoc (3.12.2) json (~> 1.4) rmagick (2.13.4) - rspec-core (2.14.8) - rspec-expectations (2.14.5) - diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.14.6) - rspec-rails (2.14.2) - actionpack (>= 3.0) - activemodel (>= 3.0) - activesupport (>= 3.0) - railties (>= 3.0) - rspec-core (~> 2.14.0) - rspec-expectations (~> 2.14.0) - rspec-mocks (~> 2.14.0) + rspec-core (3.3.2) + rspec-support (~> 3.3.0) + rspec-expectations (3.3.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.3.0) + rspec-mocks (3.3.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.3.0) + rspec-rails (3.3.3) + actionpack (>= 3.0, < 4.3) + activesupport (>= 3.0, < 4.3) + 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) sanitize (2.1.0) nokogiri (>= 1.4.4) @@ -223,7 +229,7 @@ GEM simplecov-html (~> 0.7.1) simplecov-html (0.7.1) slop (3.5.0) - sprockets (2.2.2) + sprockets (2.2.3) hike (~> 1.2) multi_json (~> 1.0) rack (~> 1.0) @@ -234,6 +240,8 @@ GEM term-ansicolor term-ansicolor (1.3.0) tins (~> 1.0) + test-unit (3.1.3) + power_assert thor (0.19.1) tilt (1.4.1) timecop (0.7.1) @@ -243,7 +251,7 @@ GEM treetop (1.4.15) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.41) + tzinfo (0.3.44) uglifier (2.5.0) execjs (>= 0.3.0) json (>= 1.8.0) @@ -270,7 +278,7 @@ DEPENDENCIES capistrano-bundler (~> 1.1.2) capistrano-rails (~> 1.1) capistrano-rbenv (~> 2.0.2) - capybara (~> 2.2.1) + capybara (~> 2.4.4) carrierwave (~> 0.10.0) codeclimate-test-reporter (~> 0.3.0) coffee-rails (~> 3.2.2) @@ -294,10 +302,10 @@ DEPENDENCIES pry-byebug (~> 1.3.2) puma (~> 2.11.1) quiet_assets (~> 1.0.2) - rails (~> 3.2.19) + rails (~> 3.2.22) rails_autolink (~> 1.1.5) rmagick (~> 2.13.4) - rspec-rails (~> 2.14.1) + rspec-rails (~> 3.3.3) sanitize (~> 2.1.0) sass (~> 3.3.4) sass-rails (~> 3.2.6) @@ -305,7 +313,11 @@ DEPENDENCIES simplecov (~> 0.7.1) sprockets (~> 2.2.1) steam-condenser! + test-unit (~> 3.1.3) timecop (~> 0.7.1) tinymce-rails (~> 3.5.9) uglifier (~> 2.5.0) will_paginate (~> 3.0.5) + +BUNDLED WITH + 1.10.5 diff --git a/config/deploy.rb b/config/deploy.rb index 25b07bb..f49dc72 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -9,7 +9,7 @@ set :repo_url, 'https://github.com/ENSL/ensl.org.git' set :keep_releases, 10 set :rbenv_type, :user -set :rbenv_ruby, '2.1.5' +set :rbenv_ruby, '2.2.2' set :bundle_flags, '--quiet' set :dotenv_role, [:app, :web] @@ -18,10 +18,10 @@ set :puma_pid, -> { File.join(shared_path, 'tmp', 'pids', 'puma.pid') } set :writable_dirs, %w{public tmp} set :linked_files, %w{.env} -set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle +set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/local public/uploads public/files} -set :normalize_asset_timestamps, %{public/images +set :normalize_asset_timestamps, %{public/images public/javascripts public/stylesheets} @@ -89,4 +89,4 @@ namespace :puma do def valid_pid? test "[ -f #{fetch(:puma_pid)} ]" and test "kill -0 $( cat #{fetch(:puma_pid)} )" end -end \ No newline at end of file +end diff --git a/spec/controllers/api/v1/maps_controller_spec.rb b/spec/controllers/api/v1/maps_controller_spec.rb index 8d1d4ba..2e76605 100644 --- a/spec/controllers/api/v1/maps_controller_spec.rb +++ b/spec/controllers/api/v1/maps_controller_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Api::V1::MapsController do before do request.accept = 'application/json' - end + end describe '#index' do let!(:map) { create :map } @@ -16,4 +16,5 @@ describe Api::V1::MapsController do expect(json_map['id']).to eq(map.id) end end -end \ No newline at end of file +end + diff --git a/spec/controllers/api/v1/servers_controller_spec.rb b/spec/controllers/api/v1/servers_controller_spec.rb index 8b55eec..c515ace 100644 --- a/spec/controllers/api/v1/servers_controller_spec.rb +++ b/spec/controllers/api/v1/servers_controller_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Api::V1::ServersController do before do request.accept = 'application/json' - end + end describe '#index' do let!(:server) { create :server, :active } @@ -17,4 +17,5 @@ describe Api::V1::ServersController do expect(json_server['id']).to eq(server.id) end end -end \ No newline at end of file +end + diff --git a/spec/controllers/api/v1/users_controller_spec.rb b/spec/controllers/api/v1/users_controller_spec.rb index 534b939..24dae61 100644 --- a/spec/controllers/api/v1/users_controller_spec.rb +++ b/spec/controllers/api/v1/users_controller_spec.rb @@ -40,18 +40,21 @@ describe Api::V1::UsersController do 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 @@ -81,7 +84,7 @@ describe Api::V1::UsersController do user_json = json["users"].first nested_team_json = user_json["team"] - + expect(user_json).to have_key("username") expect(user_json).to have_key("steamid") expect(user_json).to have_key("team") @@ -91,3 +94,4 @@ describe Api::V1::UsersController do end end end + diff --git a/spec/models/ban_spec.rb b/spec/models/ban_spec.rb index 32bb277..a58f8e8 100644 --- a/spec/models/ban_spec.rb +++ b/spec/models/ban_spec.rb @@ -18,56 +18,61 @@ require 'spec_helper' describe Ban do - let!(:user) { create :user } - let(:ban) { Ban.new } - let!(:server) { create :server } + let!(:user) { create :user } + let(:ban) { Ban.new } + let!(:server) { create :server } - describe '#check_user' do - it "assigns user by user_name" do - ban.user_name = user.username - ban.check_user - expect(ban.user).to eq(user) - end - it "assigns user and server if user_name not present" do - ban.steamid = user.steamid - ban.addr = server.addr - ban.check_user - expect(ban.user).to eq(user) - expect(ban.server).to eq(server) - end - end - - describe 'Permissions' do - let!(:user) { create :user } - let!(:admin) { create :user, :admin } - let!(:server_user) { create :user } - let(:ban) { Ban.new } + describe '#check_user' do + it "assigns user by user_name" do + ban.user_name = user.username + ban.check_user + expect(ban.user).to eq(user) + end - describe 'can_create?' do - it 'returns true for admins' do - expect(ban.can_create? admin).to be_true - end - it 'returns false for non-admins' do - expect(ban.can_create? user).to be_false - end - end + it "assigns user and server if user_name not present" do + ban.steamid = user.steamid + ban.addr = server.addr + ban.check_user + expect(ban.user).to eq(user) + expect(ban.server).to eq(server) + end + end - describe 'can_destroy?' do - it 'returns true for admin' do - expect(ban.can_destroy? admin).to be_true - end - it 'returns false for non-admins' do - expect(ban.can_destroy? user).to be_false - end - end + describe 'Permissions' do + let!(:user) { create :user } + let!(:admin) { create :user, :admin } + let!(:server_user) { create :user } + let(:ban) { Ban.new } - describe 'can_update?' do - it 'returns true for admin' do - expect(ban.can_update? admin).to be_true - end - it 'returns false for non-admins' do - expect(ban.can_update? user).to be_false - end - end - end + describe 'can_create?' do + it 'returns true for admins' do + expect(ban.can_create? admin).to be_truthy + end + + it 'returns false for non-admins' do + expect(ban.can_create? user).to be_falsey + end + end + + describe 'can_destroy?' do + it 'returns true for admin' do + expect(ban.can_destroy? admin).to be_truthy + end + + it 'returns false for non-admins' do + expect(ban.can_destroy? user).to be_falsey + end + end + + describe 'can_update?' do + it 'returns true for admin' do + expect(ban.can_update? admin).to be_truthy + end + + it 'returns false for non-admins' do + expect(ban.can_update? user).to be_falsey + end + end + end end + diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index dc5f961..fcec064 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -18,43 +18,50 @@ require 'spec_helper' describe 'User' do - describe 'Permissions' do - let!(:user) { create :user } - let!(:admin) { create :user, :admin } - let(:issue) { Issue.new } + describe 'Permissions' do + let!(:user) { create :user } + let!(:admin) { create :user, :admin } + let(:issue) { Issue.new } - describe 'can_show?' do - it 'returns true for author' do - issue.author = user - expect(issue.can_show? user).to be_true - end - it 'returns true for admin' do - expect(issue.can_show? admin).to be_true - end - it 'returns false if neither admin nor author' do - expect(issue.can_show? user).to be_false - end - end - describe 'can_create?' do - it "returns true" do - expect(issue.can_create? nil).to be_true - end - end - describe 'can_update?' do - it 'returns true for admin' do - expect(issue.can_update? admin).to be_true - end - it 'returns false for non-admin' do - expect(issue.can_update? user).to be_false - end - end - describe 'can_destroy?' do - it 'returns true for admin' do - expect(issue.can_destroy? admin).to be_true - end - it 'returns false for non-admin' do - expect(issue.can_destroy? user).to be_false - end - end - end -end \ No newline at end of file + describe 'can_show?' do + it 'returns true for author' do + issue.author = user + expect(issue.can_show? user).to be_truthy + end + + it 'returns true for admin' do + expect(issue.can_show? admin).to be_truthy + end + + it 'returns false if neither admin nor author' do + expect(issue.can_show? user).to be_falsey + end + end + + describe 'can_create?' do + it "returns true" do + expect(issue.can_create? nil).to be_truthy + end + end + + describe 'can_update?' do + it 'returns true for admin' do + expect(issue.can_update? admin).to be_truthy + end + + it 'returns false for non-admin' do + expect(issue.can_update? user).to be_falsey + end + end + + describe 'can_destroy?' do + it 'returns true for admin' do + expect(issue.can_destroy? admin).to be_truthy + end + + it 'returns false for non-admin' do + expect(issue.can_destroy? user).to be_falsey + end + end + end +end diff --git a/spec/models/message_spec.rb b/spec/models/message_spec.rb index b0aa6ef..bcedcde 100644 --- a/spec/models/message_spec.rb +++ b/spec/models/message_spec.rb @@ -17,41 +17,48 @@ require 'spec_helper' describe Message do - let!(:user) { create :user } + let!(:user) { create :user } - describe 'create' do - let(:message) { build :message } - it 'creates a new message' do - expect(message.valid?).to be_true - expect do - message.save! - end.to change(Message, :count).by(1) - end - end + describe 'create' do + let(:message) { build :message } - describe 'Permissions' do - let(:message) { Message.new } - describe 'can_create?' do - it 'returns true for user' do - expect(message.can_create?(user)).to be_true - end - it 'returns false if user is banned' do - create :ban, :mute, user: user - expect(message.can_create?(user)).to be_false - end - end + it 'creates a new message' do + expect(message.valid?).to eq(true) + expect do + message.save! + end.to change(Message, :count).by(1) + end + end + + describe 'Permissions' do + let(:message) { Message.new } + + describe 'can_create?' do + it 'returns true for user' do + expect(message.can_create?(user)).to be_truthy + end + + it 'returns false if user is banned' do + create :ban, :mute, user: user + expect(message.can_create?(user)).to be_falsey + end + end + + describe 'can_show?' do + let!(:message) { create :message } + + it 'returns true if sender' do + expect(message.can_show?(message.sender)).to be_truthy + end + + it 'returns true if receiver' do + expect(message.can_show?(message.recipient)).to be_truthy + end + + it 'returns false if neither sender nor receiver' do + expect(message.can_show?(user)).to be_falsey + end + end + end +end - describe 'can_show?' do - let!(:message) { create :message } - it 'returns true if sender' do - expect(message.can_show?(message.sender)).to be_true - end - it 'returns true if receiver' do - expect(message.can_show?(message.recipient)).to be_true - end - it 'returns false if neither sender nor receiver' do - expect(message.can_show?(user)).to be_false - end - end - end -end \ No newline at end of file diff --git a/spec/models/server_spec.rb b/spec/models/server_spec.rb index a4ec8cf..b850be9 100644 --- a/spec/models/server_spec.rb +++ b/spec/models/server_spec.rb @@ -33,65 +33,66 @@ require 'spec_helper' describe Server do - describe 'create' do - it 'sets category to 45 if domain is NS2' do - server = create :server, domain: Server::DOMAIN_NS2 - expect(server.category_id).to eq(45) - end - it 'sets category to 44 if domain is not NS2' do - server = create :server, domain: Server::DOMAIN_HLDS - expect(server.category_id).to eq(44) - end - end + describe 'create' do + it 'sets category to 45 if domain is NS2' do + server = create :server, domain: Server::DOMAIN_NS2 + expect(server.category_id).to eq(45) + end + it 'sets category to 44 if domain is not NS2' do + server = create :server, domain: Server::DOMAIN_HLDS + expect(server.category_id).to eq(44) + end + end - describe 'addr' do - it 'returns properly formatted IP and port number' do - ip = '1.1.1.1' - port = '8000' - server = create :server, ip: ip, port: port - expect(server.addr).to eq('1.1.1.1:8000') - end - end + describe 'addr' do + it 'returns properly formatted IP and port number' do + ip = '1.1.1.1' + port = '8000' + server = create :server, ip: ip, port: port + expect(server.addr).to eq('1.1.1.1:8000') + end + end - describe 'to_s' do - it 'returns server name' do - server_name = "Foo" - server = create :server, name: server_name - expect(server.to_s).to eq(server_name) - end - end + describe 'to_s' do + it 'returns server name' do + server_name = "Foo" + server = create :server, name: server_name + expect(server.to_s).to eq(server_name) + end + end - describe 'Permissions' do - let!(:user) { create :user } - let!(:admin) { create :user, :admin } - let!(:server_user) {create :user } - let!(:server) { create :server, user: server_user } + describe 'Permissions' do + let!(:user) { create :user } + let!(:admin) { create :user, :admin } + let!(:server_user) {create :user } + let!(:server) { create :server, user: server_user } - describe 'can_create?' do - it 'returns true for non-admins' do - expect(server.can_create? user).to be_true - end - end + describe 'can_create?' do + it 'returns true for non-admins' do + expect(server.can_create? user).to be_truthy + end + end - describe 'can_destroy?' do - it 'returns true for admin' do - expect(server.can_destroy? admin).to be_true - end - it 'returns false for non-admins' do - expect(server.can_destroy? user).to be_false - end - end + describe 'can_destroy?' do + it 'returns true for admin' do + expect(server.can_destroy? admin).to eq(true) + end + it 'returns false for non-admins' do + expect(server.can_destroy? user).to eq(false) + end + end - describe 'can_update?' do - it 'returns true for admin' do - expect(server.can_update? admin).to be_true - end - it 'returns true if server belongs to user' do - expect(server.can_update? server_user).to be_true - end - it 'returns false for non-admins' do - expect(server.can_update? user).to be_false - end - end - end + describe 'can_update?' do + it 'returns true for admin' do + expect(server.can_update? admin).to eq(true) + end + it 'returns true if server belongs to user' do + expect(server.can_update? server_user).to eq(true) + end + it 'returns false for non-admins' do + expect(server.can_update? user).to eq(false) + end + end + end end + diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 24ba3a2..f1d7077 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -24,21 +24,21 @@ require 'spec_helper' describe User do - let!(:user) { create :user } - - describe "#banned?" do - it "returns false if user is not banned" do - expect(user.banned?).to be_false - end + let!(:user) { create :user } - 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 - expect(user.banned?).to be_true - end + describe "#banned?" do + it "returns false if user is not banned" do + expect(user.banned?).to be_falsey + end - it "returns true for specific bans" do - ban = Ban.create! ban_type: Ban::TYPE_MUTE, expiry: Time.now + 10.days, user_name: user.username - expect(user.banned? Ban::TYPE_MUTE).to be_true - end - end -end \ No newline at end of file + 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 + expect(user.banned?).to be_truthy + end + + it "returns true for specific bans" do + ban = Ban.create! ban_type: Ban::TYPE_MUTE, expiry: Time.now + 10.days, user_name: user.username + expect(user.banned? Ban::TYPE_MUTE).to be_truthy + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8e8b650..85567d0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,7 +10,7 @@ require 'rspec/rails' require 'capybara/rspec' require 'capybara/poltergeist' -Capybara.default_wait_time = 30 +Capybara.default_wait_time = 5 Capybara.register_driver :poltergeist do |app| Capybara::Poltergeist::Driver.new(app, timeout: 30, @@ -34,6 +34,7 @@ RSpec.configure do |config| config.use_transactional_fixtures = false config.color = true config.formatter = :documentation + config.infer_spec_type_from_file_location! config.before(:each) do events_list_json = JSON.parse(File.read(Rails.root.join('spec/fixtures/google_calendar.json'))) From 4b038406f6487598c06fb6fa26c350e7274368d5 Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Sat, 15 Aug 2015 13:25:44 +0100 Subject: [PATCH 10/30] Add missing groups --- spec/factories/group.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/factories/group.rb b/spec/factories/group.rb index 0a101b3..bf72ae2 100644 --- a/spec/factories/group.rb +++ b/spec/factories/group.rb @@ -9,4 +9,14 @@ FactoryGirl.define do name "Admins" id Group::ADMINS end + + trait :champions do + name "Champions" + id Group::CHAMPIONS + end + + trait :donors do + name "Donors" + id Group::DONORS + end end From a6c7e5e592c70bd2d60f471a1ed285b429231c88 Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Sat, 15 Aug 2015 13:30:39 +0100 Subject: [PATCH 11/30] Remove IP address data from users plugin --- app/controllers/plugin_controller.rb | 103 +++++++++--------- .../plugin/plugin_controller_spec.rb | 29 +++++ 2 files changed, 80 insertions(+), 52 deletions(-) create mode 100644 spec/controllers/plugin/plugin_controller_spec.rb diff --git a/app/controllers/plugin_controller.rb b/app/controllers/plugin_controller.rb index 76a2885..8603141 100644 --- a/app/controllers/plugin_controller.rb +++ b/app/controllers/plugin_controller.rb @@ -1,58 +1,57 @@ class PluginController < ApplicationController - def user - buffer = [] - out = [] + def user + buffer = [] + out = [] + if ban = Ban.first(:conditions => ["expiry > UTC_TIMESTAMP() AND steamid = ? AND ban_type = ?", params[:id], Ban::TYPE_SERVER]) + out << "#USER#" + out << "BANNED" + out << ban.expiry.utc.to_i + out << ban.reason + out << "\r\r\r\r\r\r\r" + elsif user = User.first(:conditions => {:steamid => params[:id]}) + teamer = (user.team ? user.teamers.active.of_team(user.team).first : nil) + icon = 0 + rank = "User" + if Group.find(Group::DONORS).users.exists?(user) + rank = "Donor" + icon = icon | 1 + end + if Group.find(Group::CHAMPIONS).users.exists?(user) + icon = icon | 2 + end + if user.ref? + rank = "Referee" + icon = icon | 4 + end + if user.admin? + rank = "Admin" + icon = icon | 8 + end - if ban = Ban.first(:conditions => ["expiry > UTC_TIMESTAMP() AND steamid = ? AND ban_type = ?", params[:id], Ban::TYPE_SERVER]) - out << "#USER#" - out << "BANNED" - out << ban.expiry.utc.to_i - out << ban.reason - out << "\r\r\r\r\r\r\r" - elsif user = User.first(:conditions => {:steamid => params[:id]}) - teamer = (user.team ? user.teamers.active.of_team(user.team).first : nil) - icon = 0 - rank = "User" - if Group.find(Group::DONORS).users.exists?(user) - rank = "Donor" - icon = icon | 1 - end - if Group.find(Group::CHAMPIONS).users.exists?(user) - icon = icon | 2 - end - if user.ref? - rank = "Referee" - icon = icon | 4 - end - if user.admin? - rank = "Admin" - icon = icon | 8 - end + buffer << user.steamid + buffer << user.username + buffer << '0.0.0.0' + buffer << (user.team ? Verification.uncrap(user.team.to_s) : "No Team") + buffer << user.id + buffer << user.team_id + buffer << rank + buffer << (teamer ? teamer.ranks[teamer.rank] : "") + buffer << icon + buffer << params[:ch] ? params[:ch] : "" + buffer << (user.can_play? ? "1" : "0") - buffer << user.steamid - buffer << user.username - buffer << user.lastip - buffer << (user.team ? Verification.uncrap(user.team.to_s) : "No Team") - buffer << user.id - buffer << user.team_id - buffer << rank - buffer << (teamer ? teamer.ranks[teamer.rank] : "") - buffer << icon - buffer << params[:ch] ? params[:ch] : "" - buffer << (user.can_play? ? "1" : "0") + out << "#USER#" + out << Verification.verify(buffer.join) + out << buffer.join("\r") + else + out << "#FAIL#" + end - out << "#USER#" - out << Verification.verify(buffer.join) - out << buffer.join("\r") - else - out << "#FAIL#" - end + render_out out + end - render_out out - end - - def render_out out - @text = out.join("\r") - render :layout => false - end + def render_out out + @text = out.join("\r") + render :layout => false + end end \ No newline at end of file diff --git a/spec/controllers/plugin/plugin_controller_spec.rb b/spec/controllers/plugin/plugin_controller_spec.rb new file mode 100644 index 0000000..e9585af --- /dev/null +++ b/spec/controllers/plugin/plugin_controller_spec.rb @@ -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 \ No newline at end of file From d819a1cc9e1032badad9e9520ac5a8e6720eac96 Mon Sep 17 00:00:00 2001 From: Luke Barratt Date: Sat, 15 Aug 2015 17:44:33 +0100 Subject: [PATCH 12/30] Moved test-unit to the Gemfile to fix issues with activesupport --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 3c71a7c..8bfe310 100644 --- a/Gemfile +++ b/Gemfile @@ -23,6 +23,7 @@ gem 'country_code_select', '~> 1.0.1' gem 'active_link_to', '~> 1.0.2' gem 'rmagick', '~> 2.13.4', require: false gem 'steam-condenser', github: 'koraktor/steam-condenser-ruby' +gem 'test-unit', '~> 3.1.3' # Please install nodejs locally. gem 'therubyracer', '~> 0.12.1' if RUBY_PLATFORM == 'x86_64-linux' @@ -65,7 +66,6 @@ group :test do gem 'selenium-webdriver', '~> 2.41.0' gem 'factory_girl_rails', '~> 4.4.1' gem 'timecop', '~> 0.7.1' - gem 'test-unit', '~> 3.1.3' end group :development, :test do From c1430343a99cf8786b7d62c7720f4b9646232f73 Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Sat, 15 Aug 2015 18:42:44 +0100 Subject: [PATCH 13/30] Set new session store name and domain for staging --- config/environments/staging.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/staging.rb b/config/environments/staging.rb index 745ce9f..8bdbaa6 100644 --- a/config/environments/staging.rb +++ b/config/environments/staging.rb @@ -63,5 +63,5 @@ Ensl::Application.configure do 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.staging.ensl.org" + config.session_store :cookie_store, key: "_ENSL_session_key_staging", expire_after: 30.days.to_i, domain: ".staging.ensl.org" end From de5d548e5036475bf37abc10dbd37de3e74394b1 Mon Sep 17 00:00:00 2001 From: Luke Barratt Date: Sat, 15 Aug 2015 19:23:42 +0100 Subject: [PATCH 14/30] Style guide updates to specs --- .../api/v1/maps_controller_spec.rb | 1 - .../api/v1/servers_controller_spec.rb | 1 - .../api/v1/users_controller_spec.rb | 1 - spec/models/ban_spec.rb | 27 +++++----- spec/models/issue_spec.rb | 28 +++++----- spec/models/message_spec.rb | 23 ++++---- spec/models/server_spec.rb | 53 +++++++++++-------- spec/models/user_spec.rb | 10 +++- 8 files changed, 77 insertions(+), 67 deletions(-) diff --git a/spec/controllers/api/v1/maps_controller_spec.rb b/spec/controllers/api/v1/maps_controller_spec.rb index 2e76605..689f7c3 100644 --- a/spec/controllers/api/v1/maps_controller_spec.rb +++ b/spec/controllers/api/v1/maps_controller_spec.rb @@ -17,4 +17,3 @@ describe Api::V1::MapsController do end end end - diff --git a/spec/controllers/api/v1/servers_controller_spec.rb b/spec/controllers/api/v1/servers_controller_spec.rb index c515ace..1e3437f 100644 --- a/spec/controllers/api/v1/servers_controller_spec.rb +++ b/spec/controllers/api/v1/servers_controller_spec.rb @@ -18,4 +18,3 @@ describe Api::V1::ServersController do end end end - diff --git a/spec/controllers/api/v1/users_controller_spec.rb b/spec/controllers/api/v1/users_controller_spec.rb index 24dae61..72b42ab 100644 --- a/spec/controllers/api/v1/users_controller_spec.rb +++ b/spec/controllers/api/v1/users_controller_spec.rb @@ -94,4 +94,3 @@ describe Api::V1::UsersController do end end end - diff --git a/spec/models/ban_spec.rb b/spec/models/ban_spec.rb index a58f8e8..5bcfc74 100644 --- a/spec/models/ban_spec.rb +++ b/spec/models/ban_spec.rb @@ -15,17 +15,18 @@ # ip :string(255) # -require 'spec_helper' +require "spec_helper" describe Ban do let!(:user) { create :user } let(:ban) { Ban.new } let!(:server) { create :server } - describe '#check_user' do + describe "#check_user" do it "assigns user by user_name" do ban.user_name = user.username ban.check_user + expect(ban.user).to eq(user) end @@ -33,46 +34,46 @@ describe Ban do ban.steamid = user.steamid ban.addr = server.addr ban.check_user + expect(ban.user).to eq(user) expect(ban.server).to eq(server) end end - describe 'Permissions' do + describe "Permissions" do let!(:user) { create :user } let!(:admin) { create :user, :admin } let!(:server_user) { create :user } let(:ban) { Ban.new } - describe 'can_create?' do - it 'returns true for admins' do + describe "can_create?" do + it "returns true for admins" do expect(ban.can_create? admin).to be_truthy end - it 'returns false for non-admins' do + it "returns false for non-admins" do expect(ban.can_create? user).to be_falsey end end - describe 'can_destroy?' do - it 'returns true for admin' do + describe "can_destroy?" do + it "returns true for admin" do expect(ban.can_destroy? admin).to be_truthy end - it 'returns false for non-admins' do + it "returns false for non-admins" do expect(ban.can_destroy? user).to be_falsey end end - describe 'can_update?' do - it 'returns true for admin' do + describe "can_update?" do + it "returns true for admin" do expect(ban.can_update? admin).to be_truthy end - it 'returns false for non-admins' do + it "returns false for non-admins" do expect(ban.can_update? user).to be_falsey end end end end - diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index fcec064..7345990 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -15,51 +15,51 @@ # text_parsed :text # -require 'spec_helper' +require "spec_helper" -describe 'User' do - describe 'Permissions' do +describe "User" do + describe "Permissions" do let!(:user) { create :user } let!(:admin) { create :user, :admin } let(:issue) { Issue.new } - describe 'can_show?' do - it 'returns true for author' do + describe "can_show?" do + it "returns true for author" do issue.author = user expect(issue.can_show? user).to be_truthy end - it 'returns true for admin' do + it "returns true for admin" do expect(issue.can_show? admin).to be_truthy end - it 'returns false if neither admin nor author' do + it "returns false if neither admin nor author" do expect(issue.can_show? user).to be_falsey end end - describe 'can_create?' do + describe "can_create?" do it "returns true" do expect(issue.can_create? nil).to be_truthy end end - describe 'can_update?' do - it 'returns true for admin' do + describe "can_update?" do + it "returns true for admin" do expect(issue.can_update? admin).to be_truthy end - it 'returns false for non-admin' do + it "returns false for non-admin" do expect(issue.can_update? user).to be_falsey end end - describe 'can_destroy?' do - it 'returns true for admin' do + describe "can_destroy?" do + it "returns true for admin" do expect(issue.can_destroy? admin).to be_truthy end - it 'returns false for non-admin' do + it "returns false for non-admin" do expect(issue.can_destroy? user).to be_falsey end end diff --git a/spec/models/message_spec.rb b/spec/models/message_spec.rb index bcedcde..17a93b6 100644 --- a/spec/models/message_spec.rb +++ b/spec/models/message_spec.rb @@ -14,15 +14,15 @@ # text_parsed :text # -require 'spec_helper' +require "spec_helper" describe Message do let!(:user) { create :user } - describe 'create' do + describe "create" do let(:message) { build :message } - it 'creates a new message' do + it "creates a new message" do expect(message.valid?).to eq(true) expect do message.save! @@ -30,35 +30,34 @@ describe Message do end end - describe 'Permissions' do + describe "Permissions" do let(:message) { Message.new } - describe 'can_create?' do - it 'returns true for user' do + describe "can_create?" do + it "returns true for user" do expect(message.can_create?(user)).to be_truthy end - it 'returns false if user is banned' do + it "returns false if user is banned" do create :ban, :mute, user: user expect(message.can_create?(user)).to be_falsey end end - describe 'can_show?' do + describe "can_show?" do let!(:message) { create :message } - it 'returns true if sender' do + it "returns true if sender" do expect(message.can_show?(message.sender)).to be_truthy end - it 'returns true if receiver' do + it "returns true if receiver" do expect(message.can_show?(message.recipient)).to be_truthy end - it 'returns false if neither sender nor receiver' do + it "returns false if neither sender nor receiver" do expect(message.can_show?(user)).to be_falsey end end end end - diff --git a/spec/models/server_spec.rb b/spec/models/server_spec.rb index b850be9..bd45b15 100644 --- a/spec/models/server_spec.rb +++ b/spec/models/server_spec.rb @@ -30,69 +30,76 @@ # category_id :integer # -require 'spec_helper' +require "spec_helper" describe Server do - describe 'create' do - it 'sets category to 45 if domain is NS2' do + describe "create" do + it "sets category to 45 if domain is NS2" do server = create :server, domain: Server::DOMAIN_NS2 + expect(server.category_id).to eq(45) 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 + expect(server.category_id).to eq(44) end end - describe 'addr' do - it 'returns properly formatted IP and port number' do - ip = '1.1.1.1' - port = '8000' + describe "addr" do + it "returns properly formatted IP and port number" do + ip = "1.1.1.1" + port = "8000" 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 - describe 'to_s' do - it 'returns server name' do + describe "to_s" do + it "returns server name" do server_name = "Foo" server = create :server, name: server_name + expect(server.to_s).to eq(server_name) end end - describe 'Permissions' do + describe "Permissions" do let!(:user) { create :user } let!(:admin) { create :user, :admin } - let!(:server_user) {create :user } + let!(:server_user) { create :user } let!(:server) { create :server, user: server_user } - describe 'can_create?' do - it 'returns true for non-admins' do + describe "can_create?" do + it "returns true for non-admins" do expect(server.can_create? user).to be_truthy end end - describe 'can_destroy?' do - it 'returns true for admin' do + describe "can_destroy?" do + it "returns true for admin" do expect(server.can_destroy? admin).to eq(true) end - it 'returns false for non-admins' do + + it "returns false for non-admins" do expect(server.can_destroy? user).to eq(false) end end - describe 'can_update?' do - it 'returns true for admin' do + describe "can_update?" do + it "returns true for admin" do expect(server.can_update? admin).to eq(true) end - it 'returns true if server belongs to user' do + + it "returns true if server belongs to user" do expect(server.can_update? server_user).to eq(true) end - it 'returns false for non-admins' do + + it "returns false for non-admins" do expect(server.can_update? user).to eq(false) end end end end - diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index f1d7077..0931978 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -32,12 +32,18 @@ describe User do end 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, + expiry: Time.now + 10.days, + user_name: user.username) + expect(user.banned?).to be_truthy end 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, + expiry: Time.now + 10.days, + user_name: user.username) + expect(user.banned? Ban::TYPE_MUTE).to be_truthy end end From 7f7d09295c4b0d80c60f38a9bd1f5d0419a4bb34 Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Thu, 20 Aug 2015 15:48:19 +0100 Subject: [PATCH 15/30] Add initial forum tests --- spec/factories/forum.rb | 6 ++++++ spec/models/forum_spec.rb | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 spec/factories/forum.rb create mode 100644 spec/models/forum_spec.rb diff --git a/spec/factories/forum.rb b/spec/factories/forum.rb new file mode 100644 index 0000000..3ad7213 --- /dev/null +++ b/spec/factories/forum.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :forum do + sequence(:title) { |n| "Forum Title #{n}" } + sequence(:description) { |n| "Forum Description #{n}" } + end +end \ No newline at end of file diff --git a/spec/models/forum_spec.rb b/spec/models/forum_spec.rb new file mode 100644 index 0000000..211c244 --- /dev/null +++ b/spec/models/forum_spec.rb @@ -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 From 49a99f16f79c8be4b21f77662d7ca3d5b812cbad Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Thu, 20 Aug 2015 15:49:42 +0100 Subject: [PATCH 16/30] Add initial topic tests --- spec/factories/topic.rb | 5 +++++ spec/models/topic_spec.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 spec/factories/topic.rb create mode 100644 spec/models/topic_spec.rb diff --git a/spec/factories/topic.rb b/spec/factories/topic.rb new file mode 100644 index 0000000..159059b --- /dev/null +++ b/spec/factories/topic.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :topic do + sequence(:title) { |n| "Forum Title #{n}" } + end +end \ No newline at end of file diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb new file mode 100644 index 0000000..5cd81d1 --- /dev/null +++ b/spec/models/topic_spec.rb @@ -0,0 +1,30 @@ +# == 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 +end From d3a2b172e5d35b277fe4a5be45900f4f3db7cb4b Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Thu, 20 Aug 2015 15:57:29 +0100 Subject: [PATCH 17/30] Add initial tests for posts --- spec/factories/post.rb | 7 +++++++ spec/models/post_spec.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 spec/factories/post.rb create mode 100644 spec/models/post_spec.rb diff --git a/spec/factories/post.rb b/spec/factories/post.rb new file mode 100644 index 0000000..ec0de0b --- /dev/null +++ b/spec/factories/post.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :post do + sequence(:text) { |n| "Post Body #{n}" } + topic + user + end +end \ No newline at end of file diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb new file mode 100644 index 0000000..9ef6175 --- /dev/null +++ b/spec/models/post_spec.rb @@ -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 From 843da0db43bc5c76930f8d897caa19cfb42227d0 Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Thu, 20 Aug 2015 15:58:10 +0100 Subject: [PATCH 18/30] Fix --- spec/factories/topic.rb | 5 +++++ spec/models/user_spec.rb | 1 + 2 files changed, 6 insertions(+) diff --git a/spec/factories/topic.rb b/spec/factories/topic.rb index 159059b..1eb1820 100644 --- a/spec/factories/topic.rb +++ b/spec/factories/topic.rb @@ -1,5 +1,10 @@ FactoryGirl.define do factory :topic do sequence(:title) { |n| "Forum Title #{n}" } + forum + user + before(:create) do |topic| + topic.first_post = "My first post on the topic" + end end end \ No newline at end of file diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 0931978..49f261c 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -19,6 +19,7 @@ # time_zone :string(255) # version :integer # public_email :boolean default(FALSE), not null +# salt :string(255) # require 'spec_helper' From 551520dc736652e9553387dfd56a9d2c62fbefed Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Thu, 20 Aug 2015 16:20:40 +0100 Subject: [PATCH 19/30] Add more efficient recent topics class method --- app/models/topic.rb | 4 ++++ spec/models/topic_spec.rb | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/app/models/topic.rb b/app/models/topic.rb index 3d85a00..ba0ddbb 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -47,6 +47,10 @@ class Topic < ActiveRecord::Base acts_as_readable + def self.recent_topics + Post.order('id desc').select('DISTINCT topic_id').limit(5).map(&:topic) + end + def to_s title end diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 5cd81d1..536c50b 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -27,4 +27,20 @@ describe Topic do end.to change(Topic, :count).by(1) end end + + describe ".recent_topics" do + before(:all) do + 5.times do + topic = create :topic + 3.times do + post = create :post, topic: topic + end + end + end + it "returns 5 unique, most recently posted topics" do + recent_topics = Topic.recent_topics + expect(recent_topics.length).to eq(5) + expect(recent_topics.map(&:id).uniq.length).to eq(5) + end + end end From 4318f4116e97b4c39b2a97858c0274ec0dc5f297 Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Thu, 20 Aug 2015 16:20:50 +0100 Subject: [PATCH 20/30] Swap out old recent topics method --- app/views/topics/_index.html.erb | 2 +- app/views/widgets/_posts.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/topics/_index.html.erb b/app/views/topics/_index.html.erb index 4363ecd..d412ce5 100644 --- a/app/views/topics/_index.html.erb +++ b/app/views/topics/_index.html.erb @@ -1,5 +1,5 @@
    - <% Topic.basic.recent.latest_page(page).each do |topic| %> + <% Topic.recent_topics.each do |topic| %>
  1. <%= link_to (h topic), lastpost(topic) %>
  2. diff --git a/app/views/widgets/_posts.html.erb b/app/views/widgets/_posts.html.erb index 9a333cf..6639986 100644 --- a/app/views/widgets/_posts.html.erb +++ b/app/views/widgets/_posts.html.erb @@ -4,7 +4,7 @@
    Latest forum posts
      - <% Topic.basic.recent.latest_page(1).each do |topic| %> + <% Topic.recent_topics.each do |topic| %>
    1. <%= link_to shorten(topic, 28), lastpost(topic) %>
    2. From efc75736dd278f3fb76e9a1bf244eba113da22af Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Thu, 20 Aug 2015 16:35:25 +0100 Subject: [PATCH 21/30] Style fix --- app/models/topic.rb | 2 +- spec/factories/forum.rb | 2 +- spec/factories/post.rb | 2 +- spec/factories/topic.rb | 4 ++-- spec/models/topic_spec.rb | 4 +--- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/models/topic.rb b/app/models/topic.rb index ba0ddbb..be52570 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -48,7 +48,7 @@ class Topic < ActiveRecord::Base acts_as_readable def self.recent_topics - Post.order('id desc').select('DISTINCT topic_id').limit(5).map(&:topic) + Post.order("id desc").select("DISTINCT topic_id").limit(5).map(&:topic) end def to_s diff --git a/spec/factories/forum.rb b/spec/factories/forum.rb index 3ad7213..a5bbe09 100644 --- a/spec/factories/forum.rb +++ b/spec/factories/forum.rb @@ -3,4 +3,4 @@ FactoryGirl.define do sequence(:title) { |n| "Forum Title #{n}" } sequence(:description) { |n| "Forum Description #{n}" } end -end \ No newline at end of file +end diff --git a/spec/factories/post.rb b/spec/factories/post.rb index ec0de0b..e557bbb 100644 --- a/spec/factories/post.rb +++ b/spec/factories/post.rb @@ -4,4 +4,4 @@ FactoryGirl.define do topic user end -end \ No newline at end of file +end diff --git a/spec/factories/topic.rb b/spec/factories/topic.rb index 1eb1820..39637c0 100644 --- a/spec/factories/topic.rb +++ b/spec/factories/topic.rb @@ -4,7 +4,7 @@ FactoryGirl.define do forum user before(:create) do |topic| - topic.first_post = "My first post on the topic" + topic.first_post = "My first post on the topic" end end -end \ No newline at end of file +end diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 536c50b..836e9cb 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -32,9 +32,7 @@ describe Topic do before(:all) do 5.times do topic = create :topic - 3.times do - post = create :post, topic: topic - end + 3.times { create :post, topic: topic } end end it "returns 5 unique, most recently posted topics" do From 70171dfbbd06cdf1bb70c820cf1ea11f925f059c Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Thu, 20 Aug 2015 17:01:42 +0100 Subject: [PATCH 22/30] Remove inefficient scope --- app/models/topic.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/models/topic.rb b/app/models/topic.rb index be52570..502a35d 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -32,10 +32,6 @@ class Topic < ActiveRecord::Base scope :basic, :include => [:latest, { forum: :forumer }, :user] 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}"} } From 19b5679ff387e83386e860165a1abdb4d2b49632 Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Thu, 20 Aug 2015 17:21:56 +0100 Subject: [PATCH 23/30] Scope no longer used --- app/models/topic.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/models/topic.rb b/app/models/topic.rb index 502a35d..e34e64f 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -32,8 +32,6 @@ class Topic < ActiveRecord::Base scope :basic, :include => [:latest, { forum: :forumer }, :user] scope :ordered, :order => "state DESC, posts.id DESC" - 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_length_of :title, :in => 1..50 From 739422abef9c45646962912d56910575e263b31e Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Thu, 20 Aug 2015 18:11:29 +0100 Subject: [PATCH 24/30] Added initial forumer test --- spec/factories/forumer.rb | 7 +++++++ spec/models/forumer_spec.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 spec/factories/forumer.rb create mode 100644 spec/models/forumer_spec.rb diff --git a/spec/factories/forumer.rb b/spec/factories/forumer.rb new file mode 100644 index 0000000..50988a3 --- /dev/null +++ b/spec/factories/forumer.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :forumer do + forum + group + access Forumer::ACCESS_TOPIC + end +end diff --git a/spec/models/forumer_spec.rb b/spec/models/forumer_spec.rb new file mode 100644 index 0000000..7c04f29 --- /dev/null +++ b/spec/models/forumer_spec.rb @@ -0,0 +1,27 @@ +# == 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 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 From 5bde263e8ca5cb0ca39f6ad121b52d585a1c8b6f Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Thu, 20 Aug 2015 19:33:22 +0100 Subject: [PATCH 25/30] Added forumer exclusion on recent_topics --- app/models/topic.rb | 8 +++++++- spec/models/topic_spec.rb | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/models/topic.rb b/app/models/topic.rb index e34e64f..31800ab 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -42,7 +42,13 @@ class Topic < ActiveRecord::Base acts_as_readable def self.recent_topics - Post.order("id desc").select("DISTINCT topic_id").limit(5).map(&:topic) + Post.joins("LEFT OUTER JOIN topics ON topics.id = posts.topic_id") + .joins("LEFT OUTER JOIN forums on forums.id = topics.forum_id") + .joins("LEFT OUTER JOIN forumers on forums.id = forumers.forum_id") + .order("posts.id desc") + .where("forumers.id IS NULL") + .select("DISTINCT topic_id") + .limit(5).map(&:topic) end def to_s diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 836e9cb..e9f740c 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -29,7 +29,7 @@ describe Topic do end describe ".recent_topics" do - before(:all) do + before(:each) do 5.times do topic = create :topic 3.times { create :post, topic: topic } @@ -40,5 +40,11 @@ describe Topic do expect(recent_topics.length).to eq(5) expect(recent_topics.map(&:id).uniq.length).to eq(5) 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 From 5948364ec297017538e036d7e706330b295a618c Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Thu, 20 Aug 2015 19:36:01 +0100 Subject: [PATCH 26/30] Annotate & fix style --- app/models/topic.rb | 15 ++++++++------- spec/models/forumer_spec.rb | 15 +++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/models/topic.rb b/app/models/topic.rb index 31800ab..d1b1fe1 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -42,13 +42,14 @@ class Topic < ActiveRecord::Base acts_as_readable def self.recent_topics - Post.joins("LEFT OUTER JOIN topics ON topics.id = posts.topic_id") - .joins("LEFT OUTER JOIN forums on forums.id = topics.forum_id") - .joins("LEFT OUTER JOIN forumers on forums.id = forumers.forum_id") - .order("posts.id desc") - .where("forumers.id IS NULL") - .select("DISTINCT topic_id") - .limit(5).map(&:topic) + Post.joins("LEFT OUTER JOIN topics ON topics.id = posts.topic_id"). + joins("LEFT OUTER JOIN forums on forums.id = topics.forum_id"). + joins("LEFT OUTER JOIN forumers on forums.id = forumers.forum_id"). + order("posts.id desc"). + where("forumers.id IS NULL"). + select("DISTINCT topic_id"). + limit(5). + map(&:topic) end def to_s diff --git a/spec/models/forumer_spec.rb b/spec/models/forumer_spec.rb index 7c04f29..c66b284 100644 --- a/spec/models/forumer_spec.rb +++ b/spec/models/forumer_spec.rb @@ -1,14 +1,13 @@ # == Schema Information # -# Table name: forums +# Table name: forumers # -# id :integer not null, primary key -# title :string(255) -# description :string(255) -# category_id :integer -# created_at :datetime -# updated_at :datetime -# position :integer +# id :integer not null, primary key +# forum_id :integer +# group_id :integer +# access :integer +# created_at :datetime +# updated_at :datetime # require "spec_helper" From b4884e106c5a9c2005191e74ce7e8ba807f4bd53 Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Thu, 20 Aug 2015 23:37:26 +0100 Subject: [PATCH 27/30] Add missing index on forumers table --- .../20150820223313_add_index_to_forumers.rb | 6 + db/schema.rb | 141 ++++++++++++++++-- 2 files changed, 134 insertions(+), 13 deletions(-) create mode 100644 db/migrate/20150820223313_add_index_to_forumers.rb diff --git a/db/migrate/20150820223313_add_index_to_forumers.rb b/db/migrate/20150820223313_add_index_to_forumers.rb new file mode 100644 index 0000000..f3684e7 --- /dev/null +++ b/db/migrate/20150820223313_add_index_to_forumers.rb @@ -0,0 +1,6 @@ +class AddIndexToForumers < ActiveRecord::Migration + def change + add_index :forumers, :forum_id + add_index :forumers, :group_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 5422b4f..7f203e9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,21 @@ # # 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| 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", ["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| t.string "name" t.string "description" @@ -212,6 +236,21 @@ ActiveRecord::Schema.define(:version => 20150701233306) do 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| t.integer "forum_id" t.integer "group_id" @@ -220,6 +259,9 @@ ActiveRecord::Schema.define(:version => 20150701233306) do t.datetime "updated_at" 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| t.string "title" 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" + 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| t.string "name" 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", ["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| t.string "option" 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"], :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| t.integer "server_id" 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", ["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| t.integer "user_id" t.string "text" @@ -744,9 +855,13 @@ ActiveRecord::Schema.define(:version => 20150701233306) do t.string "time_zone" t.integer "version" t.boolean "public_email", :default => false, :null => false + t.string "salt" 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", ["username"], :name => "index_users_on_username" create_table "versions", :force => true do |t| t.string "item_type", :null => false From c8b746a97b56b837a57daf274d05d87e7ba5868b Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Thu, 20 Aug 2015 23:38:21 +0100 Subject: [PATCH 28/30] Fix style --- db/migrate/20150820223313_add_index_to_forumers.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/migrate/20150820223313_add_index_to_forumers.rb b/db/migrate/20150820223313_add_index_to_forumers.rb index f3684e7..15ad4cd 100644 --- a/db/migrate/20150820223313_add_index_to_forumers.rb +++ b/db/migrate/20150820223313_add_index_to_forumers.rb @@ -1,6 +1,6 @@ class AddIndexToForumers < ActiveRecord::Migration def change - add_index :forumers, :forum_id - add_index :forumers, :group_id + add_index :forumers, :forum_id + add_index :forumers, :group_id end end From 4377d070951e42f5dfb3b20c2d8ffb3ad64237a7 Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Sat, 22 Aug 2015 10:48:08 +0100 Subject: [PATCH 29/30] Add filter to recent topics --- app/models/topic.rb | 23 +++++++++++++++-------- spec/factories/topic.rb | 2 +- spec/models/topic_spec.rb | 13 +++++++------ 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/app/models/topic.rb b/app/models/topic.rb index d1b1fe1..deb1cdb 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -42,14 +42,21 @@ class Topic < ActiveRecord::Base acts_as_readable def self.recent_topics - Post.joins("LEFT OUTER JOIN topics ON topics.id = posts.topic_id"). - joins("LEFT OUTER JOIN forums on forums.id = topics.forum_id"). - joins("LEFT OUTER JOIN forumers on forums.id = forumers.forum_id"). - order("posts.id desc"). - where("forumers.id IS NULL"). - select("DISTINCT topic_id"). - limit(5). - map(&:topic) + self.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 diff --git a/spec/factories/topic.rb b/spec/factories/topic.rb index 39637c0..fde6d83 100644 --- a/spec/factories/topic.rb +++ b/spec/factories/topic.rb @@ -1,6 +1,6 @@ FactoryGirl.define do factory :topic do - sequence(:title) { |n| "Forum Title #{n}" } + sequence(:title) { |n| "Topic Title #{n}" } forum user before(:create) do |topic| diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index e9f740c..718315a 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -29,16 +29,17 @@ describe Topic do end describe ".recent_topics" do - before(:each) do - 5.times 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 - end - it "returns 5 unique, most recently posted topics" do recent_topics = Topic.recent_topics - expect(recent_topics.length).to eq(5) - expect(recent_topics.map(&:id).uniq.length).to eq(5) + 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" From 4cfa9a7e0d6f75db13f8ce774721c8714eea00b5 Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Sat, 22 Aug 2015 11:53:26 +0100 Subject: [PATCH 30/30] Hound --- app/models/topic.rb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/models/topic.rb b/app/models/topic.rb index deb1cdb..845d87b 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -42,20 +42,20 @@ class Topic < ActiveRecord::Base acts_as_readable def self.recent_topics - self.find_by_sql %q{ - SELECT DISTINCT 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 + 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