userstamp 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. data/Gemfile +9 -0
  2. data/Gemfile.lock +35 -0
  3. data/Rakefile +2 -2
  4. data/{README → Readme.rdoc} +27 -35
  5. data/VERSION +1 -1
  6. data/lib/stampable.rb +18 -15
  7. data/lib/userstamp.rb +4 -0
  8. data/rdoc/classes/Ddb/Userstamp.html +4 -4
  9. data/rdoc/classes/Ddb/Userstamp/Stampable/ClassMethods.html +41 -38
  10. data/rdoc/classes/Ddb/Userstamp/Stamper/InstanceMethods.html +1 -1
  11. data/rdoc/classes/Userstamp.html +118 -0
  12. data/rdoc/created.rid +1 -1
  13. data/rdoc/files/CHANGELOG.html +1 -1
  14. data/rdoc/files/LICENSE.html +1 -1
  15. data/rdoc/files/{README.html → Readme_rdoc.html} +62 -61
  16. data/rdoc/files/lib/migration_helper_rb.html +1 -1
  17. data/rdoc/files/lib/stampable_rb.html +1 -1
  18. data/rdoc/files/lib/stamper_rb.html +1 -1
  19. data/rdoc/files/lib/userstamp_rb.html +10 -1
  20. data/rdoc/fr_class_index.html +1 -0
  21. data/rdoc/fr_file_index.html +1 -1
  22. data/rdoc/index.html +1 -1
  23. data/test/compatibility_stamping_test.rb +29 -23
  24. data/test/helper.rb +61 -0
  25. data/test/models/comment.rb +1 -0
  26. data/test/models/foo.rb +3 -0
  27. data/test/models/post.rb +10 -1
  28. data/test/schema.rb +6 -8
  29. data/test/stamping_test.rb +45 -17
  30. data/test/userstamp_controller_test.rb +24 -39
  31. data/test/userstamp_test.rb +7 -0
  32. data/userstamp.gemspec +21 -24
  33. metadata +28 -24
  34. data/test/database.yml +0 -4
  35. data/test/fixtures/comments.yml +0 -16
  36. data/test/fixtures/people.yml +0 -11
  37. data/test/fixtures/posts.yml +0 -9
  38. data/test/fixtures/users.yml +0 -7
  39. data/test/helpers/functional_test_helper.rb +0 -37
  40. data/test/helpers/unit_test_helper.rb +0 -29
  41. data/test/models/ping.rb +0 -7
@@ -1 +1 @@
1
- Sat, 05 Apr 2008 15:11:35 -0600
1
+ Mon, 09 Aug 2010 20:57:24 +0200
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Sat Apr 05 11:41:29 -0600 2008</td>
59
+ <td>Fri Apr 30 22:27:47 +0200 2010</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Tue Mar 11 20:24:59 -0600 2008</td>
59
+ <td>Fri Apr 30 22:27:46 +0200 2010</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -5,7 +5,7 @@
5
5
 
6
6
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
7
  <head>
8
- <title>File: README</title>
8
+ <title>File: Readme.rdoc</title>
9
9
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
10
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
11
  <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
@@ -47,16 +47,16 @@
47
47
 
48
48
 
49
49
  <div id="fileHeader">
50
- <h1>README</h1>
50
+ <h1>Readme.rdoc</h1>
51
51
  <table class="header-table">
52
52
  <tr class="top-aligned-row">
53
53
  <td><strong>Path:</strong></td>
54
- <td>README
54
+ <td>Readme.rdoc
55
55
  </td>
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Sat Apr 05 15:01:24 -0600 2008</td>
59
+ <td>Mon Aug 09 20:56:23 +0200 2010</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -69,10 +69,12 @@
69
69
  <div id="contextContent">
70
70
 
71
71
  <div id="description">
72
- <h1>Userstamp Plugin (v 2.0)</h1>
72
+ <p>
73
+ <a href="../classes/Userstamp.html">Userstamp</a>
74
+ </p>
73
75
  <h2>Overview</h2>
74
76
  <p>
75
- The Userstamp Plugin extends <a
77
+ <a href="../classes/Userstamp.html">Userstamp</a> extends <a
76
78
  href="http://api.rubyonrails.com/classes/ActiveRecord/Base.html">ActiveRecord::Base</a>
