magic_userstamp 0.1.0

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 (65) hide show
  1. data/.gitignore +5 -0
  2. data/CHANGELOG +26 -0
  3. data/LICENSE +20 -0
  4. data/README.original +179 -0
  5. data/README.rdoc +64 -0
  6. data/Rakefile +45 -0
  7. data/VERSION +1 -0
  8. data/init.rb +12 -0
  9. data/lib/userstamp/config.rb +119 -0
  10. data/lib/userstamp/controller.rb +43 -0
  11. data/lib/userstamp/event.rb +63 -0
  12. data/lib/userstamp/magic_columns.rb +49 -0
  13. data/lib/userstamp/migration_helper.rb +17 -0
  14. data/lib/userstamp/stampable.rb +147 -0
  15. data/lib/userstamp/stamper.rb +41 -0
  16. data/lib/userstamp.rb +17 -0
  17. data/magic_userstamp.gemspec +124 -0
  18. data/rdoc/classes/Ddb/Controller/Userstamp/InstanceMethods.html +105 -0
  19. data/rdoc/classes/Ddb/Controller/Userstamp.html +125 -0
  20. data/rdoc/classes/Ddb/Controller.html +111 -0
  21. data/rdoc/classes/Ddb/Userstamp/MigrationHelper/InstanceMethods.html +142 -0
  22. data/rdoc/classes/Ddb/Userstamp/MigrationHelper.html +111 -0
  23. data/rdoc/classes/Ddb/Userstamp/Stampable/ClassMethods.html +222 -0
  24. data/rdoc/classes/Ddb/Userstamp/Stampable.html +128 -0
  25. data/rdoc/classes/Ddb/Userstamp/Stamper/ClassMethods.html +142 -0
  26. data/rdoc/classes/Ddb/Userstamp/Stamper/InstanceMethods.html +207 -0
  27. data/rdoc/classes/Ddb/Userstamp/Stamper.html +112 -0
  28. data/rdoc/classes/Ddb/Userstamp.html +121 -0
  29. data/rdoc/created.rid +1 -0
  30. data/rdoc/files/CHANGELOG.html +137 -0
  31. data/rdoc/files/LICENSE.html +129 -0
  32. data/rdoc/files/README.html +341 -0
  33. data/rdoc/files/lib/migration_helper_rb.html +101 -0
  34. data/rdoc/files/lib/stampable_rb.html +101 -0
  35. data/rdoc/files/lib/stamper_rb.html +101 -0
  36. data/rdoc/files/lib/userstamp_rb.html +101 -0
  37. data/rdoc/fr_class_index.html +37 -0
  38. data/rdoc/fr_file_index.html +33 -0
  39. data/rdoc/fr_method_index.html +33 -0
  40. data/rdoc/index.html +24 -0
  41. data/rdoc/rdoc-style.css +208 -0
  42. data/spec/compatibility_stamping_spec.rb +76 -0
  43. data/spec/config_spec.rb +155 -0
  44. data/spec/database.yml +4 -0
  45. data/spec/fixtures/comments.yml +16 -0
  46. data/spec/fixtures/people.yml +11 -0
  47. data/spec/fixtures/posts.yml +9 -0
  48. data/spec/fixtures/users.yml +7 -0
  49. data/spec/magic_column_spec.rb +171 -0
  50. data/spec/posts_controller_spec.rb +41 -0
  51. data/spec/resources/controllers/application_controller.rb +2 -0
  52. data/spec/resources/controllers/posts_controller.rb +26 -0
  53. data/spec/resources/controllers/users_controller.rb +12 -0
  54. data/spec/resources/controllers/userstamp_controller.rb +9 -0
  55. data/spec/resources/models/comment.rb +4 -0
  56. data/spec/resources/models/person.rb +4 -0
  57. data/spec/resources/models/ping.rb +7 -0
  58. data/spec/resources/models/post.rb +4 -0
  59. data/spec/resources/models/user.rb +4 -0
  60. data/spec/schema.rb +56 -0
  61. data/spec/spec.opts +6 -0
  62. data/spec/spec_helper.rb +66 -0
  63. data/spec/stamping_spec.rb +114 -0
  64. data/spec/users_controller_spec.rb +33 -0
  65. metadata +145 -0
