[Git][noosfero/noosfero][master] 3 commits: Global thread-safe current user for models use

Bráulio Bhavamitra gitlab at gitlab.com
Mon Aug 10 01:32:08 BRT 2015


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


Commits:
6b3ab931 by Braulio Bhavamitra at 2015-08-09T20:47:59Z
Global thread-safe current user for models use

- - - - -
b7f7e9fc by Braulio Bhavamitra at 2015-08-10T01:30:20Z
action_tracker: Don't use user_stamp

user_stamp depends on deprecated Sweeper code and it is quite
complicated to understand and use. Use User.current instead

- - - - -
2827fff7 by Bráulio Bhavamitra at 2015-08-10T04:31:52Z
Merge branch 'global-user' into 'master'

Global thread-safe current user for models use

See merge request !362

- - - - -


30 changed files:

- app/models/user.rb
- config/initializers/action_tracker.rb
- lib/authenticated_system.rb
- test/action_tracker_test_helper.rb
- test/functional/profile_controller_test.rb
- test/test_helper.rb
- test/unit/action_tracker_notification_test.rb
- test/unit/article_test.rb
- test/unit/comment_test.rb
- test/unit/community_test.rb
- test/unit/enterprise_test.rb
- test/unit/person_test.rb
- test/unit/textile_article_test.rb
- test/unit/uploaded_file_test.rb
- vendor/plugins/action_tracker/init.rb
- vendor/plugins/action_tracker/lib/action_tracker.rb
- vendor/plugins/action_tracker/lib/action_tracker_config.rb
- vendor/plugins/action_tracker/lib/action_tracker_model.rb
- vendor/plugins/action_tracker/test/action_tracker_config_test.rb
- vendor/plugins/action_tracker/test/action_tracker_test.rb
- − vendor/plugins/user_stamp/MIT-LICENSE
- − vendor/plugins/user_stamp/README
- − vendor/plugins/user_stamp/Rakefile
- − vendor/plugins/user_stamp/init.rb
- − vendor/plugins/user_stamp/install.rb
- − vendor/plugins/user_stamp/lib/user_stamp.rb
- − vendor/plugins/user_stamp/spec/spec_helper.rb
- − vendor/plugins/user_stamp/spec/user_stamp_class_methods_spec.rb
- − vendor/plugins/user_stamp/spec/user_stamp_spec.rb
- − vendor/plugins/user_stamp/spec/user_stamp_sweeper_spec.rb


Changes:

=====================================
app/models/user.rb
=====================================
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -15,6 +15,14 @@ class User < ActiveRecord::Base
     :email => {:label => _('Email'), :weight => 5},
   }
 
+  # see http://stackoverflow.com/a/2513456/670229
+  def self.current
+    Thread.current[:current_user]
+  end
+  def self.current=(user)
+    Thread.current[:current_user] = user
+  end
+
   def self.[](login)
     self.find_by_login(login)
   end


=====================================
config/initializers/action_tracker.rb
=====================================
--- a/config/initializers/action_tracker.rb
+++ b/config/initializers/action_tracker.rb
@@ -32,6 +32,8 @@ ActionTrackerConfig.verbs = {
   },
 }
 
-ActionTrackerConfig.current_user_method = :current_person
+ActionTrackerConfig.current_user = proc do
+  User.current.person rescue nil
+end
 
 ActionTrackerConfig.timeout = 24.hours


=====================================
lib/authenticated_system.rb
=====================================
--- a/lib/authenticated_system.rb
+++ b/lib/authenticated_system.rb
@@ -1,5 +1,20 @@
 module AuthenticatedSystem
+
   protected
+
+    # See impl. from http://stackoverflow.com/a/2513456/670229
+    def self.included? base
+      base.around_filter do
+        begin
+          User.current = current_user
+          yield
+        ensure
+          # to address the thread variable leak issues in Puma/Thin webserver
+          User.current = nil
+        end
+      end
+    end
+
     # Returns true or false if the user is logged in.
     # Preloads @current_user with the user model if they're logged in.
     def logged_in?
@@ -8,7 +23,9 @@ module AuthenticatedSystem
 
     # Accesses the current user from the session.
     def current_user
-      @current_user ||= (session[:user] && User.find_by_id(session[:user])) || nil
+      @current_user ||= begin
+        User.current = (session[:user] && User.find_by_id(session[:user])) || nil
+      end
     end
 
     # Store the given user in the session.
@@ -19,7 +36,7 @@ module AuthenticatedSystem
         session[:user] = new_user.id
         new_user.register_login
       end
-      @current_user = new_user
+      @current_user = User.current = new_user
     end
 
     # Check if the user is authorized.


=====================================
test/action_tracker_test_helper.rb
=====================================
--- a/test/action_tracker_test_helper.rb
+++ b/test/action_tracker_test_helper.rb
@@ -1,8 +1,7 @@
-class UserStampSweeper < ActionController::Caching::Sweeper
-  private
-    def current_user
-      Person.first
-    end
+class User
+  def self.current
+    Thread.current[:current_user] || User.first
+  end
 end
 
 module ActionTracker


=====================================
test/functional/profile_controller_test.rb
=====================================
--- a/test/functional/profile_controller_test.rb
+++ b/test/functional/profile_controller_test.rb
@@ -703,13 +703,13 @@ class ProfileControllerTest < ActionController::TestCase
     p1= create_user.person
     p2= create_user.person
 
-    UserStampSweeper.any_instance.stubs(:current_user).returns(p1)
+    User.current = p1.user
     scrap1 = create(Scrap, defaults_for_scrap(:sender => p1, :receiver => p2))
 
-    UserStampSweeper.any_instance.stubs(:current_user).returns(p2)
+    User.current = p2.user
     scrap2 = create(Scrap, defaults_for_scrap(:sender => p2, :receiver => p1))
 
-    UserStampSweeper.any_instance.stubs(:current_user).returns(p1)
+    User.current = p1.user
     create(TinyMceArticle, :profile => p1, :name => 'An article about free software')
     a1 = ActionTracker::Record.last
 
@@ -738,10 +738,10 @@ class ProfileControllerTest < ActionController::TestCase
     scrap1 = create(Scrap, defaults_for_scrap(:sender => p2, :receiver => p3))
     scrap2 = create(Scrap, defaults_for_scrap(:sender => p2, :receiver => profile))
 
-    UserStampSweeper.any_instance.stubs(:current_user).returns(p3)
+    User.current = p3.user
     article1 = TinyMceArticle.create!(:profile => p3, :name => 'An article about free software')
 
-    UserStampSweeper.any_instance.stubs(:current_user).returns(p2)
+    User.current = p2.user
     article2 = TinyMceArticle.create!(:profile => p2, :name => 'Another article about free software')
 
     login_as(profile.identifier)
@@ -761,15 +761,15 @@ class ProfileControllerTest < ActionController::TestCase
 
     ActionTracker::Record.delete_all
 
-    UserStampSweeper.any_instance.stubs(:current_user).returns(p1)
+    User.current = p1.user
     create(Scrap,defaults_for_scrap(:sender => p1, :receiver => p1))
     a1 = ActionTracker::Record.last
 