77
79
  to add automatic updating of &#8216;creator&#8217;, &#8216;updater&#8217;,
78
80
  and &#8216;deleter&#8217; attributes. It is based loosely on the <a
@@ -87,46 +89,35 @@ objects. The <tt>stampable</tt> method is used in models that are subject
87
89
  to being created, updated, or deleted by &#8216;stampers&#8217;.
88
90
  </p>
89
91
  <h2>Installation</h2>
90
- <p>
91
- Installation of the plugin can be done using the built in Rails plugin
92
- script. Issue the following command from the root of your application:
93
- </p>
94
92
  <pre>
95
- script/plugin install git://github.com/delynn/userstamp.git
93
+ - As Rails plugin: `script/plugin install git://github.com/delynn/userstamp.git `
94
+ - As gem: ` sudo gem install userstamp `
96
95
  </pre>
97
- <p>
98
- Once installed you will need to restart your application for the plugin to
99
- be loaded into the Rails environment.
100
- </p>
101
- <p>
102
- You might also be interested in using <a
103
- href="http://piston.rubyforge.org/index.html">Piston</a> to manage the
104
- importing and future updating of this plugin.
105
- </p>
106
96
  <h2>Usage</h2>
107
97
  <p>
108
- In this new version of the Userstamp plug-in, the assumption is that you
109
- have two different categories of objects; those that mani˝pulate, and
110
- those that are manipulated. For those objects that are being manipulated
111
- there&#8216;s the Stampable module and for the manipulators there&#8216;s
112
- the Stamper module. There&#8216;s also the actual Userstamp module for your
98
+ The assumption is that you have two different categories of objects; those
99
+ that manipulate, and those that are manipulated. For those objects that are
100
+ being manipulated there&#8216;s the Stampable module and for the
101
+ manipulators there&#8216;s the Stamper module. There&#8216;s also the
102
+ actual <a href="../classes/Userstamp.html">Userstamp</a> module for your
113
103
  controllers that assists in setting up your environment on a per request
114
104
  basis.
115
105
  </p>
106
+ <h3>Example</h3>
116
107
  <p>
117
- To better understand how all this works, I think an example is in order.
118
- For this example we will assume that a weblog application is comprised of
119
- User and Post objects. The first thing we need to do is create the
120
- migrations for these objects, and the plug-in gives you a
121
- <tt>userstamps</tt> method for very easily doing this:
108
+ Assume a weblog application has User and Post objects.
122
109
  </p>
110
+ <ol>
111
+ <li>Create the migrations for these objects
112
+
113
+ </li>
114
+ </ol>
123
115
  <pre>
124
116
  class CreateUsers &lt; ActiveRecord::Migration
125
117
  def self.up
126
118
  create_table :users, :force =&gt; true do |t|
127
- t.timestamps
128
- t.userstamps
129
- t.name
119
+ ...
120
+ t.userstamps # use t.userstamps(true) if you also want 'deleter_id'
130
121
  end
131
122
  end
132
123
 
@@ -138,9 +129,8 @@ migrations for these objects, and the plug-in gives you a
138
129
  class CreatePosts &lt; ActiveRecord::Migration
139
130
  def self.up
140
131
  create_table :posts, :force =&gt; true do |t|
141
- t.timestamps
142
- t.userstamps
143
- t.title
132
+ ...
133
+ t.userstamps # use t.userstamps(true) if you also want 'deleter_id'
144
134
  end
145
135
  end
146
136
 
@@ -149,19 +139,26 @@ migrations for these objects, and the plug-in gives you a
149
139
  end
150
140
  end
151
141
  </pre>
142
+ <ol>
143
+ <li>Users are going to manipulate Post&#8216;s, use the
144
+
145
+ </li>
146
+ </ol>
152
147
  <p>
153
- Second, since Users are going to manipulate other objects in our project,
154
- we&#8216;ll use the <tt>model_stamper</tt> method in our User class:
148
+ <tt>model_stamper</tt>:
155
149
  </p>
156
150
  <pre>
157
151
  class User &lt; ActiveRecord::Base
158
152
  model_stamper
159
153
  end
160
154
  </pre>
155
+ <ol>
156
+ <li>Setup a controller to set the current user of the application. It&#8216;s
157
+
158
+ </li>
159
+ </ol>
161
160
  <p>
