[Git][noosfero/noosfero][master] Fix scrap tests
Victor Costa
gitlab at gitlab.com
Fri Sep 4 11:07:51 BRT 2015
Victor Costa pushed to branch master at Noosfero / noosfero
Commits:
389f05f4 by Victor Costa at 2015-09-04T09:18:11Z
Fix scrap tests
Tests in scrap_test were failing in some random executions.
It was caused by the way that action_tracker gets the current user when
there is no custom_user setted in track_actions calls.
The current logged in used is obtained with ActionTracker::Record.current_user but it's not setted from unit tests.
The solution is to set the custom_user as the scrap sender, since that it will always be the same user that is logged in when a scrap is created.
- - - - -
3 changed files:
- app/models/scrap.rb
- test/functional/profile_controller_test.rb
- test/unit/scrap_test.rb
Changes:
=====================================
app/models/scrap.rb
=====================================
--- a/app/models/scrap.rb
+++ b/app/models/scrap.rb
@@ -22,11 +22,11 @@ class Scrap < ActiveRecord::Base
scope :not_replies, :conditions => {:scrap_id => nil}
- track_actions :leave_scrap, :after_create, :keep_params => ['sender.name', 'content', 'receiver.name', 'receiver.url'], :if => Proc.new{|s| s.sender != s.receiver && s.sender != s.top_root.receiver}, :custom_target => :action_tracker_target
+ track_actions :leave_scrap, :after_create, :keep_params => ['sender.name', 'content', 'receiver.name', 'receiver.url'], :if => Proc.new{|s| s.sender != s.receiver && s.sender != s.top_root.receiver}, :custom_target => :action_tracker_target, :custom_user => :sender
- track_actions :leave_scrap_to_self, :after_create, :keep_params => ['sender.name', 'content'], :if => Proc.new{|s| s.sender == s.receiver}
+ track_actions :leave_scrap_to_self, :after_create, :keep_params => ['sender.name', 'content'], :if => Proc.new{|s| s.sender == s.receiver}, :custom_user => :sender
- track_actions :reply_scrap_on_self, :after_create, :keep_params => ['sender.name', 'content'], :if => Proc.new{|s| s.sender != s.receiver && s.sender == s.top_root.receiver}
+ track_actions :reply_scrap_on_self, :after_create, :keep_params => ['sender.name', 'content'], :if => Proc.new{|s| s.sender != s.receiver && s.sender == s.top_root.receiver}, :custom_user => :sender
after_create :send_notification
=====================================
test/functional/profile_controller_test.rb
=====================================
--- a/test/functional/profile_controller_test.rb
+++ b/test/functional/profile_controller_test.rb
@@ -943,7 +943,7 @@ class ProfileControllerTest < ActionController::TestCase
@controller.stubs(:current_user).returns(user)
Person.any_instance.stubs(:follows?).returns(true)
get :index, :profile => p1.identifier
- assert_equal [s3,s2], assigns(:activities).map(&:activity)
+ assert_equal [s3,s2], assigns(:activities).map(&:activity).select {|a| a.kind_of?(Scrap)}
end
should 'the activities be the received scraps in community profile' do
=====================================
test/unit/scrap_test.rb
=====================================
--- a/test/unit/scrap_test.rb
+++ b/test/unit/scrap_test.rb
@@ -6,6 +6,7 @@ class ScrapTest < ActiveSupport::TestCase
Person.destroy_all
Scrap.destroy_all
ActionTracker::Record.destroy_all
+ Delayed::Job.destroy_all
end
should "have the content" do
View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/389f05f470561e237719c916ee0bcec12a1fa06c
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150904/46e687aa/attachment.html>
More information about the Noosfero-dev
mailing list