Commit 7809944b8a8e62fcd98fa0f3cfe84dce786b9010

Authored by Braulio Bhavamitra
1 parent 940ab514

activity: Set current user to fix random failures

test/unit/community_test.rb
... ... @@ -3,7 +3,8 @@ require_relative "../test_helper"
3 3 class CommunityTest < ActiveSupport::TestCase
4 4  
5 5 def setup
6   - @person = fast_create(Person)
  6 + @user = User.current = create_user
  7 + @person = @user.person
7 8 end
8 9  
9 10 attr_reader :person
... ... @@ -287,8 +288,8 @@ class CommunityTest &lt; ActiveSupport::TestCase
287 288  
288 289 should "update the action of article creation when an community's article is commented" do
289 290 ActionTrackerNotification.delete_all
290   - p1 = Person.first
291 291 community = fast_create(Community)
  292 + p1 = person
292 293 p2 = create_user.person
293 294 p3 = create_user.person
294 295 community.add_member(p3)
... ...
test/unit/textile_article_test.rb
... ... @@ -3,7 +3,8 @@ require_relative &quot;../test_helper&quot;
3 3 class TextileArticleTest < ActiveSupport::TestCase
4 4  
5 5 def setup
6   - @profile = create_user('testing').person
  6 + @user = User.current = create_user 'testing'
  7 + @profile = @user.person
