Commit 128b006ceda39383d1fa92b6c333eadb0363d27e
Committed by
Antonio Terceiro
1 parent
556bf994
Exists in
master
and in
29 other branches
Article's actions are not tracked by default. By now, textile and tinymce's actions are tracked
Showing
6 changed files
with
105 additions
and
11 deletions
Show diff stats
app/models/article.rb
| ... | ... | @@ -2,10 +2,10 @@ require 'hpricot' |
| 2 | 2 | |
| 3 | 3 | class Article < ActiveRecord::Base |
| 4 | 4 | |
| 5 | - track_actions :create_article, :after_create, :keep_params => [:name, :url], :if => Proc.new { |a| a.published? && !a.profile.is_a?(Community) && !a.image? } | |
| 6 | - track_actions :update_article, :before_update, :keep_params => [:name, :url], :if => Proc.new { |a| a.published? && (a.body_changed? || a.name_changed?) } | |
| 7 | - track_actions :remove_article, :before_destroy, :keep_params => [:name], :if => :published? | |
| 8 | - 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? } | |
| 5 | + 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? } | |
| 6 | + track_actions :update_article, :before_update, :keep_params => [:name, :url], :if => Proc.new { |a| a.published? && (a.body_changed? || a.name_changed?) && a.notifiable? } | |
| 7 | + track_actions :remove_article, :before_destroy, :keep_params => [:name], :if => Proc.new { |a| a.published? && a.notifiable? } | |
| 8 | + 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? } | |
| 9 | 9 | |
| 10 | 10 | # xss_terminate plugin can't sanitize array fields |
| 11 | 11 | before_save :sanitize_tag_list |
| ... | ... | @@ -360,6 +360,10 @@ class Article < ActiveRecord::Base |
| 360 | 360 | creator_id && Profile.find(creator_id) |
| 361 | 361 | end |
| 362 | 362 | |
| 363 | + def notifiable? | |
| 364 | + false | |
| 365 | + end | |
| 366 | + | |
| 363 | 367 | private |
| 364 | 368 | |
| 365 | 369 | def sanitize_tag_list | ... | ... |
app/models/textile_article.rb
app/models/tiny_mce_article.rb
| ... | ... | @@ -15,4 +15,8 @@ class TinyMceArticle < TextArticle |
| 15 | 15 | include WhiteListFilter |
| 16 | 16 | filter_iframes :abstract, :body, :whitelist => lambda { profile && profile.environment && profile.environment.trusted_sites_for_iframe } |
| 17 | 17 | |
| 18 | + def notifiable? | |
| 19 | + true | |
| 20 | + end | |
| 21 | + | |
| 18 | 22 | end | ... | ... |
test/unit/article_test.rb
| ... | ... | @@ -919,7 +919,7 @@ class ArticleTest < Test::Unit::TestCase |
| 919 | 919 | end |
| 920 | 920 | |
| 921 | 921 | should 'track action when a published article is created outside a community' do |
| 922 | - article = Article.create! :name => 'Tracked Article', :profile_id => profile.id | |
| 922 | + article = TinyMceArticle.create! :name => 'Tracked Article', :profile_id => profile.id | |
| 923 | 923 | assert article.published? |
| 924 | 924 | assert_kind_of Person, article.profile |
| 925 | 925 | ta = ActionTracker::Record.last |
| ... | ... | @@ -927,7 +927,7 @@ class ArticleTest < Test::Unit::TestCase |
| 927 | 927 | assert_equal article.url, ta.get_url.last |
| 928 | 928 | assert_kind_of Person, ta.user |
| 929 | 929 | ta.back_in_time(26.hours) |
| 930 | - article = Article.create! :name => 'Another Tracked Article', :profile_id => profile.id | |
| 930 | + article = TinyMceArticle.create! :name => 'Another Tracked Article', :profile_id => profile.id | |
| 931 | 931 | ta = ActionTracker::Record.last |
| 932 | 932 | assert_equal ['Another Tracked Article'], ta.get_name |
| 933 | 933 | assert_equal [article.url], ta.get_url |
| ... | ... | @@ -945,7 +945,7 @@ class ArticleTest < Test::Unit::TestCase |
| 945 | 945 | assert !p3.is_member_of?(community) |
| 946 | 946 | Article.destroy_all |
| 947 | 947 | ActionTracker::Record.destroy_all |
| 948 | - article = Article.create! :name => 'Tracked Article', :profile_id => community.id | |
| 948 | + article = TinyMceArticle.create! :name => 'Tracked Article', :profile_id => community.id | |
| 949 | 949 | assert article.published? |
| 950 | 950 | assert_kind_of Community, article.profile |
| 951 | 951 | ta = ActionTracker::Record.last |
| ... | ... | @@ -960,7 +960,7 @@ class ArticleTest < Test::Unit::TestCase |
| 960 | 960 | end |
| 961 | 961 | |
| 962 | 962 | should 'track action when a published article is updated' do |
| 963 | - a = Article.create! :name => 'a', :profile_id => profile.id | |
| 963 | + a = TinyMceArticle.create! :name => 'a', :profile_id => profile.id | |
| 964 | 964 | a.update_attributes! :name => 'b' |
| 965 | 965 | ta = ActionTracker::Record.last |
| 966 | 966 | assert_equal ['b'], ta.get_name |
| ... | ... | @@ -980,18 +980,44 @@ class ArticleTest < Test::Unit::TestCase |
| 980 | 980 | end |
| 981 | 981 | |
| 982 | 982 | should 'track action when a published article is removed' do |
| 983 | - a = Article.create! :name => 'a', :profile_id => profile.id | |
| 983 | + a = TinyMceArticle.create! :name => 'a', :profile_id => profile.id | |
| 984 | 984 | a.destroy |
| 985 | 985 | ta = ActionTracker::Record.last |
| 986 | 986 | assert_equal ['a'], ta.get_name |
| 987 | - a = Article.create! :name => 'b', :profile_id => profile.id | |
| 987 | + a = TinyMceArticle.create! :name => 'b', :profile_id => profile.id | |
| 988 | 988 | a.destroy |
| 989 | 989 | ta = ActionTracker::Record.last |
| 990 | 990 | assert_equal ['a','b'], ta.get_name |
| 991 | - a = Article.create! :name => 'c', :profile_id => profile.id, :published => false | |
| 991 | + a = TinyMceArticle.create! :name => 'c', :profile_id => profile.id, :published => false | |
| 992 | 992 | a.destroy |
| 993 | 993 | ta = ActionTracker::Record.last |
| 994 | 994 | assert_equal ['a','b'], ta.get_name |
| 995 | 995 | end |
| 996 | 996 | |
| 997 | + should 'notifiable is false by default' do | |
| 998 | + a = fast_create(Article) | |
| 999 | + assert !a.notifiable? | |
| 1000 | + end | |
| 1001 | + | |
| 1002 | + should 'not notify activity by default on create' do | |
| 1003 | + ActionTracker::Record.delete_all | |
| 1004 | + Article.create! :name => 'test', :profile_id => fast_create(Profile).id, :published => true | |
| 1005 | + assert_equal 0, ActionTracker::Record.count | |
| 1006 | + end | |
| 1007 | + | |
| 1008 | + should 'not notify activity by default on update' do | |
| 1009 | + ActionTracker::Record.delete_all | |
| 1010 | + a = Article.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | |
| 1011 | + a.name = 'foo' | |
| 1012 | + a.save! | |
| 1013 | + assert_equal 0, ActionTracker::Record.count | |
| 1014 | + end | |
| 1015 | + | |
| 1016 | + should 'not notify activity by default on destroy' do | |
| 1017 | + ActionTracker::Record.delete_all | |
| 1018 | + a = Article.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | |
| 1019 | + a.destroy | |
| 1020 | + assert_equal 0, ActionTracker::Record.count | |
| 1021 | + end | |
| 1022 | + | |
| 997 | 1023 | end | ... | ... |
test/unit/textile_article_test.rb
| ... | ... | @@ -27,4 +27,32 @@ class TextileArticleTest < Test::Unit::TestCase |
| 27 | 27 | end |
| 28 | 28 | end |
| 29 | 29 | |
| 30 | + should 'notifiable be true' do | |
| 31 | + a = fast_create(TextileArticle) | |
| 32 | + assert a.notifiable? | |
| 33 | + end | |
| 34 | + | |
| 35 | + should 'notify activity on create' do | |
| 36 | + ActionTracker::Record.delete_all | |
| 37 | + TextileArticle.create! :name => 'test', :profile_id => fast_create(Profile).id, :published => true | |
| 38 | + assert_equal 1, ActionTracker::Record.count | |
| 39 | + end | |
| 40 | + | |
| 41 | + should 'notify activity on update' do | |
| 42 | + ActionTracker::Record.delete_all | |
| 43 | + a = TextileArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | |
| 44 | + assert_equal 1, ActionTracker::Record.count | |
| 45 | + a.name = 'foo' | |
| 46 | + a.save! | |
| 47 | + assert_equal 2, ActionTracker::Record.count | |
| 48 | + end | |
| 49 | + | |
| 50 | + should 'notify activity on destroy' do | |
| 51 | + ActionTracker::Record.delete_all | |
| 52 | + a = TextileArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | |
| 53 | + assert_equal 1, ActionTracker::Record.count | |
| 54 | + a.destroy | |
| 55 | + assert_equal 2, ActionTracker::Record.count | |
| 56 | + end | |
| 57 | + | |
| 30 | 58 | end | ... | ... |
test/unit/tiny_mce_article_test.rb
| ... | ... | @@ -118,4 +118,32 @@ class TinyMceArticleTest < Test::Unit::TestCase |
| 118 | 118 | assert_no_match /script/, article.name |
| 119 | 119 | end |
| 120 | 120 | |
| 121 | + should 'notifiable be true' do | |
| 122 | + a = fast_create(TinyMceArticle) | |
| 123 | + assert a.notifiable? | |
| 124 | + end | |
| 125 | + | |
| 126 | + should 'notify activity on create' do | |
| 127 | + ActionTracker::Record.delete_all | |
| 128 | + TinyMceArticle.create! :name => 'test', :profile_id => fast_create(Profile).id, :published => true | |
| 129 | + assert_equal 1, ActionTracker::Record.count | |
| 130 | + end | |
| 131 | + | |
| 132 | + should 'notify activity on update' do | |
| 133 | + ActionTracker::Record.delete_all | |
| 134 | + a = TinyMceArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | |
| 135 | + assert_equal 1, ActionTracker::Record.count | |
| 136 | + a.name = 'foo' | |
| 137 | + a.save! | |
| 138 | + assert_equal 2, ActionTracker::Record.count | |
| 139 | + end | |
| 140 | + | |
| 141 | + should 'notify activity on destroy' do | |
| 142 | + ActionTracker::Record.delete_all | |
| 143 | + a = TinyMceArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | |
| 144 | + assert_equal 1, ActionTracker::Record.count | |
| 145 | + a.destroy | |
| 146 | + assert_equal 2, ActionTracker::Record.count | |
| 147 | + end | |
| 148 | + | |
| 121 | 149 | end | ... | ... |