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
This commit is contained in:
Jamie Winsor 2011-09-02 16:01:58 -07:00
parent 80ca7c1bf9
commit 6212e60f9e
20 changed files with 420 additions and 266 deletions

View file

@ -2,7 +2,7 @@ guard 'rspec', :version => 2, :cli => "--format Fuubar --color --drb" do
watch(%r{^spec/.+_spec\.rb$}) watch(%r{^spec/.+_spec\.rb$})
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] } watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/controllers/#{m[1]}_#{m[2]}_spec.rb", "spec/requests/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" } watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('spec/spec_helper.rb') { "spec" } watch('spec/spec_helper.rb') { "spec" }
watch('config/routes.rb') { "spec/routing" } watch('config/routes.rb') { "spec/routing" }

View file

@ -2,37 +2,44 @@ module Refinery
module Admin module Admin
module Blog module Blog
class CommentsController < ::Admin::BaseController class CommentsController < ::Admin::BaseController
cache_sweeper Refinery::BlogSweeper
crudify :'refinery/blog_comment', crudify :'refinery/blog_comment',
:title_attribute => :name, :title_attribute => :name,
:order => 'published_at DESC' :order => 'published_at DESC'
def index def index
@blog_comments = Refinery::BlogComment.unmoderated @blog_comments = Refinery::BlogComment.unmoderated.page(params[:page])
render :action => 'index' render :action => 'index'
end end
def approved def approved
unless params[:id].present? unless params[:id].present?
@blog_comments = Refinery::BlogComment.approved @blog_comments = Refinery::BlogComment.approved.page(params[:page])
render :action => 'index' render :action => 'index'
else else
@blog_comment = Refinery::BlogComment.find(params[:id]) @blog_comment = Refinery::BlogComment.find(params[:id])
@blog_comment.approve! @blog_comment.approve!
flash[:notice] = t('approved', :scope => 'admin.blog.comments', :author => @blog_comment.name) flash[:notice] = t('approved', :scope => 'refinery.admin.blog.comments', :author => @blog_comment.name)
redirect_to :action => params[:return_to] || 'index'
redirect_to main_app.url_for(:action => params[:return_to] || 'index')
end end
end end
def rejected def rejected
unless params[:id].present? unless params[:id].present?
@blog_comments = Refinery::BlogComment.rejected @blog_comments = Refinery::BlogComment.rejected.page(params[:page])
render :action => 'index' render :action => 'index'
else else
@blog_comment = Refinery::BlogComment.find(params[:id]) @blog_comment = Refinery::BlogComment.find(params[:id])
@blog_comment.reject! @blog_comment.reject!
flash[:notice] = t('rejected', :scope => 'admin.blog.comments', :author => @blog_comment.name) flash[:notice] = t('rejected', :scope => 'refinery.admin.blog.comments', :author => @blog_comment.name)
redirect_to :action => params[:return_to] || 'index'
redirect_to main_app.url_for(:action => params[:return_to] || 'index')
end end
end end

View file

