magic_userstamp 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/CHANGELOG +26 -0
- data/LICENSE +20 -0
- data/README.original +179 -0
- data/README.rdoc +64 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/init.rb +12 -0
- data/lib/userstamp/config.rb +119 -0
- data/lib/userstamp/controller.rb +43 -0
- data/lib/userstamp/event.rb +63 -0
- data/lib/userstamp/magic_columns.rb +49 -0
- data/lib/userstamp/migration_helper.rb +17 -0
- data/lib/userstamp/stampable.rb +147 -0
- data/lib/userstamp/stamper.rb +41 -0
- data/lib/userstamp.rb +17 -0
- data/magic_userstamp.gemspec +124 -0
- data/rdoc/classes/Ddb/Controller/Userstamp/InstanceMethods.html +105 -0
- data/rdoc/classes/Ddb/Controller/Userstamp.html +125 -0
- data/rdoc/classes/Ddb/Controller.html +111 -0
- data/rdoc/classes/Ddb/Userstamp/MigrationHelper/InstanceMethods.html +142 -0
- data/rdoc/classes/Ddb/Userstamp/MigrationHelper.html +111 -0
- data/rdoc/classes/Ddb/Userstamp/Stampable/ClassMethods.html +222 -0
- data/rdoc/classes/Ddb/Userstamp/Stampable.html +128 -0
- data/rdoc/classes/Ddb/Userstamp/Stamper/ClassMethods.html +142 -0
- data/rdoc/classes/Ddb/Userstamp/Stamper/InstanceMethods.html +207 -0
- data/rdoc/classes/Ddb/Userstamp/Stamper.html +112 -0
- data/rdoc/classes/Ddb/Userstamp.html +121 -0
- data/rdoc/created.rid +1 -0
- data/rdoc/files/CHANGELOG.html +137 -0
- data/rdoc/files/LICENSE.html +129 -0
- data/rdoc/files/README.html +341 -0
- data/rdoc/files/lib/migration_helper_rb.html +101 -0
- data/rdoc/files/lib/stampable_rb.html +101 -0
- data/rdoc/files/lib/stamper_rb.html +101 -0
- data/rdoc/files/lib/userstamp_rb.html +101 -0
- data/rdoc/fr_class_index.html +37 -0
- data/rdoc/fr_file_index.html +33 -0
- data/rdoc/fr_method_index.html +33 -0
- data/rdoc/index.html +24 -0
- data/rdoc/rdoc-style.css +208 -0
- data/spec/compatibility_stamping_spec.rb +76 -0
- data/spec/config_spec.rb +155 -0
- data/spec/database.yml +4 -0
- data/spec/fixtures/comments.yml +16 -0
- data/spec/fixtures/people.yml +11 -0
- data/spec/fixtures/posts.yml +9 -0
- data/spec/fixtures/users.yml +7 -0
- data/spec/magic_column_spec.rb +171 -0
- data/spec/posts_controller_spec.rb +41 -0
- data/spec/resources/controllers/application_controller.rb +2 -0
- data/spec/resources/controllers/posts_controller.rb +26 -0
- data/spec/resources/controllers/users_controller.rb +12 -0
- data/spec/resources/controllers/userstamp_controller.rb +9 -0
- data/spec/resources/models/comment.rb +4 -0
- data/spec/resources/models/person.rb +4 -0
- data/spec/resources/models/ping.rb +7 -0
- data/spec/resources/models/post.rb +4 -0
- data/spec/resources/models/user.rb +4 -0
- data/spec/schema.rb +56 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +66 -0
- data/spec/stamping_spec.rb +114 -0
- data/spec/users_controller_spec.rb +33 -0
- metadata +145 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
$KCODE='u'
|
3
|
+
|
4
|
+
ENV['RAILS_ENV'] ||= 'test'
|
5
|
+
unless defined?(RAILS_ENV)
|
6
|
+
RAILS_ENV = 'test'
|
7
|
+
RAILS_ROOT = File.dirname(__FILE__) unless defined?(RAILS_ROOT)
|
8
|
+
|
9
|
+
require 'rubygems'
|
10
|
+
require 'spec'
|
11
|
+
|
12
|
+
require 'active_support'
|
13
|
+
require 'active_record'
|
14
|
+
require 'active_record/fixtures'
|
15
|
+
# require 'action_mailer'
|
16
|
+
require 'action_controller'
|
17
|
+
require 'action_view'
|
18
|
+
require 'initializer'
|
19
|
+
|
20
|
+
require 'yaml'
|
21
|
+
config = YAML.load(IO.read(File.join(File.dirname(__FILE__), 'database.yml')))
|
22
|
+
ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), 'debug.log'))
|
23
|
+
ActionController::Base.logger = ActiveRecord::Base.logger
|
24
|
+
ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite3'])
|
25
|
+
|
26
|
+
load(File.join(File.dirname(__FILE__), 'schema.rb'))
|
27
|
+
|
28
|
+
ActionController::Routing::Routes.draw do |map|
|
29
|
+
map.connect ':controller/:action/:id.:format'
|
30
|
+
map.connect ':controller/:action/:id'
|
31
|
+
end
|
32
|
+
|
33
|
+
%w(resources/models resources/controllers).each do |path|
|
34
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), path)
|
35
|
+
ActiveSupport::Dependencies.load_paths << File.join(File.dirname(__FILE__), path)
|
36
|
+
end
|
37
|
+
|
38
|
+
require 'spec/autorun'
|
39
|
+
require 'spec/rails'
|
40
|
+
|
41
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
|
42
|
+
require File.join(File.dirname(__FILE__), '..', 'init')
|
43
|
+
|
44
|
+
# Dir.glob("resources/**/*.rb") do |filename|
|
45
|
+
# require filename
|
46
|
+
# end
|
47
|
+
|
48
|
+
class ActiveSupport::TestCase
|
49
|
+
include ActiveRecord::TestFixtures
|
50
|
+
self.fixture_path = File.join(File.dirname(__FILE__), 'fixtures')
|
51
|
+
self.use_transactional_fixtures = false
|
52
|
+
self.use_instantiated_fixtures = false
|
53
|
+
self.pre_loaded_fixtures = false
|
54
|
+
fixtures :all
|
55
|
+
|
56
|
+
def setup_fixtures_with_set_fixture_path
|
57
|
+
# ここでなぜか fixture_path の値が変わってしまっています。。。
|
58
|
+
self.class.fixture_path = File.join(File.dirname(__FILE__), 'fixtures')
|
59
|
+
setup_fixtures_without_set_fixture_path
|
60
|
+
end
|
61
|
+
alias_method_chain :setup_fixtures, :set_fixture_path
|
62
|
+
end
|
63
|
+
|
64
|
+
ActiveRecord::Base.configurations = true
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
3
|
+
|
4
|
+
describe Userstamp do
|
5
|
+
|
6
|
+
fixtures :users, :people, :posts
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@zeus = users(:zeus)
|
10
|
+
@hera = users(:hera)
|
11
|
+
@delynn = people(:delynn)
|
12
|
+
@nicole = people(:nicole)
|
13
|
+
@first_post = posts(:first_post)
|
14
|
+
@second_post = posts(:second_post)
|
15
|
+
User.stamper = @zeus
|
16
|
+
Person.stamper = @delynn
|
17
|
+
end
|
18
|
+
|
19
|
+
it "person_creation_with_stamped_object" do
|
20
|
+
User.stamper.should == @zeus.id
|
21
|
+
|
22
|
+
person = Person.create(:name => "David")
|
23
|
+
person.creator_id.should == @zeus.id
|
24
|
+
person.updater_id.should == @zeus.id
|
25
|
+
person.creator.should == @zeus
|
26
|
+
person.updater.should == @zeus
|
27
|
+
end
|
28
|
+
|
29
|
+
it "person_creation_with_stamped_integer" do
|
30
|
+
User.stamper = 2
|
31
|
+
User.stamper.should == 2
|
32
|
+
|
33
|
+
person = Person.create(:name => "Daniel")
|
34
|
+
person.creator_id.should == @hera.id
|
35
|
+
person.updater_id.should == @hera.id
|
36
|
+
person.creator.should == @hera
|
37
|
+
person.updater.should == @hera
|
38
|
+
end
|
39
|
+
|
40
|
+
it "post_creation_with_stamped_object" do
|
41
|
+
Person.stamper.should == @delynn.id
|
42
|
+
|
43
|
+
post = Post.create(:title => "Test Post - 1")
|
44
|
+
post.creator_id.should == @delynn.id
|
45
|
+
post.updater_id.should == @delynn.id
|
46
|
+
post.creator.should == @delynn
|
47
|
+
post.updater.should == @delynn
|
48
|
+
end
|
49
|
+
|
50
|
+
it "post_creation_with_stamped_integer" do
|
51
|
+
Person.stamper = 2
|
52
|
+
Person.stamper.should == 2
|
53
|
+
|
54
|
+
post = Post.create(:title => "Test Post - 2")
|
55
|
+
post.creator_id.should == @nicole.id
|
56
|
+
post.updater_id.should == @nicole.id
|
57
|
+
post.creator.should == @nicole
|
58
|
+
post.updater.should == @nicole
|
59
|
+
end
|
60
|
+
|
61
|
+
it "person_updating_with_stamped_object" do
|
62
|
+
User.stamper = @hera
|
63
|
+
User.stamper.should == @hera.id
|
64
|
+
|
65
|
+
@delynn.name << " Berry"
|
66
|
+
@delynn.save
|
67
|
+
@delynn.reload
|
68
|
+
@delynn.creator.should == @zeus
|
69
|
+
@delynn.updater.should == @hera
|
70
|
+
@delynn.creator_id.should == @zeus.id
|
71
|
+
@delynn.updater_id.should == @hera.id
|
72
|
+
end
|
73
|
+
|
74
|
+
it "person_updating_with_stamped_integer" do
|
75
|
+
User.stamper = 2
|
76
|
+
User.stamper.should == 2
|
77
|
+
|
78
|
+
@delynn.name << " Berry"
|
79
|
+
@delynn.save
|
80
|
+
@delynn.reload
|
81
|
+
@delynn.creator_id.should == @zeus.id
|
82
|
+
@delynn.updater_id.should == @hera.id
|
83
|
+
@delynn.creator.should == @zeus
|
84
|
+
@delynn.updater.should == @hera
|
85
|
+
end
|
86
|
+
|
87
|
+
it "post_updating_with_stamped_object" do
|
88
|
+
Person.stamper = @nicole
|
89
|
+
Person.stamper.should == @nicole.id
|
90
|
+
|
91
|
+
@first_post.title << " - Updated"
|
92
|
+
@first_post.save
|
93
|
+
@first_post.reload
|
94
|
+
@first_post.creator_id.should == @delynn.id
|
95
|
+
@first_post.updater_id.should == @nicole.id
|
96
|
+
@first_post.creator.should == @delynn
|
97
|
+
@first_post.updater.should == @nicole
|
98
|
+
end
|
99
|
+
|
100
|
+
it "post_updating_with_stamped_integer" do
|
101
|
+
Person.stamper = 2
|
102
|
+
Person.stamper.should == 2
|
103
|
+
|
104
|
+
@first_post.title << " - Updated"
|
105
|
+
@first_post.save
|
106
|
+
@first_post.reload
|
107
|
+
@first_post.creator_id.should == @delynn.id
|
108
|
+
@first_post.updater_id.should == @nicole.id
|
109
|
+
@first_post.creator.should == @delynn
|
110
|
+
@first_post.updater.should == @nicole
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe UsersController, :type => :controller do
|
4
|
+
fixtures :users
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@zeus = users(:zeus)
|
8
|
+
@hera = users(:hera)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "update" do
|
12
|
+
it "single request" do
|
13
|
+
request.session[:user_id] = 2
|
14
|
+
post :update, :id => 2, :user => {:name => 'Different'}
|
15
|
+
response.should be_success
|
16
|
+
assigns["user"].name.should == 'Different'
|
17
|
+
assigns["user"].updater.should == @hera
|
18
|
+
end
|
19
|
+
|
20
|
+
it "multiple request" do
|
21
|
+
request.session[:user_id] = 2
|
22
|
+
get :edit, :id => 2
|
23
|
+
response.should be_success
|
24
|
+
|
25
|
+
request.session[:user_id] = 1
|
26
|
+
post :update, :id => 2, :user => {:name => 'Different Second'}
|
27
|
+
response.should be_success
|
28
|
+
assigns["user"].updater.should == @zeus
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: magic_userstamp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- akimatter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-28 00:00:00 +09:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.9
|
24
|
+
version:
|
25
|
+
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.
|
26
|
+
email: akm2000@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.original
|
34
|
+
- README.rdoc
|
35
|
+
files:
|
36
|
+
- .gitignore
|
37
|
+
- CHANGELOG
|
38
|
+
- LICENSE
|
39
|
+
- README.original
|
40
|
+
- README.rdoc
|
41
|
+
- Rakefile
|
42
|
+
- VERSION
|
43
|
+
- init.rb
|
44
|
+
- lib/userstamp.rb
|
45
|
+
- lib/userstamp/config.rb
|
46
|
+
- lib/userstamp/controller.rb
|
47
|
+
- lib/userstamp/event.rb
|
48
|
+
- lib/userstamp/magic_columns.rb
|
49
|
+
- lib/userstamp/migration_helper.rb
|
50
|
+
- lib/userstamp/stampable.rb
|
51
|
+
- lib/userstamp/stamper.rb
|
52
|
+
- magic_userstamp.gemspec
|
53
|
+
- rdoc/classes/Ddb/Controller.html
|
54
|
+
- rdoc/classes/Ddb/Controller/Userstamp.html
|
55
|
+
- rdoc/classes/Ddb/Controller/Userstamp/InstanceMethods.html
|
56
|
+
- rdoc/classes/Ddb/Userstamp.html
|
57
|
+
- rdoc/classes/Ddb/Userstamp/MigrationHelper.html
|
58
|
+
- rdoc/classes/Ddb/Userstamp/MigrationHelper/InstanceMethods.html
|
59
|
+
- rdoc/classes/Ddb/Userstamp/Stampable.html
|
60
|
+
- rdoc/classes/Ddb/Userstamp/Stampable/ClassMethods.html
|
61
|
+
- rdoc/classes/Ddb/Userstamp/Stamper.html
|
62
|
+
- rdoc/classes/Ddb/Userstamp/Stamper/ClassMethods.html
|
63
|
+
- rdoc/classes/Ddb/Userstamp/Stamper/InstanceMethods.html
|
64
|
+
- rdoc/created.rid
|
65
|
+
- rdoc/files/CHANGELOG.html
|
66
|
+
- rdoc/files/LICENSE.html
|
67
|
+
- rdoc/files/README.html
|
68
|
+
- rdoc/files/lib/migration_helper_rb.html
|
69
|
+
- rdoc/files/lib/stampable_rb.html
|
70
|
+
- rdoc/files/lib/stamper_rb.html
|
71
|
+
- rdoc/files/lib/userstamp_rb.html
|
72
|
+
- rdoc/fr_class_index.html
|
73
|
+
- rdoc/fr_file_index.html
|
74
|
+
- rdoc/fr_method_index.html
|
75
|
+
- rdoc/index.html
|
76
|
+
- rdoc/rdoc-style.css
|
77
|
+
- spec/compatibility_stamping_spec.rb
|
78
|
+
- spec/config_spec.rb
|
79
|
+
- spec/database.yml
|
80
|
+
- spec/fixtures/comments.yml
|
81
|
+
- spec/fixtures/people.yml
|
82
|
+
- spec/fixtures/posts.yml
|
83
|
+
- spec/fixtures/users.yml
|
84
|
+
- spec/magic_column_spec.rb
|
85
|
+
- spec/posts_controller_spec.rb
|
86
|
+
- spec/resources/controllers/application_controller.rb
|
87
|
+
- spec/resources/controllers/posts_controller.rb
|
88
|
+
- spec/resources/controllers/users_controller.rb
|
89
|
+
- spec/resources/controllers/userstamp_controller.rb
|
90
|
+
- spec/resources/models/comment.rb
|
91
|
+
- spec/resources/models/person.rb
|
92
|
+
- spec/resources/models/ping.rb
|
93
|
+
- spec/resources/models/post.rb
|
94
|
+
- spec/resources/models/user.rb
|
95
|
+
- spec/schema.rb
|
96
|
+
- spec/spec.opts
|
97
|
+
- spec/spec_helper.rb
|
98
|
+
- spec/stamping_spec.rb
|
99
|
+
- spec/users_controller_spec.rb
|
100
|
+
has_rdoc: true
|
101
|
+
homepage: http://github.com/akm/magic_userstamp
|
102
|
+
licenses: []
|
103
|
+
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options:
|
106
|
+
- --charset=UTF-8
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: "0"
|
114
|
+
version:
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: "0"
|
120
|
+
version:
|
121
|
+
requirements: []
|
122
|
+
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 1.3.5
|
125
|
+
signing_key:
|
126
|
+
specification_version: 3
|
127
|
+
summary: creator_id/updater_id/deleter_id support with setting outside models
|
128
|
+
test_files:
|
129
|
+
- spec/compatibility_stamping_spec.rb
|
130
|
+
- spec/config_spec.rb
|
131
|
+
- spec/magic_column_spec.rb
|
132
|
+
- spec/posts_controller_spec.rb
|
133
|
+
- spec/resources/controllers/application_controller.rb
|
134
|
+
- spec/resources/controllers/posts_controller.rb
|
135
|
+
- spec/resources/controllers/users_controller.rb
|
136
|
+
- spec/resources/controllers/userstamp_controller.rb
|
137
|
+
- spec/resources/models/comment.rb
|
138
|
+
- spec/resources/models/person.rb
|
139
|
+
- spec/resources/models/ping.rb
|
140
|
+
- spec/resources/models/post.rb
|
141
|
+
- spec/resources/models/user.rb
|
142
|
+
- spec/schema.rb
|
143
|
+
- spec/spec_helper.rb
|
144
|
+
- spec/stamping_spec.rb
|
145
|
+
- spec/users_controller_spec.rb
|