7 8 end
8 9 attr_reader :profile
9 10  
... ... @@ -16,7 +17,7 @@ class TextileArticleTest &lt; ActiveSupport::TestCase
16 17 end
17 18  
18 19 should 'convert Textile to HTML' do
19   - assert_equal '<p><strong>my text</strong></p>', build(TextileArticle, :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,23 +35,21 @@ class TextileArticleTest &lt; ActiveSupport::TestCase
34 35  
35 36 should 'notify activity on create' do
36 37 ActionTracker::Record.delete_all
37   - create TextileArticle, :name => 'test', :profile_id => fast_create(Profile).id, :published => true
  38 + create TextileArticle, name: 'test', profile_id: 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   - profile = fast_create(Profile)
43 43 assert_difference 'ActionTracker::Record.count', 3 do
44   - create TextileArticle, :name => 'bar', :profile_id => profile.id, :published => true
45   - create TextileArticle, :name => 'another bar', :profile_id => profile.id, :published => true
46   - create TextileArticle, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true
  44 + create TextileArticle, name: 'bar', profile_id: profile.id, published: true
  45 + create TextileArticle, name: 'another bar', profile_id: profile.id, published: true
  46 + create TextileArticle, name: 'another bar 2', profile_id: profile.id, published: true
47 47 end
48 48 end
49 49  
50 50 should 'not update activity on update of an article' do
51 51 ActionTracker::Record.delete_all
52   - profile = fast_create(Profile)
53   - article = create(TextileArticle, :profile_id => profile.id)
  52 + article = create(TextileArticle, profile_id: profile.id)
54 53 time = article.activity.updated_at
55 54 Time.stubs(:now).returns(time + 1.day)
56 55 assert_no_difference 'ActionTracker::Record.count' do
... ... @@ -62,8 +61,8 @@ class TextileArticleTest &lt; ActiveSupport::TestCase
62 61  
63 62 should 'not create trackers activity when updating articles' do
64 63 ActionTracker::Record.delete_all
65   - a1 = create TextileArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true
66   - a2 = create TextileArticle, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true
  64 + a1 = create TextileArticle, name: 'bar', profile_id: profile.id, published: true
  65 + a2 = create TextileArticle, name: 'another bar', profile_id: profile.id, published: true
67 66 assert_no_difference 'ActionTracker::Record.count' do
68 67 a1.name = 'foo';a1.save!
69 68 a2.name = 'another foo';a2.save!
... ... @@ -72,7 +71,7 @@ class TextileArticleTest &lt; ActiveSupport::TestCase
72 71  
73 72 should 'remove activity after destroying article' do
74 73 ActionTracker::Record.delete_all
75   - a = create TextileArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true
  74 + a = create TextileArticle, name: 'bar', profile_id: profile.id, published: true
76 75 assert_difference 'ActionTracker::Record.count', -1 do
77 76 a.destroy
78 77 end
... ... @@ -80,8 +79,8 @@ class TextileArticleTest &lt; ActiveSupport::TestCase
80 79  
81 80 should 'remove activity after article is destroyed' do
82 81 ActionTracker::Record.delete_all
83   - a1 = create TextileArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true
84   - a2 = create TextileArticle, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true
  82 + a1 = create TextileArticle, name: 'bar', profile_id: profile.id, published: true
  83 + a2 = create TextileArticle, name: 'another bar', profile_id: profile.id, published: true
85 84 assert_equal 2, ActionTracker::Record.count
86 85 assert_difference 'ActionTracker::Record.count', -2 do
87 86 a1.destroy
... ... @@ -95,20 +94,20 @@ class TextileArticleTest &lt; ActiveSupport::TestCase
95 94 p1 = Person.first
96 95 community.add_member(p1)
97 96 assert p1.is_member_of?(community)
98   - article = create TextileArticle, :name => 'test', :profile_id => community.id
  97 + article = create TextileArticle, name: 'test', profile_id: community.id
99 98 assert_equal article, ActionTracker::Record.last.target
100 99 end
101 100  
102 101 should "the tracker action target be defined as the article on articles'creation in profile" do
103 102 ActionTracker::Record.delete_all
104 103 person = Person.first
105   - article = create TextileArticle, :name => 'test', :profile_id => person.id
  104 + article = create TextileArticle, name: 'test', profile_id: person.id
106 105 assert_equal article, ActionTracker::Record.last.target
107 106 end
108 107  
109 108 should 'not notify activity if the article is not advertise' do
110 109 ActionTracker::Record.delete_all
111   - a = create TextileArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true, :advertise => false
  110 + a = create TextileArticle, name: 'bar', profile_id: profile.id, published: true, advertise: false
112 111 assert_equal true, a.published?
113 112 assert_equal true, a.notifiable?
114 113 assert_equal false, a.image?
... ... @@ -121,7 +120,7 @@ class TextileArticleTest &lt; ActiveSupport::TestCase
121 120 end
122 121  
123 122 should "the common trackable conditions return the correct value" do
124   - a = build(TextileArticle, :profile => profile)
  123 + a = build(TextileArticle, profile: profile)
125 124 a.published = a.advertise = true
126 125 assert_equal true, a.published?
127 126 assert_equal true, a.notifiable?
... ... @@ -139,7 +138,7 @@ class TextileArticleTest &lt; ActiveSupport::TestCase
139 138 end
140 139  
141 140 should 'generate proper HTML for links' do
142   - assert_tag_in_string build_article('"Noosfero":http://noosfero.org/').to_html, :tag => 'a', :attributes => { :href => 'http://noosfero.org/' }
  141 + assert_tag_in_string build_article('"Noosfero":http://noosfero.org/').to_html, tag: 'a', attributes: { href: 'http://noosfero.org/' }
143 142 end
144 143  
145 144 should 'not mess up with textile markup' do
... ... @@ -153,7 +152,7 @@ class TextileArticleTest &lt; ActiveSupport::TestCase
153 152 end
154 153  
155 154 should 'not allow Javascript on links' do
156   - assert_no_tag_in_string build_article('<a href="javascript: alert(\'BOOM\')" onclick="javascript: alert(\'BOOM\')"></a>').to_html, :tag => 'a', :attributes => { :href => /./, :onclick => /./ }
  155 + assert_no_tag_in_string build_article('<a href="javascript: alert(\'BOOM\')" onclick="javascript: alert(\'BOOM\')"></a>').to_html, tag: 'a', attributes: { href: /./, onclick: /./ }
157 156 end
158 157  
159 158 should 'allow harmless HTML' do
... ... @@ -163,11 +162,11 @@ class TextileArticleTest &lt; ActiveSupport::TestCase
163 162 end
164 163  
165 164 should 'use Textile markup for lead as well' do
166   - assert_tag_in_string build_article(nil, :abstract => '"Noosfero":http://noosfero.org/').lead, :tag => 'a', :attributes => { :href => 'http://noosfero.org/' }
  165 + assert_tag_in_string build_article(nil, abstract: '"Noosfero":http://noosfero.org/').lead, tag: 'a', attributes: { href: 'http://noosfero.org/' }
167 166 end
168 167  
169 168 should 'not allow arbitrary HTML in the lead' do
170   - assert_not_equal '<script>alert(1)</script>', build_article(nil, :abstract => '<script>alert(1)</script>').lead
  169 + assert_not_equal '<script>alert(1)</script>', build_article(nil, abstract: '<script>alert(1)</script>').lead
171 170 end
172 171  
173 172 should 'not add hard breaks for single line breaks' do
... ... @@ -182,7 +181,7 @@ class TextileArticleTest &lt; ActiveSupport::TestCase
182 181 protected
183 182  
184 183 def build_article(input = nil, options = {})
185   - article = build(TextileArticle, {:body => input}.merge(options))
  184 + article = build(TextileArticle, {body: input}.merge(options))
186 185 article.valid? # trigger the xss terminate thingy
187 186 article
188 187 end
... ...