aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/refinery/blog_post.rb
diff options
context:
space:
mode:
authorJamie Winsor <jamie@enmasse.com>2011-09-02 16:01:58 -0700
committerJamie Winsor <jamie@enmasse.com>2011-09-03 21:55:30 -0700
commit6212e60f9e4d144f9a136f6c82b33abd47ddb237 (patch)
tree3ba02acc7861ef51045f0196dff6bac9efda40d5 /app/models/refinery/blog_post.rb
parent80ca7c1bf99befac70803309e542a4db54f1f198 (diff)
downloadrefinerycms-blog-6212e60f9e4d144f9a136f6c82b33abd47ddb237.tar.gz
refinerycms-blog-6212e60f9e4d144f9a136f6c82b33abd47ddb237.tar.bz2
refinerycms-blog-6212e60f9e4d144f9a136f6c82b33abd47ddb237.zip
index action of blog post controller now caches and sweeps on changes
fix various views which were broken and untested with rails-3-1 upgrade add request spec tests for admin blog comments Factory is now FactoryGirl Fix multiple issues around listing unmoderated comments use cleaner definitions to set per_page willpaginate attribute on models update all paginate calls to use new arel representation reorganize filter sections to be located at top of controller modify uncategorized class method to activerecord scope and perform a left outer join instead of iterate through an array to find uncategorized posts move request specs into their proper places update guardfile to ensure that request specs get run when their respective controllers are modified Fix show action for AdminBlogComments and added test Fix redirection link after approving or rejecting a comment
Diffstat (limited to 'app/models/refinery/blog_post.rb')
-rw-r--r--app/models/refinery/blog_post.rb39
1 files changed, 14 insertions, 25 deletions
diff --git a/app/models/refinery/blog_post.rb b/app/models/refinery/blog_post.rb
index 6b27688..8cd3dd9 100644
--- a/app/models/refinery/blog_post.rb
+++ b/app/models/refinery/blog_post.rb
@@ -40,9 +40,15 @@ module Refinery
scope :live, lambda { where( "published_at <= ? and draft = ?", Time.now, false) }
scope :previous, lambda { |i| where(["published_at < ? and draft = ?", i.published_at, false]).limit(1) }
- # next is now in << self
+
+ scope :uncategorized, lambda {
+ live.includes(:categories).where(:categories => { Refinery::Categorization.table_name => { :blog_category_id => nil } })
+ }
- attr_accessible :title, :body, :custom_teaser, :tag_list, :draft, :published_at, :custom_url, :browser_title, :meta_keywords, :meta_description, :user_id, :category_ids
+ attr_accessible :title, :body, :custom_teaser, :tag_list, :draft, :published_at, :custom_url
+ attr_accessible :browser_title, :meta_keywords, :meta_description, :user_id, :category_ids
+
+ self.per_page = Refinery::Setting.find_or_set(:blog_posts_per_page, 10)
def next
BlogPost.next(self).first
@@ -67,38 +73,23 @@ module Refinery
end
class << self
- def next current_record
+ def next(current_record)
self.send(:with_exclusive_scope) do
where(["published_at > ? and draft = ?", current_record.published_at, false]).order("published_at ASC")
end
end
def comments_allowed?
- Refinery::Setting.find_or_set(:comments_allowed, true, {
- :scoping => 'blog'
- })
+ Refinery::Setting.find_or_set(:comments_allowed, true, :scoping => 'blog')
end
def teasers_enabled?
- Refinery::Setting.find_or_set(:teasers_enabled, true, {
- :scoping => 'blog'
- })
+ Refinery::Setting.find_or_set(:teasers_enabled, true, :scoping => 'blog')
end
def teaser_enabled_toggle!
- currently = Refinery::Setting.find_or_set(:teasers_enabled, true, {
- :scoping => 'blog'
- })
- Refinery::Setting.set(:teasers_enabled, {:value => !currently, :scoping => 'blog'})
- end
-
- def uncategorized
- BlogPost.live.reject { |p| p.categories.any? }
- end
-
- # how many items to show per page
- def per_page
- Refinery::Setting.find_or_set(:blog_posts_per_page, 10)
+ currently = Refinery::Setting.find_or_set(:teasers_enabled, true, :scoping => 'blog')
+ Refinery::Setting.set(:teasers_enabled, :value => !currently, :scoping => 'blog')
end
end
@@ -107,9 +98,7 @@ module Refinery
class << self
def key
- Refinery::Setting.find_or_set(:share_this_key, BlogPost::ShareThis::DEFAULT_KEY, {
- :scoping => 'blog'
- })
+ Refinery::Setting.find_or_set(:share_this_key, BlogPost::ShareThis::DEFAULT_KEY, :scoping => 'blog')
end
def enabled?