magiclabs-userstamp 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/CHANGELOG +26 -0
  2. data/Gemfile +11 -0
  3. data/Gemfile.lock +55 -0
  4. data/LICENSE +20 -0
  5. data/Rakefile +38 -0
  6. data/Readme.rdoc +163 -0
  7. data/VERSION +1 -0
  8. data/init.rb +1 -0
  9. data/lib/migration_helper.rb +19 -0
  10. data/lib/stampable.rb +154 -0
  11. data/lib/stamper.rb +43 -0
  12. data/lib/userstamp.rb +52 -0
  13. data/magiclabs-userstamp.gemspec +85 -0
  14. data/rdoc/classes/Ddb/Controller.html +111 -0
  15. data/rdoc/classes/Ddb/Controller/Userstamp.html +125 -0
  16. data/rdoc/classes/Ddb/Controller/Userstamp/InstanceMethods.html +105 -0
  17. data/rdoc/classes/Ddb/Userstamp.html +121 -0
  18. data/rdoc/classes/Ddb/Userstamp/MigrationHelper.html +111 -0
  19. data/rdoc/classes/Ddb/Userstamp/MigrationHelper/InstanceMethods.html +142 -0
  20. data/rdoc/classes/Ddb/Userstamp/Stampable.html +128 -0
  21. data/rdoc/classes/Ddb/Userstamp/Stampable/ClassMethods.html +225 -0
  22. data/rdoc/classes/Ddb/Userstamp/Stamper.html +112 -0
  23. data/rdoc/classes/Ddb/Userstamp/Stamper/ClassMethods.html +142 -0
  24. data/rdoc/classes/Ddb/Userstamp/Stamper/InstanceMethods.html +207 -0
  25. data/rdoc/classes/Userstamp.html +118 -0
  26. data/rdoc/created.rid +1 -0
  27. data/rdoc/files/CHANGELOG.html +137 -0
  28. data/rdoc/files/LICENSE.html +129 -0
  29. data/rdoc/files/Readme_rdoc.html +301 -0
  30. data/rdoc/files/lib/migration_helper_rb.html +101 -0
  31. data/rdoc/files/lib/stampable_rb.html +101 -0
  32. data/rdoc/files/lib/stamper_rb.html +101 -0
  33. data/rdoc/files/lib/userstamp_rb.html +110 -0
  34. data/rdoc/fr_class_index.html +38 -0
  35. data/rdoc/fr_file_index.html +33 -0
  36. data/rdoc/fr_method_index.html +33 -0
  37. data/rdoc/index.html +24 -0
  38. data/rdoc/rdoc-style.css +208 -0
  39. data/test/compatibility_stamping_test.rb +69 -0
  40. data/test/controllers/posts_controller.rb +26 -0
  41. data/test/controllers/users_controller.rb +12 -0
  42. data/test/controllers/userstamp_controller.rb +9 -0
  43. data/test/helper.rb +61 -0
  44. data/test/models/comment.rb +5 -0
  45. data/test/models/foo.rb +3 -0
  46. data/test/models/person.rb +3 -0
  47. data/test/models/post.rb +13 -0
  48. data/test/models/user.rb +3 -0
  49. data/test/schema.rb +54 -0
  50. data/test/stamping_test.rb +138 -0
  51. data/test/userstamp_controller_test.rb +103 -0
  52. data/test/userstamp_test.rb +7 -0
  53. metadata +105 -0
