diff --git a/Gemfile b/Gemfile index 14029a3c9..e381bc516 100644 --- a/Gemfile +++ b/Gemfile @@ -63,6 +63,7 @@ group :development, :test do gem "capistrano-bundler", '1.1.4', require: false gem "capistrano-rails", '1.1.3', require: false gem "capistrano-rvm", require: false + gem "bullet" end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index adeb5d99f..94e26694c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -62,6 +62,9 @@ GEM debug_inspector (>= 0.0.1) browser (0.9.1) builder (3.2.2) + bullet (4.14.7) + activesupport (>= 3.0.0) + uniform_notifier (~> 1.9.0) byebug (6.0.2) cancancan (1.12.0) capistrano (3.4.0) @@ -345,6 +348,7 @@ GEM kgio (~> 2.6) rack raindrops (~> 0.7) + uniform_notifier (1.9.0) user_agent_parser (2.2.0) uuidtools (2.1.5) warden (1.2.3) @@ -368,6 +372,7 @@ DEPENDENCIES acts_as_commentable_with_threading acts_as_votable ahoy_matey (~> 1.2.1) + bullet byebug cancancan capistrano (= 3.4.0) diff --git a/app/controllers/admin/officials_controller.rb b/app/controllers/admin/officials_controller.rb index 023f0f7fc..f83aa1e18 100644 --- a/app/controllers/admin/officials_controller.rb +++ b/app/controllers/admin/officials_controller.rb @@ -1,11 +1,11 @@ class Admin::OfficialsController < Admin::BaseController def index - @officials = User.officials.page(params[:page]) + @officials = User.officials.page(params[:page]).for_render end def search - @users = User.with_email(params[:email]).page(params[:page]) + @users = User.with_email(params[:email]).page(params[:page]).for_render end def edit @@ -29,4 +29,4 @@ class Admin::OfficialsController < Admin::BaseController params.require(:user).permit(:official_position, :official_level) end -end \ No newline at end of file +end diff --git a/app/controllers/debates_controller.rb b/app/controllers/debates_controller.rb index f8e7b968a..cf6d14f65 100644 --- a/app/controllers/debates_controller.rb +++ b/app/controllers/debates_controller.rb @@ -5,13 +5,13 @@ class DebatesController < ApplicationController respond_to :html, :js def index - @debates = Debate.includes(:tags).includes(:inappropiate_flags).search(params).page(params[:page]) + @debates = Debate.search(params).page(params[:page]).for_render set_debate_votes(@debates) end def show set_debate_votes(@debate) - @comments = @debate.root_comments.with_hidden.includes(:inappropiate_flags).recent.page(params[:page]) + @comments = @debate.root_comments.recent.page(params[:page]).for_render end def new diff --git a/app/models/comment.rb b/app/models/comment.rb index dca894b7c..db8fb35fc 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -14,7 +14,6 @@ class Comment < ActiveRecord::Base has_many :inappropiate_flags, :as => :flaggable - default_scope { includes(:user) } scope :recent, -> { order(id: :desc) } scope :sorted_for_moderation, -> { order(inappropiate_flags_count: :desc, updated_at: :desc) } @@ -22,6 +21,8 @@ class Comment < ActiveRecord::Base scope :archived, -> { where("archived_at IS NOT NULL AND hidden_at IS NULL") } scope :flagged_as_inappropiate, -> { where("inappropiate_flags_count > 0") } + scope :for_render, -> { with_hidden.includes(user: :organization) } + def self.build(commentable, user, body) new commentable: commentable, user_id: user.id, diff --git a/app/models/debate.rb b/app/models/debate.rb index 7b43bc71c..15590fc60 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -27,6 +27,7 @@ class Debate < ActiveRecord::Base scope :pending, -> { where(archived_at: nil, hidden_at: nil) } scope :archived, -> { where("archived_at IS NOT NULL AND hidden_at IS NULL") } scope :flagged_as_inappropiate, -> { where("inappropiate_flags_count > 0") } + scope :for_render, -> { includes(:tags) } # Ahoy setup visitable # Ahoy will automatically assign visit_id on create diff --git a/app/models/user.rb b/app/models/user.rb index 7cff8d732..d7b77a7e0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -25,11 +25,11 @@ class User < ActiveRecord::Base accepts_nested_attributes_for :organization - default_scope { includes(:organization) } scope :administrators, -> { joins(:administrators) } scope :moderators, -> { joins(:moderator) } scope :organizations, -> { joins(:organization) } scope :officials, -> { where("official_level > 0") } + scope :for_render, -> { includes(:organization) } def self.find_for_oauth(auth, signed_in_resource = nil) # Get the identity and user if they exist diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 1b6f713ba..5ffff4a85 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -95,7 +95,7 @@ <% end %>