-    UserStampSweeper.any_instance.stubs(:current_user).returns(p2)
+    User.current = p2.user
     create(Scrap, defaults_for_scrap(:sender => p2, :receiver => p3))
     a2 = ActionTracker::Record.last
 
-    UserStampSweeper.any_instance.stubs(:current_user).returns(p3)
+    User.current = p3.user
     create(Scrap, defaults_for_scrap(:sender => p3, :receiver => p1))
     a3 = ActionTracker::Record.last
 
@@ -791,15 +791,15 @@ class ProfileControllerTest < ActionController::TestCase
 
     ActionTracker::Record.delete_all
 
-    UserStampSweeper.any_instance.stubs(:current_user).returns(p1)
+    User.current = p1.user
     create(Scrap, defaults_for_scrap(:sender => p1, :receiver => p1))
     a1 = ActionTracker::Record.last
 
-    UserStampSweeper.any_instance.stubs(:current_user).returns(p2)
+    User.current = p2.user
     create(Scrap, defaults_for_scrap(:sender => p2, :receiver => p3))
     a2 = ActionTracker::Record.last
 
-    UserStampSweeper.any_instance.stubs(:current_user).returns(p3)
+    User.current = p3.user
     create(Scrap, defaults_for_scrap(:sender => p3, :receiver => p1))
     a3 = ActionTracker::Record.last
 
@@ -833,10 +833,10 @@ class ProfileControllerTest < ActionController::TestCase
     ActionTracker::Record.destroy_all
     create(Scrap, defaults_for_scrap(:sender => p1, :receiver => p1))
     a1 = ActionTracker::Record.last
-    UserStampSweeper.any_instance.stubs(:current_user).returns(p2)
+    User.current = p2.user
     create(Scrap, defaults_for_scrap(:sender => p2, :receiver => p3))
     a2 = ActionTracker::Record.last
-    UserStampSweeper.any_instance.stubs(:current_user).returns(p3)
+    User.current = p3.user
     create(Scrap, defaults_for_scrap(:sender => p3, :receiver => p1))
     a3 = ActionTracker::Record.last
 
@@ -868,7 +868,7 @@ class ProfileControllerTest < ActionController::TestCase
     ActionTracker::Record.destroy_all
     create(Article, :name => 'a', :profile_id => community.id)
     create(Article, :name => 'b', :profile_id => community.id)
-    UserStampSweeper.any_instance.stubs(:current_user).returns(p2)
+    User.current = p2.user
     create(Article, :name => 'c', :profile_id => community.id)
     process_delayed_job_queue
 
@@ -895,10 +895,10 @@ class ProfileControllerTest < ActionController::TestCase
     ActionTracker::Record.destroy_all
     create(Scrap, defaults_for_scrap(:sender => p1, :receiver => p1))
     a1 = ActionTracker::Record.last
-    UserStampSweeper.any_instance.stubs(:current_user).returns(p2)
+    User.current = p2.user
     create(Scrap, defaults_for_scrap(:sender => p2, :receiver => p3))
     a2 = ActionTracker::Record.last
-    UserStampSweeper.any_instance.stubs(:current_user).returns(p3)
+    User.current = p3.user
     create(Scrap, defaults_for_scrap(:sender => p3, :receiver => p1))
     a3 = ActionTracker::Record.last
 
@@ -1317,7 +1317,7 @@ class ProfileControllerTest < ActionController::TestCase
     another_person = fast_create(Person)
     create(Scrap, defaults_for_scrap(:sender => another_person, :receiver => profile, :content => 'A scrap'))
 
-    UserStampSweeper.any_instance.stubs(:current_user).returns(profile)
+    User.current = profile.user
     ActionTracker::Record.destroy_all
     TinyMceArticle.create!(:profile => profile, :name => 'An article about free software')
 
@@ -1332,7 +1332,7 @@ class ProfileControllerTest < ActionController::TestCase
     another_person = fast_create(Person)
     scrap = create(Scrap, defaults_for_scrap(:sender => another_person, :receiver => profile, :content => 'A scrap'))
 
-    UserStampSweeper.any_instance.stubs(:current_user).returns(profile)
+    User.current = profile.user
     ActionTracker::Record.destroy_all
     TinyMceArticle.create!(:profile => profile, :name => 'An article about free software')
     activity = ActionTracker::Record.last
@@ -1380,7 +1380,7 @@ class ProfileControllerTest < ActionController::TestCase
   end
 
   should 'display comment in wall if user was removed after click in view all comments' do
-    UserStampSweeper.any_instance.stubs(:current_user).returns(profile)
+    User.current = profile.user
     article = TinyMceArticle.create!(:profile => profile, :name => 'An article about free software')
     to_be_removed = create_user('removed_user').person
     comment = create(Comment, :author => to_be_removed, :title => 'Test Comment', :body => 'My author does not exist =(', :source_id => article.id, :source_type => 'Article')
@@ -1397,7 +1397,7 @@ class ProfileControllerTest < ActionController::TestCase
   end
 
   should 'not display spam comments in wall' do
-    UserStampSweeper.any_instance.stubs(:current_user).returns(profile)
+    User.current = profile.user
     article = TinyMceArticle.create!(:profile => profile, :name => 'An article about spam\'s nutritional attributes')
     comment = create(Comment, :author => profile, :title => 'Test Comment', :body => 'This article makes me hungry', :source_id => article.id, :source_type => 'Article')
     comment.spam!
@@ -1408,7 +1408,7 @@ class ProfileControllerTest < ActionController::TestCase
   end
 
   should 'display comment in wall from non logged users after click in view all comments' do
-    UserStampSweeper.any_instance.stubs(:current_user).returns(profile)
+    User.current = profile.user
     article = TinyMceArticle.create!(:profile => profile, :name => 'An article about free software')
     comment = create(Comment, :name => 'outside user', :email => 'outside at localhost.localdomain', :title => 'Test Comment', :body => 'My author does not exist =(', :source_id => article.id, :source_type => 'Article')
 


=====================================
test/test_helper.rb
=====================================
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -76,6 +76,12 @@ class ActiveSupport::TestCase
 
   end
 
+  setup :global_setup
+
+  def global_setup
+    User.current = nil
+  end
+
   alias :ok :assert_block
 
   def assert_equivalent(enum1, enum2)


=====================================
test/unit/action_tracker_notification_test.rb
=====================================
--- a/test/unit/action_tracker_notification_test.rb
+++ b/test/unit/action_tracker_notification_test.rb
@@ -89,7 +89,7 @@ class ActionTrackerNotificationTest < ActiveSupport::TestCase
   end
 
   should "have comments through article action_tracker" do
-    person = fast_create(Person)
+    person = create_user.person
     article = create(TextileArticle, :profile_id => person.id)
     process_delayed_job_queue
     notification = ActionTrackerNotification.last


=====================================
test/unit/article_test.rb
=====================================
--- a/test/unit/article_test.rb
+++ b/test/unit/article_test.rb
@@ -985,12 +985,12 @@ class ArticleTest < ActiveSupport::TestCase
 
   should 'track action when a published article is created in a community' do
     community = fast_create(Community)
-    p1 = fast_create(Person)
-    p2 = fast_create(Person)
-    p3 = fast_create(Person)
+    p1 = create_user.person
+    p2 = create_user.person
+    p3 = create_user.person
     community.add_member(p1)
     community.add_member(p2)
-    UserStampSweeper.any_instance.expects(:current_user).returns(p1).at_least_once
+    User.current = p1.user
 
     article = create(TinyMceArticle, :profile_id => community.id)
     activity = article.activity
@@ -1085,11 +1085,11 @@ class ArticleTest < ActiveSupport::TestCase
   end
 
   should 'create the notification to organization and all organization members' do
-    Profile.delete_all
-    ActionTracker::Record.delete_all
+    Profile.destroy_all
+    ActionTracker::Record.destroy_all
 
     community = fast_create(Community)
-    member_1 = fast_create(Person)
+    member_1 = create_user.person
     community.add_member(member_1)
 
     article = create TinyMceArticle, :name => 'Tracked Article 1', :profile_id => community.id
@@ -1116,7 +1116,7 @@ class ArticleTest < ActiveSupport::TestCase
     Article.destroy_all
     ActionTracker::Record.destroy_all
     ActionTrackerNotification.destroy_all
-    UserStampSweeper.any_instance.expects(:current_user).returns(profile).at_least_once
+    User.current = profile.user
     article = create(TinyMceArticle, :profile_id => profile.id)
 
     process_delayed_job_queue
@@ -1127,7 +1127,7 @@ class ArticleTest < ActiveSupport::TestCase
     f1 = fast_create(Person)
     profile.add_friend(f1)
 
-    UserStampSweeper.any_instance.expects(:current_user).returns(profile).at_least_once
+    User.current = profile.user
     article = create TinyMceArticle, :name => 'Tracked Article 1', :profile_id => profile.id
     assert_equal 1, ActionTracker::Record.find_all_by_verb('create_article').count
     process_delayed_job_queue
@@ -1147,7 +1147,7 @@ class ArticleTest < ActiveSupport::TestCase
     Article.destroy_all
     ActionTracker::Record.destroy_all
     ActionTrackerNotification.destroy_all
-    UserStampSweeper.any_instance.expects(:current_user).returns(profile).at_least_once
+    User.current = profile.user
     article = create(TinyMceArticle, :profile_id => profile.id)
     activity = article.activity
 
@@ -1165,11 +1165,11 @@ class ArticleTest < ActiveSupport::TestCase
 
   should 'destroy action_tracker and notifications when an article is destroyed in a community' do
     community = fast_create(Community)
-    p1 = fast_create(Person)
-    p2 = fast_create(Person)
+    p1 = create_user.person
+    p2 = create_user.person
     community.add_member(p1)
     community.add_member(p2)
-    UserStampSweeper.any_instance.expects(:current_user).returns(p1).at_least_once
+    User.current = p1.user
 
     article = create(TinyMceArticle, :profile_id => community.id)
     activity = article.activity


=====================================
test/unit/comment_test.rb
=====================================
--- a/test/unit/comment_test.rb
+++ b/test/unit/comment_test.rb
@@ -286,7 +286,7 @@ class CommentTest < ActiveSupport::TestCase
   end
 
   should "return activities comments as a thread" do
-    person = fast_create(Person)
+    person = create_user.person
     a = TextileArticle.create!(:profile => person, :name => 'My article', :body => 'Article body')
     c0 = Comment.create!(:source => a, :body => 'My comment', :author => person)
     c1 = Comment.create!(:reply_of_id => c0.id, :source => a, :body => 'bla', :author => person)
@@ -302,7 +302,7 @@ class CommentTest < ActiveSupport::TestCase
   end
 
   should "return activities comments when some comment on thread is spam and not display its replies" do
-    person = fast_create(Person)
+    person = create_user.person
     a = TextileArticle.create!(:profile => person, :name => 'My article', :body => 'Article body')
     c0 = Comment.create(:source => a, :body => 'Root comment', :author => person)
     c1 = Comment.create(:reply_of_id => c0.id, :source => a, :body => 'c1', :author => person)


=====================================
test/unit/community_test.rb
=====================================
--- a/test/unit/community_test.rb
+++ b/test/unit/community_test.rb
@@ -301,8 +301,8 @@ class CommunityTest < ActiveSupport::TestCase
     ActionTrackerNotification.delete_all
     p1 = Person.first
     community = fast_create(Community)
-    p2 = fast_create(Person)
-    p3 = fast_create(Person)
+    p2 = create_user.person
+    p3 = create_user.person
     community.add_member(p3)
     article = create(TextileArticle, :profile_id => community.id)
     time = article.activity.updated_at + 1.day
@@ -372,10 +372,10 @@ class CommunityTest < ActiveSupport::TestCase
   end
 
   should 'return tracked_actions of community as activities' do
-    person = fast_create(Person)
+    person = create_user.person
     community = fast_create(Community)
 
-    UserStampSweeper.any_instance.expects(:current_user).returns(person).at_least_once
+    User.current = person.user
     assert_difference 'ActionTracker::Record.count', 1 do
       article = create(TinyMceArticle, :profile => community, :name => 'An article about free software')
       assert_equal [article.activity], community.activities.map { |a| a.klass.constantize.find(a.id) }
@@ -387,7 +387,7 @@ class CommunityTest < ActiveSupport::TestCase
     community = fast_create(Community)
     community2 = fast_create(Community)
 
-    UserStampSweeper.any_instance.expects(:current_user).returns(person).at_least_once
+    User.current = person.user
     article = create(TinyMceArticle, :profile => community2, :name => 'Another article about free software')
 
     assert_not_includes community.activities.map { |a| a.klass.constantize.find(a.id) }, article.activity


=====================================
test/unit/enterprise_test.rb
=====================================
--- a/test/unit/enterprise_test.rb
+++ b/test/unit/enterprise_test.rb
@@ -475,7 +475,7 @@ class EnterpriseTest < ActiveSupport::TestCase
     person = fast_create(Person)
     enterprise = fast_create(Enterprise)
 
-    UserStampSweeper.any_instance.expects(:current_user).returns(person).at_least_once
+    User.current = person.user
     article = create(TinyMceArticle, :profile => enterprise, :name => 'An article about free software')
 
     assert_equal [article.activity], enterprise.activities.map { |a| a.klass.constantize.find(a.id) }
@@ -486,7 +486,7 @@ class EnterpriseTest < ActiveSupport::TestCase
     enterprise = fast_create(Enterprise)
     enterprise2 = fast_create(Enterprise)
 
-    UserStampSweeper.any_instance.expects(:current_user).returns(person).at_least_once
+    User.current = person.user
     article = create(TinyMceArticle, :profile => enterprise2, :name => 'Another article about free software')
 
     assert_not_includes enterprise.activities.map { |a| a.klass.constantize.find(a.id) }, article.activity


=====================================
test/unit/person_test.rb
=====================================
--- a/test/unit/person_test.rb
+++ b/test/unit/person_test.rb
@@ -1249,9 +1249,9 @@ class PersonTest < ActiveSupport::TestCase
     person = create_user.person
     another_person = create_user.person
 
-    UserStampSweeper.any_instance.stubs(:current_user).returns(another_person)
+    User.current = another_person.user
     scrap = create(Scrap, defaults_for_scrap(:sender => another_person, :receiver => person, :content => 'A scrap'))
-    UserStampSweeper.any_instance.expects(:current_user).returns(person).at_least_once
+    User.current = person.user
     article = create(TinyMceArticle, :profile => person, :name => 'An article about free software')
 
     assert_equivalent [scrap,article.activity], person.activities.map { |a| a.klass.constantize.find(a.id) }
@@ -1259,17 +1259,17 @@ class PersonTest < ActiveSupport::TestCase
 
   should 'not return tracked_actions and scraps from others as activities' do
     ActionTracker::Record.destroy_all
-    person = fast_create(Person)
-    another_person = fast_create(Person)
+    person = create_user.person
+    another_person = create_user.person
 
     person_scrap = create(Scrap, defaults_for_scrap(:sender => person, :receiver => person, :content => 'A scrap from person'))
     another_person_scrap = create(Scrap, defaults_for_scrap(:sender => another_person, :receiver => another_person, :content => 'A scrap from another person'))
 
-    UserStampSweeper.any_instance.stubs(:current_user).returns(another_person)
+    User.current = another_person.user
     create(TinyMceArticle, :profile => another_person, :name => 'An article about free software from another person')
     another_person_activity = ActionTracker::Record.last
 
-    UserStampSweeper.any_instance.stubs(:current_user).returns(person)
+    User.current = person.user
     create(TinyMceArticle, :profile => person, :name => 'An article about free software')
     person_activity = ActionTracker::Record.last
 


=====================================
test/unit/textile_article_test.rb
=====================================
--- a/test/unit/textile_article_test.rb
+++ b/test/unit/textile_article_test.rb
@@ -1,10 +1,9 @@
 require_relative "../test_helper"
 
 class TextileArticleTest < ActiveSupport::TestCase
-  
+
   def setup
     @profile = create_user('testing').person
-    ActionTracker::Record.stubs(:current_user_from_model).returns(fast_create(Person))
   end
   attr_reader :profile
 
@@ -128,7 +127,7 @@ class TextileArticleTest < ActiveSupport::TestCase
     assert_equal true, a.notifiable?
     assert_equal true, a.advertise?
     assert_equal true, a.is_trackable?
-   
+
     a.published=false
     assert_equal false, a.published?
     assert_equal false, a.is_trackable?


=====================================
test/unit/uploaded_file_test.rb
=====================================
--- a/test/unit/uploaded_file_test.rb
+++ b/test/unit/uploaded_file_test.rb
@@ -325,7 +325,6 @@ class UploadedFileTest < ActiveSupport::TestCase
 
   should 'group trackers activity of image\'s upload' do
     ActionTracker::Record.delete_all
-    ActionTracker::Record.stubs(:current_user_from_model).returns(profile)
     gallery = fast_create(Gallery, :profile_id => profile.id)
 
     image1 = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => gallery, :profile => profile)


=====================================
vendor/plugins/action_tracker/init.rb
=====================================
--- a/vendor/plugins/action_tracker/init.rb
+++ b/vendor/plugins/action_tracker/init.rb
@@ -1,10 +1 @@
-require "user_stamp"
-
-UserStamp.creator_attribute = :user
-UserStamp.updater_attribute = :user
-
-class ActionController::Base
-  extend UserStamp::ClassMethods
-end
-
 require "action_tracker"


=====================================
vendor/plugins/action_tracker/lib/action_tracker.rb
=====================================
--- a/vendor/plugins/action_tracker/lib/action_tracker.rb
+++ b/vendor/plugins/action_tracker/lib/action_tracker.rb
@@ -5,7 +5,6 @@ module ActionTracker
   module ControllerMethods
 
     def self.included(base)
-      base.send :user_stamp, ActionTracker::Record
       base.send :extend, ClassMethods
     end
 
@@ -42,7 +41,7 @@ module ActionTracker
         elsif keep_params.to_s == 'all'
           stored_params = params
         end
-        user = send ActionTrackerConfig.current_user_method
+        user = send ActionTrackerConfig.current_user
         tracked_action = case ActionTrackerConfig.verb_type(verb)
           when :groupable
             Record.add_or_create :verb => verb, :user => user, :params => stored_params
@@ -90,7 +89,7 @@ module ActionTracker
 
       def save_action_for_verb(verb, keep_params = :all, post_proc = Proc.new{}, custom_user = nil, custom_target = nil)
         user = self.send(custom_user) unless custom_user.blank?
-        user ||= ActionTracker::Record.current_user_from_model
+        user ||= ActionTracker::Record.current_user
         target = self.send(custom_target) unless custom_target.blank?
         return nil if user.nil?
         if keep_params.is_a? Array
@@ -115,7 +114,7 @@ module ActionTracker
         end
         tracked_action.target = target || self
         user.tracked_actions << tracked_action
-        post_proc.call tracked_action.reload
+        post_proc.call tracked_action
       end
 
     end


=====================================
vendor/plugins/action_tracker/lib/action_tracker_config.rb
=====================================
--- a/vendor/plugins/action_tracker/lib/action_tracker_config.rb
+++ b/vendor/plugins/action_tracker/lib/action_tracker_config.rb
@@ -20,12 +20,12 @@ class ActionTrackerConfig
     verbs.keys.map(&:to_s)
   end
 
-  def self.current_user_method
-    config[:current_user_method] || :current_user
+  def self.current_user
+    config[:current_user] || proc{ nil }
   end
 
-  def self.current_user_method=(method_name)
-    UserStamp.current_user_method = config[:current_user_method] = method_name
+  def self.current_user= block
+    config[:current_user] = block
   end
 
   def self.default_filter_time


=====================================
vendor/plugins/action_tracker/lib/action_tracker_model.rb
=====================================
--- a/vendor/plugins/action_tracker/lib/action_tracker_model.rb
+++ b/vendor/plugins/action_tracker/lib/action_tracker_model.rb
@@ -27,14 +27,12 @@ module ActionTracker
     scope :recent, :conditions => ['created_at >= ?', RECENT_DELAY.days.ago]
     scope :visible, :conditions => { :visible => true }
 
-    def self.current_user_from_model
-      u = new
-      u.valid?
-      u.user
+    def self.current_user
+      ActionTrackerConfig.current_user.call
     end
 
     def self.update_or_create(params)
-      u = params[:user] || current_user_from_model
+      u = params[:user] || current_user
       return if u.nil?
       target_hash = params[:target].nil? ? {} : {:target_type => params[:target].class.base_class.to_s, :target_id => params[:target].id}
       conditions = { :user_id => u.id, :user_type => u.class.base_class.to_s, :verb => params[:verb].to_s }.merge(target_hash)
@@ -44,7 +42,7 @@ module ActionTracker
     end
 
     def self.add_or_create(params)
