Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add pending comments and spam/ham moderation

  • Loading branch information...
commit 4e52d8ebc5248c7b294c0e6763fb2a922029ebb7 1 parent fc06453
@bborn authored
View
2  Gemfile
@@ -1,9 +1,11 @@
source 'http://rubygems.org'
gem 'omniauth-facebook'
+gem 'acts_as_commentable', :git => 'https://github.com/jackdempsey/acts_as_commentable.git'
group :test do
gem 'sqlite3'
+ gem 'mocha', :require => false
end
rails_version = ENV["RAILS_VERSION"] || "default"
View
74 app/controllers/base_controller.rb
@@ -6,9 +6,10 @@ class BaseController < ApplicationController
include AuthenticatedSystem
include LocalizedApplication
- around_filter :set_locale
+ include BaseHelper
+
+ around_filter :set_locale
skip_before_filter :verify_authenticity_token, :only => :footer_content
- helper_method :commentable_url
before_filter :initialize_header_tabs
before_filter :initialize_admin_tabs
before_filter :store_location, :except => :footer_content
@@ -16,13 +17,13 @@ class BaseController < ApplicationController
caches_action :site_index, :footer_content, :if => Proc.new{|c| c.cache_action? }
def cache_action?
- !logged_in? && controller_name.eql?('base') && params[:format].blank?
- end
-
+ !logged_in? && controller_name.eql?('base') && params[:format].blank?
+ end
+
def rss_site_index
redirect_to :controller => 'base', :action => 'site_index', :format => 'rss'
end
-
+
def plaxo
render :layout => false
end
@@ -42,23 +43,23 @@ def site_index
:pub_date => :published_at}
})
end
- end
+ end
end
-
+
def footer_content
- get_recent_footer_content
- render :partial => 'shared/footer_content' and return
+ get_recent_footer_content
+ render :partial => 'shared/footer_content' and return
end
-
+
def homepage_features
@homepage_features = HomepageFeature.find_features
@homepage_features.shift
render :partial => 'homepage_feature', :collection => @homepage_features and return
end
-
+
def advertise
end
-
+
def css_help
end
@@ -67,9 +68,9 @@ def self.uses_tiny_mce(options = {}, &block)
if block_given?
options = block.call
end
-
+
new_configuration = TinyMCE::Rails.configuration.merge(options.delete(:options)).options
-
+
# Set instance vars in the current class
p = Proc.new do |c|
configuration = c.instance_variable_get(:@tiny_mce_configuration) || {}
@@ -80,23 +81,23 @@ def self.uses_tiny_mce(options = {}, &block)
before_filter p, options
end
-
-
+
+
private
def admin_required
current_user && current_user.admin? ? true : access_denied
end
-
+
def admin_or_moderator_required
current_user && (current_user.admin? || current_user.moderator?) ? true : access_denied
end
-
+
def find_user
if @user = User.active.find(params[:user_id] || params[:id])
@is_current_user = (@user && @user.eql?(current_user))
unless logged_in? || @user.profile_public?
flash[:error] = :private_user_profile_message.l
- access_denied
+ access_denied
else
return @user
end
@@ -105,7 +106,7 @@ def find_user
access_denied
end
end
-
+
def require_current_user
@user ||= User.find(params[:user_id] || params[:id] )
unless admin? || (@user && (@user.eql?(current_user)))
@@ -117,7 +118,7 @@ def require_current_user
def popular_tags(limit = 20, type = nil)
ActsAsTaggableOn::Tag.popular(limit, type)
end
-
+
def get_recent_footer_content
@recent_clippings = Clipping.find_recent(:limit => 10)
@@ -125,47 +126,34 @@ def get_recent_footer_content
@recent_comments = Comment.find_recent(:limit => 13)
@popular_tags = popular_tags(30)
@recent_activity = User.recent_activity(:size => 15, :current => 1)
-
+
end
def get_additional_homepage_data
@sidebar_right = true
@homepage_features = HomepageFeature.find_features
@homepage_features_data = @homepage_features.collect {|f| [f.id, f.image.url(:large) ] }
-
+
@active_users = User.find_by_activity({:limit => 5, :require_avatar => false})
@featured_writers = User.find_featured
@featured_posts = Post.find_featured
-
+
@topics = Topic.find(:all, :limit => 5, :order => "replied_at DESC")
- @popular_posts = Post.find_popular({:limit => 10})
+ @popular_posts = Post.find_popular({:limit => 10})
@popular_polls = Poll.find_popular(:limit => 8)
end
-
- def commentable_url(comment)
- if comment.recipient && comment.commentable
- if comment.commentable_type != "User"
- polymorphic_url([comment.recipient, comment.commentable])+"#comment_#{comment.id}"
- elsif comment
- user_url(comment.recipient)+"#comment_#{comment.id}"
- end
- elsif comment.commentable
- polymorphic_url(comment.commentable)+"#comment_#{comment.id}"
- end
- end
-
def initialize_header_tabs
# This hook allows plugins or host apps to easily add tabs to the header by adding to the @header_tabs array
# Usage: @header_tabs << {:name => "My tab", :url => my_tab_path, :section => 'my_tab_section' }
- @header_tabs = []
- end
+ @header_tabs = []
+ end
def initialize_admin_tabs
# This hook allows plugins or host apps to easily add tabs to the admin nav by adding to the @admin_nav_links array
# Usage: @admin_nav_links << {:name => "My link", :url => my_link_path, }
- @admin_nav_links = []
- end
+ @admin_nav_links = []
+ end
end
View
13 app/controllers/comments_controller.rb
@@ -1,6 +1,6 @@
class CommentsController < BaseController
before_filter :login_required, :except => [:index, :unsubscribe]
- before_filter :admin_or_moderator_required, :only => [:delete_selected, :edit, :update]
+ before_filter :admin_or_moderator_required, :only => [:delete_selected, :edit, :update, :approve, :disapprove]
if configatron.allow_anonymous_commenting
skip_before_filter :verify_authenticity_token, :only => [:create] #because the auth token might be cached anyway
@@ -28,6 +28,15 @@ def update
end
end
+ def approve
+ @comment = Comment.find(params[:id])
+ @comment.ham! if !configatron.akismet_key.nil?
+ @comment.role = 'published'
+ @comment.save!
+ respond_to do |format|
+ format.js
+ end
+ end
def index
commentable_type = get_commentable_type(params[:commentable_type])
@@ -100,8 +109,6 @@ def create
respond_to do |format|
if (logged_in? || verify_recaptcha(@comment)) && @comment.save
- @comment.send_notifications
-
flash.now[:notice] = :comment_was_successfully_created.l
format.html { redirect_to commentable_url(@comment) }
format.js
View
90 app/helpers/base_helper.rb
@@ -3,19 +3,23 @@
# Methods added to this helper will be available to all templates in the application.
module BaseHelper
include ActsAsTaggableOn::TagsHelper
-
+
def commentable_url(comment)
- if comment.commentable_type != "User"
- polymorphic_url([comment.recipient, comment.commentable])+"#comment_#{comment.id}"
- else
- user_url(comment.recipient)+"#comment_#{comment.id}"
+ if comment.recipient && comment.commentable
+ if comment.commentable_type != "User"
+ polymorphic_url([comment.recipient, comment.commentable])+"#comment_#{comment.id}"
+ elsif comment
+ user_url(comment.recipient)+"#comment_#{comment.id}"
+ end
+ elsif comment.commentable
+ polymorphic_url(comment.commentable)+"#comment_#{comment.id}"
end
end
-
+
def forum_page?
%w(forums topics sb_posts).include?(controller.controller_name)
end
-
+
def is_current_user_and_featured?(u)
u && u.eql?(current_user) && u.featured_writer?
end
@@ -28,20 +32,20 @@ def rounded(options={}, &content)
options.collect {|key,val| str << " #{key}=\"#{val}\"" }
str << '><div class="box_top"></div>'
str << "\n"
-
+
concat(str.html_safe)
yield(content)
concat('<br class="clear" /><div class="box_bottom"></div></div>'.html_safe)
end
-
+
def block_to_partial(partial_name, html_options = {}, &block)
concat(render(:partial => partial_name, :locals => {:body => capture(&block), :html_options => html_options}))
end
def box(html_options = {}, &block)
block_to_partial('shared/box', html_options, &block)
- end
-
+ end
+
def city_cloud(cities, classes)
max, min = 0, 0
cities.each { |c|
@@ -62,7 +66,7 @@ def truncate_words(text, length = 30, end_string = '...')
string = words[0..(length-1)].join(' ') + (words.length > length ? end_string : '')
string.html_safe
end
-
+
def truncate_words_with_highlight(text, phrase)
t = excerpt(text, phrase)
highlight truncate_words(t, 18), phrase
@@ -75,13 +79,13 @@ def excerpt_with_jump(text, end_string = ' ...')
if paragraph
paragraph.to_html + end_string
else
- truncate_words(text, 150, end_string)
+ truncate_words(text, 150, end_string)
end
end
def page_title
- divider = " | ".html_safe
-
+ divider = " | ".html_safe
+
app_base = configatron.community_name
tagline = " #{divider} #{configatron.community_tagline}"
title = app_base
@@ -100,10 +104,10 @@ def page_title
@canonical_url = user_post_url(@post.user, @post)
end
when 'users'
- if @user && !@user.new_record? && @user.login
+ if @user && !@user.new_record? && @user.login
title = @user.login
title += divider + app_base + tagline
- @canonical_url = user_url(@user)
+ @canonical_url = user_url(@user)
else
title = :showing_users.l+divider + app_base + tagline
end
@@ -124,7 +128,7 @@ def page_title
title = :posts_photos_and_bookmarks.l(:name => @tags.map(&:name).join(', '))
end
title += " (#{:related_tags.l}: #{@related_tags.join(', ')})" if @related_tags
- title += divider + app_base
+ title += divider + app_base
@canonical_url = tag_url(URI.escape(URI.escape(@tags_raw), /[\/.?#]/)) if @tags_raw
else
title = "Showing tags #{divider} #{app_base} #{tagline}"
@@ -133,15 +137,15 @@ def page_title
if @category and @category.name
title = :posts_photos_and_bookmarks.l(:name => @category.name) + divider + app_base + tagline
else
- title = :showing_categories.l + divider + app_base + tagline
+ title = :showing_categories.l + divider + app_base + tagline
end
when 'sessions'
- title = :login.l + divider + app_base + tagline
+ title = :login.l + divider + app_base + tagline
end
if @page_title
title = @page_title + divider + app_base + tagline
- elsif title == app_base
+ elsif title == app_base
title = :showing.l + ' ' + controller.controller_name + divider + app_base + tagline
end
@@ -152,11 +156,11 @@ def add_friend_link(user = nil)
html = "<span class='friend_request' id='friend_request_#{user.id}'>"
html += link_to_remote :request_friendship.l,
{ :update => "friend_request_#{user.id}",
- :loading => "$$('span#friend_request_#{user.id} span.spinner')[0].show(); $$('span#friend_request_#{user.id} a.add_friend_btn')[0].hide()",
+ :loading => "$$('span#friend_request_#{user.id} span.spinner')[0].show(); $$('span#friend_request_#{user.id} a.add_friend_btn')[0].hide()",
:complete => visual_effect(:highlight, "friend_request_#{user.id}", :duration => 1),
500 => "alert('#{escape_javascript(:sorry_there_was_an_error_requesting_friendship.l)}')",
- :url => hash_for_user_friendships_url(:user_id => current_user.id, :friend_id => user.id),
- :method => :post
+ :url => hash_for_user_friendships_url(:user_id => current_user.id, :friend_id => user.id),
+ :method => :post
}, {:class => "add_friend button"}
html += "<span style='display:none;' class='spinner'>"
html += image_tag('spinner.gif')
@@ -167,34 +171,34 @@ def add_friend_link(user = nil)
def topnav_tab(name, options)
classes = [options.delete(:class)]
classes << 'current' if options[:section] && (options.delete(:section).to_a.include?(@section))
-
+
string = "<li class='#{classes.join(' ')}'>" + link_to( content_tag(:span, name), options.delete(:url), options) + "</li>"
string.html_safe
end
-
+
def more_comments_links(commentable)
html = link_to "&raquo; ".html_safe + :all_comments.l, commentable_comments_url(commentable.class.to_s.tableize, commentable.to_param)
html += "<br />".html_safe
html += link_to "&raquo; ".html_safe + :comments_rss.l, commentable_comments_url(commentable.class.to_s.tableize, commentable.to_param, :format => :rss)
html.html_safe
end
-
+
def show_footer_content?
return true #you can override this in your app
end
-
+
def clippings_link
- "javascript:(function() {d=document, w=window, e=w.getSelection, k=d.getSelection, x=d.selection, s=(e?e():(k)?k():(x?x.createRange().text:0)), e=encodeURIComponent, document.location='#{home_url}new_clipping?uri='+e(document.location)+'&title='+e(document.title)+'&selection='+e(s);} )();"
+ "javascript:(function() {d=document, w=window, e=w.getSelection, k=d.getSelection, x=d.selection, s=(e?e():(k)?k():(x?x.createRange().text:0)), e=encodeURIComponent, document.location='#{home_url}new_clipping?uri='+e(document.location)+'&title='+e(document.title)+'&selection='+e(s);} )();"
end
-
+
def paginating_links(paginator, options = {}, html_options = {})
paginate paginator
- end
-
+ end
+
def last_active
session[:last_active] ||= Time.now.utc
end
-
+
def ajax_spinner_for(id, spinner="spinner.gif")
"<img src='/assets/#{spinner}' style='display:none; vertical-align:middle;' id='#{id.to_s}_spinner'> ".html_safe
end
@@ -228,7 +232,7 @@ def time_ago_in_words(from_time, to_time = Time.now, include_seconds = false)
from_time = from_time.to_time if from_time.respond_to?(:to_time)
to_time = to_time.to_time if to_time.respond_to?(:to_time)
distance_in_minutes = (((to_time - from_time).abs)/60).round
-
+
case distance_in_minutes
when 0 then :a_few_seconds_ago.l
when 1..59 then :minutes_ago.l(:count => distance_in_minutes)
@@ -247,33 +251,33 @@ def time_ago_in_words_or_date(date)
display = I18n.l(date.to_date, :format => :date_ago)
end
end
-
+
def profile_completeness(user)
segments = [
{:val => 2, :action => link_to(:upload_a_profile_photo.l, edit_user_path(user, :anchor => 'profile_details')), :test => !user.avatar.nil? },
- {:val => 1, :action => link_to(:tell_us_about_yourself.l, edit_user_path(user, :anchor => 'user_description')), :test => !user.description.blank?},
- {:val => 2, :action => link_to(:select_your_city.l, edit_user_path(user, :anchor => 'location_chooser')), :test => !user.metro_area.nil? },
- {:val => 1, :action => link_to(:tag_yourself.l, edit_user_path(user, :anchor => "user_tags")), :test => user.tags.any?},
+ {:val => 1, :action => link_to(:tell_us_about_yourself.l, edit_user_path(user, :anchor => 'user_description')), :test => !user.description.blank?},
+ {:val => 2, :action => link_to(:select_your_city.l, edit_user_path(user, :anchor => 'location_chooser')), :test => !user.metro_area.nil? },
+ {:val => 1, :action => link_to(:tag_yourself.l, edit_user_path(user, :anchor => "user_tags")), :test => user.tags.any?},
{:val => 1, :action => link_to(:invite_some_friends.l, new_invitation_path), :test => user.invitations.any?}
]
-
+
completed_score = segments.select{|s| s[:test].eql?(true)}.sum{|s| s[:val]}
incomplete = segments.select{|s| !s[:test] }
-
+
total = segments.sum{|s| s[:val] }
score = (completed_score.to_f/total.to_f)*100
{:score => score, :incomplete => incomplete, :total => total}
end
-
+
def possesive(user)
- user.gender ? (user.male? ? :his.l : :her.l) : :their.l
+ user.gender ? (user.male? ? :his.l : :her.l) : :their.l
end
def tiny_mce_init_if_needed
if !@uses_tiny_mce.blank?
- tinymce_js = tinymce_javascript(@tiny_mce_configuration)
+ tinymce_js = tinymce_javascript(@tiny_mce_configuration)
javascript_tag(tinymce_js)
end
end
View
25 app/models/comment.rb
@@ -13,6 +13,7 @@ class Comment < ActiveRecord::Base
validates_length_of :comment, :maximum => 2000
before_save :whitelist_attributes
+ after_save :send_notifications
validates_presence_of :user, :unless => Proc.new{|record| configatron.allow_anonymous_commenting }
validates_presence_of :author_email, :unless => Proc.new{|record| record.user } #require email unless logged in
@@ -29,13 +30,14 @@ def self.find_photo_comments_for(user)
def previous_commenters_to_notify
# only send a notification on recent comments
# limit the number of emails we'll send (or posting will be slooowww)
-
- User.find(:all,
- :conditions => ["users.id NOT IN (?) AND users.notify_comments = ?
- AND commentable_id = ? AND commentable_type = ?
- AND comments.notify_by_email = ?
- AND comments.created_at > ?", [user_id, recipient_id.to_i], true, commentable_id, commentable_type, true, 2.weeks.ago],
- :include => :comments_as_author, :limit => 20)
+ users = User.includes(:comments_as_author).limit(20)
+ users = users.where(:notify_comments => true).where('users.id NOT IN (?)', [user_id, recipient_id.to_i])
+ users = users.where(:comments => {
+ :commentable_id => commentable_id,
+ :commentable_type => commentable_type,
+ :notify_by_email => true
+ })
+ users = users.where('comments.created_at > ?', 2.weeks.ago)
end
def commentable_name
@@ -71,7 +73,7 @@ def can_be_deleted_by(person)
end
def should_notify_recipient?
- return unless recipient && recipient.email
+ return false unless recipient && recipient.email
return false if recipient.eql?(user)
return false unless recipient.notify_comments?
true
@@ -92,6 +94,7 @@ def notify_previous_anonymous_commenters
def send_notifications
return if commentable.respond_to?(:send_comment_notifications?) && !commentable.send_comment_notifications?
+ return unless self.role_changed? && !self.role.eql?('pending')
UserNotifier.comment_notice(self).deliver if should_notify_recipient?
self.notify_previous_commenters
self.notify_previous_anonymous_commenters if configatron.allow_anonymous_commenting
@@ -109,10 +112,14 @@ def unsubscribe_notifications(email)
def check_spam
if !configatron.akismet_key.nil? && self.spam?
- self.errors.add(:base, :comment_spam_error.l)
+ self.role = 'pending'
end
end
+ def pending?
+ role.eql?('pending')
+ end
+
protected
def whitelist_attributes
View
96 app/models/post.rb
@@ -1,44 +1,44 @@
class Post < ActiveRecord::Base
include Rakismet::Model
rakismet_attrs :comment_type => 'post'
- attr_protected :akismet_attrs
-
-
- acts_as_commentable
+ attr_protected :akismet_attrs
+
+ acts_as_moderated_commentable
+
acts_as_taggable
acts_as_activity :user, :if => Proc.new{|r| r.is_live?}
acts_as_publishable :live, :draft
-
+
belongs_to :user
belongs_to :category
has_many :polls, :dependent => :destroy
has_many :favorites, :as => :favoritable, :dependent => :destroy
-
+
validates_presence_of :raw_post
validates_presence_of :title
validates_presence_of :user
validates_presence_of :published_at, :if => Proc.new{|r| r.is_live? }
-
+
before_save :transform_post, :if => Proc.new{|r| r.raw_post_changed? }
before_validation :set_published_at
-
+
after_save do |post|
activity = Activity.find_by_item_type_and_item_id('Post', post.id)
if post.is_live? && !activity
- post.create_activity_from_self
+ post.create_activity_from_self
elsif post.is_draft? && activity
activity.destroy
end
end
-
+
attr_accessor :invalid_emails
attr_accessible :category_id, :title, :raw_post, :published_as, :send_comment_notifications
-
+
# Class Methods
class << self
-
- # Scopes
+
+ # Scopes
def by_featured_writers
where("users.featured_writer = ?", true).includes(:user)
end
@@ -46,21 +46,21 @@ def popular
order('posts.view_count DESC')
end
def since(days)
- where("posts.published_at > ?", days.ago)
+ where("posts.published_at > ?", days.ago)
end
def recent
- order("posts.published_at DESC")
+ order("posts.published_at DESC")
end
-
+
def find_related_to(post, options = {})
- options.reverse_merge!({:limit => 8,
- :order => 'published_at DESC',
+ options.reverse_merge!({:limit => 8,
+ :order => 'published_at DESC',
:conditions => [ 'posts.id != ? AND published_as = ?', post.id, 'live' ]
})
limit(options[:limit]).order(options[:order]).where(options[:conditions]).tagged_with(post.tag_list, :any => true)
end
-
+
def find_recent(options = {:limit => 5})
recent.find :all, options
end
@@ -76,7 +76,7 @@ def find_featured(options = {:limit => 10})
end
def find_most_commented(limit = 10, since = 7.days.ago)
- Post.find(:all,
+ Post.find(:all,
:select => 'posts.*, count(*) as comments_count',
:joins => "LEFT JOIN comments ON comments.commentable_id = posts.id",
:conditions => ['comments.commentable_type = ? AND posts.published_at > ?', 'Post', since],
@@ -84,24 +84,24 @@ def find_most_commented(limit = 10, since = 7.days.ago)
:order => 'comments_count DESC',
:limit => limit
)
- end
-
+ end
+
def new_from_bookmarklet(params)
self.new(
:title => "#{params[:title] || params[:uri]}",
:raw_post => "<a href='#{params[:uri]}'>#{params[:uri]}</a>#{params[:selection] ? "<p>#{params[:selection]}</p>" : ''}"
)
end
-
+
end
-
-
-
+
+
+
def to_param
id.to_s << "-" << (title ? title.parameterize : '' )
end
-
+
def display_title
t = self.title
if self.category
@@ -109,62 +109,62 @@ def display_title
end
t
end
-
+
def previous_post
self.user.posts.order('published_at DESC').where('published_at < ? and published_as = ?', published_at, 'live').first
end
def next_post
- self.user.posts.except(:order).order('published_at DESC').where('published_at > ? and published_as = ?', published_at, 'live').first
+ self.user.posts.except(:order).order('published_at DESC').where('published_at > ? and published_as = ?', published_at, 'live').first
end
-
+
def first_image_in_body(size = nil, options = {})
doc = Hpricot( post )
image = doc.at("img")
image ? image['src'] : nil
end
-
+
def tag_for_first_image_in_body
image = first_image_in_body
image.nil? ? '' : "<img src='#{image}' />"
end
-
+
## transform the text and title into valid html
def transform_post
self.post = white_list(self.raw_post)
self.title = white_list(self.title)
end
-
+
def set_published_at
if self.is_live? && !self.published_at
self.published_at = Time.now
end
end
-
+
def owner
self.user
end
-
+
def send_to(email_addresses = '', message = '', user = nil)
self.invalid_emails = []
emails = email_addresses.split(",").collect{|email| email.strip }.uniq
- emails.each do |email|
+ emails.each do |email|
self.invalid_emails << email unless email =~ /[\w._%-]+@[\w.-]+.[a-zA-Z]{2,4}/
end
if email_addresses.blank? || !invalid_emails.empty?
return false
- else
- emails = email_addresses.split(",").collect{|email| email.strip }.uniq
+ else
+ emails = email_addresses.split(",").collect{|email| email.strip }.uniq
emails.each{|email|
UserNotifier.post_recommendation((user ? user.login : 'Someone'), email, self, message, user).deliver
}
- self.increment(:emailed_count).save
+ self.increment(:emailed_count).save
end
end
-
+
def image_for_excerpt
- first_image_in_body || user.avatar_photo_url(:medium)
+ first_image_in_body || user.avatar_photo_url(:medium)
end
-
+
def create_poll(poll, choices)
new_poll = self.polls.new(:question => poll[:question])
choices.delete('')
@@ -173,7 +173,7 @@ def create_poll(poll, choices)
new_poll.add_choices(choices)
end
end
-
+
def update_poll(poll, choices)
return unless self.poll
self.poll.update_attributes(:question => poll[:question])
@@ -186,18 +186,18 @@ def update_poll(poll, choices)
self.poll.destroy
end
end
-
+
def poll
!polls.empty? && polls.first
end
-
+
def has_been_favorited_by(user = nil, remote_ip = nil)
f = Favorite.find_by_user_or_ip_address(self, user, remote_ip)
return f
- end
-
+ end
+
def published_at_display(format = :published_date)
is_live? ? I18n.l(published_at, :format => format.to_sym) : 'Draft'
end
-
+
end
View
2  app/models/user.rb
@@ -35,7 +35,7 @@ class User < ActiveRecord::Base
end
acts_as_taggable
- acts_as_commentable
+ acts_as_moderated_commentable
has_enumerated :role
tracks_unlinked_activities [:logged_in, :invited_friends, :updated_profile, :joined_the_site]
View
19 app/views/admin/comments.html.haml
@@ -3,7 +3,7 @@
-box do
= form_for @search, :url => admin_comments_path, :html => {:class => "MainForm"} do |f|
-
+
%label= :commentable_type.l
= f.text_field :commentable_type_like
@@ -14,7 +14,7 @@
= f.text_field :author_email_or_user_email_like
%p= f.submit :search.l
-
+
@@ -32,14 +32,17 @@
%thead
%tr
%th{:width => '30px', :colspan => '2'}
- %th=:author.l
+ %th=:author.l
%th{:width => "250px"}=:body_text.l
%th=:on_commentable.l
%tbody
- @comments.each do |comment|
%tr{:id => "comment_#{comment.id}"}
- %td=link_to_remote(image_tag('icons/delete.png'), {:url => commentable_comment_path(comment.commentable_type, comment.commentable_id, comment), :method => :delete, 500 => 'alert(\'Sorry, there was a server error\'); return false', :success => visual_effect(:fade, "comment_#{comment.id}"), :confirm => "Are you sure you want to permanently delete this comment"} )
+ %td=link_to_remote(image_tag('icons/delete.png'), {:url => commentable_comment_path(comment.commentable_type, comment.commentable_id, comment), :method => :delete, 500 => 'alert(\'Sorry, there was a server error\'); return false', :success => visual_effect(:fade, "comment_#{comment.id}"), :confirm => "Are you sure you want to permanently delete this comment"} )
+ %td.approve
+ -if comment.pending?
+ =link_to_remote(image_tag('icons/accept.png'), {:url => approve_commentable_comment_path(comment.commentable_type, comment.commentable_id, comment, :approve => true), :method => :put, :confirm => "Approve this comment?"} )
%td= check_box_tag "delete[]", comment.id
%td
.left
@@ -48,7 +51,7 @@
%br
%small= comment.user.email
-else
- = link_to_unless(comment.author_url.blank?, h(comment.username), h(comment.author_url)){ h(comment.username) }
+ = link_to_unless(comment.author_url.blank?, h(comment.username), h(comment.author_url)){ h(comment.username) }
%br
%small=comment.author_email
%br
@@ -61,12 +64,12 @@
%tr
%td{ :colspan => "4" }
-if @comments.any?
- %a{:href=>"#", :onclick=>"checkboxes.each(function(e){ e.checked = (e.checked == 0 ? 1 : 0) }); return false;"} Toggle all
- %p= submit_tag :delete_selected.l
+ %a{:href=>"#", :onclick=>"checkboxes.each(function(e){ e.checked = (e.checked == 0 ? 1 : 0) }); return false;"} Toggle all
+ %p= submit_tag :delete_selected.l
= paginate @comments
-content_for :end_javascript do
:javascript
var form = $('comments');
- checkboxes = form.getInputs('checkbox');
+ checkboxes = form.getInputs('checkbox');
View
3  app/views/comments/_comment.html.haml
@@ -1,3 +1,6 @@
+-if comment.pending?
+ %em This comment is awaiting approval
+
-if comment.user
.hentry{:id => "comment_#{comment.id}"}
.vcard.author
View
1  app/views/comments/approve.js.haml
@@ -0,0 +1 @@
+$$('#comment_#{@comment.id} .approve a').invoke('hide');
View
32 app/views/layouts/application.html.haml
@@ -12,27 +12,27 @@
- if @rss_title && @rss_url
= auto_discovery_link_tag(:rss, @rss_url, {:title => @rss_title})
-
- = render :partial => "shared/scripts_and_styles"
-
+
+ = render :partial => "shared/scripts_and_styles"
+
%body
- -unless configatron.auth_providers.facebook.key.blank?
- =render :partial => 'facebook/fb_require'
-
+ -unless configatron.auth_providers.facebook.key.blank?
+ =render :partial => 'facebook/fb_require'
+
#doc2{:class => "yui-t#{@sidebar_left ? 3 : 6}"}
= render :partial => "shared/header"
-
+
#bd
= render :partial => "shared/messages"
-
+
= yield
-
-
+
+
#ft
- -if show_footer_content?
+ -if show_footer_content?
.yui-gc#footer_content
= image_tag 'spinner.gif', :plugin => 'community_engine'
- =:loading_recent_content.l
+ =:loading_recent_content.l
#CommunityFooter
@@ -41,7 +41,7 @@
%a{:href=>home_url, :title=>"#{configatron.community_name} " + :home.l}= :home.l
- if !logged_in?
%li
- = link_to :log_in.l , login_path
+ = link_to :log_in.l , login_path
- else
%li
%a{:href=>logout_url, :title=>:log_out_of_your.l + " #{configatron.community_name} " + :account.l}
@@ -49,8 +49,8 @@
- Page.find(:all).each do |page|
- if (logged_in? || page.page_public)
- %li= link_to page.title, pages_path(page)
-
+ %li= link_to page.title, pages_path(page)
+
- if @rss_title && @rss_url
%li#rss= link_to :rss.l, @rss_url, {:title => @rss_title}
@@ -58,4 +58,4 @@
= :community_tagline.l
= render :partial => "shared/end_javascript"
- = yield :end_javascript
+ = yield :end_javascript
View
2  community_engine.gemspec
@@ -42,7 +42,7 @@ Gem::Specification.new do |s|
s.add_dependency(%q<friendly_id>, ["~> 3.3"])
s.add_dependency(%q<paperclip>, ["~> 3.5.1"])
s.add_dependency(%q<cocaine>, ["0.5.1"])
- s.add_dependency(%q<acts_as_commentable>, ["= 3.0.1"])
+ s.add_dependency(%q<acts_as_commentable>, ["~> 4.0.1"])
s.add_dependency(%q<recaptcha>, [">= 0"])
s.add_dependency(%q<omniauth>, ["~> 1.1.0"])
s.add_dependency(%q<prototype-rails>, [">= 0"])
View
69 config/routes.rb
@@ -7,14 +7,14 @@
resources :authorizations
match '/auth/:provider/callback' => 'authorizations#create', :as => :callback
get '/auth/failure' => 'authorizations#failure'
-
+
resources :sb_posts, :as => 'all_sb_posts' do
collection do
get :search
get :monitored
end
end
-
+
resources :monitorship
resources :sb_posts do
collection do
@@ -25,7 +25,7 @@
resources :forums do
resources :sb_posts
-
+
resources :moderators
resources :topics do
resources :sb_posts
@@ -37,9 +37,9 @@
get 'sitemap.xml' => 'sitemap#index', :format => 'xml'
get 'sitemap' => 'sitemap#index'
-
+
get '/' => 'base#site_index', :as => :home
-
+
scope "/admin" do
get 'dashboard' => 'homepage_features#index', :as => :admin_dashboard
get 'users' => 'admin#users', :as => :admin_users
@@ -51,33 +51,33 @@
get 'subscribers(.:format)' => "admin#subscribers", :as => :admin_subscribers
get 'activate_user' => "admin#activate_user", :as => :admin_activate_user
get 'deactivate_user' => 'admin#deactivate_user', :as => :admin_deactivate_user
-
+
resources :pages, :as => :admin_pages do
member do
get :preview
end
end
end
-
+
get 'pages/:id' => 'pages#show', :as => :pages
-
-
+
+
get '/login' => 'sessions#new', :as => :login
get '/signup' => 'users#new', :as => :signup
get '/logout' => 'sessions#destroy', :as => :logout
-
+
get '/signup/:inviter_id/:inviter_code' => 'users#new', :as => :signup_by_id
get '/forgot_password' => 'password_resets#new', :as => :forgot_password
resources :password_resets
get '/forgot_username' => 'users#forgot_username', :as => :forgot_username
post '/forgot_username' => 'users#forgot_username'
post '/resend_activation' => 'users#resend_activation', :as => :resend_activation
-
+
get '/new_clipping' => 'clippings#new_clipping'
- post '/load_images_from_uri' => 'clippings#load_images_from_uri', :format => 'js'
+ post '/load_images_from_uri' => 'clippings#load_images_from_uri', :format => 'js'
get '/clippings(/page/:page)' => 'clippings#site_index', :as => :site_clippings
get '/clippings.rss' => 'clippings#site_index', :as => :rss_site_clippings, :format => 'rss'
-
+
get '/featured(/page/:page)' => 'posts#featured', :as => :featured
get '/featured.rss' => 'posts#featured', :as => :featured_rss, :format => 'rss'
get '/popular(/page/:page)' => 'posts#popular', :as => :popular
@@ -113,7 +113,7 @@
end
get '/tags/:id/:type' => 'tags#show', :as => :show_tag_type
get '/search/tags' => 'tags#show', :as => :search_tags
-
+
resources :categories
post '/categories/show_tips' => 'categories#show_tips', :as => :categories_show_tips
@@ -133,25 +133,26 @@
resources :favorites
end
scope "/:commentable_type/:commentable_id" do
- resources :comments, :as => :commentable_comments do
+ resources :comments, :as => :commentable_comments do
member do
get :unsubscribe
- end
+ put :approve
+ end
end
end
resources :comments
delete '/comments/delete_selected' => 'comments#delete_selected', :as => :delete_selected_comments
-
+
resources :homepage_features
resources :metro_areas
resources :ads
resources :activities
-
+
resources :users do
-
+
get 'page/:page', :action => :index, :on => :collection
-
+
collection do
post 'return_admin'
delete 'delete_selected'
@@ -160,30 +161,30 @@
get 'dashboard'
get 'edit_account'
get 'invite'
- get 'signup_completed'
+ get 'signup_completed'
get 'activate'
-
+
put 'toggle_moderator'
put 'toggle_featured'
put 'change_profile_photo'
put 'update_account'
- put 'deactivate'
-
+ put 'deactivate'
+
get 'welcome_photo'
get 'welcome_about'
get 'welcome_invite'
get 'welcome_complete'
-
- post 'assume'
-
+
+ post 'assume'
+
get 'statistics'
get 'crop_profile_photo'
put 'crop_profile_photo'
get 'upload_profile_photo'
put 'upload_profile_photo'
end
-
+
resources :friendships do
collection do
get :accepted
@@ -201,13 +202,13 @@
end
resources :posts do
- get 'page/:page', :action => :index, :on => :collection
-
- collection do
+ get 'page/:page', :action => :index, :on => :collection
+
+ collection do
# get 'manage(/page/:page)', :action => :manage
get :manage
end
-
+
member do
post :send_to_friend
put :update_views
@@ -219,7 +220,7 @@
resources :clippings
resources :activities do
- get 'page/:page', :action => :index, :on => :collection
+ get 'page/:page', :action => :index, :on => :collection
collection do
get :network
end
@@ -256,4 +257,4 @@
get '/users/:user_id/posts/category/:category_name' => 'posts#index', :as => :users_posts_in_category
post '/users/metro_area_update' => 'users#metro_area_update', :as => :users_metro_area_update
-end
+end
View
15 db/migrate/090_add_comment_role.rb
@@ -0,0 +1,15 @@
+class AddCommentRole < ActiveRecord::Migration
+
+ def self.up
+ add_column :comments, :role, :string, :default => 'comments'
+ end
+
+ def self.down
+ remove_column :comments, :role
+ end
+
+end
+
+
+
+
View
16 lib/community_engine/engines_extensions.rb
@@ -1,7 +1,19 @@
module EnginesExtensions
def require_from_ce(path)
- require_dependency CommunityEngine::Engine.config.root.join('app', path).to_s
+ require_dependency CommunityEngine::Engine.config.root.join('app', path).to_s
end
-
+
+ def acts_as_moderated_commentable
+ acts_as_commentable :published, :pending
+ has_many :comments, {
+ :as => :commentable,
+ :dependent => :destroy,
+ :conditions => "role != 'pending'",
+ :before_add => Proc.new { |x, c| c.role = 'published' }
+ }
+ attr_protected :role
+ end
+
+
end
View
131 lib/community_engine/rails_asset_extensions.rb
@@ -1,131 +0,0 @@
-# module EnginesHelper
-# # Configuration and defaults
-#
-# mattr_accessor :autoload_assets
-# self.autoload_assets = true
-#
-# mattr_accessor :plugin_assets_directory
-# self.plugin_assets_directory = 'plugin_assets'
-#
-# module Assets
-# extend self
-#
-# # Propagate the public folders
-# def propagate
-# return if !EnginesHelper.autoload_assets
-# plugin_list.each do |plugin|
-# FileUtils.mkdir_p "#{Rails.root}/public/#{EnginesHelper.plugin_assets_directory}/#{plugin}"
-# Dir.glob("#{Rails.root}/vendor/plugins/#{plugin}/public/*").each do |asset_path|
-# FileUtils.cp_r(asset_path, "#{Rails.root}/public/#{EnginesHelper.plugin_assets_directory}/#{plugin}/.", :preserve => true)
-# end
-# end
-# end
-#
-# def update_sass_directories
-#
-# if check_for_sass
-#
-# unless Sass::Plugin.options[:template_location].is_a?(Hash)
-# Sass::Plugin.options[:template_location] = {
-# Sass::Plugin.options[:template_location] => Sass::Plugin.options[:template_location].gsub(/\/sass$/, '') }
-# end
-#
-# Dir.glob("#{Rails.root}/public/#{EnginesHelper.plugin_assets_directory}/**/sass") do |sass_dir|
-# Sass::Plugin.options[:template_location] =
-# Sass::Plugin.options[:template_location].merge({
-# sass_dir => sass_dir.gsub(/\/sass$/, '')
-# })
-# end
-#
-# end
-# end
-#
-# private
-#
-# def plugin_list
-# Dir.glob("#{Rails.root}/vendor/plugins/*").reject { |p|
-# !File.exist?("#{Rails.root}/vendor/plugins/#{File.basename(p)}/public")
-# }.map { |d| File.basename(d) }
-# end
-#
-# def check_for_sass
-# defined?(Sass) && Sass.version[:major]*10 + Sass.version[:minor] >= 21
-# end
-#
-# end
-#
-#
-# end
-#
-#
-#
-# #
-# # These helpers are right out of the original Engines plugin
-# #
-#
-# module AssetHelpers
-# def self.included(base) #:nodoc:
-# base.class_eval do
-# [:stylesheet_link_tag, :javascript_include_tag, :image_path, :image_tag].each do |m|
-# alias_method_chain m, :engine_additions
-# end
-# end
-# end
-#
-# # Adds plugin functionality to Rails' default stylesheet_link_tag method.
-# def stylesheet_link_tag_with_engine_additions(*sources)
-# stylesheet_link_tag_without_engine_additions(*AssetHelpers.pluginify_sources("stylesheets", *sources))
-# end
-#
-# # Adds plugin functionality to Rails' default javascript_include_tag method.
-# def javascript_include_tag_with_engine_additions(*sources)
-# javascript_include_tag_without_engine_additions(*AssetHelpers.pluginify_sources("javascripts", *sources))
-# end
-#
-# #
-# # Our modified image_path now takes a 'plugin' option, though it doesn't require it
-# #
-#
-# # Adds plugin functionality to Rails' default image_path method.
-# def image_path_with_engine_additions(source, options={})
-# options.stringify_keys!
-# source = AssetHelpers.plugin_asset_path(options["plugin"], "images", source) if options["plugin"]
-# image_path_without_engine_additions(source)
-# end
-#
-# # Adds plugin functionality to Rails' default image_tag method.
-# def image_tag_with_engine_additions(source, options={})
-# options.stringify_keys!
-# if options["plugin"]
-# source = AssetHelpers.plugin_asset_path(options["plugin"], "images", source)
-# options.delete("plugin")
-# end
-# image_tag_without_engine_additions(source, options)
-# end
-#
-# #
-# # The following are methods on this module directly because of the weird-freaky way
-# # Rails creates the helper instance that views actually get
-# #
-#
-# # Convert sources to the paths for the given plugin, if any plugin option is given
-# def self.pluginify_sources(type, *sources)
-# options = sources.last.is_a?(Hash) ? sources.pop.stringify_keys : { }
-# sources.map! { |s| plugin_asset_path(options["plugin"], type, s) } if options["plugin"]
-# options.delete("plugin") # we don't want it appearing in the HTML
-# sources << options # re-add options
-# end
-#
-# # Returns the publicly-addressable relative URI for the given asset, type and plugin
-# def self.plugin_asset_path(plugin_name, type, asset)
-# #raise "No plugin called '#{plugin_name}' - please use the full name of a loaded plugin." if !File.exist?("#{Rails.root}/public/#{plugin_name}/#{type}/#{asset}")
-# "/#{plugin_name}/#{type}/#{asset}"
-# end
-#
-# end
-#
-# module ::ActionView::Helpers::AssetTagHelper
-# if !self.included_modules.include? AssetHelpers
-# include AssetHelpers
-# end
-# end
View
75 lib/tasks/community_engine_tasks.rake
@@ -1,7 +1,7 @@
require 'rake/clean'
-namespace :community_engine do
-
+namespace :community_engine do
+
desc 'Assign admin role to user. Usage: rake community_engine:make_admin email=admin@foo.com'
task :make_admin => :environment do
email = ENV["email"]
@@ -14,74 +14,5 @@ namespace :community_engine do
puts "There is no user with the e-mail '#{email}'."
end
end
-
- # desc 'Test the community_engine plugin.'
- # Rake::TestTask.new(:test) do |t|
- # t.libs << 'lib'
- # t.pattern = 'vendor/plugins/community_engine/test/**/*_test.rb'
- # t.verbose = true
- # end
- # Rake::Task['community_engine:test'].comment = "Run the community_engine plugin tests."
-
- # namespace :db do
- # namespace :fixtures do
- # desc "Load community engine fixtures"
- # task :load => :environment do
- # require 'active_record/fixtures'
- # ActiveRecord::Base.establish_connection(Rails.env.to_sym)
- # Dir.glob(File.join(Rails.root, 'vendor', 'plugins', 'community_engine','test','fixtures', '*.{yml,csv}')).each do |fixture_file|
- # Fixtures.create_fixtures('vendor/plugins/community_engine/test/fixtures', File.basename(fixture_file, '.*'))
- # end
- # end
- # end
- # end
-
- # namespace :db do
- # namespace :migrate do
- #
- # desc 'For CE coming from version < 1.0.1 that stored plugin migration info in the normal Rails schema_migrations table. Move that info back into the plugin_schema_migrations table.'
- # task :upgrade_desert_plugin_migrations => :environment do
- # plugin_migration_table = Desert::PluginMigrations::Migrator.schema_migrations_table_name
- # schema_migration_table = ActiveRecord::Migrator.schema_migrations_table_name
- #
- # unless ActiveRecord::Base.connection.table_exists?(plugin_migration_table)
- # ActiveRecord::Migration.create_table(plugin_migration_table, :id => false) do |schema_migrations_table|
- # schema_migrations_table.column :version, :string, :null => false
- # schema_migrations_table.column :plugin_name, :string, :null => false
- # end
- # end
- #
- # def insert_new_version(plugin_name, version, table)
- # # Check if the row already exists for some reason - maybe run this task more than once.
- # return if ActiveRecord::Base.connection.select_rows("SELECT * FROM #{table} WHERE version = #{version} AND plugin_name = '#{plugin_name}'").size > 0
- #
- # puts "Inserting new version #{version} for plugin #{plugin_name} in #{table}."
- # ActiveRecord::Base.connection.insert("INSERT INTO #{table} (plugin_name, version) VALUES ('#{plugin_name}', #{version.to_i})")
- # end
- #
- # def remove_old_version(plugin_name, version, table)
- # puts "Removing old version #{version} for plugin #{plugin_name} in #{table}."
- # ActiveRecord::Base.connection.execute("DELETE FROM #{table} WHERE version = '#{version}-#{plugin_name}'")
- # end
- #
- # existing_migrations = ActiveRecord::Base.connection.select_rows("SELECT * FROM #{schema_migration_table}").uniq
- # migrations = {}
- # existing_migrations.flatten.each do |m|
- # plugin_version, plugin_name = m.split('-')
- # next if plugin_name.blank?
- # migrations[plugin_name] ||= []
- # migrations[plugin_name] << plugin_version
- # end
- #
- # migrations.each do |plugin_name, versions|
- # versions.each do |version|
- # insert_new_version(plugin_name, version, plugin_migration_table)
- # remove_old_version(plugin_name, version, schema_migration_table)
- # end
- # end
- #
- # end
- # end
- # end
-end
+end
View
111 test/functional/comments_controller_test.rb
@@ -2,60 +2,37 @@
class CommentsControllerTest < ActionController::TestCase
fixtures :users, :photos, :posts, :comments, :roles
-
- def test_should_create_user_comment_with_notification
- login_as :aaron
- assert_difference Comment, :count, 1 do
- assert_difference ActionMailer::Base.deliveries, :length, 1 do
- create_user_comment
- end
- end
- assert_response :redirect
- end
-
- def test_should_create_user_comment_and_notify_previous_commenters
- login_as :dwr
- # aaron should get a notification, because he's being commented on
- # quentin should get one too, because he previously commented on the profile
- assert_difference ActionMailer::Base.deliveries, :length, 2 do
- create_user_comment(:user_id => users(:aaron).id)
- end
- end
- def test_should_create_user_comment_without_notification
- users(:quentin).notify_comments = false
- users(:quentin).save!
+ def test_should_create_user_comment
login_as :aaron
assert_difference Comment, :count, 1 do
- assert_no_difference ActionMailer::Base.deliveries, :length do
create_user_comment
- end
end
assert_response :redirect
end
-
+
def test_should_fail_to_create_user_comment
login_as :aaron
assert_no_difference Comment, :count do
create_user_comment(:comment => {:comment => nil})
- end
- assert_response :redirect
+ end
+ assert_response :redirect
end
-
+
def test_should_create_photo_comment
login_as :aaron
assert_difference Comment, :count, 1 do
create_photo_comment
end
- assert_response :redirect
+ assert_response :redirect
end
-
+
def test_should_fail_to_create_photo_comment
login_as :aaron
assert_no_difference Comment, :count do
create_photo_comment(:comment => {:comment => nil})
- end
- assert_response :redirect
+ end
+ assert_response :redirect
end
def test_should_create_post_comment
@@ -63,41 +40,41 @@ def test_should_create_post_comment
assert_difference Comment, :count, 1 do
create_post_comment
end
- assert_response :redirect
+ assert_response :redirect
end
-
+
def test_should_destroy_post_comment
login_as :quentin
assert_difference Comment, :count, -1 do
delete :destroy, :commentable_type => 'Post', :commentable_id => comments(:quentins_comment_on_his_own_post).commentable_id, :id => comments(:quentins_comment_on_his_own_post)
end
end
-
+
def test_should_not_destroy_post_comment
login_as :aaron
assert_no_difference Comment, :count do
delete :destroy, :commentable_type => 'Post', :commentable_id => comments(:quentins_comment_on_his_own_post).commentable_id, :id => comments(:quentins_comment_on_his_own_post)
end
end
-
+
def test_should_fail_to_create_post_comment
login_as :aaron
assert_no_difference Comment, :count do
create_post_comment(:comment => {:comment => nil})
- end
- assert_response :redirect
+ end
+ assert_response :redirect
end
def test_should_fail_to_create_comment
login_as :aaron
- assert_raises(NameError) do
+ assert_raises(NameError) do
create_post_comment(:commentable_type => 'unkown_commentable_type')
end
end
def test_should_show_comments_index
login_as :quentin
- get :index, :commentable_type => 'users', :commentable_id => users(:aaron).to_param
+ get :index, :commentable_type => 'users', :commentable_id => users(:aaron).to_param
assert_response :success
assert !assigns(:comments).empty?
end
@@ -108,14 +85,14 @@ def test_should_show_comments_index_rss
assert_response :success
assert !assigns(:comments).empty?
end
-
+
def test_should_show_empty_comments_index
login_as :aaron
- get :index, :commentable_type => 'users', :commentable_id => users(:quentin).to_param
+ get :index, :commentable_type => 'users', :commentable_id => users(:quentin).to_param
assert_response :success
assert assigns(:comments).empty?
end
-
+
def test_should_show_empty_comments_index_rss
login_as :aaron
get :index, :commentable_type => 'users', :commentable_id => users(:quentin).to_param, :format => 'rss'
@@ -125,41 +102,41 @@ def test_should_show_empty_comments_index_rss
def test_should_show_private_comments_index_if_logged_in
login_as :quentin
- get :index, :commentable_type => 'users', :commentable_id => users(:privateuser).to_param
- assert !assigns(:comments).empty?
+ get :index, :commentable_type => 'users', :commentable_id => users(:privateuser).to_param
+ assert !assigns(:comments).empty?
assert_response :success
end
def test_should_not_show_private_comments_index
- get :index, :commentable_type => 'users', :commentable_id => users(:privateuser).to_param
+ get :index, :commentable_type => 'users', :commentable_id => users(:privateuser).to_param
assert_response :redirect
end
-
+
def test_should_show_comments_index_rss_if_logged_in
login_as :quentin
get :index, :commentable_type => 'users', :commentable_id => users(:aaron).to_param, :format => 'rss'
assert !assigns(:comments).empty?
assert_response :success
end
-
+
def test_should_unsubscribe_with_token
configatron.allow_anonymous_commenting = true
comment = Comment.create!(:comment => 'foo', :author_email => 'bar@foo.com', :author_ip => '123.123.123', :recipient => users(:quentin), :commentable => users(:quentin), :notify_by_email => true)
configatron.allow_anonymous_commenting = false
-
+
get :unsubscribe, :commentable_type => comment.commentable_type, :commentable_id => comment.commentable_id, :id => comment.id, :token => comment.token_for('bar@foo.com'), :email => 'bar@foo.com'
assert comment.reload.notify_by_email.eql?(false)
end
-
+
def test_should_not_unsubscribe_with_bad_token
configatron.allow_anonymous_commenting = true
comment = Comment.create!(:comment => 'foo', :author_email => 'bar@foo.com', :author_ip => '123.123.123', :recipient => users(:quentin), :commentable => users(:quentin), :notify_by_email => true)
configatron.allow_anonymous_commenting = false
-
- get :unsubscribe, :commentable_type => 'User', :commentable_id => users(:quentin).to_param, :id => comment.id, :token => 'badtokengoeshere'
- assert comment.reload.notify_by_email.eql?(true)
+
+ get :unsubscribe, :commentable_type => 'User', :commentable_id => users(:quentin).to_param, :id => comment.id, :token => 'badtokengoeshere'
+ assert comment.reload.notify_by_email.eql?(true)
end
-
+
def test_should_get_edit_js_as_admin
login_as :admin
get :edit, :id => comments(:quentins_comment_on_his_own_post), :format => 'js'
@@ -170,42 +147,42 @@ def test_should_update_as_admin
login_as :admin
edited_text = 'edited the comment body'
put :update, :id => comments(:quentins_comment_on_his_own_post), :comment => {:comment => edited_text}, :format => 'js'
-
+
assert assigns(:comment).comment.eql?(edited_text)
assert_response :success
end
-
+
def test_should_not_update_if_not_admin_or_moderator
login_as :quentin
-
- edited_text = 'edited the comment body'
+
+ edited_text = 'edited the comment body'
put :update, :id => comments(:quentins_comment_on_his_own_post), :comment => {:comment => edited_text}, :format => "js"
-
+
assert_response :success #js redirect
assert_not_equal(comments(:quentins_comment_on_his_own_post).comment, edited_text)
end
-
+
protected
-
+
def create_user_comment(options = {})
- post :create, {:commentable_type => (options[:commentable_type] || "users"),
- :commentable_id => (options[:user_id] || users(:quentin).id),
+ post :create, {:commentable_type => (options[:commentable_type] || "users"),
+ :commentable_id => (options[:user_id] || users(:quentin).id),
:comment => {:title => "test comment to quentin", :comment => "hey man, how are you?"}.merge(options[:comment] || {})
}
end
def create_photo_comment(options = {})
- post :create, {:commentable_type => (options[:commentable_type] || "photos"),
- :commentable_id => (options[:photo_id] || photos(:library_pic).id),
+ post :create, {:commentable_type => (options[:commentable_type] || "photos"),
+ :commentable_id => (options[:photo_id] || photos(:library_pic).id),
:comment => {:title => "test comment on a photo", :comment => "hey man, nice pic?"}.merge(options[:comment] || {})
}
end
def create_post_comment(options = {})
- post :create, {:commentable_type => (options[:commentable_type] || "posts"),
- :commentable_id => (options[:post_id] || posts(:funny_post).id),
+ post :create, {:commentable_type => (options[:commentable_type] || "posts"),
+ :commentable_id => (options[:post_id] || posts(:funny_post).id),
:comment => {:title => "test comment on a posts", :comment => "hey man, nice posts?"}.merge(options[:comment] || {})
}
end
View
1  test/test_helper.rb
@@ -12,6 +12,7 @@
require "authlogic/test_case"
require "community_engine/authenticated_test_helper"
+require "mocha/setup"
ActiveSupport::TestCase.fixture_path = (Rails.root + "../fixtures").to_s #we want a string here, not a Pathname
ActionController::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
View
7 test/testapp/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 80) do
+ActiveRecord::Schema.define(:version => 90) do
create_table "activities", :force => true do |t|
t.integer "user_id", :limit => 10
@@ -107,14 +107,15 @@
t.string "commentable_type"
t.integer "user_id"
t.integer "recipient_id"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
t.text "comment"
t.string "author_name"
t.string "author_email"
t.string "author_url"
t.string "author_ip"
t.boolean "notify_by_email", :default => true
+ t.string "role", :default => "comments"
end
add_index "comments", ["commentable_id"], :name => "index_comments_on_commentable_id"
View
113 test/unit/comment_test.rb
@@ -7,101 +7,158 @@ def test_should_find_comments_by_user
comments = Comment.find_comments_by_user(users(:quentin))
assert !comments.empty?
end
-
+
def test_comment_can_be_deleted_by
comment = comments(:aarons_comment_on_quentins_post)
assert comment.can_be_deleted_by(users(:aaron))
- assert comment.can_be_deleted_by(users(:quentin))
+ assert comment.can_be_deleted_by(users(:quentin))
assert !comment.can_be_deleted_by(users(:florian))
end
-
- def test_should_be_created_anonymously
+
+ def test_should_be_created_anonymously
configatron.allow_anonymous_commenting = true
assert_difference Comment, :count, 1 do
comment = users(:quentin).comments.create!(
- :comment => 'foo',
- :author_email => 'bar@foo.com',
- :author_ip => '123.123.123',
+ :comment => 'foo',
+ :author_email => 'bar@foo.com',
+ :author_ip => '123.123.123',
:recipient => users(:quentin)
)
end
configatron.allow_anonymous_commenting = false
end
-
+
def test_should_notify_previous_anonymous_commenter
configatron.allow_anonymous_commenting = true
users(:quentin).comments.create!(:comment => 'foo', :author_email => 'bruno@foo.com', :author_ip => '123.123.123', :recipient => users(:quentin))
- users(:quentin).comments.create!(:comment => 'bar', :author_email => 'bruno@foo.com', :author_ip => '123.123.123', :recipient => users(:quentin))
+ users(:quentin).comments.create!(:comment => 'bar', :author_email => 'bruno@foo.com', :author_ip => '123.123.123', :recipient => users(:quentin))
- comment = users(:quentin).comments.create!(:comment => 'bar', :author_email => 'alicia@foo.com', :author_ip => '123.123.123', :recipient => users(:quentin))
+ comment = users(:quentin).comments.create!(:comment => 'bar', :author_email => 'alicia@foo.com', :author_ip => '123.123.123', :recipient => users(:quentin))
assert_difference ActionMailer::Base.deliveries, :length, 1 do
comment.notify_previous_anonymous_commenters
end
configatron.allow_anonymous_commenting = false
- end
-
+ end
+
def test_should_not_notify_previous_anonymous_commenter_if_self
configatron.allow_anonymous_commenting = true
users(:quentin).comments.create!(:comment => 'foo', :author_email => 'bruno@foo.com', :author_ip => '123.123.123', :recipient => users(:quentin))
- users(:quentin).comments.create!(:comment => 'bar', :author_email => 'bruno@foo.com', :author_ip => '123.123.123', :recipient => users(:quentin))
+ users(:quentin).comments.create!(:comment => 'bar', :author_email => 'bruno@foo.com', :author_ip => '123.123.123', :recipient => users(:quentin))
- comment = users(:quentin).comments.create!(:comment => 'bar', :author_email => 'bruno@foo.com', :author_ip => '123.123.123', :recipient => users(:quentin))
+ comment = users(:quentin).comments.create!(:comment => 'bar', :author_email => 'bruno@foo.com', :author_ip => '123.123.123', :recipient => users(:quentin))
assert_difference ActionMailer::Base.deliveries, :length, 0 do
comment.notify_previous_anonymous_commenters
end
configatron.allow_anonymous_commenting = nil
- end
-
+ end
+
def test_should_not_notify_previous_anonymous_commenter_if_notify_by_email_is_false
configatron.allow_anonymous_commenting = true
users(:quentin).comments.create!(:comment => 'foo', :author_email => 'bruno@foo.com', :author_ip => '123.123.123', :recipient => users(:quentin), :notify_by_email => false)
- comment = users(:quentin).comments.create!(:comment => 'bar', :author_email => 'alicia@foo.com', :author_ip => '123.123.123', :recipient => users(:quentin))
+ comment = users(:quentin).comments.create!(:comment => 'bar', :author_email => 'alicia@foo.com', :author_ip => '123.123.123', :recipient => users(:quentin))
assert_difference ActionMailer::Base.deliveries, :length, 0 do
comment.notify_previous_anonymous_commenters
end
configatron.allow_anonymous_commenting = false
end
-
+
def test_should_not_be_created_anonymously
assert_no_difference Comment, :count do
comment = users(:quentin).comments.create(:comment => 'foo', :author_email => 'bar@foo.com', :author_ip => '123.123.123', :recipient => users(:quentin))
end
end
-
+
def test_should_be_created_without_recipient
assert_difference Comment, :count, 1 do
comment = users(:aaron).comments.create!(:comment => 'foo', :user => users(:quentin))
- end
+ end
end
def test_should_unsubscribe_notifications
configatron.allow_anonymous_commenting = true
- first_comment = users(:quentin).comments.create!(:comment => 'foo', :author_email => 'alicia@foo.com', :author_ip => '123.123.123', :recipient => users(:quentin), :notify_by_email => true)
- comment = users(:quentin).comments.create!(:comment => 'bar', :author_email => 'alicia@foo.com', :author_ip => '123.123.123', :recipient => users(:quentin), :notify_by_email => true)
+ first_comment = users(:quentin).comments.create!(:comment => 'foo', :author_email => 'alicia@foo.com', :author_ip => '123.123.123', :recipient => users(:quentin), :notify_by_email => true)
+ comment = users(:quentin).comments.create!(:comment => 'bar', :author_email => 'alicia@foo.com', :author_ip => '123.123.123', :recipient => users(:quentin), :notify_by_email => true)
assert_equal first_comment.notify_by_email, true
assert_equal comment.notify_by_email, true
- configatron.allow_anonymous_commenting = false
-
+ configatron.allow_anonymous_commenting = false
+
comment.unsubscribe_notifications('alicia@foo.com')
assert comment.reload.notify_by_email.eql?(false)
assert first_comment.reload.notify_by_email.eql?(false)
end
-
+
def test_should_not_notify_of_comments_on_post_with_send_notifications_off
post = posts(:funny_post)
post.send_comment_notifications = false
post.save!
comment = post.comments.create!(:comment => 'foo', :user => users(:aaron), :recipient => users(:quentin))
- assert_difference ActionMailer::Base.deliveries, :length, 0 do
- comment.send_notifications
+ assert_difference ActionMailer::Base.deliveries, :length, 0 do
+ comment.send_notifications
+ end
+ end
+
+ def test_new_comment_should_have_published_role
+ post = posts(:funny_post)
+ comment = post.comments.create!(:comment => 'foo', :user => users(:aaron), :recipient => users(:quentin))
+
+ assert_equal 'published', comment.role
+ end
+
+ def test_spam_comment_should_have_pending_role
+ post = posts(:funny_post)
+
+ Comment.any_instance.stubs(:spam?).returns(true)
+ configatron.stubs(:akismet_key).returns('1234')
+
+ comment = post.comments.create!(:comment => 'foo', :user => users(:aaron), :recipient => users(:quentin))
+
+ assert_equal 'pending', comment.role
+ end
+
+ def test_spam_comment_notification_handling
+ post = posts(:funny_post)
+
+ Comment.any_instance.stubs(:spam?).returns(true)
+ configatron.stubs(:akismet_key).returns('1234')
+
+ comment = post.comments.new(:comment => 'foo', :user => users(:aaron), :recipient => users(:quentin))
+ #no notifications for pending comments
+ assert_no_difference ActionMailer::Base.deliveries, :length do
+ comment.save!
+ end
+
+ Comment.any_instance.stubs(:spam?).returns(false)
+ comment.role = 'published'
+ assert_difference ActionMailer::Base.deliveries, :length, 1 do
+ comment.save!
+ end
+
+
+ end
+
+ def test_should_create_user_comment_with_notification
+ user = users(:aaron)
+ assert_difference ActionMailer::Base.deliveries, :length, 2 do
+ user.comments.create!(:comment => 'foo', :user => users(:dwr), :recipient => users(:aaron))
end
end
+ def test_should_create_user_comment_without_notification
+ user = users(:aaron)
+ user.notify_comments = false
+ user.save!
+
+ assert_no_difference ActionMailer::Base.deliveries, :length do
+ user.comments.create!(:comment => 'foo', :user => users(:quentin), :recipient => users(:aaron))
+ end
+ end
+
+
end
-
+

0 comments on commit 4e52d8e

Please sign in to comment.
Something went wrong with that request. Please try again.