Commit 2cc91ce2b208de26dd8f367933d1110605c9281b

Authored by Rodrigo Souto
1 parent 2fe1ebd0

rails3: fix textile_article tests

test/unit/textile_article_test.rb
@@ -4,6 +4,7 @@ class TextileArticleTest < ActiveSupport::TestCase @@ -4,6 +4,7 @@ class TextileArticleTest < ActiveSupport::TestCase
4 4
5 def setup 5 def setup
6 @profile = create_user('testing').person 6 @profile = create_user('testing').person
  7 + ActionTracker::Record.stubs(:current_user_from_model).returns(fast_create(Person))
7 end 8 end
8 attr_reader :profile 9 attr_reader :profile
9 10
@@ -16,7 +17,7 @@ class TextileArticleTest < ActiveSupport::TestCase @@ -16,7 +17,7 @@ class TextileArticleTest < ActiveSupport::TestCase
16 end 17 end
17 18
18 should 'convert Textile to HTML' do 19 should 'convert Textile to HTML' do
19 - assert_equal '<p><strong>my text</strong></p>', TextileArticle.new(:body => '*my text*').to_html 20 + assert_equal '<p><strong>my text</strong></p>', build(TextileArticle, :body => '*my text*').to_html
20 end 21 end
21 22
22 should 'accept empty body' do 23 should 'accept empty body' do
@@ -34,17 +35,17 @@ class TextileArticleTest &lt; ActiveSupport::TestCase @@ -34,17 +35,17 @@ class TextileArticleTest &lt; ActiveSupport::TestCase
34 35
35 should 'notify activity on create' do 36 should 'notify activity on create' do
36 ActionTracker::Record.delete_all 37 ActionTracker::Record.delete_all
37 - TextileArticle.create! :name => 'test', :profile_id => fast_create(Profile).id, :published => true 38 + create TextileArticle, :name => 'test', :profile_id => fast_create(Profile).id, :published => true
38 assert_equal 1, ActionTracker::Record.count 39 assert_equal 1, ActionTracker::Record.count
39 end 40 end
40 41
41 should 'not group trackers activity of article\'s creation' do 42 should 'not group trackers activity of article\'s creation' do
42 - ActionTracker::Record.delete_all  
43 profile = fast_create(Profile) 43 profile = fast_create(Profile)
44 - TextileArticle.create! :name => 'bar', :profile_id => profile.id, :published => true  
45 - TextileArticle.create! :name => 'another bar', :profile_id => profile.id, :published => true  
46 - TextileArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true  
47 - assert_equal 3, ActionTracker::Record.count 44 + assert_difference ActionTracker::Record, :count, 3 do
  45 + create TextileArticle, :name => 'bar', :profile_id => profile.id, :published => true
  46 + create TextileArticle, :name => 'another bar', :profile_id => profile.id, :published => true
  47 + create TextileArticle, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true
  48 + end
48 end 49 end
49 50
50 should 'not update activity on update of an article' do 51 should 'not update activity on update of an article' do
@@ -62,8 +63,8 @@ class TextileArticleTest &lt; ActiveSupport::TestCase @@ -62,8 +63,8 @@ class TextileArticleTest &lt; ActiveSupport::TestCase
62 63
63 should 'not create trackers activity when updating articles' do 64 should 'not create trackers activity when updating articles' do
64 ActionTracker::Record.delete_all 65 ActionTracker::Record.delete_all
65 - a1 = TextileArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true  
66 - a2 = TextileArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true 66 + a1 = create TextileArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true
  67 + a2 = create TextileArticle, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true
67 assert_no_difference ActionTracker::Record, :count do 68 assert_no_difference ActionTracker::Record, :count do
68 a1.name = 'foo';a1.save! 69 a1.name = 'foo';a1.save!
69 a2.name = 'another foo';a2.save! 70 a2.name = 'another foo';a2.save!
@@ -72,7 +73,7 @@ class TextileArticleTest &lt; ActiveSupport::TestCase @@ -72,7 +73,7 @@ class TextileArticleTest &lt; ActiveSupport::TestCase
72 73
73 should 'remove activity after destroying article' do 74 should 'remove activity after destroying article' do
74 ActionTracker::Record.delete_all 75 ActionTracker::Record.delete_all
75 - a = TextileArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true 76 + a = create TextileArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true
76 assert_difference ActionTracker::Record, :count, -1 do 77 assert_difference ActionTracker::Record, :count, -1 do
77 a.destroy 78 a.destroy
78 end 79 end
@@ -80,8 +81,8 @@ class TextileArticleTest &lt; ActiveSupport::TestCase @@ -80,8 +81,8 @@ class TextileArticleTest &lt; ActiveSupport::TestCase
80 81
81 should 'remove activity after article is destroyed' do 82 should 'remove activity after article is destroyed' do
82 ActionTracker::Record.delete_all 83 ActionTracker::Record.delete_all
83 - a1 = TextileArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true  
84 - a2 = TextileArticle.create! :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true 84 + a1 = create TextileArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true
  85 + a2 = create TextileArticle, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true