-      u = params[:user] || current_user_from_model
+      u = params[:user] || current_user
       return if u.nil?
       target_hash = params[:target].nil? ? {} : {:target_type => params[:target].class.base_class.to_s, :target_id => params[:target].id}
       l = last :conditions => { :user_id => u.id, :user_type => u.class.base_class.to_s, :verb => params[:verb].to_s }.merge(target_hash)


=====================================
vendor/plugins/action_tracker/test/action_tracker_config_test.rb
=====================================
--- a/vendor/plugins/action_tracker/test/action_tracker_config_test.rb
+++ b/vendor/plugins/action_tracker/test/action_tracker_config_test.rb
@@ -33,16 +33,6 @@ class ActionTrackerConfigTest < ActiveSupport::TestCase
     %w(search delete login).each { |verb| assert ActionTrackerConfig.verb_names.include?(verb) }
   end
 
-  def test_current_user_is_default_method
-    ActionTrackerConfig.config[:current_user_method] = nil
-    assert_equal :current_user, ActionTrackerConfig.current_user_method
-  end
-
-  def test_current_user_can_be_set
-    ActionTrackerConfig.current_user_method = :logged_in_user
-    assert_equal :logged_in_user, ActionTrackerConfig.current_user_method
-  end
-
   def test_default_filter_time_is_after
     ActionTrackerConfig.config[:default_filter_time] = nil
     assert_equal :after, ActionTrackerConfig.default_filter_time
@@ -66,7 +56,7 @@ class ActionTrackerConfigTest < ActiveSupport::TestCase
   def test_get_verb_return_hash
     assert_kind_of Hash, ActionTrackerConfig.get_verb(:search)
   end
-  
+
   def test_get_verb_symbol_search_by_symbol
     ActionTrackerConfig.verbs = { :search => { :description => "Got it" } }
     assert_equal "Got it", ActionTrackerConfig.get_verb(:search)[:description]


=====================================
vendor/plugins/action_tracker/test/action_tracker_test.rb
=====================================
--- a/vendor/plugins/action_tracker/test/action_tracker_test.rb
+++ b/vendor/plugins/action_tracker/test/action_tracker_test.rb
@@ -43,10 +43,6 @@ class ThingsController < ActionController::Base
     render :text => "test"
   end
 
-  def current_user
-    SomeModel.first || SomeModel.create!
-  end
-
   def rescue_action(e)
     raise e
   end
