Refactored everything (models, helpers) into proper namespace of Refinery::Blog. Requires refinery commit 25162b585b9c4023d39fd1a9796140bfa4ecb909
This commit is contained in:
parent
d18364d359
commit
36c005ecd1
47 changed files with 725 additions and 718 deletions
|
@ -3,7 +3,7 @@ module Refinery
|
|||
module Blog
|
||||
class CategoriesController < ::Refinery::AdminController
|
||||
|
||||
crudify :'refinery/blog_category',
|
||||
crudify :'refinery/blog/category',
|
||||
:title_attribute => :title,
|
||||
:order => 'title ASC'
|
||||
|
||||
|
|
|
@ -5,23 +5,23 @@ module Refinery
|
|||
|
||||
cache_sweeper Refinery::BlogSweeper
|
||||
|
||||
crudify :'refinery/blog_comment',
|
||||
crudify :'refinery/blog/comment',
|
||||
:title_attribute => :name,
|
||||
:order => 'published_at DESC'
|
||||
|
||||
def index
|
||||
@blog_comments = Refinery::BlogComment.unmoderated.page(params[:page])
|
||||
@blog_comments = Refinery::Blog::Comment.unmoderated.page(params[:page])
|
||||
|
||||
render :action => 'index'
|
||||
end
|
||||
|
||||
def approved
|
||||
unless params[:id].present?
|
||||
@blog_comments = Refinery::BlogComment.approved.page(params[:page])
|
||||
@blog_comments = Refinery::Blog::Comment.approved.page(params[:page])
|
||||
|
||||
render :action => 'index'
|
||||
else
|
||||
@blog_comment = Refinery::BlogComment.find(params[:id])
|
||||
@blog_comment = Refinery::Blog::Comment.find(params[:id])
|
||||
@blog_comment.approve!
|
||||
flash[:notice] = t('approved', :scope => 'refinery.admin.blog.comments', :author => @blog_comment.name)
|
||||
|
||||
|
@ -31,11 +31,11 @@ module Refinery
|
|||
|
||||
def rejected
|
||||
unless params[:id].present?
|
||||
@blog_comments = Refinery::BlogComment.rejected.page(params[:page])
|
||||
@blog_comments = Refinery::Blog::Comment.rejected.page(params[:page])
|
||||
|
||||
render :action => 'index'
|
||||
else
|
||||
@blog_comment = Refinery::BlogComment.find(params[:id])
|
||||
@blog_comment = Refinery::Blog::Comment.find(params[:id])
|
||||
@blog_comment.reject!
|
||||
flash[:notice] = t('rejected', :scope => 'refinery.admin.blog.comments', :author => @blog_comment.name)
|
||||
|
||||
|
|
|
@ -2,20 +2,21 @@ module Refinery
|
|||
module Admin
|
||||
module Blog
|
||||
class PostsController < ::Refinery::AdminController
|
||||
|
||||
|
||||
cache_sweeper Refinery::BlogSweeper
|
||||
|
||||
crudify :'refinery/blog_post',
|
||||
crudify :'refinery/blog/post',
|
||||
:title_attribute => :title,
|
||||
:order => 'published_at DESC'
|
||||
|
||||
:order => 'published_at DESC',
|
||||
:redirect_to_url => "main_app.refinery_admin_blog_posts_path"
|
||||
|
||||
before_filter :find_all_categories,
|
||||
:only => [:new, :edit, :create, :update]
|
||||
|
||||
before_filter :check_category_ids, :only => :update
|
||||
before_filter :check_category_ids, :only => :update
|
||||
|
||||
def uncategorized
|
||||
@blog_posts = Refinery::BlogPost.uncategorized.page(params[:page])
|
||||
@blog_posts = Refinery::Blog::Post.uncategorized.page(params[:page])
|
||||
end
|
||||
|
||||
def tags
|
||||
|
@ -31,7 +32,7 @@ module Refinery
|
|||
else
|
||||
'%'
|
||||
end
|
||||
@tags = Refinery::BlogPost.tag_counts_on(:tags).where(
|
||||
@tags = Refinery::Blog::Post.tag_counts_on(:tags).where(
|
||||
["tags.name #{op} ?", "#{wildcard}#{params[:term].to_s.downcase}#{wildcard}"]
|
||||
).map { |tag| {:id => tag.id, :value => tag.name}}
|
||||
render :json => @tags.flatten
|
||||
|
@ -39,19 +40,19 @@ module Refinery
|
|||
|
||||
def create
|
||||
# if the position field exists, set this object as last object, given the conditions of this class.
|
||||
if Refinery::BlogPost.column_names.include?("position")
|
||||
if Refinery::Blog::Post.column_names.include?("position")
|
||||
params[:blog_post].merge!({
|
||||
:position => ((Refinery::BlogPost.maximum(:position, :conditions => "")||-1) + 1)
|
||||
:position => ((Refinery::Blog::Post.maximum(:position, :conditions => "")||-1) + 1)
|
||||
})
|
||||
end
|
||||
|
||||
if Refinery::BlogPost.column_names.include?("user_id")
|
||||
if Refinery::Blog::Post.column_names.include?("user_id")
|
||||
params[:blog_post].merge!({
|
||||
:user_id => current_refinery_user.id
|
||||
})
|
||||
end
|
||||
|
||||
if (@blog_post = Refinery::BlogPost.create(params[:blog_post])).valid?
|
||||
if (@blog_post = Refinery::Blog::Post.create(params[:blog_post])).valid?
|
||||
(request.xhr? ? flash.now : flash).notice = t(
|
||||
'refinery.crudify.created',
|
||||
:what => "'#{@blog_post.title}'"
|
||||
|
@ -85,7 +86,7 @@ module Refinery
|
|||
|
||||
protected
|
||||
def find_all_categories
|
||||
@blog_categories = Refinery::BlogCategory.find(:all)
|
||||
@blog_categories = Refinery::Blog::Category.find(:all)
|
||||
end
|
||||
|
||||
def check_category_ids
|
||||
|
|
|
@ -4,12 +4,12 @@ module Refinery
|
|||
class SettingsController < ::Refinery::AdminController
|
||||
|
||||
def notification_recipients
|
||||
@recipients = Refinery::BlogComment::Notification.recipients
|
||||
@recipients = Refinery::Blog::Comment::Notification.recipients
|
||||
|
||||
if request.post?
|
||||
Refinery::BlogComment::Notification.recipients = params[:recipients]
|
||||
Refinery::Blog::Comment::Notification.recipients = params[:recipients]
|
||||
flash[:notice] = t('updated', :scope => 'admin.blog.settings.notification_recipients',
|
||||
:recipients => Refinery::BlogComment::Notification.recipients)
|
||||
:recipients => Refinery::Blog::Comment::Notification.recipients)
|
||||
unless request.xhr? or from_dialog?
|
||||
redirect_back_or_default(admin_blog_posts_path)
|
||||
else
|
||||
|
@ -20,7 +20,7 @@ module Refinery
|
|||
end
|
||||
|
||||
def moderation
|
||||
enabled = Refinery::BlogComment::Moderation.toggle!
|
||||
enabled = Refinery::Blog::Comment::Moderation.toggle!
|
||||
unless request.xhr?
|
||||
redirect_back_or_default(admin_blog_posts_path)
|
||||
else
|
||||
|
@ -30,7 +30,7 @@ module Refinery
|
|||
end
|
||||
|
||||
def comments
|
||||
enabled = Refinery::BlogComment.toggle!
|
||||
enabled = Refinery::Blog::Comment.toggle!
|
||||
unless request.xhr?
|
||||
redirect_back_or_default(admin_blog_posts_path)
|
||||
else
|
||||
|
@ -40,7 +40,7 @@ module Refinery
|
|||
end
|
||||
|
||||
def teasers
|
||||
enabled = Refinery::BlogPost.teaser_enabled_toggle!
|
||||
enabled = Refinery::Blog::Post.teaser_enabled_toggle!
|
||||
unless request.xhr?
|
||||
redirect_back_or_default(admin_blog_posts_path)
|
||||
else
|
||||
|
|
|
@ -4,7 +4,7 @@ module Refinery
|
|||
|
||||
include ControllerHelper
|
||||
|
||||
helper :'refinery/blog_posts'
|
||||
helper :'refinery/blog/posts'
|
||||
before_filter :find_page, :find_all_blog_categories
|
||||
|
||||
protected
|
||||
|
|
|
@ -3,8 +3,8 @@ module Refinery
|
|||
class CategoriesController < BaseController
|
||||
|
||||
def show
|
||||
@category = Refinery::BlogCategory.find(params[:id])
|
||||
@blog_posts = @category.posts.live.includes(:comments, :categories).page(params[:page])
|
||||
@blog_category = Refinery::Blog::Category.find(params[:id])
|
||||
@blog_posts = @blog_category.posts.live.includes(:comments, :categories).page(params[:page])
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -12,7 +12,7 @@ module Refinery
|
|||
|
||||
def index
|
||||
# Rss feeders are greedy. Let's give them every blog post instead of paginating.
|
||||
(@blog_posts = Refinery::BlogPost.live.includes(:comments, :categories).all) if request.format.rss?
|
||||
(@blog_posts = Refinery::Blog::Post.live.includes(:comments, :categories).all) if request.format.rss?
|
||||
respond_with (@blog_posts) do |format|
|
||||
format.html
|
||||
format.rss
|
||||
|
@ -20,7 +20,7 @@ module Refinery
|
|||
end
|
||||
|
||||
def show
|
||||
@blog_comment = Refinery::BlogComment.new
|
||||
@blog_comment = Refinery::Blog::Comment.new
|
||||
|
||||
respond_with (@blog_post) do |format|
|
||||
format.html { present(@blog_post) }
|
||||
|
@ -30,7 +30,7 @@ module Refinery
|
|||
|
||||
def comment
|
||||
if (@blog_comment = @blog_post.comments.create(params[:blog_comment])).valid?
|
||||
if Refinery::BlogComment::Moderation.enabled? or @blog_comment.ham?
|
||||
if Refinery::Blog::Comment::Moderation.enabled? or @blog_comment.ham?
|
||||
begin
|
||||
Refinery::Blog::CommentMailer.notification(@blog_comment, request).deliver
|
||||
rescue
|
||||
|
@ -38,7 +38,7 @@ module Refinery
|
|||
end
|
||||
end
|
||||
|
||||
if Refinery::BlogComment::Moderation.enabled?
|
||||
if Refinery::Blog::Comment::Moderation.enabled?
|
||||
flash[:notice] = t('thank_you_moderated', :scope => 'refinery.blog.posts.comments')
|
||||
redirect_to main_app.blog_post_url(params[:id])
|
||||
else
|
||||
|
@ -56,12 +56,12 @@ module Refinery
|
|||
date = "#{params[:month]}/#{params[:year]}"
|
||||
@archive_date = Time.parse(date)
|
||||
@date_title = @archive_date.strftime('%B %Y')
|
||||
@blog_posts = Refinery::BlogPost.live.by_archive(@archive_date).page(params[:page])
|
||||
@blog_posts = Refinery::Blog::Post.live.by_archive(@archive_date).page(params[:page])
|
||||
else
|
||||
date = "01/#{params[:year]}"
|
||||
@archive_date = Time.parse(date)
|
||||
@date_title = @archive_date.strftime('%Y')
|
||||
@blog_posts = Refinery::BlogPost.live.by_year(@archive_date).page(params[:page])
|
||||
@blog_posts = Refinery::Blog::Post.live.by_year(@archive_date).page(params[:page])
|
||||
end
|
||||
respond_with (@blog_posts)
|
||||
end
|
||||
|
@ -69,7 +69,7 @@ module Refinery
|
|||
def tagged
|
||||
@tag = ActsAsTaggableOn::Tag.find(params[:tag_id])
|
||||
@tag_name = @tag.name
|
||||
@blog_posts = Refinery::BlogPost.tagged_with(@tag_name).page(params[:page])
|
||||
@blog_posts = Refinery::Blog::Post.tagged_with(@tag_name).page(params[:page])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,9 +5,9 @@ module Refinery
|
|||
protected
|
||||
|
||||
def find_blog_post
|
||||
unless (@blog_post = Refinery::BlogPost.find(params[:id])).try(:live?)
|
||||
unless (@blog_post = Refinery::Blog::Post.find(params[:id])).try(:live?)
|
||||
if refinery_user? and current_refinery_user.authorized_plugins.include?("refinerycms_blog")
|
||||
@blog_post = Refinery::BlogPost.find(params[:id])
|
||||
@blog_post = Refinery::Blog::Post.find(params[:id])
|
||||
else
|
||||
error_404
|
||||
end
|
||||
|
@ -15,15 +15,15 @@ module Refinery
|
|||
end
|
||||
|
||||
def find_all_blog_posts
|
||||
@blog_posts = Refinery::BlogPost.live.includes(:comments, :categories).page(params[:page])
|
||||
@blog_posts = Refinery::Blog::Post.live.includes(:comments, :categories).page(params[:page])
|
||||
end
|
||||
|
||||
def find_tags
|
||||
@tags = Refinery::BlogPost.tag_counts_on(:tags)
|
||||
@tags = Refinery::Blog::Post.tag_counts_on(:tags)
|
||||
end
|
||||
|
||||
def find_all_blog_categories
|
||||
@blog_categories = Refinery::BlogCategory.all
|
||||
@blog_categories = Refinery::Blog::Category.all
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
51
app/helpers/refinery/blog/posts_helper.rb
Normal file
51
app/helpers/refinery/blog/posts_helper.rb
Normal file
|
@ -0,0 +1,51 @@
|
|||
module Refinery
|
||||
module Blog
|
||||
module PostsHelper
|
||||
def blog_archive_widget
|
||||
posts = Refinery::Blog::Post.select('published_at').all_previous
|
||||
return nil if posts.blank?
|
||||
|
||||
render :partial => "/refinery/blog/widgets/blog_archive", :locals => { :posts => posts }
|
||||
end
|
||||
alias_method :blog_archive_list, :blog_archive_widget
|
||||
|
||||
def next_or_previous?(post)
|
||||
post.next.present? or post.prev.present?
|
||||
end
|
||||
|
||||
def blog_post_teaser_enabled?
|
||||
Refinery::Blog::Post.teasers_enabled?
|
||||
end
|
||||
|
||||
def blog_post_teaser(post)
|
||||
if post.respond_to?(:custom_teaser) && post.custom_teaser.present?
|
||||
post.custom_teaser.html_safe
|
||||
else
|
||||
truncate(post.body, {
|
||||
:length => Refinery::Setting.find_or_set(:blog_post_teaser_length, 250),
|
||||
:preserve_html_tags => true
|
||||
}).html_safe
|
||||
end
|
||||
end
|
||||
|
||||
def archive_link(post)
|
||||
if post.published_at >= Time.now.end_of_year.advance(:years => -3)
|
||||
post_date = post.published_at.strftime('%m/%Y')
|
||||
year = post_date.split('/')[1]
|
||||
month = post_date.split('/')[0]
|
||||
count = Blog::Post.by_archive(Time.parse(post_date)).size
|
||||
text = t("date.month_names")[month.to_i] + " #{year} (#{count})"
|
||||
|
||||
link_to(text, main_app.archive_blog_posts_path(:year => year, :month => month))
|
||||
else
|
||||
post_date = post.published_at.strftime('01/%Y')
|
||||
year = post_date.split('/')[1]
|
||||
count = Refinery::Blog::Post.by_year(Time.parse(post_date)).size
|
||||
text = "#{year} (#{count})"
|
||||
|
||||
link_to(text, main_app.archive_blog_posts_path(:year => year))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,49 +0,0 @@
|
|||
module Refinery
|
||||
module BlogPostsHelper
|
||||
def blog_archive_widget
|
||||
posts = Refinery::BlogPost.select('published_at').all_previous
|
||||
return nil if posts.blank?
|
||||
|
||||
render :partial => "/refinery/blog/widgets/blog_archive", :locals => { :posts => posts }
|
||||
end
|
||||
alias_method :blog_archive_list, :blog_archive_widget
|
||||
|
||||
def next_or_previous?(post)
|
||||
post.next.present? or post.prev.present?
|
||||
end
|
||||
|
||||
def blog_post_teaser_enabled?
|
||||
Refinery::BlogPost.teasers_enabled?
|
||||
end
|
||||
|
||||
def blog_post_teaser(post)
|
||||
if post.respond_to?(:custom_teaser) && post.custom_teaser.present?
|
||||
post.custom_teaser.html_safe
|
||||
else
|
||||
truncate(post.body, {
|
||||
:length => Refinery::Setting.find_or_set(:blog_post_teaser_length, 250),
|
||||
:preserve_html_tags => true
|
||||
}).html_safe
|
||||
end
|
||||
end
|
||||
|
||||
def archive_link(post)
|
||||
if post.published_at >= Time.now.end_of_year.advance(:years => -3)
|
||||
post_date = post.published_at.strftime('%m/%Y')
|
||||
year = post_date.split('/')[1]
|
||||
month = post_date.split('/')[0]
|
||||
count = BlogPost.by_archive(Time.parse(post_date)).size
|
||||
text = t("date.month_names")[month.to_i] + " #{year} (#{count})"
|
||||
|
||||
link_to(text, main_app.archive_blog_posts_path(:year => year, :month => month))
|
||||
else
|
||||
post_date = post.published_at.strftime('01/%Y')
|
||||
year = post_date.split('/')[1]
|
||||
count = Refinery::BlogPost.by_year(Time.parse(post_date)).size
|
||||
text = "#{year} (#{count})"
|
||||
|
||||
link_to(text, main_app.archive_blog_posts_path(:year => year))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,11 +3,11 @@ module Refinery
|
|||
class CommentMailer < ActionMailer::Base
|
||||
|
||||
def notification(comment, request)
|
||||
subject BlogComment::Notification.subject
|
||||
recipients BlogComment::Notification.recipients
|
||||
subject Blog::Comment::Notification.subject
|
||||
recipients Blog::Comment::Notification.recipients
|
||||
from "\"#{RefinerySetting[:site_name]}\" <no-reply@#{request.domain(RefinerySetting.find_or_set(:tld_length, 1))}>"
|
||||
sent_on Time.now
|
||||
@comment = comment
|
||||
@blog_comment = comment
|
||||
end
|
||||
|
||||
end
|
||||
|
|
26
app/models/refinery/blog/category.rb
Normal file
26
app/models/refinery/blog/category.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
module Refinery
|
||||
module Blog
|
||||
class Category < ActiveRecord::Base
|
||||
|
||||
has_many :categorizations, :dependent => :destroy, :foreign_key => :blog_category_id
|
||||
has_many :posts, :through => :categorizations, :source => :blog_post
|
||||
|
||||
acts_as_indexed :fields => [:title]
|
||||
|
||||
validates :title, :presence => true, :uniqueness => true
|
||||
|
||||
has_friendly_id :title, :use_slug => true,
|
||||
:default_locale => (::Refinery::I18n.default_frontend_locale rescue :en),
|
||||
:approximate_ascii => Refinery::Setting.find_or_set(:approximate_ascii, false, :scoping => 'blog'),
|
||||
:strip_non_ascii => Refinery::Setting.find_or_set(:strip_non_ascii, false, :scoping => 'blog')
|
||||
|
||||
def post_count
|
||||
posts.select(&:live?).count
|
||||
end
|
||||
|
||||
# how many items to show per page
|
||||
self.per_page = Refinery::Setting.find_or_set(:blog_posts_per_page, 10)
|
||||
|
||||
end
|
||||
end
|
||||
end
|
125
app/models/refinery/blog/comment.rb
Normal file
125
app/models/refinery/blog/comment.rb
Normal file
|
@ -0,0 +1,125 @@
|
|||
module Refinery
|
||||
module Blog
|
||||
class Comment < ActiveRecord::Base
|
||||
|
||||
attr_accessible :name, :email, :message
|
||||
|
||||
filters_spam :author_field => :name,
|
||||
:email_field => :email,
|
||||
:message_field => :body
|
||||
|
||||
belongs_to :post, :class_name => 'Refinery::Blog::Post', :foreign_key => 'blog_post_id'
|
||||
|
||||
acts_as_indexed :fields => [:name, :email, :message]
|
||||
|
||||
alias_attribute :message, :body
|
||||
|
||||
validates :name, :message, :presence => true
|
||||
validates :email, :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i }
|
||||
|
||||
scope :unmoderated, :conditions => {:state => nil}
|
||||
scope :approved, :conditions => {:state => 'approved'}
|
||||
scope :rejected, :conditions => {:state => 'rejected'}
|
||||
|
||||
self.per_page = Refinery::Setting.find_or_set(:blog_comments_per_page, 10)
|
||||
|
||||
def avatar_url(options = {})
|
||||
options = {:size => 60}
|
||||
require 'digest/md5'
|
||||
size = ("?s=#{options[:size]}" if options[:size])
|
||||
"http://gravatar.com/avatar/#{Digest::MD5.hexdigest(self.email.to_s.strip.downcase)}#{size}.jpg"
|
||||
end
|
||||
|
||||
def approve!
|
||||
self.update_attribute(:state, 'approved')
|
||||
end
|
||||
|
||||
def reject!
|
||||
self.update_attribute(:state, 'rejected')
|
||||
end
|
||||
|
||||
def rejected?
|
||||
self.state == 'rejected'
|
||||
end
|
||||
|
||||
def approved?
|
||||
self.state == 'approved'
|
||||
end
|
||||
|
||||
def unmoderated?
|
||||
self.state.nil?
|
||||
end
|
||||
|
||||
def self.toggle!
|
||||
currently = Refinery::Setting.find_or_set(:comments_allowed, true, {
|
||||
:scoping => 'blog'
|
||||
})
|
||||
Refinery::Setting.set(:comments_allowed, {:value => !currently, :scoping => 'blog'})
|
||||
end
|
||||
|
||||
before_create do |comment|
|
||||
unless Moderation.enabled?
|
||||
comment.state = comment.ham? ? 'approved' : 'rejected'
|
||||
end
|
||||
end
|
||||
|
||||
module Moderation
|
||||
class << self
|
||||
def enabled?
|
||||
Refinery::Setting.find_or_set(:comment_moderation, true, {
|
||||
:scoping => 'blog',
|
||||
:restricted => false
|
||||
})
|
||||
end
|
||||
|
||||
def toggle!
|
||||
new_value = {
|
||||
:value => !Blog::Comment::Moderation.enabled?,
|
||||
:scoping => 'blog',
|
||||
:restricted => false
|
||||
}
|
||||
Refinery::Setting.set(:comment_moderation, new_value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Notification
|
||||
class << self
|
||||
def recipients
|
||||
Refinery::Setting.find_or_set(:comment_notification_recipients, (Refinery::Role[:refinery].users.first.email rescue ''),
|
||||
{
|
||||
:scoping => 'blog',
|
||||
:restricted => false
|
||||
})
|
||||
end
|
||||
|
||||
def recipients=(emails)
|
||||
new_value = {
|
||||
:value => emails,
|
||||
:scoping => 'blog',
|
||||
:restricted => false
|
||||
}
|
||||
Refinery::Setting.set(:comment_notification_recipients, new_value)
|
||||
end
|
||||
|
||||
def subject
|
||||
Refinery::Setting.find_or_set(:comment_notification_subject, "New inquiry from your website", {
|
||||
:scoping => 'blog',
|
||||
:restricted => false
|
||||
})
|
||||
end
|
||||
|
||||
def subject=(subject_line)
|
||||
new_value = {
|
||||
:value => subject_line,
|
||||
:scoping => 'blog',
|
||||
:restricted => false
|
||||
}
|
||||
Refinery::Setting.set(:comment_notification_subject, new_value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
114
app/models/refinery/blog/post.rb
Normal file
114
app/models/refinery/blog/post.rb
Normal file
|
@ -0,0 +1,114 @@
|
|||
require 'acts-as-taggable-on'
|
||||
require 'seo_meta'
|
||||
|
||||
module Refinery
|
||||
module Blog
|
||||
class Post < ActiveRecord::Base
|
||||
|
||||
is_seo_meta if self.table_exists?
|
||||
|
||||
default_scope :order => 'published_at DESC'
|
||||
#.first & .last will be reversed -- consider a with_exclusive_scope on these?
|
||||
|
||||
belongs_to :author, :class_name => 'Refinery::User', :foreign_key => :user_id, :readonly => true
|
||||
|
||||
has_many :comments, :class_name => 'Refinery::Blog::Comment', :dependent => :destroy, :foreign_key => :blog_post_id
|
||||
acts_as_taggable
|
||||
|
||||
has_many :categorizations, :dependent => :destroy, :foreign_key => :blog_post_id
|
||||
has_many :categories, :through => :categorizations, :source => :blog_category
|
||||
|
||||
acts_as_indexed :fields => [:title, :body]
|
||||
|
||||
validates :title, :presence => true, :uniqueness => true
|
||||
validates :body, :presence => true
|
||||
|
||||
has_friendly_id :friendly_id_source, :use_slug => true,
|
||||
:default_locale => (::Refinery::I18n.default_frontend_locale rescue :en),
|
||||
:approximate_ascii => Refinery::Setting.find_or_set(:approximate_ascii, false, :scoping => 'blog'),
|
||||
:strip_non_ascii => Refinery::Setting.find_or_set(:strip_non_ascii, false, :scoping => 'blog')
|
||||
|
||||
scope :by_archive, lambda { |archive_date|
|
||||
where(['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month])
|
||||
}
|
||||
|
||||
scope :by_year, lambda { |archive_year|
|
||||
where(['published_at between ? and ?', archive_year.beginning_of_year, archive_year.end_of_year])
|
||||
}
|
||||
|
||||
scope :all_previous, lambda { where(['published_at <= ?', Time.now.beginning_of_month]) }
|
||||
|
||||
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 :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
|
||||
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
|
||||
self.class.next(self).first
|
||||
end
|
||||
|
||||
def prev
|
||||
self.class.previous(self).first
|
||||
end
|
||||
|
||||
def live?
|
||||
!draft and published_at <= Time.now
|
||||
end
|
||||
|
||||
def category_ids=(ids)
|
||||
self.categories = ids.reject{|id| id.blank?}.collect {|c_id|
|
||||
Refinery::Blog::Category.find(c_id.to_i) rescue nil
|
||||
}.compact
|
||||
end
|
||||
|
||||
def friendly_id_source
|
||||
custom_url.present? ? custom_url : title
|
||||
end
|
||||
|
||||
class << self
|
||||
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')
|
||||
end
|
||||
|
||||
def teasers_enabled?
|
||||
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
|
||||
end
|
||||
|
||||
module ShareThis
|
||||
DEFAULT_KEY = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||
|
||||
class << self
|
||||
def key
|
||||
Refinery::Setting.find_or_set(:share_this_key, Blog::Post::ShareThis::DEFAULT_KEY, :scoping => 'blog')
|
||||
end
|
||||
|
||||
def enabled?
|
||||
key = Blog::Post::ShareThis.key
|
||||
key.present? and key != Blog::Post::ShareThis::DEFAULT_KEY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,24 +0,0 @@
|
|||
module Refinery
|
||||
class BlogCategory < ActiveRecord::Base
|
||||
|
||||
has_many :categorizations, :dependent => :destroy
|
||||
has_many :posts, :through => :categorizations, :source => :blog_post
|
||||
|
||||
acts_as_indexed :fields => [:title]
|
||||
|
||||
validates :title, :presence => true, :uniqueness => true
|
||||
|
||||
has_friendly_id :title, :use_slug => true,
|
||||
:default_locale => (::Refinery::I18n.default_frontend_locale rescue :en),
|
||||
:approximate_ascii => Refinery::Setting.find_or_set(:approximate_ascii, false, :scoping => 'blog'),
|
||||
:strip_non_ascii => Refinery::Setting.find_or_set(:strip_non_ascii, false, :scoping => 'blog')
|
||||
|
||||
def post_count
|
||||
posts.select(&:live?).count
|
||||
end
|
||||
|
||||
# how many items to show per page
|
||||
self.per_page = Refinery::Setting.find_or_set(:blog_posts_per_page, 10)
|
||||
|
||||
end
|
||||
end
|
|
@ -1,135 +0,0 @@
|
|||
module Refinery
|
||||
class BlogComment < ActiveRecord::Base
|
||||
|
||||
attr_accessible :name, :email, :message
|
||||
|
||||
filters_spam :author_field => :name,
|
||||
:email_field => :email,
|
||||
:message_field => :body
|
||||
|
||||
belongs_to :post, :class_name => 'Refinery::BlogPost', :foreign_key => 'blog_post_id'
|
||||
|
||||
acts_as_indexed :fields => [:name, :email, :message]
|
||||
|
||||
alias_attribute :message, :body
|
||||
|
||||
validates :name, :message, :presence => true
|
||||
validates :email, :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i }
|
||||
|
||||
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}
|
||||
require 'digest/md5'
|
||||
size = ("?s=#{options[:size]}" if options[:size])
|
||||
"http://gravatar.com/avatar/#{Digest::MD5.hexdigest(self.email.to_s.strip.downcase)}#{size}.jpg"
|
||||
end
|
||||
|
||||
def approve!
|
||||
self.update_attribute(:state, 'approved')
|
||||
end
|
||||
|
||||
def reject!
|
||||
self.update_attribute(:state, 'rejected')
|
||||
end
|
||||
|
||||
def rejected?
|
||||
self.state == 'rejected'
|
||||
end
|
||||
|
||||
def approved?
|
||||
self.state == 'approved'
|
||||
end
|
||||
|
||||
def unmoderated?
|
||||
self.state.nil?
|
||||
end
|
||||
|
||||
def self.toggle!
|
||||
currently = Refinery::Setting.find_or_set(:comments_allowed, true, {
|
||||
:scoping => 'blog'
|
||||
})
|
||||
Refinery::Setting.set(:comments_allowed, {:value => !currently, :scoping => 'blog'})
|
||||
end
|
||||
|
||||
before_create do |comment|
|
||||
unless Moderation.enabled?
|
||||
comment.state = comment.ham? ? 'approved' : 'rejected'
|
||||
end
|
||||
end
|
||||
|
||||
module Moderation
|
||||
class << self
|
||||
def enabled?
|
||||
Refinery::Setting.find_or_set(:comment_moderation, true, {
|
||||
:scoping => 'blog',
|
||||
:restricted => false
|
||||
})
|
||||
end
|
||||
|
||||
def toggle!
|
||||
new_value = {
|
||||
:value => !BlogComment::Moderation.enabled?,
|
||||
:scoping => 'blog',
|
||||
:restricted => false
|
||||
}
|
||||
if Refinery::Setting.respond_to?(:set)
|
||||
Refinery::Setting.set(:comment_moderation, new_value)
|
||||
else
|
||||
Refinery::Setting[:comment_moderation] = new_value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Notification
|
||||
class << self
|
||||
def recipients
|
||||
Refinery::Setting.find_or_set(:comment_notification_recipients, (Refinery::Role[:refinery].users.first.email rescue ''),
|
||||
{
|
||||
:scoping => 'blog',
|
||||
:restricted => false
|
||||
})
|
||||
end
|
||||
|
||||
def recipients=(emails)
|
||||
new_value = {
|
||||
:value => emails,
|
||||
:scoping => 'blog',
|
||||
:restricted => false
|
||||
}
|
||||
if Refinery::Setting.respond_to?(:set)
|
||||
Refinery::Setting.set(:comment_notification_recipients, new_value)
|
||||
else
|
||||
Refinery::Setting[:comment_notification_recipients] = new_value
|
||||
end
|
||||
end
|
||||
|
||||
def subject
|
||||
Refinery::Setting.find_or_set(:comment_notification_subject, "New inquiry from your website", {
|
||||
:scoping => 'blog',
|
||||
:restricted => false
|
||||
})
|
||||
end
|
||||
|
||||
def subject=(subject_line)
|
||||
new_value = {
|
||||
:value => subject_line,
|
||||
:scoping => 'blog',
|
||||
:restricted => false
|
||||
}
|
||||
if Refinery::Setting.respond_to?(:set)
|
||||
Refinery::Setting.set(:comment_notification_subject, new_value)
|
||||
else
|
||||
Refinery::Setting[:comment_notification_subject] = new_value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,112 +0,0 @@
|
|||
require 'acts-as-taggable-on'
|
||||
require 'seo_meta'
|
||||
|
||||
module Refinery
|
||||
class BlogPost < ActiveRecord::Base
|
||||
|
||||
is_seo_meta if self.table_exists?
|
||||
|
||||
default_scope :order => 'published_at DESC'
|
||||
#.first & .last will be reversed -- consider a with_exclusive_scope on these?
|
||||
|
||||
belongs_to :author, :class_name => 'Refinery::User', :foreign_key => :user_id, :readonly => true
|
||||
|
||||
has_many :comments, :class_name => 'Refinery::BlogComment', :dependent => :destroy
|
||||
acts_as_taggable
|
||||
|
||||
has_many :categorizations, :dependent => :destroy
|
||||
has_many :categories, :through => :categorizations, :source => :blog_category
|
||||
|
||||
acts_as_indexed :fields => [:title, :body]
|
||||
|
||||
validates :title, :presence => true, :uniqueness => true
|
||||
validates :body, :presence => true
|
||||
|
||||
has_friendly_id :friendly_id_source, :use_slug => true,
|
||||
:default_locale => (::Refinery::I18n.default_frontend_locale rescue :en),
|
||||
:approximate_ascii => Refinery::Setting.find_or_set(:approximate_ascii, false, :scoping => 'blog'),
|
||||
:strip_non_ascii => Refinery::Setting.find_or_set(:strip_non_ascii, false, :scoping => 'blog')
|
||||
|
||||
scope :by_archive, lambda { |archive_date|
|
||||
where(['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month])
|
||||
}
|
||||
|
||||
scope :by_year, lambda { |archive_year|
|
||||
where(['published_at between ? and ?', archive_year.beginning_of_year, archive_year.end_of_year])
|
||||
}
|
||||
|
||||
scope :all_previous, lambda { where(['published_at <= ?', Time.now.beginning_of_month]) }
|
||||
|
||||
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 :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
|
||||
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
|
||||
end
|
||||
|
||||
def prev
|
||||
BlogPost.previous(self).first
|
||||
end
|
||||
|
||||
def live?
|
||||
!draft and published_at <= Time.now
|
||||
end
|
||||
|
||||
def category_ids=(ids)
|
||||
self.categories = ids.reject{|id| id.blank?}.collect {|c_id|
|
||||
Refinery::BlogCategory.find(c_id.to_i) rescue nil
|
||||
}.compact
|
||||
end
|
||||
|
||||
def friendly_id_source
|
||||
custom_url.present? ? custom_url : title
|
||||
end
|
||||
|
||||
class << self
|
||||
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')
|
||||
end
|
||||
|
||||
def teasers_enabled?
|
||||
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
|
||||
end
|
||||
|
||||
module ShareThis
|
||||
DEFAULT_KEY = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||
|
||||
class << self
|
||||
def key
|
||||
Refinery::Setting.find_or_set(:share_this_key, BlogPost::ShareThis::DEFAULT_KEY, :scoping => 'blog')
|
||||
end
|
||||
|
||||
def enabled?
|
||||
key = BlogPost::ShareThis.key
|
||||
key.present? and key != BlogPost::ShareThis::DEFAULT_KEY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -2,8 +2,8 @@ module Refinery
|
|||
class Categorization < ActiveRecord::Base
|
||||
|
||||
set_table_name 'refinery_blog_categories_blog_posts'
|
||||
belongs_to :blog_post
|
||||
belongs_to :blog_category
|
||||
belongs_to :blog_post, :class_name => 'Refinery::Blog::Post', :foreign_key => :blog_post_id
|
||||
belongs_to :blog_category, :class_name => 'Refinery::Blog::Category', :foreign_key => :blog_category_id
|
||||
|
||||
end
|
||||
end
|
|
@ -1,26 +1,26 @@
|
|||
module Refinery
|
||||
class BlogSweeper < ActionController::Caching::Sweeper
|
||||
observe BlogPost, BlogComment
|
||||
|
||||
observe Blog::Post, Blog::Comment
|
||||
|
||||
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)
|
||||
# TODO: Convert these to url helpers
|
||||
expire_page '/blog'
|
||||
expire_page '/blog/feed.rss'
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -26,11 +26,11 @@
|
|||
:class => 'page_add_icon' %>
|
||||
</li>
|
||||
</ul>
|
||||
<% if Refinery::BlogPost.comments_allowed? %>
|
||||
<% if Refinery::Blog::Post.comments_allowed? %>
|
||||
<ul class='collapsible_menu'>
|
||||
<li class='not_a_link'>
|
||||
<% if Refinery::BlogComment.unmoderated.any? %>
|
||||
<% title = t('.comments.title_with_count', :new_count => Refinery::BlogComment.unmoderated.size) %>
|
||||
<% if Refinery::Blog::Comment.unmoderated.any? %>
|
||||
<% title = t('.comments.title_with_count', :new_count => Refinery::Blog::Comment.unmoderated.size) %>
|
||||
<% else %>
|
||||
<% title = t('.comments.title') %>
|
||||
<% end %>
|
||||
|
@ -74,11 +74,11 @@
|
|||
</li>
|
||||
<li>
|
||||
<%= link_to t('.settings.comments'), main_app.comments_refinery_admin_blog_settings_path,
|
||||
:class => "#{Refinery::BlogPost.comments_allowed? ? 'success' : 'failure'}_icon" %>
|
||||
:class => "#{Refinery::Blog::Post.comments_allowed? ? 'success' : 'failure'}_icon" %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link_to t('.settings.moderation'), main_app.moderation_refinery_admin_blog_settings_path,
|
||||
:class => "#{Refinery::BlogComment::Moderation.enabled? ? 'success' : 'failure'}_icon" %>
|
||||
:class => "#{Refinery::Blog::Comment::Moderation.enabled? ? 'success' : 'failure'}_icon" %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link_to t('.settings.update_notified'),
|
||||
|
@ -87,7 +87,7 @@
|
|||
</li>
|
||||
<li>
|
||||
<%= link_to t('.settings.teasers'),
|
||||
main_app.teasers_refinery_admin_blog_settings_path, :class => "#{Refinery::BlogPost.teasers_enabled? ? 'success' : 'failure'}_icon" %>
|
||||
main_app.teasers_refinery_admin_blog_settings_path, :class => "#{Refinery::Blog::Post.teasers_enabled? ? 'success' : 'failure'}_icon" %>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
</ul>
|
||||
|
||||
<div id='page_part_editors'>
|
||||
|
||||
<% part_index = -1 %>
|
||||
<%= render :partial => 'form_part',
|
||||
:locals => {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<% content_for :body_content_title, @category.title %>
|
||||
<% content_for :body_content_title, @blog_category.title %>
|
||||
|
||||
<% content_for :body_content_left do %>
|
||||
<% if @blog_posts.any? %>
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
|
||||
<%=raw t('.comment_starts') %>
|
||||
|
||||
<%=raw t('.from') %>: <%= @comment.name %>
|
||||
<%=raw t('.email') %>: <%= @comment.email %>
|
||||
<%=raw t('.from') %>: <%= @blog_comment.name %>
|
||||
<%=raw t('.email') %>: <%= @blog_comment.email %>
|
||||
<%=raw t('.message') %>:
|
||||
<%=simple_format strip_tags(@comment.body) %>
|
||||
<%=simple_format strip_tags(@blog_comment.body) %>
|
||||
|
||||
<%=raw t('.comment_ends') %>
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
</header>
|
||||
<%= @blog_post.body.html_safe %>
|
||||
|
||||
<% if Refinery::BlogPost::ShareThis.enabled? %>
|
||||
<% if Refinery::Blog::Post::ShareThis.enabled? %>
|
||||
<span class="st_sharethis" displayText="ShareThis"></span>
|
||||
<% end %>
|
||||
</article>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<%= render 'post' %>
|
||||
</div>
|
||||
|
||||
<% if Refinery::BlogPost.comments_allowed? %>
|
||||
<% if Refinery::Blog::Post.comments_allowed? %>
|
||||
<%= render 'comments'%>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
@ -17,5 +17,5 @@
|
|||
<%# enable AJAX'd post nav at your own risk until html5 history API implemented. %>
|
||||
<%#= javascript_include_tag('refinery/blog/frontend') %>
|
||||
<script src="http://w.sharethis.com/button/buttons.js"></script>
|
||||
<script>stLight.options({publisher:'<%= BlogPost::ShareThis.key %>'});</script>
|
||||
<% end if Refinery::BlogPost::ShareThis.enabled? %>
|
||||
<script>stLight.options({publisher:'<%= Blog::Post::ShareThis.key %>'});</script>
|
||||
<% end if Refinery::Blog::Post::ShareThis.enabled? %>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<h2><%= t('.title') %></h2>
|
||||
<ul id='categories'>
|
||||
<% @blog_categories.each do |category| %>
|
||||
<li<%= " class='selected'" if @category.present? and @category.id == category.id %>>
|
||||
<li<%= " class='selected'" if @blog_category.present? and @blog_category.id == category.id %>>
|
||||
<%= link_to "#{category.title} (#{category.post_count})", main_app.blog_category_path(category) %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
<%= link_to t('read_more', :scope => 'refinery.blog.shared.posts'), main_app.blog_post_path(post) if blog_post_teaser_enabled? %>
|
||||
</p>
|
||||
<aside class='comment_count'>
|
||||
<% if Refinery::BlogPost.comments_allowed? %>
|
||||
<% if Refinery::Blog::Post.comments_allowed? %>
|
||||
<% if post.comments.any? %>
|
||||
(<%= pluralize(post.comments.approved.count, t('singular', :scope => 'refinery.blog.shared.comments')) %>)
|
||||
<% else %>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class CreateBlogStructure < ActiveRecord::Migration
|
||||
|
||||
def up
|
||||
create_table Refinery::BlogPost.table_name, :id => true do |t|
|
||||
create_table Refinery::Blog::Post.table_name, :id => true do |t|
|
||||
t.string :title
|
||||
t.text :body
|
||||
t.boolean :draft
|
||||
|
@ -9,9 +9,9 @@ class CreateBlogStructure < ActiveRecord::Migration
|
|||
t.timestamps
|
||||
end
|
||||
|
||||
add_index Refinery::BlogPost.table_name, :id
|
||||
add_index Refinery::Blog::Post.table_name, :id
|
||||
|
||||
create_table Refinery::BlogComment.table_name, :id => true do |t|
|
||||
create_table Refinery::Blog::Comment.table_name, :id => true do |t|
|
||||
t.integer :blog_post_id
|
||||
t.boolean :spam
|
||||
t.string :name
|
||||
|
@ -21,14 +21,14 @@ class CreateBlogStructure < ActiveRecord::Migration
|
|||
t.timestamps
|
||||
end
|
||||
|
||||
add_index Refinery::BlogComment.table_name, :id
|
||||
add_index Refinery::Blog::Comment.table_name, :id
|
||||
|
||||
create_table Refinery::BlogCategory.table_name, :id => true do |t|
|
||||
create_table Refinery::Blog::Category.table_name, :id => true do |t|
|
||||
t.string :title
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index Refinery::BlogCategory.table_name, :id
|
||||
add_index Refinery::Blog::Category.table_name, :id
|
||||
|
||||
create_table Refinery::Categorization.table_name, :id => true do |t|
|
||||
t.integer :blog_category_id
|
||||
|
@ -43,8 +43,8 @@ class CreateBlogStructure < ActiveRecord::Migration
|
|||
|
||||
Refinery::Page.delete_all({:link_url => "/blog"})
|
||||
|
||||
drop_table Refinery::BlogPost.table_name
|
||||
drop_table Refinery::BlogComment.table_name
|
||||
drop_table Refinery::Blog::Post.table_name
|
||||
drop_table Refinery::Blog::Comment.table_name
|
||||
drop_table Refinery::Category.table_name
|
||||
drop_table Refinery::Categorization.table_name
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class AddUserIdToBlogPosts < ActiveRecord::Migration
|
||||
|
||||
def change
|
||||
add_column Refinery::BlogPost.table_name, :user_id, :integer
|
||||
add_column Refinery::Blog::Post.table_name, :user_id, :integer
|
||||
end
|
||||
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
class AddCachedSlugs < ActiveRecord::Migration
|
||||
def change
|
||||
add_column Refinery::BlogCategory.table_name, :cached_slug, :string
|
||||
add_column Refinery::BlogPost.table_name, :cached_slug, :string
|
||||
add_column Refinery::Blog::Category.table_name, :cached_slug, :string
|
||||
add_column Refinery::Blog::Post.table_name, :cached_slug, :string
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class AddCustomUrlFieldToBlogPosts < ActiveRecord::Migration
|
||||
def change
|
||||
add_column Refinery::BlogPost.table_name, :custom_url, :string
|
||||
add_column Refinery::Blog::Post.table_name, :custom_url, :string
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class AddCustomTeaserFieldToBlogPosts < ActiveRecord::Migration
|
||||
def change
|
||||
add_column Refinery::BlogPost.table_name, :custom_teaser, :text
|
||||
add_column Refinery::Blog::Post.table_name, :custom_teaser, :text
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -17,4 +17,11 @@ if defined?(Refinery::Page)
|
|||
Refinery::Page.default_parts.each do |default_page_part|
|
||||
page.parts.create(:title => default_page_part, :body => nil)
|
||||
end
|
||||
end
|
||||
end# Refinery seeds
|
||||
Dir[Rails.root.join('db', 'seeds', '*.rb').to_s].each do |file|
|
||||
puts "Loading db/seeds/#{file.split(File::SEPARATOR).last}"
|
||||
load(file)
|
||||
end
|
||||
|
||||
# Added by RefineryCMS Pages engine
|
||||
Refinery::Pages::Engine.load_seed
|
||||
|
|
|
@ -6,6 +6,7 @@ module Refinery
|
|||
autoload :BlogGenerator, 'generators/refinery/blog/blog_generator'
|
||||
|
||||
module Blog
|
||||
|
||||
require 'refinery/blog/engine' if defined?(Rails)
|
||||
|
||||
autoload :Version, 'refinery/blog/version'
|
||||
|
@ -30,6 +31,10 @@ module Refinery
|
|||
def factory_paths
|
||||
@factory_paths ||= [ root.join("spec/factories").to_s ]
|
||||
end
|
||||
|
||||
def table_name_prefix
|
||||
'refinery_blog_'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@ module Refinery
|
|||
plugin.url = app.routes.url_helpers.refinery_admin_blog_posts_path
|
||||
plugin.menu_match = /^\/refinery\/blog\/?(posts|comments|categories)?/
|
||||
plugin.activity = {
|
||||
:class_name => :'refinery/blog_post'
|
||||
:class_name => :'refinery/blog/post'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
FactoryGirl.define do
|
||||
factory :blog_category, :class => Refinery::BlogCategory do
|
||||
factory :blog_category, :class => Refinery::Blog::Category do
|
||||
sequence(:title) { |n| "Shopping #{n}" }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
FactoryGirl.define do
|
||||
factory :blog_comment, :class => Refinery::BlogComment do
|
||||
factory :blog_comment, :class => Refinery::Blog::Comment do
|
||||
name "Joe Commenter"
|
||||
sequence(:email) { |n| "person#{n}@example.com" }
|
||||
body "Which one is the best for picking up new shoes?"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
FactoryGirl.define do
|
||||
factory :blog_post, :class => Refinery::BlogPost do
|
||||
factory :blog_post, :class => Refinery::Blog::Post do
|
||||
sequence(:title) { |n| "Top #{n} Shopping Centers in Chicago" }
|
||||
body "These are the top ten shopping centers in Chicago. You're going to read a long blog post about them. Come to peace with it."
|
||||
draft false
|
||||
|
|
42
spec/models/refinery/blog/category_spec.rb
Normal file
42
spec/models/refinery/blog/category_spec.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
require 'spec_helper'
|
||||
|
||||
module Refinery
|
||||
module Blog
|
||||
describe Category do
|
||||
let(:category) { FactoryGirl.create(:blog_category) }
|
||||
|
||||
describe "validations" do
|
||||
it "requires title" do
|
||||
FactoryGirl.build(:blog_category, :title => "").should_not be_valid
|
||||
end
|
||||
|
||||
it "won't allow duplicate titles" do
|
||||
FactoryGirl.build(:blog_category, :title => category.title).should_not be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "blog posts association" do
|
||||
it "has a posts attribute" do
|
||||
category.should respond_to(:posts)
|
||||
end
|
||||
|
||||
it "returns posts by published_at date in descending order" do
|
||||
first_post = category.posts.create!({ :title => "Breaking News: Joe Sak is hot stuff you guys!!", :body => "True story.", :published_at => Time.now.yesterday })
|
||||
latest_post = category.posts.create!({ :title => "parndt is p. okay", :body => "For a Kiwi.", :published_at => Time.now })
|
||||
|
||||
category.posts.first.should == latest_post
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#post_count" do
|
||||
it "returns post count in category" do
|
||||
2.times do
|
||||
category.posts << FactoryGirl.create(:blog_post)
|
||||
end
|
||||
category.post_count.should == 2
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
19
spec/models/refinery/blog/comment_spec.rb
Normal file
19
spec/models/refinery/blog/comment_spec.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
require 'spec_helper'
|
||||
|
||||
module Refinery
|
||||
module Blog
|
||||
describe Comment do
|
||||
context "wiring up" do
|
||||
let(:comment) { FactoryGirl.create(:blog_comment) }
|
||||
|
||||
it "saves" do
|
||||
comment.should_not be_nil
|
||||
end
|
||||
|
||||
it "has a blog post" do
|
||||
comment.post.should_not be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
220
spec/models/refinery/blog/post_spec.rb
Normal file
220
spec/models/refinery/blog/post_spec.rb
Normal file
|
@ -0,0 +1,220 @@
|
|||
require 'spec_helper'
|
||||
|
||||
module Refinery
|
||||
module Blog
|
||||
describe Post do
|
||||
let(:post) { FactoryGirl.create(:blog_post) }
|
||||
|
||||
describe "validations" do
|
||||
it "requires title" do
|
||||
FactoryGirl.build(:blog_post, :title => "").should_not be_valid
|
||||
end
|
||||
|
||||
it "won't allow duplicate titles" do
|
||||
FactoryGirl.build(:blog_post, :title => post.title).should_not be_valid
|
||||
end
|
||||
|
||||
it "requires body" do
|
||||
FactoryGirl.build(:blog_post, :body => nil).should_not be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "comments association" do
|
||||
|
||||
it "have a comments attribute" do
|
||||
post.should respond_to(:comments)
|
||||
end
|
||||
|
||||
it "destroys associated comments" do
|
||||
FactoryGirl.create(:blog_comment, :blog_post_id => post.id)
|
||||
post.destroy
|
||||
Blog::Comment.where(:blog_post_id => post.id).should be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe "categories association" do
|
||||
it "have categories attribute" do
|
||||
post.should respond_to(:categories)
|
||||
end
|
||||
end
|
||||
|
||||
describe "tags" do
|
||||
it "acts as taggable" do
|
||||
post.should respond_to(:tag_list)
|
||||
|
||||
#the factory has default tags, including 'chicago'
|
||||
post.tag_list.should include("chicago")
|
||||
end
|
||||
end
|
||||
|
||||
describe "authors" do
|
||||
it "are authored" do
|
||||
subject.class.instance_methods.map(&:to_sym).should include(:author)
|
||||
end
|
||||
end
|
||||
|
||||
describe "by_archive scope" do
|
||||
before do
|
||||
@blog_post1 = FactoryGirl.create(:blog_post, :published_at => Date.new(2011, 3, 11))
|
||||
@blog_post2 = FactoryGirl.create(:blog_post, :published_at => Date.new(2011, 3, 12))
|
||||
|
||||
#2 months before
|
||||
FactoryGirl.create(:blog_post, :published_at => Date.new(2011, 1, 10))
|
||||
end
|
||||
|
||||
it "returns all posts from specified month" do
|
||||
#check for this month
|
||||
date = "03/2011"
|
||||
subject.class.by_archive(Time.parse(date)).count.should be == 2
|
||||
subject.class.by_archive(Time.parse(date)).should == [@blog_post2, @blog_post1]
|
||||
end
|
||||
end
|
||||
|
||||
describe "all_previous scope" do
|
||||
before do
|
||||
@blog_post1 = FactoryGirl.create(:blog_post, :published_at => Time.now - 2.months)
|
||||
@blog_post2 = FactoryGirl.create(:blog_post, :published_at => Time.now - 1.month)
|
||||
FactoryGirl.create(:blog_post, :published_at => Time.now)
|
||||
end
|
||||
|
||||
it "returns all posts from previous months" do
|
||||
subject.class.all_previous.count.should be == 2
|
||||
subject.class.all_previous.should == [@blog_post2, @blog_post1]
|
||||
end
|
||||
end
|
||||
|
||||
describe "live scope" do
|
||||
before do
|
||||
@blog_post1 = FactoryGirl.create(:blog_post, :published_at => Time.now.advance(:minutes => -2))
|
||||
@blog_post2 = FactoryGirl.create(:blog_post, :published_at => Time.now.advance(:minutes => -1))
|
||||
FactoryGirl.create(:blog_post, :draft => true)
|
||||
FactoryGirl.create(:blog_post, :published_at => Time.now + 1.minute)
|
||||
end
|
||||
|
||||
it "returns all posts which aren't in draft and pub date isn't in future" do
|
||||
subject.class.live.count.should be == 2
|
||||
subject.class.live.should == [@blog_post2, @blog_post1]
|
||||
end
|
||||
end
|
||||
|
||||
describe "uncategorized scope" do
|
||||
before do
|
||||
@uncategorized_post = FactoryGirl.create(:blog_post)
|
||||
@categorized_post = FactoryGirl.create(:blog_post)
|
||||
|
||||
@categorized_post.categories << FactoryGirl.create(:blog_category)
|
||||
end
|
||||
|
||||
it "returns uncategorized posts if they exist" do
|
||||
subject.class.uncategorized.should include @uncategorized_post
|
||||
subject.class.uncategorized.should_not include @categorized_post
|
||||
end
|
||||
end
|
||||
|
||||
describe "#live?" do
|
||||
it "returns true if post is not in draft and it's published" do
|
||||
FactoryGirl.create(:blog_post).live?.should be_true
|
||||
end
|
||||
|
||||
it "returns false if post is in draft" do
|
||||
FactoryGirl.create(:blog_post, :draft => true).live?.should be_false
|
||||
end
|
||||
|
||||
it "returns false if post pub date is in future" do
|
||||
FactoryGirl.create(:blog_post, :published_at => Time.now.advance(:minutes => 1)).live?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe "#next" do
|
||||
before do
|
||||
FactoryGirl.create(:blog_post, :published_at => Time.now.advance(:minutes => -1))
|
||||
@blog_post = FactoryGirl.create(:blog_post)
|
||||
end
|
||||
|
||||
it "returns next article when called on current article" do
|
||||
subject.class.last.next.should == @blog_post
|
||||
end
|
||||
end
|
||||
|
||||
describe "#prev" do
|
||||
before do
|
||||
FactoryGirl.create(:blog_post)
|
||||
@blog_post = FactoryGirl.create(:blog_post, :published_at => Time.now.advance(:minutes => -1))
|
||||
end
|
||||
|
||||
it "returns previous article when called on current article" do
|
||||
subject.class.first.prev.should == @blog_post
|
||||
end
|
||||
end
|
||||
|
||||
describe "#category_ids=" do
|
||||
before do
|
||||
@cat1 = FactoryGirl.create(:blog_category, :id => 1)
|
||||
@cat2 = FactoryGirl.create(:blog_category, :id => 2)
|
||||
@cat3 = FactoryGirl.create(:blog_category, :id => 3)
|
||||
post.category_ids = [1,2,"","",3]
|
||||
end
|
||||
|
||||
it "rejects blank category ids" do
|
||||
post.categories.count.should == 3
|
||||
end
|
||||
|
||||
it "returns array of categories based on given ids" do
|
||||
post.categories.should == [@cat1, @cat2, @cat3]
|
||||
end
|
||||
end
|
||||
|
||||
describe ".comments_allowed?" do
|
||||
context "with Refinery::Setting comments_allowed set to true" do
|
||||
before do
|
||||
Refinery::Setting.set(:comments_allowed, { :scoping => 'blog', :value => true })
|
||||
end
|
||||
|
||||
it "should be true" do
|
||||
subject.class.comments_allowed?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with Refinery::Setting comments_allowed set to false" do
|
||||
before do
|
||||
Refinery::Setting.set(:comments_allowed, { :scoping => 'blog', :value => false })
|
||||
end
|
||||
|
||||
it "should be false" do
|
||||
subject.class.comments_allowed?.should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "custom teasers" do
|
||||
it "should allow a custom teaser" do
|
||||
FactoryGirl.create(:blog_post, :custom_teaser => 'This is some custom content').should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe ".teasers_enabled?" do
|
||||
context "with Refinery::Setting teasers_enabled set to true" do
|
||||
before do
|
||||
Refinery::Setting.set(:teasers_enabled, { :scoping => 'blog', :value => true })
|
||||
end
|
||||
|
||||
it "should be true" do
|
||||
subject.class.teasers_enabled?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with Refinery::Setting teasers_enabled set to false" do
|
||||
before do
|
||||
Refinery::Setting.set(:teasers_enabled, { :scoping => 'blog', :value => false })
|
||||
end
|
||||
|
||||
it "should be false" do
|
||||
subject.class.teasers_enabled?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,42 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
module Refinery
|
||||
describe BlogCategory do
|
||||
before(:each) do
|
||||
@blog_category = FactoryGirl.create(:blog_category)
|
||||
end
|
||||
|
||||
describe "validations" do
|
||||
it "requires title" do
|
||||
FactoryGirl.build(:blog_category, :title => "").should_not be_valid
|
||||
end
|
||||
|
||||
it "won't allow duplicate titles" do
|
||||
FactoryGirl.build(:blog_category, :title => @blog_category.title).should_not be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "blog posts association" do
|
||||
it "has a posts attribute" do
|
||||
@blog_category.should respond_to(:posts)
|
||||
end
|
||||
|
||||
it "returns posts by published_at date in descending order" do
|
||||
first_post = @blog_category.posts.create!({ :title => "Breaking News: Joe Sak is hot stuff you guys!!", :body => "True story.", :published_at => Time.now.yesterday })
|
||||
latest_post = @blog_category.posts.create!({ :title => "parndt is p. okay", :body => "For a Kiwi.", :published_at => Time.now })
|
||||
|
||||
@blog_category.posts.first.should == latest_post
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "#post_count" do
|
||||
it "returns post count in category" do
|
||||
2.times do
|
||||
@blog_category.posts << FactoryGirl.create(:blog_post)
|
||||
end
|
||||
@blog_category.post_count.should == 2
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
module Refinery
|
||||
describe BlogComment do
|
||||
|
||||
context "wiring up" do
|
||||
|
||||
before(:each) do
|
||||
@comment = FactoryGirl.create(:blog_comment)
|
||||
end
|
||||
|
||||
it "saves" do
|
||||
@comment.should_not be_nil
|
||||
end
|
||||
|
||||
it "has a blog post" do
|
||||
@comment.post.should_not be_nil
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,218 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
module Refinery
|
||||
describe BlogPost do
|
||||
let(:blog_post) { FactoryGirl.create(:blog_post) }
|
||||
|
||||
describe "validations" do
|
||||
it "requires title" do
|
||||
FactoryGirl.build(:blog_post, :title => "").should_not be_valid
|
||||
end
|
||||
|
||||
it "won't allow duplicate titles" do
|
||||
FactoryGirl.build(:blog_post, :title => blog_post.title).should_not be_valid
|
||||
end
|
||||
|
||||
it "requires body" do
|
||||
FactoryGirl.build(:blog_post, :body => nil).should_not be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe "comments association" do
|
||||
|
||||
it "have a comments attribute" do
|
||||
blog_post.should respond_to(:comments)
|
||||
end
|
||||
|
||||
it "destroys associated comments" do
|
||||
FactoryGirl.create(:blog_comment, :blog_post_id => blog_post.id)
|
||||
blog_post.destroy
|
||||
BlogComment.find_by_blog_post_id(blog_post.id).should == nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "categories association" do
|
||||
it "have categories attribute" do
|
||||
blog_post.should respond_to(:categories)
|
||||
end
|
||||
end
|
||||
|
||||
describe "tags" do
|
||||
it "acts as taggable" do
|
||||
blog_post.should respond_to(:tag_list)
|
||||
|
||||
#the factory has default tags, including 'chicago'
|
||||
blog_post.tag_list.should include("chicago")
|
||||
end
|
||||
end
|
||||
|
||||
describe "authors" do
|
||||
it "are authored" do
|
||||
BlogPost.instance_methods.map(&:to_sym).should include(:author)
|
||||
end
|
||||
end
|
||||
|
||||
describe "by_archive scope" do
|
||||
before do
|
||||
@blog_post1 = FactoryGirl.create(:blog_post, :published_at => Date.new(2011, 3, 11))
|
||||
@blog_post2 = FactoryGirl.create(:blog_post, :published_at => Date.new(2011, 3, 12))
|
||||
|
||||
#2 months before
|
||||
FactoryGirl.create(:blog_post, :published_at => Date.new(2011, 1, 10))
|
||||
end
|
||||
|
||||
it "returns all posts from specified month" do
|
||||
#check for this month
|
||||
date = "03/2011"
|
||||
BlogPost.by_archive(Time.parse(date)).count.should be == 2
|
||||
BlogPost.by_archive(Time.parse(date)).should == [@blog_post2, @blog_post1]
|
||||
end
|
||||
end
|
||||
|
||||
describe "all_previous scope" do
|
||||
before do
|
||||
@blog_post1 = FactoryGirl.create(:blog_post, :published_at => Time.now - 2.months)
|
||||
@blog_post2 = FactoryGirl.create(:blog_post, :published_at => Time.now - 1.month)
|
||||
FactoryGirl.create(:blog_post, :published_at => Time.now)
|
||||
end
|
||||
|
||||
it "returns all posts from previous months" do
|
||||
BlogPost.all_previous.count.should be == 2
|
||||
BlogPost.all_previous.should == [@blog_post2, @blog_post1]
|
||||
end
|
||||
end
|
||||
|
||||
describe "live scope" do
|
||||
before do
|
||||
@blog_post1 = FactoryGirl.create(:blog_post, :published_at => Time.now.advance(:minutes => -2))
|
||||
@blog_post2 = FactoryGirl.create(:blog_post, :published_at => Time.now.advance(:minutes => -1))
|
||||
FactoryGirl.create(:blog_post, :draft => true)
|
||||
FactoryGirl.create(:blog_post, :published_at => Time.now + 1.minute)
|
||||
end
|
||||
|
||||
it "returns all posts which aren't in draft and pub date isn't in future" do
|
||||
BlogPost.live.count.should be == 2
|
||||
BlogPost.live.should == [@blog_post2, @blog_post1]
|
||||
end
|
||||
end
|
||||
|
||||
describe "uncategorized scope" do
|
||||
before do
|
||||
@uncategorized_blog_post = FactoryGirl.create(:blog_post)
|
||||
@categorized_blog_post = FactoryGirl.create(:blog_post)
|
||||
|
||||
@categorized_blog_post.categories << FactoryGirl.create(:blog_category)
|
||||
end
|
||||
|
||||
it "returns uncategorized posts if they exist" do
|
||||
BlogPost.uncategorized.should include @uncategorized_blog_post
|
||||
BlogPost.uncategorized.should_not include @categorized_blog_post
|
||||
end
|
||||
end
|
||||
|
||||
describe "#live?" do
|
||||
it "returns true if post is not in draft and it's published" do
|
||||
FactoryGirl.create(:blog_post).live?.should be_true
|
||||
end
|
||||
|
||||
it "returns false if post is in draft" do
|
||||
FactoryGirl.create(:blog_post, :draft => true).live?.should be_false
|
||||
end
|
||||
|
||||
it "returns false if post pub date is in future" do
|
||||
FactoryGirl.create(:blog_post, :published_at => Time.now.advance(:minutes => 1)).live?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe "#next" do
|
||||
before do
|
||||
FactoryGirl.create(:blog_post, :published_at => Time.now.advance(:minutes => -1))
|
||||
@blog_post = FactoryGirl.create(:blog_post)
|
||||
end
|
||||
|
||||
it "returns next article when called on current article" do
|
||||
BlogPost.last.next.should == @blog_post
|
||||
end
|
||||
end
|
||||
|
||||
describe "#prev" do
|
||||
before do
|
||||
FactoryGirl.create(:blog_post)
|
||||
@blog_post = FactoryGirl.create(:blog_post, :published_at => Time.now.advance(:minutes => -1))
|
||||
end
|
||||
|
||||
it "returns previous article when called on current article" do
|
||||
BlogPost.first.prev.should == @blog_post
|
||||
end
|
||||
end
|
||||
|
||||
describe "#category_ids=" do
|
||||
before do
|
||||
@cat1 = FactoryGirl.create(:blog_category, :id => 1)
|
||||
@cat2 = FactoryGirl.create(:blog_category, :id => 2)
|
||||
@cat3 = FactoryGirl.create(:blog_category, :id => 3)
|
||||
blog_post.category_ids = [1,2,"","",3]
|
||||
end
|
||||
|
||||
it "rejects blank category ids" do
|
||||
blog_post.categories.count.should == 3
|
||||
end
|
||||
|
||||
it "returns array of categories based on given ids" do
|
||||
blog_post.categories.should == [@cat1, @cat2, @cat3]
|
||||
end
|
||||
end
|
||||
|
||||
describe ".comments_allowed?" do
|
||||
context "with Refinery::Setting comments_allowed set to true" do
|
||||
before do
|
||||
Refinery::Setting.set(:comments_allowed, { :scoping => 'blog', :value => true })
|
||||
end
|
||||
|
||||
it "should be true" do
|
||||
BlogPost.comments_allowed?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with Refinery::Setting comments_allowed set to false" do
|
||||
before do
|
||||
Refinery::Setting.set(:comments_allowed, { :scoping => 'blog', :value => false })
|
||||
end
|
||||
|
||||
it "should be false" do
|
||||
BlogPost.comments_allowed?.should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "custom teasers" do
|
||||
it "should allow a custom teaser" do
|
||||
FactoryGirl.create(:blog_post, :custom_teaser => 'This is some custom content').should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
describe ".teasers_enabled?" do
|
||||
context "with Refinery::Setting teasers_enabled set to true" do
|
||||
before do
|
||||
Refinery::Setting.set(:teasers_enabled, { :scoping => 'blog', :value => true })
|
||||
end
|
||||
|
||||
it "should be true" do
|
||||
BlogPost.teasers_enabled?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with Refinery::Setting teasers_enabled set to false" do
|
||||
before do
|
||||
Refinery::Setting.set(:teasers_enabled, { :scoping => 'blog', :value => false })
|
||||
end
|
||||
|
||||
it "should be false" do
|
||||
BlogPost.teasers_enabled?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,13 +1,13 @@
|
|||
require "spec_helper"
|
||||
|
||||
module Refinery
|
||||
describe "AdminBlogComments" do
|
||||
describe "AdminBlog::Comments" do
|
||||
login_refinery_user
|
||||
|
||||
describe "#index" do
|
||||
context "when has no new unapproved comments" do
|
||||
before(:each) do
|
||||
BlogComment.delete_all
|
||||
Blog::Comment.delete_all
|
||||
visit refinery_admin_blog_comments_path
|
||||
end
|
||||
|
||||
|
@ -44,7 +44,7 @@ module Refinery
|
|||
describe "#approved" do
|
||||
context "when has no approved comments" do
|
||||
before(:each) do
|
||||
BlogComment.delete_all
|
||||
Blog::Comment.delete_all
|
||||
visit approved_refinery_admin_blog_comments_path
|
||||
end
|
||||
|
||||
|
@ -76,7 +76,7 @@ module Refinery
|
|||
describe "#rejected" do
|
||||
context "when has no rejected comments" do
|
||||
before(:each) do
|
||||
BlogComment.delete_all
|
||||
Blog::Comment.delete_all
|
||||
visit rejected_refinery_admin_blog_comments_path
|
||||
end
|
||||
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
require "spec_helper"
|
||||
|
||||
module Refinery
|
||||
describe "AdminBlogPosts" do
|
||||
describe "AdminBlog::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 }
|
||||
|
||||
before(:each) { Refinery::Blog::Post.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
|
||||
|
@ -30,7 +30,7 @@ module Refinery
|
|||
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"
|
||||
|
@ -38,25 +38,25 @@ module Refinery
|
|||
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)
|
||||
::Refinery::Blog::Post.all.size.should eq(1)
|
||||
end
|
||||
|
||||
it "should belong to me" do
|
||||
::Refinery::BlogPost.first.author.login.should eq(::Refinery::User.last.login)
|
||||
::Refinery::Blog::Post.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)
|
||||
::Refinery::Blog::Post.last.categories.count.should eq(1)
|
||||
::Refinery::Blog::Post.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"
|
||||
|
@ -65,29 +65,29 @@ module Refinery
|
|||
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)
|
||||
::Refinery::Blog::Post.all.size.should eq(1)
|
||||
end
|
||||
|
||||
|
||||
it "should have the specified tags" do
|
||||
::Refinery::BlogPost.last.tag_list.should eq(@tag_list.split(', '))
|
||||
::Refinery::Blog::Post.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
|
||||
|
||||
describe "edit blog post" do
|
||||
it "should succeed" do
|
||||
page.should have_content(blog_post.title)
|
||||
|
||||
|
@ -111,7 +111,7 @@ module Refinery
|
|||
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"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require "spec_helper"
|
||||
|
||||
module Refinery
|
||||
describe "BlogPosts" do
|
||||
describe "Blog::Posts" do
|
||||
login_refinery_user
|
||||
|
||||
context "when has blog posts" do
|
||||
|
@ -28,7 +28,7 @@ module Refinery
|
|||
@blog_post = FactoryGirl.create(:blog_post,
|
||||
:title => "I Love my city",
|
||||
:tag_list => @tag_name)
|
||||
@tag = ::Refinery::BlogPost.tag_counts_on(:tags).first
|
||||
@tag = ::Refinery::Blog::Post.tag_counts_on(:tags).first
|
||||
end
|
||||
|
||||
it "should have one tagged post" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue