diff --git a/app/models/article.rb b/app/models/article.rb index 551470b..1c6c0fb 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -2,10 +2,10 @@ require 'hpricot' class Article < ActiveRecord::Base - track_actions :create_article, :after_create, :keep_params => [:name, :url], :if => Proc.new { |a| a.published? && !a.profile.is_a?(Community) && !a.image? } - track_actions :update_article, :before_update, :keep_params => [:name, :url], :if => Proc.new { |a| a.published? && (a.body_changed? || a.name_changed?) } - track_actions :remove_article, :before_destroy, :keep_params => [:name], :if => :published? - track_actions :publish_article_in_community, :after_create, :keep_params => ["name", "url", "profile.url", "profile.name"], :if => Proc.new { |a| a.published? && a.profile.is_a?(Community) && !a.image? } + track_actions :create_article, :after_create, :keep_params => [:name, :url], :if => Proc.new { |a| a.published? && !a.profile.is_a?(Community) && !a.image? && a.notifiable? } + track_actions :update_article, :before_update, :keep_params => [:name, :url], :if => Proc.new { |a| a.published? && (a.body_changed? || a.name_changed?) && a.notifiable? } + track_actions :remove_article, :before_destroy, :keep_params => [:name], :if => Proc.new { |a| a.published? && a.notifiable? } + track_actions :publish_article_in_community, :after_create, :keep_params => ["name", "url", "profile.url", "profile.name"], :if => Proc.new { |a| a.published? && a.profile.is_a?(Community) && !a.image? && a.notifiable? } # xss_terminate plugin can't sanitize array fields before_save :sanitize_tag_list @@ -360,6 +360,10 @@ class Article < ActiveRecord::Base creator_id && Profile.find(creator_id) end + def notifiable? + false + end + private def sanitize_tag_list diff --git a/app/models/textile_article.rb b/app/models/textile_article.rb index 895a540..8bf2c4d 100644 --- a/app/models/textile_article.rb +++ b/app/models/textile_article.rb @@ -12,4 +12,8 @@ class TextileArticle < TextArticle RedCloth.new(self.body|| '').to_html end + def notifiable? + true + end + end diff --git a/app/models/tiny_mce_article.rb b/app/models/tiny_mce_article.rb index bd13290..3788945 100644 --- a/app/models/tiny_mce_article.rb +++ b/app/models/tiny_mce_article.rb @@ -15,4 +15,8 @@ class TinyMceArticle < TextArticle include WhiteListFilter filter_iframes :abstract, :body, :whitelist => lambda { profile && profile.environment && profile.environment.trusted_sites_for_iframe } + def notifiable? + true + end + end diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 0f9822d..aababad 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -919,7 +919,7 @@ class ArticleTest < Test::Unit::TestCase end should 'track action when a published article is created outside a community' do - article = Article.create! :name => 'Tracked Article', :profile_id => profile.id + article = TinyMceArticle.create! :name => 'Tracked Article', :profile_id => profile.id assert article.published? assert_kind_of Person, article.profile ta = ActionTracker::Record.last @@ -927,7 +927,7 @@ class ArticleTest < Test::Unit::TestCase assert_equal article.url, ta.get_url.last assert_kind_of Person, ta.user ta.back_in_time(26.hours) - article = Article.create! :name => 'Another Tracked Article', :profile_id => profile.id + article = TinyMceArticle.create! :name => 'Another Tracked Article', :profile_id => profile.id ta = ActionTracker::Record.last assert_equal ['Another Tracked Article'], ta.get_name assert_equal [article.url], ta.get_url @@ -945,7 +945,7 @@ class ArticleTest < Test::Unit::TestCase assert !p3.is_member_of?(community) Article.destroy_all ActionTracker::Record.destroy_all - article = Article.create! :name => 'Tracked Article', :profile_id => community.id + article = TinyMceArticle.create! :name => 'Tracked Article', :profile_id => community.id assert article.published? assert_kind_of Community, article.profile ta = ActionTracker::Record.last @@ -960,7 +960,7 @@ class ArticleTest < Test::Unit::TestCase end should 'track action when a published article is updated' do - a = Article.create! :name => 'a', :profile_id => profile.id + a = TinyMceArticle.create! :name => 'a', :profile_id => profile.id a.update_attributes! :name => 'b' ta = ActionTracker::Record.last assert_equal ['b'], ta.get_name @@ -980,18 +980,44 @@ class ArticleTest < Test::Unit::TestCase end should 'track action when a published article is removed' do - a = Article.create! :name => 'a', :profile_id => profile.id + a = TinyMceArticle.create! :name => 'a', :profile_id => profile.id a.destroy ta = ActionTracker::Record.last assert_equal ['a'], ta.get_name - a = Article.create! :name => 'b', :profile_id => profile.id + a = TinyMceArticle.create! :name => 'b', :profile_id => profile.id a.destroy ta = ActionTracker::Record.last assert_equal ['a','b'], ta.get_name - a = Article.create! :name => 'c', :profile_id => profile.id, :published => false + a = TinyMceArticle.create! :name => 'c', :profile_id => profile.id, :published => false a.destroy ta = ActionTracker::Record.last assert_equal ['a','b'], ta.get_name end + should 'notifiable is false by default' do + a = fast_create(Article) + assert !a.notifiable? + end + + should 'not notify activity by default on create' do + ActionTracker::Record.delete_all + Article.create! :name => 'test', :profile_id => fast_create(Profile).id, :published => true + assert_equal 0, ActionTracker::Record.count + end + + should 'not notify activity by default on update' do + ActionTracker::Record.delete_all + a = Article.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true + a.name = 'foo' + a.save! + assert_equal 0, ActionTracker::Record.count + end + + should 'not notify activity by default on destroy' do + ActionTracker::Record.delete_all + a = Article.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true + a.destroy + assert_equal 0, ActionTracker::Record.count + end + end diff --git a/test/unit/textile_article_test.rb b/test/unit/textile_article_test.rb index e2a90b7..61ecf03 100644 --- a/test/unit/textile_article_test.rb +++ b/test/unit/textile_article_test.rb @@ -27,4 +27,32 @@ class TextileArticleTest < Test::Unit::TestCase end end + should 'notifiable be true' do + a = fast_create(TextileArticle) + assert a.notifiable? + end + + should 'notify activity on create' do + ActionTracker::Record.delete_all + TextileArticle.create! :name => 'test', :profile_id => fast_create(Profile).id, :published => true + assert_equal 1, ActionTracker::Record.count + end + + should 'notify activity on update' do + ActionTracker::Record.delete_all + a = TextileArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true + assert_equal 1, ActionTracker::Record.count + a.name = 'foo' + a.save! + assert_equal 2, ActionTracker::Record.count + end + + should 'notify activity on destroy' do + ActionTracker::Record.delete_all + a = TextileArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true + assert_equal 1, ActionTracker::Record.count + a.destroy + assert_equal 2, ActionTracker::Record.count + end + end diff --git a/test/unit/tiny_mce_article_test.rb b/test/unit/tiny_mce_article_test.rb index 6f9909d..859450b 100644 --- a/test/unit/tiny_mce_article_test.rb +++ b/test/unit/tiny_mce_article_test.rb @@ -118,4 +118,32 @@ class TinyMceArticleTest < Test::Unit::TestCase assert_no_match /script/, article.name end + should 'notifiable be true' do + a = fast_create(TinyMceArticle) + assert a.notifiable? + end + + should 'notify activity on create' do + ActionTracker::Record.delete_all + TinyMceArticle.create! :name => 'test', :profile_id => fast_create(Profile).id, :published => true + assert_equal 1, ActionTracker::Record.count + end + + should 'notify activity on update' do + ActionTracker::Record.delete_all + a = TinyMceArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true + assert_equal 1, ActionTracker::Record.count + a.name = 'foo' + a.save! + assert_equal 2, ActionTracker::Record.count + end + + should 'notify activity on destroy' do + ActionTracker::Record.delete_all + a = TinyMceArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true + assert_equal 1, ActionTracker::Record.count + a.destroy + assert_equal 2, ActionTracker::Record.count + end + end -- libgit2 0.21.2