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