@@ -0,0 +1,76 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe Userstamp do
4
+
5
+ Userstamp.compatibility_mode = true
6
+
7
+ class CompatiblePerson < ActiveRecord::Base
8
+ set_table_name('people')
9
+ model_stamper
10
+ end
11
+
12
+ class CompatibleComment < ActiveRecord::Base
13
+ set_table_name('comments')
14
+ stampable :stamper_class_name => :compatible_person
15
+ belongs_to :post
16
+ end
17
+
18
+ Userstamp.compatibility_mode = false
19
+
20
+ fixtures :people, :comments
21
+
22
+ before(:each) do
23
+ @delynn = CompatiblePerson.find(people(:delynn).id)
24
+ @nicole = CompatiblePerson.find(people(:nicole).id)
25
+ @first_comment = CompatibleComment.find(comments(:first_comment).id)
26
+ @second_comment = CompatibleComment.find(comments(:second_comment).id)
27
+ CompatiblePerson.stamper = @delynn
28
+ end
29
+
30
+ it "comment_creation_with_stamped_object" do
31
+ CompatiblePerson.stamper.should == @delynn.id
32
+
33
+ comment = CompatibleComment.create(:comment => "Test Comment")
34
+ comment.created_by.should == @delynn.id
35
+ comment.updated_by.should == @delynn.id
36
+ comment.creator.should == @delynn
37
+ comment.updater.should == @delynn
38
+ end
39
+
40
+ it "comment_creation_with_stamped_integer" do
41
+ CompatiblePerson.stamper = 2
42
+ CompatiblePerson.stamper.should == 2
43
+
44
+ comment = CompatibleComment.create(:comment => "Test Comment - 2")
45
+ comment.created_by.should == @nicole.id
46
+ comment.updated_by.should == @nicole.id
47
+ comment.creator.should == @nicole
48
+ comment.updater.should == @nicole
49
+ end
50
+
51
+ it "comment_updating_with_stamped_object" do
52
+ CompatiblePerson.stamper = @nicole
53
+ assert_equal @nicole.id, CompatiblePerson.stamper
54
+
55
+ @first_comment.comment << " - Updated"
56
+ @first_comment.save
57
+ @first_comment.reload
58
+ @first_comment.created_by.should == @delynn.id
59
+ @first_comment.updated_by.should == @nicole.id
60
+ @first_comment.creator.should == @delynn
61
+ @first_comment.updater.should == @nicole
62
+ end
63
+
64
+ it "comment_updating_with_stamped_integer" do
65
+ CompatiblePerson.stamper = 2
66
+ CompatiblePerson.stamper.should == 2
67
+
68
+ @first_comment.comment << " - Updated"
69
+ @first_comment.save
70
+ @first_comment.reload
71
+ @first_comment.created_by.should == @delynn.id
72
+ @first_comment.updated_by.should == @nicole.id
73
+ @first_comment.creator.should == @delynn
74
+ @first_comment.updater.should == @nicole
75
+ end
76
+ end
@@ -0,0 +1,155 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe Userstamp::Config do
4
+
5
+ class Foo
6
+ end
7
+
8
+ class Bar
9
+ end
10
+
11
+ class Baz
12
+ end
13
+
14
+
15
+ before(:each) do
16
+ @config = Userstamp::Config.new
17
+ end
18
+
19
+ describe "on" do
20
+ it "option's default value" do
21
+ pattern = @config.on(:create, :creator_id)
22
+ pattern.event_name.should == :create
23
+ pattern.column_name.should == :creator_id
24
+ pattern.stampable_class_names.should == nil # means all classes
25
+ pattern.stamper_class_name.should == 'User'
26
+ pattern.stamper_attr_name.should == nil # means PK attr name
27
+ [Foo, Bar, Baz].each do |klass|
28
+ pattern.stampable?(klass, 'creator_id').should == true
29
+ pattern.stampable?(klass, 'updater_id').should == false
30
+ pattern.stampable?(klass, 'deleter_id').should == false
31
+ pattern.stampable?(klass, :creator_id).should == true
32
+ pattern.stampable?(klass, :updater_id).should == false
33
+ pattern.stampable?(klass, :deleter_id).should == false
34
+
35
+ @config.pattern_for(klass, 'creator_id').should == pattern
36
+ @config.pattern_for(klass, 'updater_id').should == nil
37
+ @config.pattern_for(klass, 'deleter_id').should == nil
38
+ end
39
+ end
40
+
41
+ it "full options" do
42
+ pattern = @config.on(:create, :creator_no,
43
+ :stampable_class_names => %w(Bar Baz),
44
+ :stamper_class_name => 'Admin',
45
+ :stamper_attr_name => 'admin_no'
46
+ )
47
+ pattern.event_name.should == :create
48
+ pattern.column_name.should == :creator_no
49
+ pattern.stampable_class_names.should == ['Bar', 'Baz'] # means all classes
50
+ pattern.stamper_class_name.should == 'Admin'
51
+ pattern.stamper_attr_name.should == 'admin_no' # means PK attr name
52
+ [Bar, Baz].each do |klass|
53
+ pattern.stampable?(klass, 'creator_no').should == true
54
+ pattern.stampable?(klass, 'creator_id').should == false
55
+ pattern.stampable?(klass, 'updater_id').should == false
56
+ pattern.stampable?(klass, 'deleter_id').should == false
57
+
58
+ @config.pattern_for(klass, 'creator_no').should == pattern
59
+ @config.pattern_for(klass, 'creator_id').should == nil
60
+ @config.pattern_for(klass, 'updater_id').should == nil
61
+ @config.pattern_for(klass, 'deleter_id').should == nil
62
+ end
63
+ end
64
+ end
65
+
66
+ describe "defaults" do
67
+ it "should define about creator_id, updater_id" do
68
+ @config.defaults
69
+ @config.patterns.length.should == 2
70
+ [Foo, Bar, Baz].each do |klass|
71
+ @config.pattern_for(klass, 'creator_id').should_not be_nil
72
+ @config.pattern_for(klass, 'updater_id').should_not be_nil
73
+ @config.pattern_for(klass, 'deleter_id').should be_nil
74
+ @config.pattern_for(klass, 'creator_by').should be_nil
75
+ @config.pattern_for(klass, 'updater_by').should be_nil
76
+ @config.pattern_for(klass, 'deleter_by').should be_nil
77
+ end
78
+ end
79
+
80
+ it "should define about creator_id, updater_id, deleter_id with_destroy" do
81
+ @config.with_destroy = true
82
+ @config.defaults
83
+ @config.patterns.length.should == 3
84
+ [Foo, Bar, Baz].each do |klass|
85
+ @config.pattern_for(klass, 'creator_id').should_not be_nil
86
+ @config.pattern_for(klass, 'updater_id').should_not be_nil
87
+ @config.pattern_for(klass, 'deleter_id').should_not be_nil
88
+ @config.pattern_for(klass, 'creator_by').should be_nil
89
+ @config.pattern_for(klass, 'updater_by').should be_nil
90
+ @config.pattern_for(klass, 'deleter_by').should be_nil
91
+ end
92
+ end
93
+ end
94
+
95
+
96
+ describe "compatibles" do
97
+ it "should define about creator_by, updater_by" do
98
+ @config.compatibles
99
+ @config.patterns.length.should == 2
100
+ [Foo, Bar, Baz].each do |klass|
101
+ @config.pattern_for(klass, 'creator_id').should be_nil
102
+ @config.pattern_for(klass, 'updater_id').should be_nil
103
+ @config.pattern_for(klass, 'deleter_id').should be_nil
104
+ @config.pattern_for(klass, 'created_by').should_not be_nil
105
+ @config.pattern_for(klass, 'updated_by').should_not be_nil
106
+ @config.pattern_for(klass, 'deleted_by').should be_nil
107
+ end
108
+ end
109
+
110
+ it "should define about creator_by, updater_by, deleter_by with_destroy" do
111
+ @config.with_destroy = true
112
+ @config.compatibles
113
+ @config.patterns.length.should == 3
114
+ [Foo, Bar, Baz].each do |klass|
115
+ @config.pattern_for(klass, 'creator_id').should be_nil
116
+ @config.pattern_for(klass, 'updater_id').should be_nil
117
+ @config.pattern_for(klass, 'deleter_id').should be_nil
118
+ @config.pattern_for(klass, 'created_by').should_not be_nil
119
+ @config.pattern_for(klass, 'updated_by').should_not be_nil
120
+ @config.pattern_for(klass, 'deleted_by').should_not be_nil
121
+ end
122
+ end
123
+ end
124
+
125
+ describe Userstamp::Config::Pattern do
126
+ describe "args_for_stampable_on" do
127
+
128
+ it "should return args to call Userstamp::Stampable.stampable_on" do
129
+ @config.defaults
130
+ p1 = @config.pattern_for(Foo, "creator_id")
131
+ p1.args_for_stampable_on.should == [:create, {
132
+ :attribute => :creator_id,
133
+ :stamper_class_name=>"User",
134
+ :stamper_attr_name=>nil}]
135
+ end
136
+
137
+ it "should return args to call Userstamp::Stampable.stampable_on with options" do
138
+ @config.on(:update, :updater_id, :actual_hook => :before_update,
139
+ :stamper_name => 'foo_updater', :stamper_class_name => 'Foo',
140
+ :stamper_attr_name => 'cd')
141
+ p1 = @config.pattern_for(Foo, "updater_id")
142
+ p1.args_for_stampable_on.should == [:update, {
143
+ :attribute => :updater_id,
144
+ :actual_hook => :before_update,
145
+ :stamper_name => 'foo_updater', :stamper_class_name => 'Foo',
146
+ :stamper_attr_name => 'cd'}]
147
+ end
148
+
149
+ end
150
+
151
+ end
152
+
153
+
154
+
155
+ end
data/spec/database.yml ADDED
@@ -0,0 +1,4 @@
1
+ sqlite3:
2
+ adapter: sqlite3
3
+ database: userstamp_plugin_test.sqlite3
4
+ timeout: 5000
@@ -0,0 +1,16 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+ first_comment:
3
+ id: 1
4
+ post_id: 1
5
+ comment: First Comment
6
+ created_by: 1
7
+ second_comment:
8
+ id: 2
9
+ post_id: 1
10
+ comment: Second Comment
11
+ created_by: 2
12
+ third_comment:
13
+ id: 3
14
+ post_id: 2
15
+ comment: Third Comment
16
+ created_by: 1
@@ -0,0 +1,11 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+ delynn:
3
+ id: 1
4
+ name: DeLynn
5
+ creator_id: 1
6
+ updater_id: 1
7
+ nicole:
8
+ id: 2
9
+ name: Nicole
10
+ creator_id: 2
11
+ updater_id: 2
@@ -0,0 +1,9 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+ first_post:
3
+ id: 1
4
+ title: First Post
5
+ creator_id: 1
6
+ second_post:
7
+ id: 2
8
+ title: Second Post
9
+ creator_id: 1
@@ -0,0 +1,7 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+ zeus:
3
+ id: 1
4
+ name: Zeus
5
+ hera:
6
+ id: 2
7
+ name: Hera
@@ -0,0 +1,171 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.join(File.dirname(__FILE__), 'spec_helper')
3
+
4
+ describe Userstamp do
5
+
6
+ Userstamp::Config.setup do |config|
7
+ # config.verbose = true
8
+
9
+ config.defaults(:stamper_class_name => 'MagicPerson', :stampable_class_names => %w(MagicPost))
10
+ config.compatibles(:stamper_class_name => 'MagicPerson', :stampable_class_names => %w(MagicComment))
11
+
12
+ config.with_options(:stamper_class_name => 'MagicPerson', :stamper_attr_name => :name, :stampable_class_names => %w(MagicPing)) do |c|
13
+ c.on(:create , :creator_name)
14
+ c.on(:update , :updater_name)
15
+ # c.on(:destroy, :deleter_name)
16
+ end
17
+
18
+ config.defaults(:stamper_class_name => 'MagicUser')
19
+ end
20
+
21
+ class MagicUser < ActiveRecord::Base
22
+ set_table_name 'users'
23
+ # model_stamper
24
+ end
25
+
26
+ class MagicPerson < ActiveRecord::Base
27
+ set_table_name 'people'
28
+ # model_stamper
29
+ end
30
+
31
+ class MagicPost < ActiveRecord::Base
32
+ set_table_name 'posts'
33
+ # stampable :stamper_class_name => :person
34
+ end
35
+
36
+ class MagicComment < ActiveRecord::Base
37
+ set_table_name 'comments'
38
+ # stampable :stamper_class_name => :person
39
+ end
40
+
41
+ class MagicPing < ActiveRecord::Base
42
+ set_table_name 'pings'
43
+ # stampable :stamper_class_name => :person
44
+ end
45
+
46
+ after(:all) do
47
+ Userstamp::Config.clear
48
+ end
49
+
50
+ fixtures :users, :people, :posts
51
+
52
+ before(:each) do
53
+ @zeus = MagicUser.find(users(:zeus).id)
54
+ @hera = MagicUser.find(users(:hera).id)
55
+ @delynn = MagicPerson.find(people(:delynn).id)
56
+ @nicole = MagicPerson.find(people(:nicole).id)
57
+ @first_post = MagicPost.find(posts(:first_post).id)
58
+ @second_post = MagicPost.find(posts(:second_post).id)
59
+ MagicUser.model_stamper # 通常なら必要ないばすだけど、ここでは必要
60
+ MagicUser.stamper = @zeus
61
+ MagicPerson.model_stamper # 通常なら必要ないばすだけど、ここでは必要
62
+ MagicPerson.stamper = @delynn
63
+ end
64
+
65
+ it "Userstamp.config.pattern_for" do
66
+ Userstamp.config.patterns.length.should == 8
67
+ p1 = Userstamp.config.pattern_for(MagicUser, "creator_id")
68
+ p1.should_not be_nil
69
+ p2 = Userstamp.config.pattern_for(MagicPerson, "creator_id")
70
+ p2.should_not be_nil
71
+ p1 = Userstamp.config.pattern_for(MagicPost, "creator_id")
72
+ p1.should_not be_nil
73
+ end
74
+
75
+
76
+ it "person_creation_with_stamped_object" do
77
+ MagicUser.stamper.should == @zeus.id
78
+
79
+ person = MagicPerson.create(:name => "David")
80
+ person.creator_id.should == @zeus.id
81
+ person.updater_id.should == @zeus.id
82
+ person.creator.should == @zeus
83
+ person.updater.should == @zeus
84
+ end
85
+
86
+ it "person_creation_with_stamped_integer" do
87
+ MagicUser.stamper = 2
88
+ MagicUser.stamper.should == 2
89
+
90
+ person = MagicPerson.create(:name => "Daniel")
91
+ person.creator_id.should == @hera.id
92
+ person.updater_id.should == @hera.id
93
+ person.creator.should == @hera
94
+ person.updater.should == @hera
95
+ end
96
+
97
+ it "post_creation_with_stamped_object" do
98
+ MagicPerson.stamper.should == @delynn.id
99
+
100
+ post = MagicPost.create(:title => "Test Post - 1")
101
+ post.creator_id.should == @delynn.id
102
+ post.updater_id.should == @delynn.id
103
+ post.creator.should == @delynn
104
+ post.updater.should == @delynn
105
+ end
106
+
107
+ it "post_creation_with_stamped_integer" do
108
+ MagicPerson.stamper = 2
109
+ MagicPerson.stamper.should == 2
110
+
111
+ post = MagicPost.create(:title => "Test Post - 2")
112
+ post.creator_id.should == @nicole.id
113
+ post.updater_id.should == @nicole.id
114
+ post.creator.should == @nicole
115
+ post.updater.should == @nicole
116
+ end
117
+
118
+ it "person_updating_with_stamped_object" do
119
+ MagicUser.stamper = @hera
120
+ MagicUser.stamper.should == @hera.id
121
+
122
+ @delynn.name << " Berry"
123
+ @delynn.save
124
+ @delynn.reload
125
+ @delynn.creator.should == @zeus
126
+ @delynn.updater.should == @hera
127
+ @delynn.creator_id.should == @zeus.id
128
+ @delynn.updater_id.should == @hera.id
129
+ end
130
+
131
+ it "person_updating_with_stamped_integer" do
132
+ MagicUser.stamper = 2
133
+ MagicUser.stamper.should == 2
134
+
135
+ @delynn.name << " Berry"
136
+ @delynn.save
137
+ @delynn.reload
138
+ @delynn.creator_id.should == @zeus.id
139
+ @delynn.updater_id.should == @hera.id
140
+ @delynn.creator.should == @zeus
141
+ @delynn.updater.should == @hera
142
+ end
143
+
144
+ it "post_updating_with_stamped_object" do
145
+ MagicPerson.stamper = @nicole
146
+ MagicPerson.stamper.should == @nicole.id
147
+
148
+ @first_post.title << " - Updated"
149
+ @first_post.save
150
+ @first_post.reload
151
+ @first_post.creator_id.should == @delynn.id
152
+ @first_post.updater_id.should == @nicole.id
153
+ @first_post.creator.should == @delynn
154
+ @first_post.updater.should == @nicole
155
+ end
156
+
157
+ it "post_updating_with_stamped_integer" do
158
+ MagicPerson.stamper = 2
159
+ MagicPerson.stamper.should == 2
160
+
161
+ @first_post.title << " - Updated"
162
+ @first_post.save
163
+ @first_post.reload
164
+ @first_post.creator_id.should == @delynn.id
165
+ @first_post.updater_id.should == @nicole.id
166
+ @first_post.creator.should == @delynn
167
+ @first_post.updater.should == @nicole
168
+ end
169
+
170
+ end
171
+
@@ -0,0 +1,41 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe PostsController, :type => :controller do
4
+ fixtures :people, :posts
5
+
6
+ before(:each) do
7
+ @delynn = people(:delynn)
8
+ @nicole = people(:nicole)
9
+ @first_post = posts(:first_post)
10
+ @second_post = posts(:second_post)
11
+ end
12
+
13
+ describe "update" do
14
+ it "single request" do
15
+ request.session[:person_id] = 1
16
+ post :update, :id => 1, :post => {:title => 'Different'}
17
+ response.should be_success
18
+ assigns["post"].title.should == 'Different'
19
+ assigns["post"].updater.should == @delynn
20
+ end
21
+
22
+ it "multiple request" do
23
+ request.session[:person_id] = 1
24
+ get :edit, :id => 2
25
+ response.should be_success
26
+
27
+ request.session[:person_id] = 2
28
+ post :update, :id => 1, :post => {:title => 'Different Second'}
29
+ response.should be_success
30
+ assigns["post"].title.should == 'Different Second'
31
+ assigns["post"].updater.should == @nicole
32
+
33
+ request.session[:person_id] = 1
34
+ post :update, :id => 2, :post => {:title => 'Different'}
35
+ assert_response :success
36
+ assert_equal 'Different', assigns["post"].title
37
+ assert_equal @delynn, assigns["post"].updater
38
+ end
39
+ end
40
+
41
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationController < ActionController::Base
2
+ end
@@ -0,0 +1,26 @@
1
+ class PostsController < UserstampController
2
+ def edit
3
+ @post = Post.find(params[:id])
4
+ render(:inline => "<%= @post.title %>")
5
+ end
6
+
7
+ def update
8
+ @post = Post.find(params[:id])
9
+ @post.update_attributes(params[:post])
10
+ render(:inline => "<%= @post.title %>")
11
+ end
12
+
13
+ protected
14
+ def current_user
15
+ Person.find(session[:person_id])
16
+ end
17
+
18
+ def set_stamper
19
+ Person.stamper = self.current_user
20
+ end
21
+
22
+ def reset_stamper
23
+ Person.reset_stamper
24
+ end
25
+ #end
26
+ end
@@ -0,0 +1,12 @@
1
+ class UsersController < UserstampController
2
+ def edit
3
+ @user = User.find(params[:id])
4
+ render(:inline => "<%= @user.name %>")
5
+ end
6
+
7
+ def update
8
+ @user = User.find(params[:id])
9
+ @user.update_attributes(params[:user])
10
+ render(:inline => "<%= @user.name %>")
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ class UserstampController < ApplicationController
2
+ include Userstamp::Controller
3
+
4
+ protected
5
+ def current_user
6
+ User.find(session[:user_id])
7
+ end
8
+ #end
9
+ end
@@ -0,0 +1,4 @@
1
+ class Comment < ActiveRecord::Base
2
+ stampable :stamper_class_name => :person
3
+ belongs_to :post
4
+ end
@@ -0,0 +1,4 @@
1
+ class Person < ActiveRecord::Base
2
+ model_stamper
3
+ stampable
4
+ end
@@ -0,0 +1,7 @@
1
+ class Ping < ActiveRecord::Base
2
+ stampable :stamper_class_name => :person,
3
+ :creator_attribute => :creator_name,
4
+ :updater_attribute => :updater_name,
5
+ :deleter_attribute => :deleter_name
6
+ belongs_to :post
7
+ end
@@ -0,0 +1,4 @@
1
+ class Post < ActiveRecord::Base
2
+ stampable :stamper_class_name => :person
3
+ has_many :comments
4
+ end
@@ -0,0 +1,4 @@
1
+ class User < ActiveRecord::Base
2
+ model_stamper
3
+ stampable
4
+ end
data/spec/schema.rb ADDED
@@ -0,0 +1,56 @@
1
+ ActiveRecord::Schema.define(:version => 0) do
2
+ # Users are created and updated by other Users
3
+ create_table :users, :force => true do |t|
4
+ t.column :name, :string
5
+ t.column :creator_id, :integer
6
+ t.column :created_on, :datetime
7
+ t.column :updater_id, :integer
8
+ t.column :updated_at, :datetime
9
+ end
10
+
11
+ # People are created and updated by Users
12
+ create_table :people, :force => true do |t|
13
+ t.column :name, :string
14
+ t.column :creator_id, :integer
15
+ t.column :created_on, :datetime
16
+ t.column :updater_id, :integer
17
+ t.column :updated_at, :datetime
18
+ end
19
+
20
+ # Posts are created and updated by People
21
+ create_table :posts, :force => true do |t|
22
+ t.column :title, :string
23
+ t.column :creator_id, :integer
24
+ t.column :created_on, :datetime
25
+ t.column :updater_id, :integer
26
+ t.column :updated_at, :datetime
27
+ t.column :deleter_id, :integer
28
+ t.column :deleted_at, :datetime
29
+ end
30
+
31
+ # Comments are created and updated by People
32
+ # and also use non-standard foreign keys.
33
+ create_table :comments, :force => true do |t|
34
+ t.column :post_id, :integer
35
+ t.column :comment, :string
36
+ t.column :created_by, :integer
37
+ t.column :created_at, :datetime
38
+ t.column :updated_by, :integer
39
+ t.column :updated_at, :datetime
40
+ t.column :deleted_by, :integer
41
+ t.column :deleted_at, :datetime
42
+ end
43
+
44
+ # Pings are created and updated by People,
45
+ # but they store their foreign keys as strings.
46
+ create_table :pings, :force => true do |t|
47
+ t.column :post_id, :integer
48
+ t.column :ping, :string
49
+ t.column :creator_name, :string
50
+ t.column :created_at, :datetime
51
+ t.column :updater_name, :string
52
+ t.column :updated_at, :datetime
53
+ t.column :deleter_name, :string
54
+ t.column :deleted_at, :datetime
55
+ end
56
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,6 @@
1
+ --colour
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
6
+ --reverse