162
- Finally, we need to setup a controller to set the current user of the
163
- application. It&#8216;s recommended that you do this in your
164
- ApplicationController:
161
+ recommended that you do this in your ApplicationController:
165
162
  </p>
166
163
  <pre>
167
164
  class ApplicationController &lt; ActionController::Base
@@ -207,19 +204,15 @@ look like this:
207
204
  end
208
205
  </pre>
209
206
  <p>
210
- The big change with this new version is that we are now using
211
- Thread.current to save the current stamper so as to avoid conflict with
212
- concurrent requests.
213
- </p>
214
- <p>
215
207
  The <tt>stampable</tt> method allows you to customize what columns will get
216
208
  stamped, and also creates the <tt>creator</tt>, <tt>updater</tt>, and
217
209
  <tt>deleter</tt> associations.
218
210
  </p>
219
211
  <p>
220
- The Userstamp module that we included into our ApplicationController uses
221
- the setter method to set which user is currently making the request. By
222
- default the &#8216;set_stampers&#8217; method works perfectly with the <a
212
+ The <a href="../classes/Userstamp.html">Userstamp</a> module that we
213
+ included into our ApplicationController uses the setter method to set which
214
+ user is currently making the request. By default the
215
+ &#8216;set_stampers&#8217; method works perfectly with the <a
223
216
  href="http://svn.techno-weenie.net/projects/plugins/restful_authentication">RestfulAuthentication</a>
224
217
  plug-in:
225
218
  </p>
@@ -231,7 +224,8 @@ plug-in:
231
224
  <p>
232
225
  If you aren&#8216;t using ActsAsAuthenticated, then you need to create your
233
226
  own version of the <tt>set_stampers</tt> method in the controller where
234
- you&#8216;ve included the Userstamp module.
227
+ you&#8216;ve included the <a href="../classes/Userstamp.html">Userstamp</a>
228
+ module.
235
229
  </p>
236
230
  <p>
237
231
  Now, let&#8216;s get back to the Stampable module (since it really is the
@@ -246,25 +240,27 @@ quick example:
246
240
  </p>
247
241
  <pre>
248
242
  class Post &lt; ActiveRecord::Base
249
- acts_as_stampable :stamper_class_name =&gt; :person,
250
- :creator_attribute =&gt; :create_user,
251
- :updater_attribute =&gt; :update_user,
252
- :deleter_attribute =&gt; :delete_user
243
+ stampable :stamper_class_name =&gt; :person,
244
+ :creator_attribute =&gt; :create_user,
245
+ :updater_attribute =&gt; :update_user,
246
+ :deleter_attribute =&gt; :delete_user
253
247
  end
254
248
  </pre>
255
249
  <p>
256
- If you are upgrading your application from the old version of Userstamp,
257
- there is a compatibility mode to have the plug-in use the old
258
- &quot;_by&quot; columns by default. To enable this mode, add the following
259
- line to the RAILS_ROOT/config/environment.rb file:
250
+ If you are upgrading your application from the old version of <a
251
+ href="../classes/Userstamp.html">Userstamp</a>, there is a compatibility
252
+ mode to have the plug-in use the old &quot;_by&quot; columns by default. To
253
+ enable this mode, add the following line to the
254
+ RAILS_ROOT/config/environment.rb file:
260
255
  </p>
261
256
  <pre>
262
257
  Ddb::Userstamp.compatibility_mode = true
263
258
  </pre>
264
259
  <p>
265
- If you are having a difficult time getting the Userstamp plug-in to work, I
266
- recommend you checkout the sample application that I created. You can find
267
- this application on <a
260
+ If you are having a difficult time getting the <a
261
+ href="../classes/Userstamp.html">Userstamp</a> plug-in to work, I recommend
262
+ you checkout the sample application that I created. You can find this
263
+ application on <a
268
264
  href="http://github.com/delynn/userstamp_sample">GitHub</a>
269
265
  </p>
270
266
  <h2>Uninstall</h2>
@@ -306,6 +302,11 @@ The original idea for this plugin came from the Rails Wiki article entitled
306
302
  href="http://wiki.rubyonrails.com/rails/pages/ExtendingActiveRecordExample">Extending
307
303
  ActiveRecord</a>.
308
304
  </p>
