diff options
author | Jamie Winsor <jamie@enmasse.com> | 2011-09-02 16:01:58 -0700 |
---|---|---|
committer | Jamie Winsor <jamie@enmasse.com> | 2011-09-03 21:55:30 -0700 |
commit | 6212e60f9e4d144f9a136f6c82b33abd47ddb237 (patch) | |
tree | 3ba02acc7861ef51045f0196dff6bac9efda40d5 /app | |
parent | 80ca7c1bf99befac70803309e542a4db54f1f198 (diff) | |
download | refinerycms-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')
11 files changed, 86 insertions, 62 deletions
diff --git a/app/controllers/refinery/admin/blog/comments_controller.rb b/app/controllers/refinery/admin/blog/comments_controller.rb index 9f78caa..f14e8eb 100644 --- a/app/controllers/refinery/admin/blog/comments_controller.rb +++ b/app/controllers/refinery/admin/blog/comments_controller.rb @@ -2,37 +2,44 @@ module Refinery module Admin module Blog class CommentsController < ::Admin::BaseController + + cache_sweeper Refinery::BlogSweeper crudify :'refinery/blog_comment', :title_attribute => :name, :order => 'published_at DESC' def index - @blog_comments = Refinery::BlogComment.unmoderated + @blog_comments = Refinery::BlogComment.unmoderated.page(params[:page]) + render :action => 'index' end def approved unless params[:id].present? - @blog_comments = Refinery::BlogComment.approved + @blog_comments = Refinery::BlogComment.approved.page(params[:page]) + render :action => 'index' else @blog_comment = Refinery::BlogComment.find(params[:id]) @blog_comment.approve! - flash[:notice] = t('approved', :scope => 'admin.blog.comments', :author => @blog_comment.name) - redirect_to :action => params[:return_to] || 'index' + flash[:notice] = t('approved', :scope => 'refinery.admin.blog.comments', :author => @blog_comment.name) + + redirect_to main_app.url_for(:action => params[:return_to] || 'index') end end def rejected unless params[:id].present? - @blog_comments = Refinery::BlogComment.rejected + @blog_comments = Refinery::BlogComment.rejected.page(params[:page]) + render :action => 'index' else @blog_comment = Refinery::BlogComment.find(params[:id]) @blog_comment.reject! - flash[:notice] = t('rejected', :scope => 'admin.blog.comments', :author => @blog_comment.name) - redirect_to :action => params[:return_to] || 'index' + flash[:notice] = t('rejected', :scope => 'refinery.admin.blog.comments', :author => @blog_comment.name) + + redirect_to main_app.url_for(:action => params[:return_to] || 'index') end end diff --git a/app/controllers/refinery/admin/blog/posts_controller.rb b/app/controllers/refinery/admin/blog/posts_controller.rb index 548f8c9..17ebe87 100644 --- a/app/controllers/refinery/admin/blog/posts_controller.rb +++ b/app/controllers/refinery/admin/blog/posts_controller.rb @@ -1,18 +1,21 @@ -require 'will_paginate/array' - module Refinery module Admin module Blog class PostsController < ::Admin::BaseController - + + cache_sweeper Refinery::BlogSweeper crudify :'refinery/blog_post', :title_attribute => :title, :order => 'published_at DESC' + + before_filter :find_all_categories, + :only => [:new, :edit, :create, :update] + + before_filter :check_category_ids, :only => :update def uncategorized - @blog_posts = Refinery::BlogPost.uncategorized.paginate(:page => params[:page], - :per_page => Refinery::BlogPost.per_page) + @blog_posts = Refinery::BlogPost.uncategorized.page(params[:page]) end def tags @@ -71,7 +74,7 @@ module Refinery unless request.xhr? render :action => 'new' else - render :partial => "/shared/admin/error_messages", + render :partial => "/refinery/admin/error_messages", :locals => { :object => @blog_post, :include_object_name => true @@ -80,11 +83,6 @@ module Refinery end end - before_filter :find_all_categories, - :only => [:new, :edit, :create, :update] - - before_filter :check_category_ids, :only => :update - protected def find_all_categories @blog_categories = Refinery::BlogCategory.find(:all) diff --git a/app/controllers/refinery/blog/posts_controller.rb b/app/controllers/refinery/blog/posts_controller.rb index 167aef3..aa7d45e 100644 --- a/app/controllers/refinery/blog/posts_controller.rb +++ b/app/controllers/refinery/blog/posts_controller.rb @@ -1,6 +1,9 @@ module Refinery module Blog class PostsController < BlogController + + caches_page :index + # cache_sweeper Refinery::BlogSweeper, :only => [:comment] before_filter :find_all_blog_posts, :except => [:archive] before_filter :find_blog_post, :only => [:show, :comment, :update_nav] @@ -38,10 +41,10 @@ module Refinery if Refinery::BlogComment::Moderation.enabled? flash[:notice] = t('thank_you_moderated', :scope => 'blog.posts.comments') - redirect_to blog_post_url(params[:id]) + redirect_to main_app.blog_post_url(params[:id]) else flash[:notice] = t('thank_you', :scope => 'blog.posts.comments') - redirect_to blog_post_url(params[:id], + redirect_to main_app.blog_post_url(params[:id], :anchor => "comment-#{@blog_comment.to_param}") end else diff --git a/app/models/refinery/blog_comment.rb b/app/models/refinery/blog_comment.rb index e5869a8..f7c1c84 100644 --- a/app/models/refinery/blog_comment.rb +++ b/app/models/refinery/blog_comment.rb @@ -19,6 +19,8 @@ module Refinery scope :unmoderated, :conditions => {:state => nil} scope :approved, :conditions => {:state => 'approved'} scope :rejected, :conditions => {:state => 'rejected'} + + self.per_page = Setting.find_or_set(:blog_comments_per_page, 10) def avatar_url(options = {}) options = {:size => 60} @@ -55,7 +57,7 @@ module Refinery end before_create do |comment| - unless BlogComment::Moderation.enabled? + unless Moderation.enabled? comment.state = comment.ham? ? 'approved' : 'rejected' end end 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? diff --git a/app/sweepers/refinery/blog_sweeper.rb b/app/sweepers/refinery/blog_sweeper.rb new file mode 100644 index 0000000..adf97fc --- /dev/null +++ b/app/sweepers/refinery/blog_sweeper.rb @@ -0,0 +1,25 @@ +module Refinery + class BlogSweeper < ActionController::Caching::Sweeper + observe BlogPost, BlogComment + + def after_create(record) + expire_cache_for(record) + end + + def after_update(record) + expire_cache_for(record) + end + + def after_destroy(record) + expire_cache_for(record) + end + + private + + def expire_cache_for(record) + expire_page '/blog' + expire_page '/blog/feed.rss' + end + + end +end diff --git a/app/views/refinery/admin/blog/comments/_comment.html.erb b/app/views/refinery/admin/blog/comments/_comment.html.erb index 547b9e4..f5eba4d 100644 --- a/app/views/refinery/admin/blog/comments/_comment.html.erb +++ b/app/views/refinery/admin/blog/comments/_comment.html.erb @@ -5,16 +5,16 @@ </span> <span class='actions'> <%= link_to refinery_icon_tag("application_go.png"), - blog_post_url(comment.post, :anchor => "comment-#{comment.to_param}"), + main_app.blog_post_path(comment.post, :anchor => "comment-#{comment.to_param}"), :title => t('.view_live_html'), :target => "_blank" unless comment.unmoderated? %> - <%= link_to refinery_icon_tag('zoom.png'), admin_blog_comment_path(comment), + <%= link_to refinery_icon_tag('zoom.png'), main_app.refinery_admin_blog_comment_path(comment), :title => t('.read') %> <%= link_to refinery_icon_tag("cross.png"), - rejected_admin_blog_comment_path(comment, :return_to => request.path.split('/').last.gsub(/^comments$/, 'index')), + main_app.rejected_refinery_admin_blog_comment_path(comment, :return_to => request.path.split('/').last.gsub(/^comments$/, 'index')), :title => t('.reject') unless comment.rejected? %> <%= link_to refinery_icon_tag("tick.png"), - approved_admin_blog_comment_path(comment, :return_to => request.path.split('/').last.gsub(/^comments$/, 'index')), + main_app.approved_refinery_admin_blog_comment_path(comment, :return_to => request.path.split('/').last.gsub(/^comments$/, 'index')), :title => t('.approve') unless comment.approved? %> </span> </li> diff --git a/app/views/refinery/admin/blog/comments/_sortable_list.html.erb b/app/views/refinery/admin/blog/comments/_sortable_list.html.erb index e141dee..f781ba1 100644 --- a/app/views/refinery/admin/blog/comments/_sortable_list.html.erb +++ b/app/views/refinery/admin/blog/comments/_sortable_list.html.erb @@ -1,7 +1,7 @@ <ul id='sortable_list'> <%= render :partial => 'comment', :collection => @blog_comments %> </ul> -<%= render :partial => "/shared/admin/sortable_list", +<%= render :partial => "/refinery/admin/sortable_list", :locals => { :continue_reordering => (defined?(continue_reordering) ? continue_reordering : true) } %> diff --git a/app/views/refinery/admin/blog/comments/index.html.erb b/app/views/refinery/admin/blog/comments/index.html.erb index bf2be9c..059ef59 100644 --- a/app/views/refinery/admin/blog/comments/index.html.erb +++ b/app/views/refinery/admin/blog/comments/index.html.erb @@ -1,30 +1,30 @@ -<%= render :partial => '/admin/blog/submenu' %> +<%= render :partial => '/refinery/admin/blog/submenu' %> <div id='records'> <% if searching? %> <h2><%= t('results_for', :scope => 'shared.admin.search', :query => params[:search]) %></h2> <% if @blog_comments.any? %> - <%=# will_paginate @blog_comments %> + <%= will_paginate @blog_comments %> <ul> <%= render :partial => "blog_comments", :collection => @blog_comments %> </ul> - <%=# will_paginate @blog_comments %> + <%= will_paginate @blog_comments %> <% else %> <p><%= t('search_no_results', :scope => 'admin') %></p> <% end %> <% else %> <% if @blog_comments.any? %> - <%=# will_paginate @blog_comments %> + <%= will_paginate @blog_comments %> <%= render :partial => "sortable_list" %> - <%=# will_paginate @blog_comments %> + <%= will_paginate @blog_comments %> <% else %> <h3> <%= t('.no_items_yet', - :type => t(action_name.gsub('index', 'new'), :scope => 'admin.blog.submenu.comments').downcase) %> + :type => action_name.gsub('index', 'new')).downcase %> </h3> <% end %> <% end %> diff --git a/app/views/refinery/admin/blog/comments/show.html.erb b/app/views/refinery/admin/blog/comments/show.html.erb index 2e72eb0..3dc50ff 100644 --- a/app/views/refinery/admin/blog/comments/show.html.erb +++ b/app/views/refinery/admin/blog/comments/show.html.erb @@ -6,14 +6,14 @@ <h2><%= t('.actions') %></h2> <ul> <li> - <%= link_to t('.back'), {:action => 'index'}, :class => "back_icon" %> + <%= link_to t('.back'), main_app.refinery_admin_blog_comments_path, :class => "back_icon" %> </li> <li> - <%= link_to t('.reject'), rejected_admin_blog_comment_path(@blog_comment, :return_to => 'rejected'), + <%= link_to t('.reject'), main_app.rejected_refinery_admin_blog_comment_path(@blog_comment, :return_to => 'rejected'), :class => 'comment_cross_icon' unless @blog_comment.rejected? %> </li> <li> - <%= link_to t('.approve'), approved_admin_blog_comment_path(@blog_comment, :return_to => 'approved'), + <%= link_to t('.approve'), main_app.approved_refinery_admin_blog_comment_path(@blog_comment, :return_to => 'approved'), :class => 'comment_tick_icon' unless @blog_comment.approved? %> </li> </ul> @@ -27,7 +27,7 @@ </td> <td> <%= link_to @blog_comment.post.title, - blog_post_url(@blog_comment.post, :anchor => "comment-#{@blog_comment.to_param}"), + main_app.blog_post_path(@blog_comment.post, :anchor => "comment-#{@blog_comment.to_param}"), :target => '_blank' %> </td> </tr> diff --git a/app/views/refinery/admin/blog/settings/notification_recipients.html.erb b/app/views/refinery/admin/blog/settings/notification_recipients.html.erb index 41e7f2d..d321ded 100644 --- a/app/views/refinery/admin/blog/settings/notification_recipients.html.erb +++ b/app/views/refinery/admin/blog/settings/notification_recipients.html.erb @@ -14,7 +14,7 @@ <%= t('.example') %> </p> - <%= render :partial => "/shared/admin/form_actions", + <%= render :partial => "/refinery/admin/form_actions", :locals => { :f => nil, :continue_editing => false, |