public
Description: This Rails plugin extends ActiveRecord::Base to add automatic updating of created_by and updated_by attributes of your models in much the same way that the ActiveRecord::Timestamp module updates created_(at/on) and updated_(at/on) attributes.
Clone URL: git://github.com/delynn/userstamp.git
Search Repo:
Decided to not use AR#find in the stamper method as it could cause strange 
behavior. Thanks to Aaron Eisenberger for pointing this out.
delynn (author)
Wed Apr 16 20:04:09 -0700 2008
commit  210dad9ad56f80fd2eee4959578687755c4afdd2
tree    8ac76e51641af1581061303989926533efb44507
parent  6218f5b63098902d4950eb2d1848ef44c174c918
...
89
90
91
92
 
93
94
95
...
118
119
120
121
 
122
123
124
125
126
127
 
128
129
130
131
132
133
134
 
135
136
137
138
139
140
141
 
142
143
144
...
89
90
91
 
92
93
94
95
...
118
119
120
 
121
122
123
124
125
126
 
127
128
129
130
131
132
133
 
134
135
136
137
138
139
140
 
141
142
143
144
0
@@ -89,7 +89,7 @@ module Ddb #:nodoc:
0
             before_create :set_creator_attribute
0
                                  
0
             if defined?(Caboose::Acts::Paranoid)
0
- belongs_to :deleter, :class_name => self.stamper_class_name,
0
+ belongs_to :deleter, :class_name => self.stamper_class_name.to_s.singularize.camelize,
0
                                    :foreign_key => self.deleter_attribute
0
               before_destroy :set_deleter_attribute
0
             end
0
@@ -118,27 +118,27 @@ module Ddb #:nodoc:
0
       module InstanceMethods #:nodoc:
0
         private
0
           def has_stamper?
0
- !self.class.stamper_class.nil? && !self.class.stamper_class.stamper.nil?
0
+ !self.class.stamper_class.nil? && !self.class.stamper_class.stamper.nil? rescue false
0
           end
0
 
0
           def set_creator_attribute
0
             return unless self.record_userstamp
0
             if respond_to?(self.creator_attribute.to_sym) && has_stamper?
0
- self.creator = self.class.stamper_class.stamper
0
+ self.send("#{self.creator_attribute}=".to_sym, self.class.stamper_class.stamper)
0
             end
0
           end
0
 
0
           def set_updater_attribute
0
             return unless self.record_userstamp
0
             if respond_to?(self.updater_attribute.to_sym) && has_stamper?
0
- self.updater = self.class.stamper_class.stamper
0
+ self.send("#{self.updater_attribute}=".to_sym, self.class.stamper_class.stamper)
0
             end
0
           end
0
 
0
           def set_deleter_attribute
0
             return unless self.record_userstamp
0
             if respond_to?(self.deleter_attribute.to_sym) && has_stamper?
0
- self.deleter = self.class.stamper_class.stamper
0
+ self.send("#{self.deleter_attribute}=".to_sym, self.class.stamper_class.stamper)
0
               save
0
             end
0
           end
...
28
29
30
31
 
32
33
34
...
28
29
30
 
31
32
33
34
0
@@ -28,7 +28,7 @@ module Ddb #:nodoc:
0
 
0
         # Retrieves the existing stamper for the current request.
0
         def stamper
0
- find(Thread.current["#{self.to_s.downcase}_#{self.object_id}_stamper"])
0
+ Thread.current["#{self.to_s.downcase}_#{self.object_id}_stamper"]
0
         end
0
 
0
         # Sets the stamper back to +nil+ to prepare for the next request.
...
15
16
17
18
 
19
20
21
...
26
27
28
29
 
30
31
32
...
37
38
39
40
 
41
42
43
...
50
51
52
53
 
54
55
56
...
15
16
17
 
18
19
20
21
...
26
27
28
 
29
30
31
32
...
37
38
39
 
40
41
42
43
...
50
51
52
 
53
54
55
56
0
@@ -15,7 +15,7 @@ class CompatibilityStampingTests< Test::Unit::TestCase # :nodoc:
0
   end
0
 
0
   def test_comment_creation_with_stamped_object
0
- assert_equal @delynn, Person.stamper
0
+ assert_equal @delynn.id, Person.stamper
0
 
0
     comment = Comment.create(:comment => "Test Comment")
0
     assert_equal @delynn.id, comment.created_by
0
@@ -26,7 +26,7 @@ class CompatibilityStampingTests< Test::Unit::TestCase # :nodoc:
0
 
0
   def test_comment_creation_with_stamped_integer
0
     Person.stamper = 2
0
- assert_equal 2, Person.stamper.id
0
+ assert_equal 2, Person.stamper
0
 
0
     comment = Comment.create(:comment => "Test Comment - 2")
0
     assert_equal @nicole.id, comment.created_by
0
@@ -37,7 +37,7 @@ class CompatibilityStampingTests< Test::Unit::TestCase # :nodoc:
0
   