305
+ <h2>Contributors / maintenance / enhancement</h2>
306
+ <pre>
307
+ - {Michael Grosser}[http://pragmatig.com]
308
+ - {John Dell}[http://blog.spovich.com/]
309
+ </pre>
309
310
 
310
311
  </div>
311
312
 
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Sat Apr 05 11:37:18 -0600 2008</td>
59
+ <td>Mon Aug 09 20:17:35 +0200 2010</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Sat Apr 05 14:16:35 -0600 2008</td>
59
+ <td>Mon Aug 09 20:36:07 +0200 2010</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Sat Apr 05 14:16:03 -0600 2008</td>
59
+ <td>Mon Aug 09 20:17:35 +0200 2010</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Sat Apr 05 14:57:26 -0600 2008</td>
59
+ <td>Mon Aug 09 20:18:00 +0200 2010</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -69,6 +69,15 @@
69
69
  <div id="contextContent">
70
70
 
71
71
 
72
+ <div id="requires-list">
73
+ <h3 class="section-bar">Required files</h3>
74
+
75
+ <div class="name-list">
76
+ stamper&nbsp;&nbsp;
77
+ stampable&nbsp;&nbsp;
78
+ migration_helper&nbsp;&nbsp;
79
+ </div>
80
+ </div>
72
81
 
73
82
  </div>
74
83
 
@@ -31,6 +31,7 @@
31
31
  <a href="classes/Ddb/Userstamp/Stamper.html">Ddb::Userstamp::Stamper</a><br />
32
32
  <a href="classes/Ddb/Userstamp/Stamper/ClassMethods.html">Ddb::Userstamp::Stamper::ClassMethods</a><br />
33
33
  <a href="classes/Ddb/Userstamp/Stamper/InstanceMethods.html">Ddb::Userstamp::Stamper::InstanceMethods</a><br />
34
+ <a href="classes/Userstamp.html">Userstamp</a><br />
34
35
  </div>
35
36
  </div>
36
37
  </body>
@@ -22,7 +22,7 @@
22
22
  <div id="index-entries">
23
23
  <a href="files/CHANGELOG.html">CHANGELOG</a><br />
24
24
  <a href="files/LICENSE.html">LICENSE</a><br />
25
- <a href="files/README.html">README</a><br />
25
+ <a href="files/Readme_rdoc.html">Readme.rdoc</a><br />
26
26
  <a href="files/lib/migration_helper_rb.html">lib/migration_helper.rb</a><br />
27
27
  <a href="files/lib/stampable_rb.html">lib/stampable.rb</a><br />
28
28
  <a href="files/lib/stamper_rb.html">lib/stamper.rb</a><br />
@@ -19,6 +19,6 @@
19
19
  <frame src="fr_class_index.html" name="Classes" />
20
20
  <frame src="fr_method_index.html" name="Methods" />
21
21
  </frameset>
22
- <frame src="files/README.html" name="docwin" />
22
+ <frame src="files/Readme_rdoc.html" name="docwin" />
23
23
  </frameset>
24
24
  </html>
@@ -1,32 +1,28 @@
1
- $:.unshift(File.dirname(__FILE__))
2
-
3
- require 'helpers/unit_test_helper'
4
- Ddb::Userstamp.compatibility_mode = true
5
- require 'models/user'
6
- require 'models/person'
7
- require 'models/post'
8
- require 'models/comment'
9
-
10
- class CompatibilityStampingTests< Test::Unit::TestCase # :nodoc:
11
- fixtures :people, :comments
1
+ require 'test/helper'
12
2
 
3
+ class CompatibilityStampingTests < Test::Unit::TestCase # :nodoc:
13
4
  def setup
14
- Person.stamper = @delynn
5
+ create_test_models
6
+ Ddb::Userstamp.compatibility_mode = true
7
+ require 'test/models/comment'
8
+ Comment.delete_all
9
+ @first_comment = Comment.create!(:comment => 'a comment', :post => @first_post)
15
10
  end
16
11
 
17
- def test_comment_creation_with_stamped_object
18
- assert_equal @delynn.id, Person.stamper
12
+ def test_comment_creation_with_stamped_integer
13
+ Person.stamper = @nicole.id
14
+ assert_equal @nicole.id, Person.stamper
19
15
 
20
- comment = Comment.create(:comment => "Test Comment")
21
- assert_equal @delynn.id, comment.created_by
22
- assert_equal @delynn.id, comment.updated_by
23
- assert_equal @delynn, comment.creator
24
- assert_equal @delynn, comment.updater
16
+ comment = Comment.create(:comment => "Test Comment - 2")
17
+ assert_equal @nicole.id, comment.created_by
18
+ assert_equal @nicole.id, comment.updated_by
19
+ assert_equal @nicole, comment.creator
20
+ assert_equal @nicole, comment.updater
25
21
  end
26
22
 
27
23
  def test_comment_creation_with_stamped_integer
28
- Person.stamper = 2
29
- assert_equal 2, Person.stamper
24
+ Person.stamper = @nicole.id
25
+ assert_equal @nicole.id, Person.stamper
30
26
 
31
27
  comment = Comment.create(:comment => "Test Comment - 2")
32
28
  assert_equal @nicole.id, comment.created_by
@@ -34,6 +30,16 @@ class CompatibilityStampingTests< Test::Unit::TestCase # :nodoc:
34
30
  assert_equal @nicole, comment.creator
35
31
  assert_equal @nicole, comment.updater
36
32
  end
33
+
34
+ def test_comment_creation_with_stamped_object
35
+ assert_equal @delynn.id, Person.stamper
36
+
37
+ comment = Comment.create(:comment => "Test Comment")
38
+ assert_equal @delynn.id, comment.created_by
39
+ assert_equal @delynn.id, comment.updated_by
40
+ assert_equal @delynn, comment.creator
41
+ assert_equal @delynn, comment.updater
42
+ end
37
43
 
38
44
  def test_comment_updating_with_stamped_object
39
45
  Person.stamper = @nicole
@@ -49,8 +55,8 @@ class CompatibilityStampingTests< Test::Unit::TestCase # :nodoc:
49
55
  end
50
56
 
51
57
  def test_comment_updating_with_stamped_integer
52
- Person.stamper = 2
53
- assert_equal 2, Person.stamper
58
+ Person.stamper = @nicole.id
59
+ assert_equal @nicole.id, Person.stamper
54
60
 
55
61
  @first_comment.comment << " - Updated"
56
62
  @first_comment.save
@@ -0,0 +1,61 @@
1
+ require 'rubygems'
2
+
3
+ $LOAD_PATH.unshift('lib')
4
+
5
+ # load normal stuff
6
+ require 'active_support'
7
+ require 'active_record'
8
+ require 'action_controller'
9
+ require 'init'
10
+
11
+ # connect to db
12
+ ActiveRecord::Base.establish_connection({
13
+ :adapter => "sqlite3",
14
+ :database => ":memory:",
15
+ })
16
+ require 'test/schema'
17
+
18
+ # load test framework
19
+ require 'test/unit'
20
+ begin
21
+ require 'redgreen'
22
+ rescue LoadError
23
+ end
24
+ require 'active_support/test_case'
25
+ require 'action_controller/test_case'
26
+ require 'action_controller/test_process'
27
+ require 'action_controller/integration'
28
+
29
+ # load test models/controllers
30
+ require 'test/controllers/userstamp_controller'
31
+ require 'test/controllers/users_controller'
32
+ require 'test/controllers/posts_controller'
33
+ require 'test/models/user'
34
+ require 'test/models/person'
35
+ require 'test/models/post'
36
+ require 'test/models/foo'
37
+
38
+ ActionController::Routing::Routes.draw do |map|
39
+ map.connect ':controller/:action/:id'
40
+ end
41
+
42
+ def reset_to_defaults
43
+ Ddb::Userstamp.compatibility_mode = false
44
+ create_test_models
45
+ end
46
+
47
+ def create_test_models
48
+ User.delete_all
49
+ Person.delete_all
50
+ Post.delete_all
51
+
52
+ @zeus = User.create!(:name => 'Zeus')
53
+ @hera = User.create!(:name => 'Hera')
54
+ User.stamper = @zeus.id
55
+
56
+ @delynn = Person.create!(:name => 'Delynn')
57
+ @nicole = Person.create!(:name => 'Nicole')
58
+ Person.stamper = @delynn.id
59
+
60
+ @first_post = Post.create!(:title => 'a title')
61
+ end