From 7f7d09295c4b0d80c60f38a9bd1f5d0419a4bb34 Mon Sep 17 00:00:00 2001 From: Chris Blanchard Date: Thu, 20 Aug 2015 15:48:19 +0100 Subject: [PATCH 01/16] 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 02/16] 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 03/16] 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 04/16] 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 05/16] 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 06/16] 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 07/16] 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 08/16] 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 09/16] 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 10/16] 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 11/16] 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 12/16] 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 13/16] 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 14/16] 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 15/16] 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 16/16] 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