diff --git a/config/initializers/action_tracker.rb b/config/initializers/action_tracker.rb index 7ef594a..6508e41 100644 --- 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 diff --git a/test/action_tracker_test_helper.rb b/test/action_tracker_test_helper.rb index bc6fea3..5d160df 100644 --- 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 diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index 5f4a779..0d09c6d 100644 --- 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@localhost.localdomain', :title => 'Test Comment', :body => 'My author does not exist =(', :source_id => article.id, :source_type => 'Article') diff --git a/test/test_helper.rb b/test/test_helper.rb index 96366a5..40e066e 100644 --- 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) diff --git a/test/unit/action_tracker_notification_test.rb b/test/unit/action_tracker_notification_test.rb index 99eec0d..d386d36 100644 --- 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 diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 68ae33f..4dd29f7 100644 --- 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 diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 802045a..f4e4cf7 100644 --- 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) diff --git a/test/unit/community_test.rb b/test/unit/community_test.rb index c5b10bd..7c2fc9e 100644 --- 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 diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb index 04a549a..e2d7153 100644 --- 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 diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index a2cb697..4f29fbd 100644 --- 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 diff --git a/test/unit/textile_article_test.rb b/test/unit/textile_article_test.rb index 86fc884..6dd6c2a 100644 --- 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? diff --git a/test/unit/uploaded_file_test.rb b/test/unit/uploaded_file_test.rb index b7e7526..63b755f 100644 --- 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) diff --git a/vendor/plugins/action_tracker/init.rb b/vendor/plugins/action_tracker/init.rb index d875352..9496439 100644 --- 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" diff --git a/vendor/plugins/action_tracker/lib/action_tracker.rb b/vendor/plugins/action_tracker/lib/action_tracker.rb index 5d4ff67..932776c 100644 --- 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 diff --git a/vendor/plugins/action_tracker/lib/action_tracker_config.rb b/vendor/plugins/action_tracker/lib/action_tracker_config.rb index 82aa930..24aa822 100644 --- 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 diff --git a/vendor/plugins/action_tracker/lib/action_tracker_model.rb b/vendor/plugins/action_tracker/lib/action_tracker_model.rb index 66f50b7..1c31e9b 100644 --- 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) diff --git a/vendor/plugins/action_tracker/test/action_tracker_config_test.rb b/vendor/plugins/action_tracker/test/action_tracker_config_test.rb index fffda80..d532e1a 100755 --- 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] diff --git a/vendor/plugins/action_tracker/test/action_tracker_test.rb b/vendor/plugins/action_tracker/test/action_tracker_test.rb index 084bb85..d06d1d9 100644 --- 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 diff --git a/vendor/plugins/user_stamp/MIT-LICENSE b/vendor/plugins/user_stamp/MIT-LICENSE deleted file mode 100644 index f5eca46..0000000 --- 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. diff --git a/vendor/plugins/user_stamp/README b/vendor/plugins/user_stamp/README deleted file mode 100644 index 3f512d6..0000000 --- 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 diff --git a/vendor/plugins/user_stamp/Rakefile b/vendor/plugins/user_stamp/Rakefile deleted file mode 100644 index cf2dd88..0000000 --- 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 diff --git a/vendor/plugins/user_stamp/init.rb b/vendor/plugins/user_stamp/init.rb deleted file mode 100644 index 18d0ac4..0000000 --- a/vendor/plugins/user_stamp/init.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'user_stamp' - -class ActionController::Base - extend UserStamp::ClassMethods -end diff --git a/vendor/plugins/user_stamp/install.rb b/vendor/plugins/user_stamp/install.rb deleted file mode 100644 index d562416..0000000 --- a/vendor/plugins/user_stamp/install.rb +++ /dev/null @@ -1,15 +0,0 @@ -instructions = < 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 -- libgit2 0.21.2