From e06356ebbe597f38673235a86728a9181af23ca8 Mon Sep 17 00:00:00 2001 From: Einar Jonsson Date: Fri, 30 Aug 2013 17:39:31 +0000 Subject: [PATCH] Extracted a fake_admin method --- app/models/category_featured_topic.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/models/category_featured_topic.rb b/app/models/category_featured_topic.rb index 5bbdc3acae7..3329cd4b249 100644 --- a/app/models/category_featured_topic.rb +++ b/app/models/category_featured_topic.rb @@ -18,12 +18,7 @@ class CategoryFeaturedTopic < ActiveRecord::Base CategoryFeaturedTopic.transaction do CategoryFeaturedTopic.delete_all(category_id: c.id) - # fake an admin - admin = User.new - admin.admin = true - admin.id = -1 - - query = TopicQuery.new(admin, per_page: SiteSetting.category_featured_topics, except_topic_id: c.topic_id, visible: true) + query = TopicQuery.new(self.fake_admin, per_page: SiteSetting.category_featured_topics, except_topic_id: c.topic_id, visible: true) results = query.list_category(c) if results.present? results.topic_ids.each_with_index do |topic_id, idx| @@ -33,6 +28,15 @@ class CategoryFeaturedTopic < ActiveRecord::Base end end + private + def self.fake_admin + # fake an admin + admin = User.new + admin.admin = true + admin.id = -1 + admin + end + end # == Schema Information