[Git][noosfero/noosfero][master] activity: Set current user to fix random failures

Bráulio Bhavamitra gitlab at mg.gitlab.com
Thu Mar 17 18:38:04 BRT 2016


Bráulio Bhavamitra pushed to branch master at Noosfero / noosfero


Commits:
7809944b by Braulio Bhavamitra at 2016-03-17T18:36:06-03:00
activity: Set current user to fix random failures

- - - - -


2 changed files:

- test/unit/community_test.rb
- test/unit/textile_article_test.rb


Changes:

=====================================
test/unit/community_test.rb
=====================================
--- a/test/unit/community_test.rb
+++ b/test/unit/community_test.rb
@@ -3,7 +3,8 @@ require_relative "../test_helper"
 class CommunityTest < ActiveSupport::TestCase
 
   def setup
-    @person = fast_create(Person)
+    @user = User.current = create_user
+    @person = @user.person
   end
 
   attr_reader :person
@@ -287,8 +288,8 @@ class CommunityTest < ActiveSupport::TestCase
 
   should "update the action of article creation when an community's article is commented" do
     ActionTrackerNotification.delete_all
-    p1 = Person.first
     community = fast_create(Community)
+    p1 = person
     p2 = create_user.person
     p3 = create_user.person
     community.add_member(p3)


=====================================
test/unit/textile_article_test.rb
=====================================
--- a/test/unit/textile_article_test.rb
+++ b/test/unit/textile_article_test.rb
@@ -3,7 +3,8 @@ require_relative "../test_helper"
 class TextileArticleTest < ActiveSupport::TestCase
 
   def setup
-    @profile = create_user('testing').person
+    @user = User.current = create_user 'testing'
+    @profile = @user.person
   end
   attr_reader :profile
 
@@ -16,7 +17,7 @@ class TextileArticleTest < ActiveSupport::TestCase
   end
 
   should 'convert Textile to HTML' do
-    assert_equal '<p><strong>my text</strong></p>', build(TextileArticle, :body => '*my text*').to_html
+    assert_equal '<p><strong>my text</strong></p>', build(TextileArticle, body: '*my text*').to_html
   end
 
   should 'accept empty body' do
@@ -34,23 +35,21 @@ class TextileArticleTest < ActiveSupport::TestCase
 
   should 'notify activity on create' do
     ActionTracker::Record.delete_all
-    create TextileArticle, :name => 'test', :profile_id => fast_create(Profile).id, :published => true
+    create TextileArticle, name: 'test', profile_id: profile.id, published: true
     assert_equal 1, ActionTracker::Record.count
   end
 
   should 'not group trackers activity of article\'s creation' do
-    profile = fast_create(Profile)
     assert_difference 'ActionTracker::Record.count', 3 do
-      create TextileArticle, :name => 'bar', :profile_id => profile.id, :published => true
-      create TextileArticle, :name => 'another bar', :profile_id => profile.id, :published => true
-      create TextileArticle, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true
+      create TextileArticle, name: 'bar', profile_id: profile.id, published: true
+      create TextileArticle, name: 'another bar', profile_id: profile.id, published: true
+      create TextileArticle, name: 'another bar 2', profile_id: profile.id, published: true
     end
   end
 
   should 'not update activity on update of an article' do
     ActionTracker::Record.delete_all
-    profile = fast_create(Profile)
-    article = create(TextileArticle, :profile_id => profile.id)
+    article = create(TextileArticle, profile_id: profile.id)
     time = article.activity.updated_at
     Time.stubs(:now).returns(time + 1.day)
     assert_no_difference 'ActionTracker::Record.count' do
@@ -62,8 +61,8 @@ class TextileArticleTest < ActiveSupport::TestCase
 
   should 'not create trackers activity when updating articles' do
     ActionTracker::Record.delete_all
-    a1 = create TextileArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true
-    a2 = create TextileArticle, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true
+    a1 = create TextileArticle, name: 'bar', profile_id: profile.id, published: true
+    a2 = create TextileArticle, name: 'another bar', profile_id: profile.id, published: true
     assert_no_difference 'ActionTracker::Record.count' do
       a1.name = 'foo';a1.save!
       a2.name = 'another foo';a2.save!
@@ -72,7 +71,7 @@ class TextileArticleTest < ActiveSupport::TestCase
 
   should 'remove activity after destroying article' do
     ActionTracker::Record.delete_all
-    a = create TextileArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true
+    a = create TextileArticle, name: 'bar', profile_id: profile.id, published: true
     assert_difference 'ActionTracker::Record.count', -1 do
       a.destroy
     end