0
   def test_comment_updating_with_stamped_object
0
     Person.stamper = @nicole
0
- assert_equal @nicole, Person.stamper
0
+ assert_equal @nicole.id, Person.stamper
0
 
0
     @first_comment.comment << " - Updated"
0
     @first_comment.save
0
@@ -50,7 +50,7 @@ class CompatibilityStampingTests< Test::Unit::TestCase # :nodoc:
0
 
0
   def test_comment_updating_with_stamped_integer
0
     Person.stamper = 2
0
- assert_equal 2, Person.stamper.id
0
+ assert_equal 2, Person.stamper
0
 
0
     @first_comment.comment << " - Updated"
0
     @first_comment.save
...
1
2
 
3
4
5
...
1
 
2
3
4
5
0
@@ -1,5 +1,5 @@
0
 class UserstampController < ActionController::Base
0
- include Userstamp
0
+ include Ddb::Controller::Userstamp
0
 
0
   protected
0
     def current_user
...
15
16
17
18
 
19
20
21
...
26
27
28
29
 
30
31
32
...
36
37
38
39
 
40
41
42
...
47
48
49
50
 
51
52
53
...
58
59
60
61
 
62
63
64
...
71
72
73
74
 
75
76
77
...
84
85
86
87
 
88
89
90
...
97
98
99
100
 
101
102
103
...
15
16
17
 
18
19
20
21
...
26
27
28
 
29
30
31
32
...
36
37
38
 
39
40
41
42
...
47
48
49
 
50
51
52
53
...
58
59
60
 
61
62
63
64
...
71
72
73
 
74
75
76
77
...
84
85
86
 
87
88
89
90
...
97
98
99
 
100
101
102
103
0
@@ -15,7 +15,7 @@ class StampingTests < Test::Unit::TestCase # :nodoc:
0
   end
0
 
0
   def test_person_creation_with_stamped_object
0
- assert_equal @zeus, User.stamper
0
+ assert_equal @zeus.id, User.stamper
0
     
0
     person = Person.create(:name => "David")
0
     assert_equal @zeus.id, person.creator_id
0
@@ -26,7 +26,7 @@ class StampingTests < Test::Unit::TestCase # :nodoc:
0
 
0
   def test_person_creation_with_stamped_integer
0
     User.stamper = 2
0
- assert_equal 2, User.stamper.id
0
+ assert_equal 2, User.stamper
0
 
0
     person = Person.create(:name => "Daniel")
0
     assert_equal @hera.id, person.creator_id
0
@@ -36,7 +36,7 @@ class StampingTests < Test::Unit::TestCase # :nodoc:
0
   end
0
 
0
   def test_post_creation_with_stamped_object
0
- assert_equal @delynn, Person.stamper
0
+ assert_equal @delynn.id, Person.stamper
0
 
0
     post = Post.create(:title => "Test Post - 1")
0
     assert_equal @delynn.id, post.creator_id
0
@@ -47,7 +47,7 @@ class StampingTests < Test::Unit::TestCase # :nodoc:
0
 
0
   def test_post_creation_with_stamped_integer
0
     Person.stamper = 2
0
- assert_equal 2, Person.stamper.id
0
+ assert_equal 2, Person.stamper
0
 
0
     post = Post.create(:title => "Test Post - 2")
0
     assert_equal @nicole.id, post.creator_id
0
@@ -58,7 +58,7 @@ class StampingTests < Test::Unit::TestCase # :nodoc:
0
 
0
   def test_person_updating_with_stamped_object
0
     User.stamper = @hera
0
- assert_equal @hera, User.stamper
0
+ assert_equal @hera.id, User.stamper
0
 
0
     @delynn.name << " Berry"
0
     @delynn.save
0
@@ -71,7 +71,7 @@ class StampingTests < Test::Unit::TestCase # :nodoc:
0
 
0
   def test_person_updating_with_stamped_integer
0
     User.stamper = 2
0
- assert_equal 2, User.stamper.id
0
+ assert_equal 2, User.stamper
0
 
0
     @delynn.name << " Berry"
0
     @delynn.save
0
@@ -84,7 +84,7 @@ class StampingTests < Test::Unit::TestCase # :nodoc:
0
 
0
   def test_post_updating_with_stamped_object
0
     Person.stamper = @nicole
0
- assert_equal @nicole, Person.stamper
0
+ assert_equal @nicole.id, Person.stamper
0
 
0
     @first_post.title << " - Updated"
0
     @first_post.save
0
@@ -97,7 +97,7 @@ class StampingTests < Test::Unit::TestCase # :nodoc:
0
 
0
   def test_post_updating_with_stamped_integer
0
     Person.stamper = 2
0
- assert_equal 2, Person.stamper.id
0
+ assert_equal 2, Person.stamper
0
 
0
     @first_post.title << " - Updated"
0
     @first_post.save

Comments

    No one has commented yet.