@ -1,18 +1,21 @@
require 'will_paginate/array'
module Refinery module Refinery
module Admin module Admin
module Blog module Blog
class PostsController < ::Admin::BaseController class PostsController < ::Admin::BaseController
cache_sweeper Refinery::BlogSweeper
crudify :'refinery/blog_post', crudify :'refinery/blog_post',
:title_attribute => :title, :title_attribute => :title,
:order => 'published_at DESC' :order => 'published_at DESC'
before_filter :find_all_categories,
:only => [:new, :edit, :create, :update]
before_filter :check_category_ids, :only => :update
def uncategorized def uncategorized
@blog_posts = Refinery::BlogPost.uncategorized.paginate(:page => params[:page], @blog_posts = Refinery::BlogPost.uncategorized.page(params[:page])
:per_page => Refinery::BlogPost.per_page)
end end
def tags def tags
@ -71,7 +74,7 @@ module Refinery
unless request.xhr? unless request.xhr?
render :action => 'new' render :action => 'new'
else else
render :partial => "/shared/admin/error_messages", render :partial => "/refinery/admin/error_messages",
:locals => { :locals => {
:object => @blog_post, :object => @blog_post,
:include_object_name => true :include_object_name => true
@ -80,11 +83,6 @@ module Refinery
end end
end end
before_filter :find_all_categories,
:only => [:new, :edit, :create, :update]
before_filter :check_category_ids, :only => :update
protected protected
def find_all_categories def find_all_categories
@blog_categories = Refinery::BlogCategory.find(:all) @blog_categories = Refinery::BlogCategory.find(:all)

View file

@ -1,6 +1,9 @@
module Refinery module Refinery
module Blog module Blog
class PostsController < BlogController class PostsController < BlogController
caches_page :index
# cache_sweeper Refinery::BlogSweeper, :only => [:comment]
before_filter :find_all_blog_posts, :except => [:archive] before_filter :find_all_blog_posts, :except => [:archive]
before_filter :find_blog_post, :only => [:show, :comment, :update_nav] before_filter :find_blog_post, :only => [:show, :comment, :update_nav]
@ -38,10 +41,10 @@ module Refinery
if Refinery::BlogComment::Moderation.enabled? if Refinery::BlogComment::Moderation.enabled?
flash[:notice] = t('thank_you_moderated', :scope => 'blog.posts.comments') 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 else
flash[:notice] = t('thank_you', :scope => 'blog.posts.comments') 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}") :anchor => "comment-#{@blog_comment.to_param}")
end end
else else

View file

@ -19,6 +19,8 @@ module Refinery
scope :unmoderated, :conditions => {:state => nil} scope :unmoderated, :conditions => {:state => nil}
scope :approved, :conditions => {:state => 'approved'} scope :approved, :conditions => {:state => 'approved'}
scope :rejected, :conditions => {:state => 'rejected'} scope :rejected, :conditions => {:state => 'rejected'}
self.per_page = Setting.find_or_set(:blog_comments_per_page, 10)
def avatar_url(options = {}) def avatar_url(options = {})
options = {:size => 60} options = {:size => 60}
@ -55,7 +57,7 @@ module Refinery
end end
before_create do |comment| before_create do |comment|
unless BlogComment::Moderation.enabled? unless Moderation.enabled?
comment.state = comment.ham? ? 'approved' : 'rejected' comment.state = comment.ham? ? 'approved' : 'rejected'
end end
end end

View file

@ -40,9 +40,15 @@ module Refinery
scope :live, lambda { where( "published_at <= ? and draft = ?", Time.now, false) } 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) } 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 def next
BlogPost.next(self).first BlogPost.next(self).first
@ -67,38 +73,23 @@ module Refinery
end end
class << self class << self
def next current_record def next(current_record)
self.send(:with_exclusive_scope) do self.send(:with_exclusive_scope) do
where(["published_at > ? and draft = ?", current_record.published_at, false]).order("published_at ASC") where(["published_at > ? and draft = ?", current_record.published_at, false]).order("published_at ASC")
end end
end end
def comments_allowed? def comments_allowed?
Refinery::Setting.find_or_set(:comments_allowed, true, { Refinery::Setting.find_or_set(:comments_allowed, true, :scoping => 'blog')
:scoping => 'blog'
})
end end
def teasers_enabled? def teasers_enabled?
Refinery::Setting.find_or_set(:teasers_enabled, true, { Refinery::Setting.find_or_set(:teasers_enabled, true, :scoping => 'blog')
:scoping => 'blog'
})
end end
def teaser_enabled_toggle! def teaser_enabled_toggle!
currently = Refinery::Setting.find_or_set(:teasers_enabled, true, { currently = Refinery::Setting.find_or_set(:teasers_enabled, true, :scoping => 'blog')
:scoping => 'blog' Refinery::Setting.set(:teasers_enabled, :value => !currently, :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)
end end
end end
@ -107,9 +98,7 @@ module Refinery
class << self class << self
def key def key
Refinery::Setting.find_or_set(:share_this_key, BlogPost::ShareThis::DEFAULT_KEY, { Refinery::Setting.find_or_set(:share_this_key, BlogPost::ShareThis::DEFAULT_KEY, :scoping => 'blog')
:scoping => 'blog'
})
end end
def enabled? def enabled?

View file

@ -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

View file

@ -5,16 +5,16 @@
</span> </span>
<span class='actions'> <span class='actions'>
<%= link_to refinery_icon_tag("application_go.png"), <%= 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'), :title => t('.view_live_html'),
:target => "_blank" unless comment.unmoderated? %> :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') %> :title => t('.read') %>
<%= link_to refinery_icon_tag("cross.png"), <%= 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? %> :title => t('.reject') unless comment.rejected? %>
<%= link_to refinery_icon_tag("tick.png"), <%= 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? %> :title => t('.approve') unless comment.approved? %>
</span> </span>
</li> </li>

View file

@ -1,7 +1,7 @@
<ul id='sortable_list'> <ul id='sortable_list'>
<%= render :partial => 'comment', :collection => @blog_comments %> <%= render :partial => 'comment', :collection => @blog_comments %>
</ul> </ul>
<%= render :partial => "/shared/admin/sortable_list", <%= render :partial => "/refinery/admin/sortable_list",
:locals => { :locals => {
:continue_reordering => (defined?(continue_reordering) ? continue_reordering : true) :continue_reordering => (defined?(continue_reordering) ? continue_reordering : true)
} %> } %>

View file

@ -1,30 +1,30 @@
<%= render :partial => '/admin/blog/submenu' %> <%= render :partial => '/refinery/admin/blog/submenu' %>
<div id='records'> <div id='records'>
<% if searching? %> <% if searching? %>
<h2><%= t('results_for', :scope => 'shared.admin.search', :query => params[:search]) %></h2> <h2><%= t('results_for', :scope => 'shared.admin.search', :query => params[:search]) %></h2>
<% if @blog_comments.any? %> <% if @blog_comments.any? %>
<%=# will_paginate @blog_comments %> <%= will_paginate @blog_comments %>
<ul> <ul>
<%= render :partial => "blog_comments", <%= render :partial => "blog_comments",
:collection => @blog_comments %> :collection => @blog_comments %>
</ul> </ul>
<%=# will_paginate @blog_comments %> <%= will_paginate @blog_comments %>
<% else %> <% else %>
<p><%= t('search_no_results', :scope => 'admin') %></p> <p><%= t('search_no_results', :scope => 'admin') %></p>
<% end %> <% end %>
<% else %> <% else %>
<% if @blog_comments.any? %> <% if @blog_comments.any? %>
<%=# will_paginate @blog_comments %> <%= will_paginate @blog_comments %>
<%= render :partial => "sortable_list" %> <%= render :partial => "sortable_list" %>
<%=# will_paginate @blog_comments %> <%= will_paginate @blog_comments %>
<% else %> <% else %>
<h3> <h3>
<%= t('.no_items_yet', <%= 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> </h3>
<% end %> <% end %>
<% end %> <% end %>

View file

@ -6,14 +6,14 @@
<h2><%= t('.actions') %></h2> <h2><%= t('.actions') %></h2>
<ul> <ul>
<li> <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>
<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? %> :class => 'comment_cross_icon' unless @blog_comment.rejected? %>
</li> </li>
<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? %> :class => 'comment_tick_icon' unless @blog_comment.approved? %>
</li> </li>
</ul> </ul>
@ -27,7 +27,7 @@
</td> </td>
<td> <td>
<%= link_to @blog_comment.post.title, <%= 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' %> :target => '_blank' %>
</td> </td>
</tr> </tr>

View file

@ -14,7 +14,7 @@
<%= t('.example') %> <%= t('.example') %>
</p> </p>
<%= render :partial => "/shared/admin/form_actions", <%= render :partial => "/refinery/admin/form_actions",
:locals => { :locals => {
:f => nil, :f => nil,
:continue_editing => false, :continue_editing => false,

View file

@ -11,7 +11,7 @@ Dummy::Application.configure do
# Show full error reports and disable caching # Show full error reports and disable caching
config.consider_all_requests_local = true config.consider_all_requests_local = true
config.action_controller.perform_caching = false config.action_controller.perform_caching = true
# Don't care if the mailer can't send # Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false config.action_mailer.raise_delivery_errors = false

View file

@ -1,23 +0,0 @@
require "spec_helper"
describe "blog categories" do
login_refinery_user
context "has one category and post" do
before(:each) do
@blog_post = FactoryGirl.create(:blog_post, :title => "Refinery CMS blog post")
@blog_category = FactoryGirl.create(:blog_category, :title => "Video Games")
@blog_post.categories << @blog_category
@blog_post.save!
end
describe "show categories blog posts" do
before(:each) { visit blog_category_path(@blog_category) }
it "should displays categories blog posts" do
page.should have_content("Refinery CMS blog post")
page.should have_content("Video Games")
end
end
end
end

View file

@ -1,38 +0,0 @@
require "spec_helper"
describe "blog posts" do
login_refinery_user
context "when has blog posts" do
let(:blog_post) { Factory(:blog_post, :title => "Refinery CMS blog post") }
it "should display blog post" do
visit blog_post_path(blog_post)
page.should have_content("Refinery CMS blog post")
end
it "should display the blog rss feed" do
get blog_rss_feed_path
response.should be_success
response.content_type.should eq("application/rss+xml")
end
end
describe "list tagged posts" do
context "when has tagged blog posts" do
before(:each) do
@tag_name = "chicago"
@blog_post = FactoryGirl.create(:blog_post,
:title => "I Love my city",
:tag_list => @tag_name)
tag = ::Refinery::BlogPost.tag_counts_on(:tags).first
visit tagged_posts_path(tag.id, @tag_name.parameterize)
end
it "should have one tagged post" do
page.should have_content(@tag_name)
page.should have_content(@blog_post.title)
end
end
end
end

View file

@ -1,141 +0,0 @@
require "spec_helper"
describe "manage blog posts" do
login_refinery_user
let!(:blog_category) { FactoryGirl.create(:blog_category, :title => "Video Games") }
context "when no blog posts" do
before(:each) { Refinery::BlogPost.destroy_all }
describe "blog post listing" do
before(:each) { visit refinery_admin_blog_posts_path }
it "invites to create new post" do
page.should have_content("There are no Blog Posts yet. Click \"Create new post\" to add your first blog post.")
end
end
describe "new blog post form" do
before(:each) do
visit refinery_admin_blog_posts_path
click_link "Create new post"
end
it "should have Tags" do
page.should have_content("Tags")
end
it "should have Video Games" do
page.should have_content(blog_category.title)
end
describe "create blog post" do
before(:each) do
fill_in "Title", :with => "This is my blog post"
fill_in "blog_post_body", :with => "And I love it"
check blog_category.title
click_button "Save"
end
it "should succeed" do
page.should have_content("was successfully added.")
end
it "should be the only blog post" do
::Refinery::BlogPost.all.size.should eq(1)
end
it "should belong to me" do
::Refinery::BlogPost.first.author.login.should eq(::Refinery::User.last.login)
end
it "should save categories" do
::Refinery::BlogPost.last.categories.count.should eq(1)
::Refinery::BlogPost.last.categories.first.title.should eq(blog_category.title)
end
end
describe "create blog post with tags" do
before(:each) do
@tag_list = "chicago, bikes, beers, babes"
fill_in "Title", :with => "This is a tagged blog post"
fill_in "blog_post_body", :with => "And I also love it"
fill_in "Tags", :with => @tag_list
click_button "Save"
end
it "should succeed" do
page.should have_content("was successfully added.")
end
it "should be the only blog post" do
::Refinery::BlogPost.all.size.should eq(1)
end
it "should have the specified tags" do
::Refinery::BlogPost.last.tag_list.should eq(@tag_list.split(', '))
end
end
end
end
context "when has blog posts" do
let!(:blog_post) { Factory(:blog_post) }
describe "blog post listing" do
before(:each) { visit refinery_admin_blog_posts_path }
describe "edit blog post" do
it "should succeed" do
page.should have_content(blog_post.title)
click_link("Edit this blog post")
current_path.should == edit_refinery_admin_blog_post_path(blog_post)
fill_in "Title", :with => "hax0r"
click_button "Save"
page.should_not have_content(blog_post.title)
page.should have_content("'hax0r' was successfully updated.")
end
end
describe "deleting blog post" do
it "should succeed" do
page.should have_content(blog_post.title)
click_link "Remove this blog post forever"
page.should have_content("'#{blog_post.title}' was successfully removed.")
end
end
describe "view live" do
it "redirects to blog post in the frontend" do
click_link "View this blog post live"
current_path.should == blog_post_path(blog_post)
page.should have_content(blog_post.title)
end
end
end
context "when uncategorized post" do
it "shows up in the list" do
visit uncategorized_refinery_admin_blog_posts_path
page.should have_content(blog_post.title)
end
end
context "when categorized post" do
it "won't show up in the list" do
blog_post.categories << blog_category
blog_post.save!
visit uncategorized_refinery_admin_blog_posts_path
page.should_not have_content(blog_post.title)
end
end
end
end

View file

@ -0,0 +1,124 @@
require "spec_helper"
module Refinery
describe "AdminBlogComments" do
login_refinery_user
describe "#index" do
context "when has no new unapproved comments" do
before(:each) do
BlogComment.delete_all
visit refinery_admin_blog_comments_path
end
it "should list no comments" do
visit refinery_admin_blog_comments_path
page.should have_content('there are no new comments')
end
end
context "when has new unapproved comments" do
let!(:blog_comment) { FactoryGirl.create(:blog_comment) }
before(:each) { visit refinery_admin_blog_comments_path }
it "should list comments" do
page.should have_content(blog_comment.body)
page.should have_content(blog_comment.name)
end
it "should allow me to approve a comment" do
click_link "Approve this comment"
page.should have_content("has been approved")
end
it "should allow me to reject a comment" do
click_link "Reject this comment"
page.should have_content("has been rejected")
end
end
end
describe "#approved" do
context "when has no approved comments" do
before(:each) do
BlogComment.delete_all
visit approved_refinery_admin_blog_comments_path
end
it "should list no comments" do
page.should have_content('there are no approved comments')
end
end
context "when has approved comments" do
let!(:blog_comment) do
FactoryGirl.create(:blog_comment,
:state => 'approved')
end
before(:each) { visit approved_refinery_admin_blog_comments_path }
it "should list comments" do
page.should have_content(blog_comment.body)
page.should have_content(blog_comment.name)
end
it "should allow me to reject a comment" do
click_link "Reject this comment"
page.should have_content("has been rejected")
end
end
end
describe "#rejected" do
context "when has no rejected comments" do
before(:each) do
BlogComment.delete_all
visit rejected_refinery_admin_blog_comments_path
end
it "should list no comments" do
page.should have_content('there are no rejected comments')
end
end
context "when has rejected comments" do
let!(:blog_comment) do
FactoryGirl.create(:blog_comment,
:state => 'rejected')
end
before(:each) { visit rejected_refinery_admin_blog_comments_path }
it "should list comments" do
page.should have_content(blog_comment.body)
page.should have_content(blog_comment.name)
end
it "should allow me to approve a comment" do
click_link "Approve this comment"
page.should have_content("has been approved")
end
end
end
describe "#show" do
let!(:blog_comment) { FactoryGirl.create(:blog_comment) }
before(:each) { visit refinery_admin_blog_comment_path(blog_comment) }
it "should display the comment" do
page.should have_content(blog_comment.body)
page.should have_content(blog_comment.name)
end
it "should allow me to approve the comment" do
click_link "Approve this comment"
page.should have_content("has been approved")
end
end
end
end

View file

@ -0,0 +1,143 @@
require "spec_helper"
module Refinery
describe "AdminBlogPosts" do
login_refinery_user
let!(:blog_category) { FactoryGirl.create(:blog_category, :title => "Video Games") }
context "when no blog posts" do
before(:each) { Refinery::BlogPost.destroy_all }
describe "blog post listing" do
before(:each) { visit refinery_admin_blog_posts_path }
it "invites to create new post" do
page.should have_content("There are no Blog Posts yet. Click \"Create new post\" to add your first blog post.")
end
end
describe "new blog post form" do
before(:each) do
visit refinery_admin_blog_posts_path
click_link "Create new post"
end
it "should have Tags" do
page.should have_content("Tags")
end
it "should have Video Games" do
page.should have_content(blog_category.title)
end
describe "create blog post" do
before(:each) do
fill_in "Title", :with => "This is my blog post"
fill_in "blog_post_body", :with => "And I love it"
check blog_category.title
click_button "Save"
end
it "should succeed" do
page.should have_content("was successfully added.")
end
it "should be the only blog post" do
::Refinery::BlogPost.all.size.should eq(1)
end
it "should belong to me" do
::Refinery::BlogPost.first.author.login.should eq(::Refinery::User.last.login)
end
it "should save categories" do
::Refinery::BlogPost.last.categories.count.should eq(1)
::Refinery::BlogPost.last.categories.first.title.should eq(blog_category.title)
end
end
describe "create blog post with tags" do
before(:each) do
@tag_list = "chicago, bikes, beers, babes"
fill_in "Title", :with => "This is a tagged blog post"
fill_in "blog_post_body", :with => "And I also love it"
fill_in "Tags", :with => @tag_list
click_button "Save"
end
it "should succeed" do
page.should have_content("was successfully added.")
end
it "should be the only blog post" do
::Refinery::BlogPost.all.size.should eq(1)
end
it "should have the specified tags" do
::Refinery::BlogPost.last.tag_list.should eq(@tag_list.split(', '))
end
end
end
end
context "when has blog posts" do
let!(:blog_post) { FactoryGirl.create(:blog_post) }
describe "blog post listing" do
before(:each) { visit refinery_admin_blog_posts_path }
describe "edit blog post" do
it "should succeed" do
page.should have_content(blog_post.title)
click_link("Edit this blog post")
current_path.should == edit_refinery_admin_blog_post_path(blog_post)
fill_in "Title", :with => "hax0r"
click_button "Save"
page.should_not have_content(blog_post.title)
page.should have_content("'hax0r' was successfully updated.")
end
end
describe "deleting blog post" do
it "should succeed" do
page.should have_content(blog_post.title)
click_link "Remove this blog post forever"
page.should have_content("'#{blog_post.title}' was successfully removed.")
end
end
describe "view live" do
it "redirects to blog post in the frontend" do
click_link "View this blog post live"
current_path.should == blog_post_path(blog_post)
page.should have_content(blog_post.title)
end
end
end
context "when uncategorized post" do
it "shows up in the list" do
visit uncategorized_refinery_admin_blog_posts_path
page.should have_content(blog_post.title)
end
end
context "when categorized post" do
it "won't show up in the list" do
blog_post.categories << blog_category
blog_post.save!
visit uncategorized_refinery_admin_blog_posts_path
page.should_not have_content(blog_post.title)
end
end
end
end
end

View file

@ -0,0 +1,25 @@
require "spec_helper"
module Refinery
describe "BlogCategories" do
login_refinery_user
context "has one category and post" do
before(:each) do
@blog_post = FactoryGirl.create(:blog_post, :title => "Refinery CMS blog post")
@blog_category = FactoryGirl.create(:blog_category, :title => "Video Games")
@blog_post.categories << @blog_category
@blog_post.save!
end
describe "show categories blog posts" do
before(:each) { visit blog_category_path(@blog_category) }
it "should displays categories blog posts" do
page.should have_content("Refinery CMS blog post")
page.should have_content("Video Games")
end
end
end
end
end

View file

@ -0,0 +1,40 @@
require "spec_helper"
module Refinery
describe "BlogPosts" do
login_refinery_user
context "when has blog posts" do
let(:blog_post) { FactoryGirl.create(:blog_post, :title => "Refinery CMS blog post") }
it "should display blog post" do
visit blog_post_path(blog_post)
page.should have_content("Refinery CMS blog post")
end
it "should display the blog rss feed" do
get blog_rss_feed_path
response.should be_success
response.content_type.should eq("application/rss+xml")
end
end
describe "list tagged posts" do
context "when has tagged blog posts" do
before(:each) do
@tag_name = "chicago"
@blog_post = FactoryGirl.create(:blog_post,
:title => "I Love my city",
:tag_list => @tag_name)
tag = ::Refinery::BlogPost.tag_counts_on(:tags).first
visit tagged_posts_path(tag.id, @tag_name.parameterize)
end
it "should have one tagged post" do
page.should have_content(@tag_name)
page.should have_content(@blog_post.title)
end
end
end
end
end