@@ -0,0 +1,138 @@
1
+ require 'test/helper'
2
+
3
+ class StampingTests < Test::Unit::TestCase # :nodoc:
4
+ def setup
5
+ reset_to_defaults
6
+ User.stamper = @zeus
7
+ Person.stamper = @delynn
8
+ end
9
+
10
+ def test_person_creation_with_stamped_object
11
+ assert_equal @zeus.id, User.stamper
12
+
13
+ person = Person.create(:name => "David")
14
+ assert_equal @zeus.id, person.creator_id
15
+ assert_equal @zeus.id, person.updater_id
16
+ assert_equal @zeus, person.creator
17
+ assert_equal @zeus, person.updater
18
+ end
19
+
20
+ def test_person_creation_with_stamped_integer
21
+ User.stamper = @nicole.id
22
+ assert_equal @nicole.id, User.stamper
23
+
24
+ person = Person.create(:name => "Daniel")
25
+ assert_equal @hera.id, person.creator_id
26
+ assert_equal @hera.id, person.updater_id
27
+ assert_equal @hera, person.creator
28
+ assert_equal @hera, person.updater
29
+ end
30
+
31
+ def test_post_creation_with_stamped_object
32
+ assert_equal @delynn.id, Person.stamper
33
+
34
+ post = Post.create(:title => "Test Post - 1")
35
+ assert_equal @delynn.id, post.creator_id
36
+ assert_equal @delynn.id, post.updater_id
37
+ assert_equal @delynn, post.creator
38
+ assert_equal @delynn, post.updater
39
+ end
40
+
41
+ def test_post_creation_with_stamped_integer
42
+ Person.stamper = @nicole.id
43
+ assert_equal @nicole.id, Person.stamper
44
+
45
+ post = Post.create(:title => "Test Post - 2")
46
+ assert_equal @nicole.id, post.creator_id
47
+ assert_equal @nicole.id, post.updater_id
48
+ assert_equal @nicole, post.creator
49
+ assert_equal @nicole, post.updater
50
+ end
51
+
52
+ def test_person_updating_with_stamped_object
53
+ User.stamper = @hera
54
+ assert_equal @hera.id, User.stamper
55
+
56
+ @delynn.name << " Berry"
57
+ @delynn.save
58
+ @delynn.reload
59
+ assert_equal @zeus, @delynn.creator
60
+ assert_equal @hera, @delynn.updater
61
+ assert_equal @zeus.id, @delynn.creator_id
62
+ assert_equal @hera.id, @delynn.updater_id
63
+ end
64
+
65
+ def test_person_updating_with_stamped_integer
66
+ User.stamper = @hera.id
67
+ assert_equal @hera.id, User.stamper
68
+
69
+ @delynn.name << " Berry"
70
+ @delynn.save
71
+ @delynn.reload
72
+ assert_equal @zeus.id, @delynn.creator_id
73
+ assert_equal @hera.id, @delynn.updater_id
74
+ assert_equal @zeus, @delynn.creator
75
+ assert_equal @hera, @delynn.updater
76
+ end
77
+
78
+ def test_post_updating_with_stamped_object
79
+ Person.stamper = @nicole
80
+ assert_equal @nicole.id, Person.stamper
81
+
82
+ @first_post.title << " - Updated"
83
+ @first_post.save
84
+ @first_post.reload
85
+ assert_equal @delynn.id, @first_post.creator_id
86
+ assert_equal @nicole.id, @first_post.updater_id
87
+ assert_equal @delynn, @first_post.creator
88
+ assert_equal @nicole, @first_post.updater
89
+ end
90
+
91
+ def test_post_updating_with_stamped_integer
92
+ Person.stamper = @nicole.id
93
+ assert_equal @nicole.id, Person.stamper
94
+
95
+ @first_post.title << " - Updated"
96
+ @first_post.save
97
+ @first_post.reload
98
+ assert_equal @delynn.id, @first_post.creator_id
99
+ assert_equal @nicole.id, @first_post.updater_id
100
+ assert_equal @delynn, @first_post.creator
101
+ assert_equal @nicole, @first_post.updater
102
+ end
103
+
104
+ def test_delete_post_sets_deleter_id
105
+ assert_equal nil, @first_post.deleted_at
106
+
107
+ Person.stamper = @nicole.id
108
+ assert_equal @nicole.id, Person.stamper
109
+
110
+ @first_post.destroy
111
+ @first_post.save
112
+ @first_post.reload
113
+
114
+ assert_not_equal nil, @first_post.deleted_at
115
+ assert_equal @nicole.id, @first_post.deleter_id
116
+ end
117
+
118
+ def test_deleter_not_present_did_not_create_deleter_relation
119
+ @comment = Comment.create
120
+ assert_equal true, @comment.respond_to?('creator')
121
+ assert_equal true, @comment.respond_to?('updater')
122
+ assert_equal false, @comment.respond_to?('deleter')
123
+ end
124
+
125
+ def test_deleter_true_created_deleter_relation
126
+ assert_equal true, @first_post.respond_to?('creator')
127
+ assert_equal true, @first_post.respond_to?('updater')
128
+ assert_equal true, @first_post.respond_to?('deleter')
129
+ end
130
+
131
+ def test_deleter_attribute_set_created_deleter_relation
132
+ @foo = Foo.create
133
+ assert_equal true, @foo.respond_to?('creator')
134
+ assert_equal true, @foo.respond_to?('updater')
135
+ assert_equal true, @foo.respond_to?('deleter')
136
+ end
137
+
138
+ end
@@ -0,0 +1,103 @@
1
+ require 'test/helper'
2
+
3
+ class PostsControllerTest < ActionController::TestCase
4
+ def setup
5
+ reset_to_defaults
6
+ @controller = PostsController.new
7
+ @request = ActionController::TestRequest.new
8
+ @response = ActionController::TestResponse.new
9
+ end
10
+
11
+ def test_update_post
12
+ @request.session = {:person_id => @delynn.id}
13
+ post :update, :id => @first_post.id, :post => {:title => 'Different'}
14
+ assert_response :success
15
+ assert_equal 'Different', assigns["post"].title
16
+ assert_equal @delynn, assigns["post"].updater
17
+ end
18
+
19
+ def test_update_with_multiple_requests
20
+ @request.session = {:person_id => @delynn.id}
21
+ get :edit, :id => @first_post.id
22
+ assert_response :success
23
+
24
+ simulate_second_request
25
+
26
+ post :update, :id => @first_post.id, :post => {:title => 'Different'}
27
+ assert_response :success
28
+ assert_equal 'Different', assigns["post"].title
29
+ assert_equal @delynn, assigns["post"].updater
30
+ end
31
+
32
+ def simulate_second_request
33
+ @second_controller = PostsController.new
34
+ @second_request = ActionController::TestRequest.new
35
+ @second_response = ActionController::TestResponse.new
36
+ @second_response.session = {:person_id => @nicole.id}
37
+
38
+ @second_request.env['REQUEST_METHOD'] = "POST"
39
+ @second_request.action = 'update'
40
+
41
+ parameters = {:id => @first_post.id, :post => {:title => 'Different Second'}}
42
+ @second_request.assign_parameters(@second_controller.class.controller_path, 'update', parameters)
43
+ @second_request.session = ActionController::TestSession.new(@second_response.session)
44
+
45
+ options = @second_controller.send(:rewrite_options, parameters)
46
+ options.update(:only_path => true, :action => 'update')
47
+
48
+ url = ActionController::UrlRewriter.new(@second_request, parameters)
49
+ @second_request.set_REQUEST_URI(url.rewrite(options))
50
+ @second_controller.process(@second_request, @second_response)
51
+
52
+ assert_equal @nicole, @second_response.template.instance_variable_get("@post").updater
53
+ end
54
+ end
55
+
56
+ class UsersControllerTest < ActionController::TestCase
57
+ def setup
58
+ reset_to_defaults
59
+ @controller = UsersController.new
60
+ @request = ActionController::TestRequest.new
61
+ @response = ActionController::TestResponse.new
62
+ end
63
+
64
+ def test_update_user
65
+ @request.session = {:user_id => @hera.id}
66
+ post :update, :id => @hera.id, :user => {:name => 'Different'}
67
+ assert_response :success
68
+ assert_equal 'Different', assigns["user"].name
69
+ assert_equal @hera, assigns["user"].updater
70
+ end
71
+
72
+ def test_update_with_multiple_requests
73
+ @request.session = {:user_id => @hera.id}
74
+ get :edit, :id => @hera.id
75
+ assert_response :success
76
+
77
+ simulate_second_request
78
+ end
79
+
80
+ def simulate_second_request
81
+ @second_controller = UsersController.new
82
+ @second_request = ActionController::TestRequest.new
83
+ @second_response = ActionController::TestResponse.new
84
+ @second_response.session = {:user_id => @zeus.id}
85
+
86
+ @second_request.env['REQUEST_METHOD'] = "POST"
87
+ @second_request.action = 'update'
88
+
89
+ parameters = {:id => @hera.id, :user => {:name => 'Different Second'}}
90
+ @second_request.assign_parameters(@second_controller.class.controller_path, 'update', parameters)
91
+
92
+ @second_request.session = ActionController::TestSession.new(@second_response.session)
93
+
94
+ options = @second_controller.send(:rewrite_options, parameters)
95
+ options.update(:only_path => true, :action => 'update')
96
+
97
+ url = ActionController::UrlRewriter.new(@second_request, parameters)
98
+ @second_request.set_REQUEST_URI(url.rewrite(options))
99
+ @second_controller.process(@second_request, @second_response)
100
+
101
+ assert_equal @zeus, @second_response.template.instance_variable_get("@user").updater
102
+ end
103
+ end
@@ -0,0 +1,7 @@
1
+ require 'test/helper'
2
+
3
+ class UserstampTests < ActiveSupport::TestCase
4
+ test "it has a VERSION" do
5
+ assert_match /^\d+\.\d+\.\d+$/, Userstamp::VERSION
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: magiclabs-userstamp
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 2.0.2
6
+ platform: ruby
7
+ authors:
8
+ - DeLynn Berry
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-11-07 00:00:00 Z
14
+ dependencies: []
15
+
16
+ description:
17
+ email: delynn@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ files:
25
+ - CHANGELOG
26
+ - Gemfile
27
+ - Gemfile.lock
28
+ - LICENSE
29
+ - Rakefile
30
+ - Readme.rdoc
31
+ - VERSION
32
+ - init.rb
33
+ - lib/migration_helper.rb
34
+ - lib/stampable.rb
35
+ - lib/stamper.rb
36
+ - lib/userstamp.rb
37
+ - magiclabs-userstamp.gemspec
38
+ - rdoc/classes/Ddb/Controller.html
39
+ - rdoc/classes/Ddb/Controller/Userstamp.html
40
+ - rdoc/classes/Ddb/Controller/Userstamp/InstanceMethods.html
41
+ - rdoc/classes/Ddb/Userstamp.html
42
+ - rdoc/classes/Ddb/Userstamp/MigrationHelper.html
43
+ - rdoc/classes/Ddb/Userstamp/MigrationHelper/InstanceMethods.html
44
+ - rdoc/classes/Ddb/Userstamp/Stampable.html
45
+ - rdoc/classes/Ddb/Userstamp/Stampable/ClassMethods.html
46
+ - rdoc/classes/Ddb/Userstamp/Stamper.html
47
+ - rdoc/classes/Ddb/Userstamp/Stamper/ClassMethods.html
48
+ - rdoc/classes/Ddb/Userstamp/Stamper/InstanceMethods.html
49
+ - rdoc/classes/Userstamp.html
50
+ - rdoc/created.rid
51
+ - rdoc/files/CHANGELOG.html
52
+ - rdoc/files/LICENSE.html
53
+ - rdoc/files/Readme_rdoc.html
54
+ - rdoc/files/lib/migration_helper_rb.html
55
+ - rdoc/files/lib/stampable_rb.html
56
+ - rdoc/files/lib/stamper_rb.html
57
+ - rdoc/files/lib/userstamp_rb.html
58
+ - rdoc/fr_class_index.html
59
+ - rdoc/fr_file_index.html
60
+ - rdoc/fr_method_index.html
61
+ - rdoc/index.html
62
+ - rdoc/rdoc-style.css
63
+ - test/compatibility_stamping_test.rb
64
+ - test/controllers/posts_controller.rb
65
+ - test/controllers/users_controller.rb
66
+ - test/controllers/userstamp_controller.rb
67
+ - test/helper.rb
68
+ - test/models/comment.rb
69
+ - test/models/foo.rb
70
+ - test/models/person.rb
71
+ - test/models/post.rb
72
+ - test/models/user.rb
73
+ - test/schema.rb
74
+ - test/stamping_test.rb
75
+ - test/userstamp_controller_test.rb
76
+ - test/userstamp_test.rb
77
+ homepage: https://github.com/magiclabs/userstamp
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options: []
82
+
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: "0"
97
+ requirements: []
98
+
99
+ rubyforge_project:
100
+ rubygems_version: 1.8.11
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: 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.
104
+ test_files: []
105
+