85 assert_equal 2, ActionTracker::Record.count 86 assert_equal 2, ActionTracker::Record.count
86 assert_difference ActionTracker::Record, :count, -2 do 87 assert_difference ActionTracker::Record, :count, -2 do
87 a1.destroy 88 a1.destroy
@@ -95,20 +96,20 @@ class TextileArticleTest &lt; ActiveSupport::TestCase @@ -95,20 +96,20 @@ class TextileArticleTest &lt; ActiveSupport::TestCase
95 p1 = Person.first 96 p1 = Person.first
96 community.add_member(p1) 97 community.add_member(p1)
97 assert p1.is_member_of?(community) 98 assert p1.is_member_of?(community)
98 - article = TextileArticle.create! :name => 'test', :profile_id => community.id 99 + article = create TextileArticle, :name => 'test', :profile_id => community.id
99 assert_equal article, ActionTracker::Record.last.target 100 assert_equal article, ActionTracker::Record.last.target
100 end 101 end
101 102
102 should "the tracker action target be defined as the article on articles'creation in profile" do 103 should "the tracker action target be defined as the article on articles'creation in profile" do
103 ActionTracker::Record.delete_all 104 ActionTracker::Record.delete_all
104 person = Person.first 105 person = Person.first
105 - article = TextileArticle.create! :name => 'test', :profile_id => person.id 106 + article = create TextileArticle, :name => 'test', :profile_id => person.id
106 assert_equal article, ActionTracker::Record.last.target 107 assert_equal article, ActionTracker::Record.last.target
107 end 108 end
108 109
109 should 'not notify activity if the article is not advertise' do 110 should 'not notify activity if the article is not advertise' do
110 ActionTracker::Record.delete_all 111 ActionTracker::Record.delete_all
111 - a = TextileArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true, :advertise => false 112 + a = create TextileArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true, :advertise => false
112 assert_equal true, a.published? 113 assert_equal true, a.published?
113 assert_equal true, a.notifiable? 114 assert_equal true, a.notifiable?
114 assert_equal false, a.image? 115 assert_equal false, a.image?
@@ -121,7 +122,7 @@ class TextileArticleTest &lt; ActiveSupport::TestCase @@ -121,7 +122,7 @@ class TextileArticleTest &lt; ActiveSupport::TestCase
121 end 122 end
122 123
123 should "the common trackable conditions return the correct value" do 124 should "the common trackable conditions return the correct value" do
124 - a = TextileArticle.new(:profile => profile) 125 + a = build(TextileArticle, :profile => profile)
125 a.published = a.advertise = true 126 a.published = a.advertise = true
126 assert_equal true, a.published? 127 assert_equal true, a.published?
127 assert_equal true, a.notifiable? 128 assert_equal true, a.notifiable?
@@ -177,7 +178,7 @@ class TextileArticleTest &lt; ActiveSupport::TestCase @@ -177,7 +178,7 @@ class TextileArticleTest &lt; ActiveSupport::TestCase
177 protected 178 protected
178 179
179 def build_article(input = nil, options = {}) 180 def build_article(input = nil, options = {})
180 - article = TextileArticle.new({:body => input}.merge(options)) 181 + article = build(TextileArticle, {:body => input}.merge(options))
181 article.valid? # trigger the xss terminate thingy 182 article.valid? # trigger the xss terminate thingy
182 article 183 article
183 end 184 end
vendor/plugins/action_tracker_has_comments/init.rb
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 2
3 ActionTracker::Record.module_eval do 3 ActionTracker::Record.module_eval do
4 4
5 - has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :finder_sql => 'SELECT * FROM comments WHERE #{conditions_for_comments} ORDER BY created_at ASC', :counter_sql => 'SELECT * FROM comments WHERE #{conditions_for_comments}' 5 + has_many :comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :finder_sql => Proc.new { %Q{SELECT * FROM comments WHERE #{conditions_for_comments} ORDER BY created_at ASC}}, :counter_sql => Proc.new { %Q{SELECT * FROM comments WHERE #{conditions_for_comments}} }
6 6
7 def conditions_for_comments 7 def conditions_for_comments
8 type, id = (self.target_type == 'Article' ? ['Article', self.target_id] : [self.class.to_s, self.id]) 8 type, id = (self.target_type == 'Article' ? ['Article', self.target_id] : [self.class.to_s, self.id])