Commit 389f05f470561e237719c916ee0bcec12a1fa06c

Authored by Victor Costa
1 parent 04576c7e

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.
app/models/scrap.rb
... ... @@ -22,11 +22,11 @@ class Scrap < ActiveRecord::Base
22 22  
23 23 scope :not_replies, :conditions => {:scrap_id => nil}
24 24  
25   - 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
  25 + 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
26 26  
27   - track_actions :leave_scrap_to_self, :after_create, :keep_params => ['sender.name', 'content'], :if => Proc.new{|s| s.sender == s.receiver}
  27 + track_actions :leave_scrap_to_self, :after_create, :keep_params => ['sender.name', 'content'], :if => Proc.new{|s| s.sender == s.receiver}, :custom_user => :sender
28 28  
29   - 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}
  29 + 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
30 30  
31 31 after_create :send_notification
32 32  
... ...
test/functional/profile_controller_test.rb
... ... @@ -943,7 +943,7 @@ class ProfileControllerTest < ActionController::TestCase
943 943 @controller.stubs(:current_user).returns(user)
944 944 Person.any_instance.stubs(:follows?).returns(true)
945 945 get :index, :profile => p1.identifier
946   - assert_equal [s3,s2], assigns(:activities).map(&:activity)
  946 + assert_equal [s3,s2], assigns(:activities).map(&:activity).select {|a| a.kind_of?(Scrap)}
947 947 end
948 948  
949 949 should 'the activities be the received scraps in community profile' do
... ...
test/unit/scrap_test.rb
... ... @@ -6,6 +6,7 @@ class ScrapTest < ActiveSupport::TestCase
6 6 Person.destroy_all
7 7 Scrap.destroy_all
8 8 ActionTracker::Record.destroy_all
  9 + Delayed::Job.destroy_all
9 10 end
10 11  
11 12 should "have the content" do
... ...