userstamp 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +9 -0
- data/Gemfile.lock +35 -0
- data/Rakefile +2 -2
- data/{README → Readme.rdoc} +27 -35
- data/VERSION +1 -1
- data/lib/stampable.rb +18 -15
- data/lib/userstamp.rb +4 -0
- data/rdoc/classes/Ddb/Userstamp.html +4 -4
- data/rdoc/classes/Ddb/Userstamp/Stampable/ClassMethods.html +41 -38
- data/rdoc/classes/Ddb/Userstamp/Stamper/InstanceMethods.html +1 -1
- data/rdoc/classes/Userstamp.html +118 -0
- data/rdoc/created.rid +1 -1
- data/rdoc/files/CHANGELOG.html +1 -1
- data/rdoc/files/LICENSE.html +1 -1
- data/rdoc/files/{README.html → Readme_rdoc.html} +62 -61
- data/rdoc/files/lib/migration_helper_rb.html +1 -1
- data/rdoc/files/lib/stampable_rb.html +1 -1
- data/rdoc/files/lib/stamper_rb.html +1 -1
- data/rdoc/files/lib/userstamp_rb.html +10 -1
- data/rdoc/fr_class_index.html +1 -0
- data/rdoc/fr_file_index.html +1 -1
- data/rdoc/index.html +1 -1
- data/test/compatibility_stamping_test.rb +29 -23
- data/test/helper.rb +61 -0
- data/test/models/comment.rb +1 -0
- data/test/models/foo.rb +3 -0
- data/test/models/post.rb +10 -1
- data/test/schema.rb +6 -8
- data/test/stamping_test.rb +45 -17
- data/test/userstamp_controller_test.rb +24 -39
- data/test/userstamp_test.rb +7 -0
- data/userstamp.gemspec +21 -24
- metadata +28 -24
- data/test/database.yml +0 -4
- data/test/fixtures/comments.yml +0 -16
- data/test/fixtures/people.yml +0 -11
- data/test/fixtures/posts.yml +0 -9
- data/test/fixtures/users.yml +0 -7
- data/test/helpers/functional_test_helper.rb +0 -37
- data/test/helpers/unit_test_helper.rb +0 -29
- data/test/models/ping.rb +0 -7
data/rdoc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Mon, 09 Aug 2010 20:57:24 +0200
|
data/rdoc/files/CHANGELOG.html
CHANGED
data/rdoc/files/LICENSE.html
CHANGED
@@ -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:
|
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>
|
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>
|
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>
|
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
|
-
<
|
72
|
+
<p>
|
73
|
+
<a href="../classes/Userstamp.html">Userstamp</a>
|
74
|
+
</p>
|
73
75
|
<h2>Overview</h2>
|
74
76
|
<p>
|
75
|
-
|
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 ‘creator’, ‘updater’,
|
78
80
|
and ‘deleter’ 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 ‘stampers’.
|
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
|
-
|
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
|
-
|
109
|
-
|
110
|
-
|
111
|
-
there‘s the
|
112
|
-
|
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‘s the Stampable module and for the
|
101
|
+
manipulators there‘s the Stamper module. There‘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
|
-
|
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 < ActiveRecord::Migration
|
125
117
|
def self.up
|
126
118
|
create_table :users, :force => true do |t|
|
127
|
-
|
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 < ActiveRecord::Migration
|
139
130
|
def self.up
|
140
131
|
create_table :posts, :force => true do |t|
|
141
|
-
|
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‘s, use the
|
144
|
+
|
145
|
+
</li>
|
146
|
+
</ol>
|
152
147
|
<p>
|
153
|
-
|
154
|
-
we‘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 < 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‘s
|
157
|
+
|
158
|
+
</li>
|
159
|
+
</ol>
|
161
160
|
<p>
|
162
|
-
|
163
|
-
application. It‘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 < 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
|
221
|
-
the setter method to set which
|
222
|
-
|
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
|
+
‘set_stampers’ 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‘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‘ve included the Userstamp
|
227
|
+
you‘ve included the <a href="../classes/Userstamp.html">Userstamp</a>
|
228
|
+
module.
|
235
229
|
</p>
|
236
230
|
<p>
|
237
231
|
Now, let‘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 < ActiveRecord::Base
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
243
|
+
stampable :stamper_class_name => :person,
|
244
|
+
:creator_attribute => :create_user,
|
245
|
+
:updater_attribute => :update_user,
|
246
|
+
:deleter_attribute => :delete_user
|
253
247
|
end
|
254
248
|
</pre>
|
255
249
|
<p>
|
256
|
-
If you are upgrading your application from the old version of
|
257
|
-
there is a compatibility
|
258
|
-
"_by" columns by default. To
|
259
|
-
line to the
|
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 "_by" 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
|
266
|
-
|
267
|
-
|
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>
|
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
|
77
|
+
stampable
|
78
|
+
migration_helper
|
79
|
+
</div>
|
80
|
+
</div>
|
72
81
|
|
73
82
|
</div>
|
74
83
|
|
data/rdoc/fr_class_index.html
CHANGED
@@ -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>
|
data/rdoc/fr_file_index.html
CHANGED
@@ -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/
|
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 />
|
data/rdoc/index.html
CHANGED
@@ -1,32 +1,28 @@
|
|
1
|
-
|
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
|
-
|
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
|
18
|
-
|
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 @
|
22
|
-
assert_equal @
|
23
|
-
assert_equal @
|
24
|
-
assert_equal @
|
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 =
|
29
|
-
assert_equal
|
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 =
|
53
|
-
assert_equal
|
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
|
data/test/helper.rb
ADDED
@@ -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
|