@@ -58,9 +54,7 @@ ActionController::Routing::Routes.draw { |map| map.resources :things, :collectio
 class ActionTrackerTest < ActiveSupport::TestCase
 
   def setup
-    UserStamp.creator_attribute = :user
-    UserStamp.updater_attribute = :user
-    ActionTrackerConfig.current_user_method = :current_user
+    ActionTrackerConfig.current_user = proc{ SomeModel.first || SomeModel.create! }
     ActionTracker::Record.delete_all
     ActionTrackerConfig.verbs = { :some_verb => { :description => "Did something" } }
     @request = ActionController::TestRequest.new
@@ -108,7 +102,7 @@ class ActionTrackerTest < ActiveSupport::TestCase
   end
 
   def test_track_actions_executes_block
-    @controller = create_controller do 
+    @controller = create_controller do
       track_actions :some_verb do
         throw :some_symbol
       end
@@ -162,7 +156,7 @@ class ActionTrackerTest < ActiveSupport::TestCase
     assert_difference 'ActionTracker::Record.count' do
       get :index, :foo => 5
     end
-    assert_equal({"action"=>"index", "foo"=>"5", "controller"=>"things"}, ActionTracker::Record.first.params) 
+    assert_equal({"action"=>"index", "foo"=>"5", "controller"=>"things"}, ActionTracker::Record.first.params)
 	end
 
   def test_keep_params_not_set_should_store_all_params
@@ -228,16 +222,15 @@ class ActionTrackerTest < ActiveSupport::TestCase
   def test_store_user
     @controller = create_controller do
 			track_actions_before :some_verb
-			def current_user
-				SomeModel.create! :some_column => "test"
-			end
 		end
+    ActionTrackerConfig.current_user = proc{ SomeModel.create! :some_column => "test" }
+
     assert_difference 'ActionTracker::Record.count' do
       get :test
     end
 		assert_equal "test", ActionTracker::Record.last.user.some_column
   end
- 
+
   def test_should_update_when_verb_is_updatable_and_no_timeout
     ActionTrackerConfig.verbs = { :some_verb => { :description => "Did something", :type => :updatable } }
     ActionTrackerConfig.timeout = 5.minutes
@@ -252,7 +245,7 @@ class ActionTrackerTest < ActiveSupport::TestCase
 	  assert_no_difference 'ActionTracker::Record.count' do
       get :test
     end
-  end 
+  end
 
   def test_should_create_when_verb_is_updatable_and_timeout
     ActionTrackerConfig.verbs = { :some_verb => { :description => "Did something", :type => :updatable } }
@@ -268,7 +261,7 @@ class ActionTrackerTest < ActiveSupport::TestCase
 	  assert_difference 'ActionTracker::Record.count' do
       get :test
     end
-  end 
+  end
 
   def test_should_update_when_verb_is_groupable_and_no_timeout
     ActionTrackerConfig.verbs = { :some_verb => { :description => "Did something", :type => :groupable } }
@@ -284,7 +277,7 @@ class ActionTrackerTest < ActiveSupport::TestCase
 	  assert_no_difference 'ActionTracker::Record.count' do
       get :test, :foo => "test"
     end
-  end 
+  end
 
   def test_should_create_when_verb_is_groupable_and_timeout
     ActionTrackerConfig.verbs = { :some_verb => { :description => "Did something", :type => :groupable } }
@@ -330,7 +323,7 @@ class ActionTrackerTest < ActiveSupport::TestCase
   def test_should_get_time_spent_doing_something
     ActionTrackerConfig.verbs = { :some_verb => { :type => :updatable }, :other_verb => { :type => :updatable } }
     m = SomeModel.create!
-    @controller = create_controller do 
+    @controller = create_controller do
       track_actions :some_verb
     end
     @controller.stubs(:current_user).returns(m)
@@ -394,7 +387,7 @@ class ActionTrackerTest < ActiveSupport::TestCase
 		assert_equal "foo", ActionTracker::Record.last.params["other_column"]
 		assert_nil ActionTracker::Record.last.params["another_column"]
   end
-  
+
   def test_replace_dots_by_underline_in_param_name
     ActionTrackerConfig.verbs = { :test => { :description => "Some" } }
     model = create_model do
@@ -407,7 +400,7 @@ class ActionTrackerTest < ActiveSupport::TestCase
 		assert_equal 3, ActionTracker::Record.last.params["other_column_size"]
 		assert_equal 5, ActionTracker::Record.last.params["another_column"]
   end
-  
+
   def test_track_actions_store_all_params
     ActionTrackerConfig.verbs = { :test => { :description => "Some" } }
     model = create_model do
@@ -452,7 +445,7 @@ class ActionTrackerTest < ActiveSupport::TestCase
     model = create_model { track_actions :test, :after_create, :keep_params => :all, :if => Proc.new { 2 > 1 } }
     @controller = create_controller_for_model(model)
     assert_difference('ActionTracker::Record.count') { get :test }
-    
+
     model = create_model { track_actions :test, :after_create, :keep_params => :all, :if => Proc.new { 2 < 1 } }
     @controller = create_controller_for_model(model)
     assert_no_difference('ActionTracker::Record.count') { get :test }
@@ -460,7 +453,7 @@ class ActionTrackerTest < ActiveSupport::TestCase
     model = create_model { track_actions :test, :after_create, :keep_params => :all, :unless => Proc.new { 2 > 1 } }
     @controller = create_controller_for_model(model)
     assert_no_difference('ActionTracker::Record.count') { get :test }
-    
+
     model = create_model { track_actions :test, :after_create, :keep_params => :all, :unless => Proc.new { 2 < 1 } }
     @controller = create_controller_for_model(model)
     assert_difference('ActionTracker::Record.count') { get :test }
@@ -498,13 +491,11 @@ class ActionTrackerTest < ActiveSupport::TestCase
     ActionTrackerConfig.verbs = { :test => { :description => "Some" } }
     model = create_model do
       track_actions :test, :after_create, :custom_user => :test_custom_user
-      def current_user
-        SomeModel.create!
-      end
       def test_custom_user
         OtherModel.create!
       end
     end
+    ActionTrackerConfig.current_user = proc{ SomeModel.create! }
     @controller = create_controller_for_model(model, :another_column => 2)
     assert_difference('ActionTracker::Record.count') { get :test }
 		assert_kind_of OtherModel, ActionTracker::Record.last.user
@@ -514,13 +505,11 @@ class ActionTrackerTest < ActiveSupport::TestCase
     ActionTrackerConfig.verbs = { :test => { :description => "Some" } }
     model = create_model do
       track_actions :test, :after_create, "custom_user" => :test_custom_user
-      def current_user
-        SomeModel.create!
-      end
       def test_custom_user
         OtherModel.create!
       end
     end
+    ActionTrackerConfig.current_user = proc{ SomeModel.create! }
     @controller = create_controller_for_model(model, :another_column => 2)
     assert_difference('ActionTracker::Record.count') { get :test }
 		assert_kind_of OtherModel, ActionTracker::Record.last.user
@@ -530,13 +519,11 @@ class ActionTrackerTest < ActiveSupport::TestCase
     ActionTrackerConfig.verbs = { :test => { :description => "Some" } }
     model = create_model do
       track_actions :test, :after_create
-      def current_user
-        SomeModel.create!
-      end
       def test_custom_user
         OtherModel.create!
       end
     end
+    ActionTrackerConfig.current_user = proc{ SomeModel.create! }
     @controller = create_controller_for_model(model, :another_column => 2)
     assert_difference('ActionTracker::Record.count') { get :test }
 		assert_kind_of SomeModel, ActionTracker::Record.last.user
@@ -625,10 +612,8 @@ class ActionTrackerTest < ActiveSupport::TestCase
         render :text => "test"
       end
 
-			def current_user
-				SomeModel.create! :some_column => "test"
-			end
 		end
+    ActionTrackerConfig.current_user = proc{ SomeModel.create! :some_column => "test" }
   end
 
 end


=====================================
vendor/plugins/user_stamp/MIT-LICENSE deleted
=====================================
--- a/vendor/plugins/user_stamp/MIT-LICENSE
+++ /dev/null
@@ -1,20 +0,0 @@
-Copyright (c) 2008 [John Nunemaker]
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


=====================================
vendor/plugins/user_stamp/README deleted
=====================================
--- a/vendor/plugins/user_stamp/README
+++ /dev/null
@@ -1,37 +0,0 @@
-= UserStamp
-
-Rails plugin that makes stamping records with a user when they are 
-created and updated dirt simple. It assumes that your controller has 
-a current_user method. It also assumes that any record being stamped
-has two attributes--creator_id and updater_id. You can override both
-of these assumptions easily.
-
-== Setup
-
-1. script/plugin install git://github.com/jnunemaker/user_stamp.git
-2. Add user_stamp to application.rb, like the following:
-		
-		class ApplicationController < ActionController::Base
-		  user_stamp Post, Asset, Job
-		end
-
-
-== Defaults
-
-  UserStamp.creator_attribute   = :creator_id
-  UserStamp.updater_attribute   = :updater_id
-  UserStamp.current_user_method = :current_user
-
-If your user stamped columns and current_user method are different, 
-just create an initializer such as config/initializers/user_stamp.rb
-and copy and paste the defaults above, changing them to fit your app.
-
-== Problems?
-
-Use the issue tracker on Github.
-
-== Docs
-
-http://rdoc.info/projects/jnunemaker/user_stamp
-
-Copyright (c) 2008 [John Nunemaker], released under the MIT license


=====================================
vendor/plugins/user_stamp/Rakefile deleted
=====================================
--- a/vendor/plugins/user_stamp/Rakefile
+++ /dev/null
@@ -1,11 +0,0 @@
-require 'rake'
-require 'spec/rake/spectask'
-
-desc 'Default: run specs.'
-task :default => :spec
- 
-desc 'Run the specs'
-Spec::Rake::SpecTask.new(:spec) do |t|
-  t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
-  t.spec_files = FileList['spec/**/*_spec.rb']
-end
\ No newline at end of file


=====================================
vendor/plugins/user_stamp/init.rb deleted
=====================================
--- a/vendor/plugins/user_stamp/init.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require 'user_stamp'
-
-class ActionController::Base
-  extend UserStamp::ClassMethods
-end


=====================================
vendor/plugins/user_stamp/install.rb deleted
=====================================
--- a/vendor/plugins/user_stamp/install.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-instructions = <<EOF
-
-#{'*' * 62}
-Don't forget to add user stamp to your application controller.
-  
-  class ApplicationController < ActionController::Base
-    user_stamp Post, Asset, Job
-  end
-
-View the README for more information.
-#{'*' * 62}
-
-EOF
-
-puts instructions
\ No newline at end of file


=====================================
vendor/plugins/user_stamp/lib/user_stamp.rb deleted
=====================================
--- a/vendor/plugins/user_stamp/lib/user_stamp.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-module UserStamp
-  mattr_accessor :creator_attribute
-  mattr_accessor :updater_attribute
-  mattr_accessor :current_user_method
-  
-  def self.creator_assignment_method
-    "#{UserStamp.creator_attribute}="
-  end
-  
-  def self.updater_assignment_method
-    "#{UserStamp.updater_attribute}="
-  end
-  
-  module ClassMethods
-    def user_stamp(*models)
-      models.each { |klass| UserStampSweeper.observe(klass) }
-      
-      class_eval do
-        cache_sweeper :user_stamp_sweeper
-      end
-    end
-  end
-end
-
-UserStamp.creator_attribute   = :creator_id
-UserStamp.updater_attribute   = :updater_id
-UserStamp.current_user_method = :current_user
-
-class UserStampSweeper < ActionController::Caching::Sweeper
-  def before_validation(record)
-    return unless current_user
-    
-    attribute, method = UserStamp.creator_attribute, UserStamp.creator_assignment_method
-    if record.respond_to?(method) && record.new_record?
-      record.send(method, current_user) unless record.send("#{attribute}_id_changed?") || record.send("#{attribute}_type_changed?")
-    end
-    
-    attribute, method = UserStamp.updater_attribute, UserStamp.updater_assignment_method
-    if record.respond_to?(method)
-      record.send(method, current_user) if record.send(attribute).blank?
-    end
-  end
-  
-  private  
-    def current_user
-      if controller.respond_to?(UserStamp.current_user_method)
-        controller.send UserStamp.current_user_method
-      end
-    end
-end


=====================================
vendor/plugins/user_stamp/spec/spec_helper.rb deleted
=====================================
--- a/vendor/plugins/user_stamp/spec/spec_helper.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require 'rubygems'
-
-gem 'rspec'
-require 'spec'
-
-%w[activesupport activerecord actionpack].each do |lib|
-  gem lib
-  require lib
-end
-
-require 'action_controller'
-
-$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
-require 'user_stamp'
-
-UserStampSweeper.instance
-
-class User
-  attr_accessor :id
-  
-  def initialize(id);
-    @id = id
-  end
-end


=====================================
vendor/plugins/user_stamp/spec/user_stamp_class_methods_spec.rb deleted
=====================================
--- a/vendor/plugins/user_stamp/spec/user_stamp_class_methods_spec.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-require File.dirname(__FILE__) + '/spec_helper'
-
-class FauxModelBase
-  def self.add_observer(observer_instance); end
-end
-
-class Post < FauxModelBase; end
-class Category < FauxModelBase; end
-class Label < FauxModelBase; end
-
-class FauxApplicationController  
-  def self.cache_sweeper(sweepers); end
-  
-  def self.current_user
-    User.new(220)
-  end
-end
-
-class PostsController < FauxApplicationController
-  extend UserStamp::ClassMethods
-end
-
-describe UserStamp::ClassMethods do
-  before do
-    UserStamp.creator_attribute   = :creator_id
-    UserStamp.updater_attribute   = :updater_id
-    UserStamp.current_user_method = :current_user
-  end
-  
-  it "should add user_stamp method" do
-    PostsController.respond_to?(:user_stamp).should == true
-  end
-  
-  def user_stamp
-    PostsController.user_stamp Post, Category, Label
-  end
-  
-  describe "#user_stamp" do
-    it "should add UserStampSweeper as observer for each model" do
-      [Post, Category, Label].each do |klass|
-        klass.should_receive(:add_observer).with(UserStampSweeper.instance).once
-      end
-      user_stamp
-    end
-    
-    it "should setup cache sweeper for controller" do
-      PostsController.should_receive(:cache_sweeper).with(:user_stamp_sweeper).once
-      user_stamp
-    end
-  end
-end
\ No newline at end of file


=====================================
vendor/plugins/user_stamp/spec/user_stamp_spec.rb deleted
=====================================
--- a/vendor/plugins/user_stamp/spec/user_stamp_spec.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-require File.dirname(__FILE__) + '/spec_helper'
-
-describe UserStamp do
-  before do
-    UserStamp.creator_attribute   = :creator_id
-    UserStamp.updater_attribute   = :updater_id
-    UserStamp.current_user_method = :current_user
-  end
-  
-  it "should default creator_attribute to creator_id" do
-    UserStamp.creator_attribute.should == :creator_id
-  end
-
-  it "should default updater_attribute to updater_id" do
-    UserStamp.updater_attribute.should == :updater_id
-  end
-  
-  it "should default current_user_method to current_user" do
-    UserStamp.current_user_method.should == :current_user
-  end
-  
-  it "should have accessor for creator_attribute" do
-    UserStamp.creator_attribute = 'mofo_id'
-    UserStamp.creator_attribute.should == 'mofo_id'
-  end
-  
-  it "should have accessor for updater_attribute" do
-    UserStamp.updater_attribute = 'mofo_id'
-    UserStamp.updater_attribute.should == 'mofo_id'
-  end
-  
-  it "should have accessor for current_user_method" do
-    UserStamp.current_user_method = 'my_current_user'
-    UserStamp.current_user_method.should == 'my_current_user'
-  end
-  
-  describe "assignment methods" do
-    before do
-      UserStamp.creator_attribute = 'creator_mofo_id'
-      UserStamp.updater_attribute = 'updater_mofo_id'
-    end
-    
-    it "should include creator assignment method" do
-      UserStamp.creator_assignment_method.should == 'creator_mofo_id='
-    end
-    
-    it "should include updater assignment method" do
-      UserStamp.updater_assignment_method.should == 'updater_mofo_id='
-    end
-  end
-end
\ No newline at end of file


=====================================
vendor/plugins/user_stamp/spec/user_stamp_sweeper_spec.rb deleted
=====================================
--- a/vendor/plugins/user_stamp/spec/user_stamp_sweeper_spec.rb
+++ /dev/null
@@ -1,194 +0,0 @@
-require File.dirname(__FILE__) + '/spec_helper'
-
-class PostsController
-  def self.current_user
-    @@user
-  end
-end
-
-describe UserStampSweeper, "#before_validation" do
-  before do
-    @@user = User.new(220)
-    UserStamp.creator_attribute   = :creator
-    UserStamp.updater_attribute   = :updater
-    UserStamp.current_user_method = :current_user
-    @sweeper = UserStampSweeper.instance
-    @sweeper.stub!(:controller).and_return(PostsController)
-  end
-  
-  describe "(with new record)" do
-    it "should set creator if attribute exists" do
-      record = mock('Record', :creator= => nil, :updater= => nil, :new_record? => true, :updater => nil, :creator_id_changed? => false, :creator_type_changed? => false, :updater_id_changed? => false, :updater_type_changed? => false)
-      record.should_receive(:creator=).with(@@user).once
-      @sweeper.before_validation(record)
-    end
-    
-    it "should NOT set creator if attribute does not exist" do
-      record = mock('Record', :new_record? => true, :updater= => nil, :respond_to? => false)
-      record.should_receive(:respond_to?).with("creator=").and_return(false)
-      record.should_not_receive(:creator=)
-      @sweeper.before_validation(record)
-    end
-  end
-  
-  describe "(with non new record)" do
-    it "should NOT set creator if attribute exists" do
-      record = mock('Record', :creator= => nil, :updater= => nil, :updater => nil, :new_record? => false, :creator_id_changed? => false, :creator_type_changed? => false, :updater_id_changed? => false, :updater_type_changed? => false)
-      record.should_not_receive(:creator=)
-      @sweeper.before_validation(record)
-    end
-    
-    it "should NOT set creator if attribute does not exist" do
-      record = mock('Record', :updater= => nil, :updater => nil, :new_record? => false, :creator_id_changed? => false, :creator_type_changed? => false, :updater_id_changed? => false, :updater_type_changed? => false)
-      record.should_not_receive(:creator=)
-      @sweeper.before_validation(record)
-    end
-  end
-  
-  it "should set updater if attribute exists" do
-    record = mock('Record', :creator= => nil, :updater= => nil, :new_record? => false, :updater => nil)
-    record.should_receive(:updater=)
-    @sweeper.before_validation(record)
-  end
-  
-  it "should NOT set updater if attribute does not exist" do
-    record = mock('Record', :creator= => nil, :updater= => nil, :new_record? => :false, :respond_to? => false)
-    record.should_receive(:respond_to?).with("updater=").and_return(false)
-    record.should_not_receive(:updater=)
-    @sweeper.before_validation(record)
-  end
-end
-
-describe UserStampSweeper, "#before_validation (with custom attribute names)" do
-  before do
-    UserStamp.creator_attribute   = :created_by
-    UserStamp.updater_attribute   = :updated_by
-    UserStamp.current_user_method = :current_user
-    @sweeper = UserStampSweeper.instance
-    @sweeper.stub!(:controller).and_return(PostsController)
-  end
-  
-  describe "(with new record)" do
-    it "should set created_by if attribute exists" do
-      record = mock('Record', :created_by= => nil, :updated_by => nil, :updated_by= => nil, :new_record? => true, :created_by_id_changed? => false, :created_by_type_changed? => false, :updated_by_id_changed? => false, :updated_by_type_changed? => false)
-      record.should_receive(:created_by=).with(@@user).once
-      @sweeper.before_validation(record)
-    end
-    
-    it "should NOT set created_by if attribute does not exist" do
-      record = mock('Record', :new_record? => true, :updated_by= => nil, :respond_to? => false)
-      record.should_receive(:respond_to?).with("created_by=").and_return(false)
-      record.should_not_receive(:created_by=)
-      @sweeper.before_validation(record)
-    end
-  end
-  
-  describe "(with non new record)" do
-    it "should NOT set created_by if attribute exists" do
-      record = mock('Record', :created_by= => nil, :updated_by => nil, :updated_by= => nil, :new_record? => false, :updated_by_id_changed? => false, :updated_by_type_changed? => false)
-      record.should_not_receive(:created_by=)
-      @sweeper.before_validation(record)
-    end
-    
-    it "should NOT set created_by if attribute does not exist" do
-      record = mock('Record', :updated_by= => nil, :updated_by => nil, :new_record? => false, :updated_by_id_changed? => false, :updated_by_type_changed? => false)
-      record.should_not_receive(:created_by=)
-      @sweeper.before_validation(record)
-    end
-  end
-  
-  it "should set updated_by if attribute exists" do
-    record = mock('Record', :created_by= => nil, :updated_by= => nil, :updated_by => nil, :new_record? => :false, :created_by_id_changed? => false, :created_by_type_changed? => false, :updated_by_id_changed? => false, :updated_by_type_changed? => false)
-    record.should_receive(:updated_by=)
-    @sweeper.before_validation(record)
-  end
-  
-  it "should NOT set updated_by if attribute does not exist" do
-    record = mock('Record', :created_by= => nil, :updated_by= => nil, :new_record? => :false, :respond_to? => false)
-    record.should_receive(:respond_to?).with("updated_by=").and_return(false)
-    record.should_not_receive(:updated_by=)
-    @sweeper.before_validation(record)
-  end
-
-  it "should NOT set created_by if attribute changed" do
-    record = mock('Record', :created_by= => nil, :updated_by= => nil, :new_record? => true, :created_by_id_changed? => true, :created_by_type_changed? => true)
-    record.should_receive(:respond_to?).with("updated_by=").and_return(false)
-    record.should_receive(:respond_to?).with("created_by=").and_return(true)
-    record.should_not_receive(:created_by=)
-    @sweeper.before_validation(record)
-  end
-
-  it "should NOT set updated_by if attribute is not nil" do
-    record = mock('Record', :created_by= => nil, :updated_by= => nil, :updated_by => 1, :new_record? => false)
-    record.should_receive(:respond_to?).with("updated_by=").and_return(true)
-    record.should_receive(:respond_to?).with("created_by=").and_return(false)
-    record.should_not_receive(:updated_by=)
-    @sweeper.before_validation(record)
-  end
-
-  it "should set created_by if attribute has not changed" do
-    record = mock('Record', :created_by= => nil, :updated_by= => nil, :new_record? => true, :created_by_id_changed? => false, :created_by_type_changed? => false)
-    record.should_receive(:respond_to?).with("updated_by=").and_return(false)
-    record.should_receive(:respond_to?).with("created_by=").and_return(true)
-    record.should_receive(:created_by=)
-    @sweeper.before_validation(record)
-  end
-
-  it "should set updated_by if attribute is nil" do
-    record = mock('Record', :created_by= => nil, :updated_by= => nil, :updated_by => nil, :new_record? => false)
-    record.should_receive(:respond_to?).with("updated_by=").and_return(true)
-    record.should_receive(:respond_to?).with("created_by=").and_return(false)
-    record.should_receive(:updated_by=)
-    @sweeper.before_validation(record)
-  end
-end
-
-describe UserStampSweeper, "#current_user" do
-  before do
-    UserStamp.creator_attribute   = :creator
-    UserStamp.updater_attribute   = :updater
-    UserStamp.current_user_method = :current_user
-    @sweeper = UserStampSweeper.instance
-  end
-  
-  it "should send current_user if controller responds to it" do
-    user = mock('User')
-    controller = mock('Controller', :current_user => user)
-    @sweeper.stub!(:controller).and_return(controller)
-    controller.should_receive(:current_user)
-    @sweeper.send(:current_user)
-  end
-  
-  it "should not send current_user if controller does not respond to it" do
-    user = mock('User')
-    controller = mock('Controller', :respond_to? => false)
-    @sweeper.stub!(:controller).and_return(controller)
-    controller.should_not_receive(:current_user)
-    @sweeper.send(:current_user)
-  end
-end
-
-describe UserStampSweeper, "#current_user (with custom current_user_method)" do
-  before do
-    UserStamp.creator_attribute   = :creator
-    UserStamp.updater_attribute   = :updater
-    UserStamp.current_user_method = :my_user
-    @sweeper = UserStampSweeper.instance
-  end
-  
-  it "should send current_user if controller responds to it" do
-    user = mock('User')
-    controller = mock('Controller', :my_user => user)
-    @sweeper.stub!(:controller).and_return(controller)
-    controller.should_receive(:my_user)
-    @sweeper.send(:current_user)
-  end
-  
-  it "should not send current_user if controller does not respond to it" do
-    user = mock('User')
-    controller = mock('Controller', :respond_to? => false)
-    @sweeper.stub!(:controller).and_return(controller)
-    controller.should_not_receive(:my_user)
-    @sweeper.send(:current_user)
-  end
-end



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/608ddc9dfd943981559cdd26efc827c61d78f9c4...2827fff7c76aa180de0323ab2b99339fe4e71cf9
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150810/a776e5e9/attachment-0001.html>


More information about the Noosfero-dev mailing list