Commit 2cc91ce2b208de26dd8f367933d1110605c9281b
1 parent
2fe1ebd0
Exists in
master
and in
29 other branches
rails3: fix textile_article tests
Showing
2 changed files
with
19 additions
and
18 deletions
Show diff stats
test/unit/textile_article_test.rb
... | ... | @@ -4,6 +4,7 @@ class TextileArticleTest < ActiveSupport::TestCase |
4 | 4 | |
5 | 5 | def setup |
6 | 6 | @profile = create_user('testing').person |
7 | + ActionTracker::Record.stubs(:current_user_from_model).returns(fast_create(Person)) | |
7 | 8 | end |
8 | 9 | attr_reader :profile |
9 | 10 | |
... | ... | @@ -16,7 +17,7 @@ class TextileArticleTest < ActiveSupport::TestCase |
16 | 17 | end |
17 | 18 | |
18 | 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 | 21 | end |
21 | 22 | |
22 | 23 | should 'accept empty body' do |
... | ... | @@ -34,17 +35,17 @@ class TextileArticleTest < ActiveSupport::TestCase |
34 | 35 | |
35 | 36 | should 'notify activity on create' do |
36 | 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 | 39 | assert_equal 1, ActionTracker::Record.count |
39 | 40 | end |
40 | 41 | |
41 | 42 | should 'not group trackers activity of article\'s creation' do |
42 | - ActionTracker::Record.delete_all | |
43 | 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 | 49 | end |
49 | 50 | |
50 | 51 | should 'not update activity on update of an article' do |
... | ... | @@ -62,8 +63,8 @@ class TextileArticleTest < ActiveSupport::TestCase |
62 | 63 | |
63 | 64 | should 'not create trackers activity when updating articles' do |
64 | 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 | 68 | assert_no_difference ActionTracker::Record, :count do |
68 | 69 | a1.name = 'foo';a1.save! |
69 | 70 | a2.name = 'another foo';a2.save! |
... | ... | @@ -72,7 +73,7 @@ class TextileArticleTest < ActiveSupport::TestCase |
72 | 73 | |
73 | 74 | should 'remove activity after destroying article' do |
74 | 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 | 77 | assert_difference ActionTracker::Record, :count, -1 do |
77 | 78 | a.destroy |
78 | 79 | end |
... | ... | @@ -80,8 +81,8 @@ class TextileArticleTest < ActiveSupport::TestCase |
80 | 81 | |
81 | 82 | should 'remove activity after article is destroyed' do |
82 | 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 | 86 | assert_equal 2, ActionTracker::Record.count |
86 | 87 | assert_difference ActionTracker::Record, :count, -2 do |
87 | 88 | a1.destroy |
... | ... | @@ -95,20 +96,20 @@ class TextileArticleTest < ActiveSupport::TestCase |
95 | 96 | p1 = Person.first |
96 | 97 | community.add_member(p1) |
97 | 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 | 100 | assert_equal article, ActionTracker::Record.last.target |
100 | 101 | end |
101 | 102 | |
102 | 103 | should "the tracker action target be defined as the article on articles'creation in profile" do |
103 | 104 | ActionTracker::Record.delete_all |
104 | 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 | 107 | assert_equal article, ActionTracker::Record.last.target |
107 | 108 | end |
108 | 109 | |
109 | 110 | should 'not notify activity if the article is not advertise' do |
110 | 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 | 113 | assert_equal true, a.published? |
113 | 114 | assert_equal true, a.notifiable? |
114 | 115 | assert_equal false, a.image? |
... | ... | @@ -121,7 +122,7 @@ class TextileArticleTest < ActiveSupport::TestCase |
121 | 122 | end |
122 | 123 | |
123 | 124 | should "the common trackable conditions return the correct value" do |
124 | - a = TextileArticle.new(:profile => profile) | |
125 | + a = build(TextileArticle, :profile => profile) | |
125 | 126 | a.published = a.advertise = true |
126 | 127 | assert_equal true, a.published? |
127 | 128 | assert_equal true, a.notifiable? |
... | ... | @@ -177,7 +178,7 @@ class TextileArticleTest < ActiveSupport::TestCase |
177 | 178 | protected |
178 | 179 | |
179 | 180 | def build_article(input = nil, options = {}) |
180 | - article = TextileArticle.new({:body => input}.merge(options)) | |
181 | + article = build(TextileArticle, {:body => input}.merge(options)) | |
181 | 182 | article.valid? # trigger the xss terminate thingy |
182 | 183 | article |
183 | 184 | end | ... | ... |
vendor/plugins/action_tracker_has_comments/init.rb
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 | |
3 | 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 | 7 | def conditions_for_comments |
8 | 8 | type, id = (self.target_type == 'Article' ? ['Article', self.target_id] : [self.class.to_s, self.id]) | ... | ... |