@@ -80,8 +79,8 @@ class TextileArticleTest < ActiveSupport::TestCase
 
   should 'remove activity after article is destroyed' do
     ActionTracker::Record.delete_all
-    a1 = create TextileArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true
-    a2 = create TextileArticle, :name => 'another bar', :profile_id => fast_create(Profile).id, :published => true
+    a1 = create TextileArticle, name: 'bar', profile_id: profile.id, published: true
+    a2 = create TextileArticle, name: 'another bar', profile_id: profile.id, published: true
     assert_equal 2, ActionTracker::Record.count
     assert_difference 'ActionTracker::Record.count', -2 do
       a1.destroy
@@ -95,20 +94,20 @@ class TextileArticleTest < ActiveSupport::TestCase
     p1 = Person.first
     community.add_member(p1)
     assert p1.is_member_of?(community)
-    article = create TextileArticle, :name => 'test', :profile_id => community.id
+    article = create TextileArticle, name: 'test', profile_id: community.id
     assert_equal article, ActionTracker::Record.last.target
   end
 
   should "the tracker action target be defined as the article on articles'creation in profile" do
     ActionTracker::Record.delete_all
     person = Person.first
-    article = create TextileArticle, :name => 'test', :profile_id => person.id
+    article = create TextileArticle, name: 'test', profile_id: person.id
     assert_equal article, ActionTracker::Record.last.target
   end
 
   should 'not notify activity if the article is not advertise' do
     ActionTracker::Record.delete_all
-    a = create TextileArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true, :advertise => false
+    a = create TextileArticle, name: 'bar', profile_id: profile.id, published: true, advertise: false
     assert_equal true, a.published?
     assert_equal true, a.notifiable?
     assert_equal false, a.image?
@@ -121,7 +120,7 @@ class TextileArticleTest < ActiveSupport::TestCase
   end
 
   should "the common trackable conditions return the correct value" do
-    a =  build(TextileArticle, :profile => profile)
+    a =  build(TextileArticle, profile: profile)
     a.published = a.advertise = true
     assert_equal true, a.published?
     assert_equal true, a.notifiable?
@@ -139,7 +138,7 @@ class TextileArticleTest < ActiveSupport::TestCase
   end
 
   should 'generate proper HTML for links' do
-    assert_tag_in_string build_article('"Noosfero":http://noosfero.org/').to_html, :tag => 'a', :attributes => { :href => 'http://noosfero.org/' }
+    assert_tag_in_string build_article('"Noosfero":http://noosfero.org/').to_html, tag: 'a', attributes: { href: 'http://noosfero.org/' }
   end
 
   should 'not mess up with textile markup' do
@@ -153,7 +152,7 @@ class TextileArticleTest < ActiveSupport::TestCase
   end
 
   should 'not allow Javascript on links' do
-    assert_no_tag_in_string build_article('<a href="javascript: alert(\'BOOM\')" onclick="javascript: alert(\'BOOM\')"></a>').to_html, :tag => 'a', :attributes => { :href => /./, :onclick => /./ }
+    assert_no_tag_in_string build_article('<a href="javascript: alert(\'BOOM\')" onclick="javascript: alert(\'BOOM\')"></a>').to_html, tag: 'a', attributes: { href: /./, onclick: /./ }
   end
 
   should 'allow harmless HTML' do
@@ -163,11 +162,11 @@ class TextileArticleTest < ActiveSupport::TestCase
   end
 
   should 'use Textile markup for lead as well' do
-    assert_tag_in_string build_article(nil, :abstract => '"Noosfero":http://noosfero.org/').lead, :tag => 'a', :attributes => { :href => 'http://noosfero.org/' }
+    assert_tag_in_string build_article(nil, abstract: '"Noosfero":http://noosfero.org/').lead, tag: 'a', attributes: { href: 'http://noosfero.org/' }
   end
 
   should 'not allow arbitrary HTML in the lead' do
-    assert_not_equal '<script>alert(1)</script>', build_article(nil, :abstract => '<script>alert(1)</script>').lead
+    assert_not_equal '<script>alert(1)</script>', build_article(nil, abstract: '<script>alert(1)</script>').lead
   end
 
   should 'not add hard breaks for single line breaks' do
@@ -182,7 +181,7 @@ class TextileArticleTest < ActiveSupport::TestCase
   protected
 
   def build_article(input = nil, options = {})
-    article = build(TextileArticle, {:body => input}.merge(options))
+    article = build(TextileArticle, {body: input}.merge(options))
     article.valid? # trigger the xss terminate thingy
     article
   end



View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/7809944b8a8e62fcd98fa0f3cfe84dce786b9010
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20160317/989c4926/attachment-0001.html>


More information about the Noosfero-dev mailing list