aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Arndt <parndt@gmail.com>2011-09-03 22:09:51 -0700
committerPhilip Arndt <parndt@gmail.com>2011-09-03 22:09:51 -0700
commit40be4f71ee425ee55ecedea96ff2b0dc510d71db (patch)
tree3ba02acc7861ef51045f0196dff6bac9efda40d5
parent80ca7c1bf99befac70803309e542a4db54f1f198 (diff)
parent6212e60f9e4d144f9a136f6c82b33abd47ddb237 (diff)
downloadrefinerycms-blog-40be4f71ee425ee55ecedea96ff2b0dc510d71db.tar.gz
refinerycms-blog-40be4f71ee425ee55ecedea96ff2b0dc510d71db.tar.bz2
refinerycms-blog-40be4f71ee425ee55ecedea96ff2b0dc510d71db.zip
Merge pull request #126 from enmasse-entertainment/fix-comments
Fix comments
-rw-r--r--Guardfile2
-rw-r--r--app/controllers/refinery/admin/blog/comments_controller.rb21
-rw-r--r--app/controllers/refinery/admin/blog/posts_controller.rb20
-rw-r--r--app/controllers/refinery/blog/posts_controller.rb7
-rw-r--r--app/models/refinery/blog_comment.rb4
-rw-r--r--app/models/refinery/blog_post.rb39
-rw-r--r--app/sweepers/refinery/blog_sweeper.rb25
-rw-r--r--app/views/refinery/admin/blog/comments/_comment.html.erb8
-rw-r--r--app/views/refinery/admin/blog/comments/_sortable_list.html.erb2
-rw-r--r--app/views/refinery/admin/blog/comments/index.html.erb12
-rw-r--r--app/views/refinery/admin/blog/comments/show.html.erb8
-rw-r--r--app/views/refinery/admin/blog/settings/notification_recipients.html.erb2
-rw-r--r--spec/dummy/config/environments/development.rb2
-rw-r--r--spec/requests/blog_categories_spec.rb23
-rw-r--r--spec/requests/blog_posts_spec.rb38
-rw-r--r--spec/requests/manage_blog_posts_spec.rb141
-rw-r--r--spec/requests/refinery/admin/blog/comments_spec.rb124
-rw-r--r--spec/requests/refinery/admin/blog/posts_spec.rb143
-rw-r--r--spec/requests/refinery/blog/categories_spec.rb25
-rw-r--r--spec/requests/refinery/blog/posts_spec.rb40
20 files changed, 420 insertions, 266 deletions
diff --git a/Guardfile b/Guardfile
index 7774821..0de2882 100644
--- a/Guardfile
+++ b/Guardfile
@@ -2,7 +2,7 @@ guard 'rspec', :version => 2, :cli => "--format Fuubar --color --drb" do
watch(%r{^spec/.+_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{^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('spec/spec_helper.rb') { "spec" }
watch('config/routes.rb') { "spec/routing" }
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,
diff --git a/spec/dummy/config/environments/development.rb b/spec/dummy/config/environments/development.rb
index 8604338..c777820 100644
--- a/spec/dummy/config/environments/development.rb
+++ b/spec/dummy/config/environments/development.rb
@@ -11,7 +11,7 @@ Dummy::Application.configure do
# Show full error reports and disable caching
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
config.action_mailer.raise_delivery_errors = false
diff --git a/spec/requests/blog_categories_spec.rb b/spec/requests/blog_categories_spec.rb
deleted file mode 100644
index a554891..0000000
--- a/spec/requests/blog_categories_spec.rb
+++ /dev/null
@@ -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
diff --git a/spec/requests/blog_posts_spec.rb b/spec/requests/blog_posts_spec.rb
deleted file mode 100644
index ec84b90..0000000
--- a/spec/requests/blog_posts_spec.rb
+++ /dev/null
@@ -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
diff --git a/spec/requests/manage_blog_posts_spec.rb b/spec/requests/manage_blog_posts_spec.rb
deleted file mode 100644
index 2a299d0..0000000
--- a/spec/requests/manage_blog_posts_spec.rb
+++ /dev/null
@@ -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
diff --git a/spec/requests/refinery/admin/blog/comments_spec.rb b/spec/requests/refinery/admin/blog/comments_spec.rb
new file mode 100644
index 0000000..a0213f6
--- /dev/null
+++ b/spec/requests/refinery/admin/blog/comments_spec.rb
@@ -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
diff --git a/spec/requests/refinery/admin/blog/posts_spec.rb b/spec/requests/refinery/admin/blog/posts_spec.rb
new file mode 100644
index 0000000..73bdf93
--- /dev/null
+++ b/spec/requests/refinery/admin/blog/posts_spec.rb
@@ -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
diff --git a/spec/requests/refinery/blog/categories_spec.rb b/spec/requests/refinery/blog/categories_spec.rb
new file mode 100644
index 0000000..48a3417
--- /dev/null
+++ b/spec/requests/refinery/blog/categories_spec.rb
@@ -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
diff --git a/spec/requests/refinery/blog/posts_spec.rb b/spec/requests/refinery/blog/posts_spec.rb
new file mode 100644
index 0000000..eba6131
--- /dev/null
+++ b/spec/requests/refinery/blog/posts_spec.rb
@@ -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