blamer 3.0.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.
- checksums.yaml +15 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +30 -0
- data/LICENSE +20 -0
- data/README.md +83 -0
- data/Rakefile +12 -0
- data/lib/blamer.rb +52 -0
- data/test/blame_test.rb +28 -0
- data/test/models/monkey.rb +3 -0
- data/test/models/sprocket.rb +2 -0
- data/test/models/user.rb +3 -0
- data/test/models/widget.rb +2 -0
- data/test/override_userstamp_object_test.rb +31 -0
- data/test/partial_blame_test.rb +28 -0
- data/test/schema.rb +22 -0
- data/test/test_helper.rb +19 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NTU4ZTNkZGIwZmZkZGNjMzRmNmNjMzUyNTliMDk5YjI2NjI2YTc2ZA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NDM3MDg3MmFhYzRmOTAzYTAxZGNiZWViNTFkNjlmMjMzOTBmMmJkYw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OTQxZGQ1YjM2ZGM3YTM3YzA0YTRmZWRmMmEwMWFjNWEyOWY5MTY0YmEyNWRi
|
10
|
+
MTNiZDEyM2Q3ZWRjNmMxNDdlMjc1OWZmNzY4M2IzN2ZiZWZiZWRhNjc0ZDVl
|
11
|
+
N2Q0ZjNkNDY4MWJiN2VhOGJlODFhM2RhZWRkMGNjZDRjMGM4N2Q=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZjEyMDA3NTJhZDNiZjE2MGZjMzI0OGNlMjI0Yzc5YzQ2NjAxNTE3YjZlNDg0
|
14
|
+
ZTFlZWE0ZDIyZTY5NDllMTdiMjkyOGE0MWNkNDczMzg4Njg1YmIzZmZkMDY3
|
15
|
+
YWI0MmExMjNhMTU0MzY3MzFjMzgzZGJhNjMzYWYwYTFkN2RiM2M=
|
data/CHANGELOG.md
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
blamer (2.0.0)
|
5
|
+
activerecord (> 2.3.0, < 3.2.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
specs:
|
9
|
+
activemodel (3.0.8)
|
10
|
+
activesupport (= 3.0.8)
|
11
|
+
builder (~> 2.1.2)
|
12
|
+
i18n (~> 0.5.0)
|
13
|
+
activerecord (3.0.8)
|
14
|
+
activemodel (= 3.0.8)
|
15
|
+
activesupport (= 3.0.8)
|
16
|
+
arel (~> 2.0.10)
|
17
|
+
tzinfo (~> 0.3.23)
|
18
|
+
activesupport (3.0.8)
|
19
|
+
arel (2.0.10)
|
20
|
+
builder (2.1.2)
|
21
|
+
i18n (0.5.4)
|
22
|
+
sqlite3 (1.3.10)
|
23
|
+
tzinfo (0.3.43)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
blamer!
|
30
|
+
sqlite3
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008-2014 Keith Morrison <keithm@infused.org>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# Blamer
|
2
|
+
|
3
|
+
Automatically userstamps create and update operations if the table has columns named *created_by* and/or *updated_by*.
|
4
|
+
The Blamer plugin attempts to mirror the simplicity of ActiveRecord's timestamp module.
|
5
|
+
|
6
|
+
Blamer assumes that you are using restful-authentication and expects User.current_user to return the current user. You
|
7
|
+
can override this behavior by writing your own *userstamp_object* method in ActiveRecord::Base or any of your models. For example:
|
8
|
+
|
9
|
+
def userstamp_object
|
10
|
+
User.find(session[:user_id])
|
11
|
+
end
|
12
|
+
|
13
|
+
If you don't like created_by/updated_by you can customize the column names:
|
14
|
+
|
15
|
+
# Globally in environment.rb
|
16
|
+
ActiveRecord::Base.created_userstamp_column = :creator_id
|
17
|
+
|
18
|
+
# In a model definition
|
19
|
+
class Subscription
|
20
|
+
self.created_userstamp_column = :creator_id
|
21
|
+
self.updated_userstamp_column = :updater_id
|
22
|
+
end
|
23
|
+
|
24
|
+
Automatic userstamping can be turned off globally by setting:
|
25
|
+
|
26
|
+
ActiveRecord::Base.record_userstamps = false
|
27
|
+
|
28
|
+
Blamer adds a *userstamps* migration helper which will add the created_by and updated_by columns (or your custom column names) to your table:
|
29
|
+
|
30
|
+
create_table :widgets do |t|
|
31
|
+
t.string :name
|
32
|
+
t.timestamps
|
33
|
+
t.userstamps
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
## Installation
|
38
|
+
|
39
|
+
|
40
|
+
### Rails 2.x
|
41
|
+
|
42
|
+
Add a line to your environment.rb
|
43
|
+
|
44
|
+
config.gem 'blame'
|
45
|
+
|
46
|
+
|
47
|
+
### Rails 3.x +
|
48
|
+
|
49
|
+
Add to your Gemfile
|
50
|
+
|
51
|
+
gem 'blame'
|
52
|
+
|
53
|
+
|
54
|
+
## Credit
|
55
|
+
|
56
|
+
Thanks to DeLynn Berry <delynn@gmail.com> for writing the original Userstamp plugin
|
57
|
+
(http://github.com/delynn/userstamp/tree/master), which was the inspiration for this plugin.
|
58
|
+
|
59
|
+
|
60
|
+
## License
|
61
|
+
|
62
|
+
Copyright (c) 2008-2014 Keith Morrison <<keithm@infused.org>>
|
63
|
+
|
64
|
+
Permission is hereby granted, free of charge, to any person
|
65
|
+
obtaining a copy of this software and associated documentation
|
66
|
+
files (the "Software"), to deal in the Software without
|
67
|
+
restriction, including without limitation the rights to use,
|
68
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
69
|
+
copies of the Software, and to permit persons to whom the
|
70
|
+
Software is furnished to do so, subject to the following
|
71
|
+
conditions:
|
72
|
+
|
73
|
+
The above copyright notice and this permission notice shall be
|
74
|
+
included in all copies or substantial portions of the Software.
|
75
|
+
|
76
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
77
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
78
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
79
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
80
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
81
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
82
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
83
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/lib/blamer.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module Blamer
|
4
|
+
module Userstamp
|
5
|
+
def self.included(base)
|
6
|
+
base.alias_method_chain :create, :userstamps
|
7
|
+
base.alias_method_chain :update, :userstamps
|
8
|
+
|
9
|
+
base.class_inheritable_accessor :record_userstamps, :instance_writer => false
|
10
|
+
base.record_userstamps = true
|
11
|
+
|
12
|
+
base.class_inheritable_accessor :created_userstamp_column, :instance_writer => false
|
13
|
+
base.created_userstamp_column = :created_by
|
14
|
+
|
15
|
+
base.class_inheritable_accessor :updated_userstamp_column, :instance_writer => false
|
16
|
+
base.updated_userstamp_column = :updated_by
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def userstamp_object
|
22
|
+
User.current_user
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_with_userstamps
|
26
|
+
if record_userstamps && userstamp_object
|
27
|
+
write_attribute(created_userstamp_column, userstamp_object.id) if respond_to?(created_userstamp_column)
|
28
|
+
write_attribute(updated_userstamp_column, userstamp_object.id) if respond_to?(updated_userstamp_column)
|
29
|
+
end
|
30
|
+
create_without_userstamps
|
31
|
+
end
|
32
|
+
|
33
|
+
def update_with_userstamps(*args)
|
34
|
+
if record_userstamps && userstamp_object && (!partial_updates? || changed?)
|
35
|
+
write_attribute(updated_userstamp_column, userstamp_object.id) if respond_to?(updated_userstamp_column)
|
36
|
+
end
|
37
|
+
update_without_userstamps
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
module UserstampMigrationHelper
|
43
|
+
def userstamps
|
44
|
+
column ActiveRecord::Base.created_userstamp_column, :integer
|
45
|
+
column ActiveRecord::Base.updated_userstamp_column, :integer
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
ActiveRecord::Base.send :include, Blamer::Userstamp
|
52
|
+
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Blamer::UserstampMigrationHelper
|
data/test/blame_test.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class BlamerTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
ActiveRecord::Base.partial_updates = false
|
6
|
+
@user1 = User.create
|
7
|
+
@user2 = User.create
|
8
|
+
User.current_user = @user1
|
9
|
+
@widget = Widget.create :name => 'One'
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_partial_updates_disabled
|
13
|
+
assert !ActiveRecord::Base.partial_updates
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_create
|
17
|
+
assert_equal @user1.id, @widget.created_by
|
18
|
+
assert_equal @user1.id, @widget.updated_by
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_update
|
22
|
+
User.current_user = @user2
|
23
|
+
@widget.update_attribute(:name, 'Two')
|
24
|
+
assert_equal @user1.id, @widget.created_by
|
25
|
+
assert_equal @user2.id, @widget.updated_by
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/test/models/user.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class OverrideBlamerTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
# Override the default userstamp_object method
|
6
|
+
class Sprocket < ActiveRecord::Base
|
7
|
+
def userstamp_object
|
8
|
+
Monkey.banana
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@monkey1 = Monkey.create
|
14
|
+
@monkey2 = Monkey.create
|
15
|
+
Monkey.banana = @monkey1
|
16
|
+
@sprocket = Sprocket.create :name => 'One'
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_create
|
20
|
+
assert_equal @monkey1.id, @sprocket.created_by
|
21
|
+
assert_equal @monkey1.id, @sprocket.updated_by
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_update
|
25
|
+
Monkey.banana = @monkey2
|
26
|
+
@sprocket.update_attribute(:name, 'Two')
|
27
|
+
assert_equal @monkey1.id, @sprocket.created_by
|
28
|
+
assert_equal @monkey2.id, @sprocket.updated_by
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class PartialBlamerTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
ActiveRecord::Base.partial_updates = true
|
6
|
+
@user1 = User.create
|
7
|
+
@user2 = User.create
|
8
|
+
User.current_user = @user1
|
9
|
+
@widget = Widget.create :name => 'One'
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_partial_updates_enabled
|
13
|
+
assert ActiveRecord::Base.partial_updates
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_create
|
17
|
+
assert_equal @user1.id, @widget.created_by
|
18
|
+
assert_equal @user1.id, @widget.updated_by
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_update
|
22
|
+
User.current_user = @user2
|
23
|
+
@widget.update_attribute(:name, 'Two')
|
24
|
+
assert_equal @user1.id, @widget.created_by
|
25
|
+
assert_equal @user2.id, @widget.updated_by
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/test/schema.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Stop ActiveRecord from printing schema statements to the console
|
2
|
+
$stdout = StringIO.new
|
3
|
+
|
4
|
+
ActiveRecord::Schema.define(:version => 1) do
|
5
|
+
create_table :users do |t|
|
6
|
+
t.string :name
|
7
|
+
end
|
8
|
+
|
9
|
+
create_table :monkeys do |t|
|
10
|
+
t.string :name
|
11
|
+
end
|
12
|
+
|
13
|
+
create_table :widgets do |t|
|
14
|
+
t.string :name
|
15
|
+
t.userstamps
|
16
|
+
end
|
17
|
+
|
18
|
+
create_table :sprockets do |t|
|
19
|
+
t.string :name
|
20
|
+
t.userstamps
|
21
|
+
end
|
22
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
Bundler.setup(:default, :test)
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
# Initialize the plugin
|
7
|
+
require File.dirname(__FILE__) + '/../lib/blamer'
|
8
|
+
|
9
|
+
# Use in-memory sqlite3
|
10
|
+
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
11
|
+
|
12
|
+
# Create test tables
|
13
|
+
require File.dirname(__FILE__) + '/schema'
|
14
|
+
|
15
|
+
# Load test models
|
16
|
+
require File.dirname(__FILE__) + '/models/user'
|
17
|
+
require File.dirname(__FILE__) + '/models/monkey'
|
18
|
+
require File.dirname(__FILE__) + '/models/widget'
|
19
|
+
require File.dirname(__FILE__) + '/models/sprocket'
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blamer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Keith Morrison
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>'
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.3.0
|
20
|
+
- - <
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.2.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ! '>'
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.3.0
|
30
|
+
- - <
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.2.0
|
33
|
+
description: Automatically userstamps create and update operations if the table has
|
34
|
+
created_by and/or updated_by columns
|
35
|
+
email: keithm@infused.org
|
36
|
+
executables: []
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files:
|
39
|
+
- README.md
|
40
|
+
- CHANGELOG.md
|
41
|
+
- LICENSE
|
42
|
+
files:
|
43
|
+
- CHANGELOG.md
|
44
|
+
- Gemfile
|
45
|
+
- Gemfile.lock
|
46
|
+
- LICENSE
|
47
|
+
- README.md
|
48
|
+
- Rakefile
|
49
|
+
- lib/blamer.rb
|
50
|
+
- test/blame_test.rb
|
51
|
+
- test/models/monkey.rb
|
52
|
+
- test/models/sprocket.rb
|
53
|
+
- test/models/user.rb
|
54
|
+
- test/models/widget.rb
|
55
|
+
- test/override_userstamp_object_test.rb
|
56
|
+
- test/partial_blame_test.rb
|
57
|
+
- test/schema.rb
|
58
|
+
- test/test_helper.rb
|
59
|
+
homepage: http://github.com/infused/blame
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options:
|
65
|
+
- --charset=UTF-8
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.3.0
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.4.5
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Userstamps for ActiveRecord
|
84
|
+
test_files:
|
85
|
+
- test/blame_test.rb
|
86
|
+
- test/override_userstamp_object_test.rb
|
87
|
+
- test/partial_blame_test.rb
|