blamer 3.0.1 → 4.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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ Mjg3YTVhMzdjNjZmMmU1MmMyY2MyYmMxYWZiNzY4MDJhMDE1YTRmMA==
5
+ data.tar.gz: !binary |-
6
+ Zjc2NjEyYTQ4N2NkOGYzMTM2ZGYzZTU5NmU5MTQyMmJjNzAyZGU5Yg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZmIyNTIwYzA3ZjM1MGMyMTVlOGQ5ZTMyNTJhNDk3OTA4ZDhjZTJkNWNhMDgx
10
+ NWEwMGE5NjljNzg5NDFkYWZhZDI3N2UzZDhjNDZkNzRjMjY4MGFiYmNlZDZm
11
+ MTBjNTk4YjNjM2Y4MWEyZGQwODU3M2JiOGJlZDNjOGY4ZjhkOWQ=
12
+ data.tar.gz: !binary |-
13
+ OTZkMTU5MTMxZjExYjk4NzU0ZTg1ZTMzNTFiODkyNTc4ZDM0NTg4OWMzODJk
14
+ ZDAxMDhkNzNhOGFiYjA4YmQ1NDg4OTY2OTk0ZmVlYjQxMGFkOGUzMmNlMDkz
15
+ YmE3MWE2MzA3YTdlOTA0NDVlYTQwMzU2MTcwYzY2ODJjMTc2N2I=
data/Gemfile CHANGED
@@ -1,5 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
1
3
  gemspec
2
4
 
3
5
  group :test do
6
+ gem 'rake'
4
7
  gem 'sqlite3'
8
+ gem 'test-unit'
5
9
  end
@@ -1,39 +1,46 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- blamer (3.0.0)
5
- activerecord (> 2.3.0, < 3.2.0)
4
+ blame (4.0.0)
5
+ activerecord (>= 4.0.0)
6
+ activesupport (>= 4.0.0)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
- activemodel (3.1.12)
11
- activesupport (= 3.1.12)
12
- builder (~> 3.0.0)
13
- i18n (~> 0.6)
14
- activerecord (3.1.12)
15
- activemodel (= 3.1.12)
16
- activesupport (= 3.1.12)
17
- arel (~> 2.2.3)
18
- tzinfo (~> 0.3.29)
19
- activesupport (3.1.12)
20
- multi_json (~> 1.0)
21
- arel (2.2.3)
22
- builder (3.0.4)
11
+ activemodel (4.0.13)
12
+ activesupport (= 4.0.13)
13
+ builder (~> 3.1.0)
14
+ activerecord (4.0.13)
15
+ activemodel (= 4.0.13)
16
+ activerecord-deprecated_finders (~> 1.0.2)
17
+ activesupport (= 4.0.13)
18
+ arel (~> 4.0.0)
19
+ activerecord-deprecated_finders (1.0.3)
20
+ activesupport (4.0.13)
21
+ i18n (~> 0.6, >= 0.6.9)
22
+ minitest (~> 4.2)
23
+ multi_json (~> 1.3)
24
+ thread_safe (~> 0.1)
25
+ tzinfo (~> 0.3.37)
26
+ arel (4.0.2)
27
+ builder (3.1.4)
23
28
  i18n (0.7.0)
29
+ minitest (4.7.5)
24
30
  multi_json (1.10.1)
25
31
  power_assert (0.2.2)
26
32
  rake (10.4.2)
27
33
  sqlite3 (1.3.10)
28
- test-unit (3.0.9)
34
+ test-unit (3.0.8)
29
35
  power_assert
36
+ thread_safe (0.3.4)
30
37
  tzinfo (0.3.43)
31
38
 
32
39
  PLATFORMS
33
40
  ruby
34
41
 
35
42
  DEPENDENCIES
36
- blamer!
43
+ blame!
37
44
  rake
38
45
  sqlite3
39
46
  test-unit
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008-2014 Keith Morrison <keithm@infused.org>
1
+ Copyright (c) 2008-2015 Keith Morrison <keithm@infused.org>
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,13 +1,30 @@
1
1
  # Blamer
2
2
 
3
+ [![Version](http://img.shields.io/gem/v/blamer.svg?style=flat)](https://rubygems.org/gems/blamer)
4
+ [![Build Status](http://img.shields.io/travis/infused/blamer/master.svg?style=flat)](http://travis-ci.org/infused/blamer)
5
+ [![Code Quality](http://img.shields.io/codeclimate/github/infused/blamer.svg?style=flat)](https://codeclimate.com/github/infused/blamer)
6
+
3
7
  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.
8
+ The Blame plugin attempts to mirror the simplicity of ActiveRecord's timestamp module.
9
+
10
+ Blamer expects User.current_user to return the current user. Basic setup involves assigning to `User.current_user` in a controller before filter:
11
+
12
+ class User < ActiveRecord::Base
13
+ cattr_accessor :current_user
14
+ end
15
+
16
+ class ApplicationController < ActionController::Base
17
+ before_filter :set_userstamp
18
+
19
+ def set_userstamp
20
+ User.current_user = User.find(session[:user_id])
21
+ end
22
+ end
5
23
 
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:
24
+ If you don't want to use `User.current_user` you can override this behavior by writing your own *userstamp_object* method in ActiveRecord::Base or any of your models. For example, to use Person.current:
8
25
 
9
26
  def userstamp_object
10
- User.find(session[:user_id])
27
+ Person.current
11
28
  end
12
29
 
13
30
  If you don't like created_by/updated_by you can customize the column names:
@@ -41,25 +58,38 @@ Blamer adds a *userstamps* migration helper which will add the created_by and up
41
58
 
42
59
  Add a line to your environment.rb
43
60
 
44
- config.gem 'blame'
61
+ config.gem 'Blamer', '~> 2.0.0'
45
62
 
63
+ ### Rails 3.x
46
64
 
47
- ### Rails 3.x +
65
+ Add to your Gemfile
66
+
67
+ gem 'Blamer', '~> 3.0.0'
68
+
69
+ Or
70
+
71
+ gem 'Blamer', :github => 'infused/blame', :branch => '3_stable'
72
+
73
+ ### Rails 4.x
48
74
 
49
75
  Add to your Gemfile
50
76
 
51
- gem 'blame'
77
+ gem 'Blamer', '~> 4.0.0'
78
+
79
+ Or
80
+
81
+ gem 'Blamer', :github => 'infused/blame', :branch => '4_stable'
52
82
 
53
83
 
54
84
  ## Credit
55
85
 
56
86
  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.
87
+ (http://github.com/delynn/userstamp/), which was the inspiration for this plugin.
58
88
 
59
89
 
60
90
  ## License
61
91
 
62
- Copyright (c) 2008-2014 Keith Morrison <<keithm@infused.org>>
92
+ Copyright (c) 2008-2015 Keith Morrison <<keithm@infused.org>>
63
93
 
64
94
  Permission is hereby granted, free of charge, to any person
65
95
  obtaining a copy of this software and associated documentation
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rake'
2
2
  require 'rake/testtask'
3
+ require 'rdoc/task'
3
4
 
4
5
  desc 'Default: run unit tests.'
5
6
  task :default => :test
@@ -10,3 +11,17 @@ Rake::TestTask.new(:test) do |t|
10
11
  t.pattern = 'test/**/*_test.rb'
11
12
  t.verbose = true
12
13
  end
14
+
15
+ desc 'Generate documentation for the blame plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'Blame'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
23
+
24
+ desc "Open an irb session preloaded with this library"
25
+ task :console do
26
+ sh "irb -rubygems -I lib -r blame.rb"
27
+ end
@@ -0,0 +1,23 @@
1
+ lib = File.expand_path('../lib/', __FILE__)
2
+ $:.unshift lib unless $:.include?(lib)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'blamer'
6
+ s.version = '4.0.0'
7
+ s.authors = ['Keith Morrison']
8
+ s.email = 'keithm@infused.org'
9
+ s.homepage = 'http://github.com/infused/blamer'
10
+ s.summary = 'Userstamps for ActiveRecord'
11
+ s.description = 'Automatically userstamps create and update operations if the table has created_by and/or updated_by columns'
12
+ s.license = 'MIT'
13
+
14
+ s.rdoc_options = ['--charset=UTF-8']
15
+ s.extra_rdoc_files = ['README.md', 'CHANGELOG.md', 'LICENSE']
16
+ s.files = Dir['[A-Z]*', '{lib,test}/**/*', 'blamer.gemspec']
17
+ s.test_files = Dir.glob('test/**/*_test.rb')
18
+ s.require_paths = ['lib']
19
+
20
+ s.required_rubygems_version = '>= 1.3.0'
21
+ s.add_dependency 'activerecord', '>= 4.0.0'
22
+ s.add_dependency 'activesupport', '>= 4.0.0'
23
+ end
@@ -1,57 +1,19 @@
1
+ require 'active_support'
1
2
  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
- if base.respond_to?(:class_attribute)
10
- base.class_attribute :record_userstamps
11
- base.class_attribute :created_userstamp_column
12
- base.class_attribute :updated_userstamp_column
13
- else
14
- base.class_inheritable_accessor :record_userstamps, :instance_writer => false
15
- base.class_inheritable_accessor :created_userstamp_column, :instance_writer => false
16
- base.class_inheritable_accessor :updated_userstamp_column, :instance_writer => false
17
- end
18
-
19
- base.record_userstamps = true
20
- base.created_userstamp_column = :created_by
21
- base.updated_userstamp_column = :updated_by
22
- end
23
-
24
- private
25
-
26
- def userstamp_object
27
- User.current_user
28
- end
29
-
30
- def create_with_userstamps
31
- if record_userstamps && userstamp_object
32
- write_attribute(created_userstamp_column, userstamp_object.id) if respond_to?(created_userstamp_column)
33
- write_attribute(updated_userstamp_column, userstamp_object.id) if respond_to?(updated_userstamp_column)
3
+ require 'blamer/userstamp'
4
+
5
+ if defined?(Rails::Railtie)
6
+ class Railtie < Rails::Railtie
7
+ initializer 'blame.insert_into_active_record' do
8
+ ActiveSupport.on_load :active_record do
9
+ ActiveRecord::Base.send :include, Blamer::Userstamp
10
+ ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Blamer::UserstampMigrationHelper
34
11
  end
35
- create_without_userstamps
36
12
  end
37
-
38
- def update_with_userstamps(*args)
39
- if record_userstamps && userstamp_object && (!partial_updates? || changed?)
40
- write_attribute(updated_userstamp_column, userstamp_object.id) if respond_to?(updated_userstamp_column)
41
- end
42
- update_without_userstamps
43
- end
44
-
45
13
  end
46
-
47
- module UserstampMigrationHelper
48
- def userstamps
49
- column ActiveRecord::Base.created_userstamp_column, :integer
50
- column ActiveRecord::Base.updated_userstamp_column, :integer
51
- end
14
+ else
15
+ if defined?(ActiveRecord)
16
+ ActiveRecord::Base.send :include, Blamer::Userstamp
17
+ ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Blamer::UserstampMigrationHelper
52
18
  end
53
-
54
19
  end
55
-
56
- ActiveRecord::Base.send :include, Blamer::Userstamp
57
- ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Blamer::UserstampMigrationHelper
@@ -0,0 +1,47 @@
1
+ module Blamer
2
+ module Userstamp
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ class_attribute :record_userstamps, :instance_writer => false
7
+ class_attribute :created_userstamp_column, :instance_writer => false
8
+ class_attribute :updated_userstamp_column, :instance_writer => false
9
+
10
+ self.record_userstamps = true
11
+ self.created_userstamp_column = :created_by
12
+ self.updated_userstamp_column = :updated_by
13
+ end
14
+
15
+ private
16
+
17
+ def userstamp_object
18
+ User.current_user
19
+ end
20
+
21
+ def _create_record(*args)
22
+ if record_userstamps && userstamp_object
23
+ write_attribute(created_userstamp_column, userstamp_object.id) if respond_to?(created_userstamp_column)
24
+ write_attribute(updated_userstamp_column, userstamp_object.id) if respond_to?(updated_userstamp_column)
25
+ end
26
+
27
+ super
28
+ end
29
+
30
+ def _update_record(*args)
31
+ if record_userstamps && userstamp_object && changed?
32
+ write_attribute(updated_userstamp_column, userstamp_object.id) if respond_to?(updated_userstamp_column)
33
+ end
34
+
35
+ super
36
+ end
37
+
38
+ end
39
+
40
+ module UserstampMigrationHelper
41
+ def userstamps
42
+ column ActiveRecord::Base.created_userstamp_column, :integer
43
+ column ActiveRecord::Base.updated_userstamp_column, :integer
44
+ end
45
+ end
46
+
47
+ end
@@ -1,28 +1,28 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
2
 
3
- class BlamerTest < Test::Unit::TestCase
3
+ class BlameTest < Test::Unit::TestCase
4
4
  def setup
5
- ActiveRecord::Base.partial_updates = false
6
- @user1 = User.create
7
- @user2 = User.create
5
+ @user1 = User.create!
6
+ @user2 = User.create!
8
7
  User.current_user = @user1
9
- @widget = Widget.create :name => 'One'
8
+ @widget = Widget.create! :name => 'One'
10
9
  end
11
-
12
- def test_partial_updates_disabled
13
- assert !ActiveRecord::Base.partial_updates
14
- end
15
-
10
+
16
11
  def test_create
12
+ assert_equal 'One', @widget.name
17
13
  assert_equal @user1.id, @widget.created_by
18
14
  assert_equal @user1.id, @widget.updated_by
19
15
  end
20
-
16
+
21
17
  def test_update
22
18
  User.current_user = @user2
23
19
  @widget.update_attribute(:name, 'Two')
20
+
21
+ @widget.reload
22
+
23
+ assert_equal 'Two', @widget.name
24
24
  assert_equal @user1.id, @widget.created_by
25
25
  assert_equal @user2.id, @widget.updated_by
26
26
  end
27
-
28
- end
27
+
28
+ end
@@ -1,31 +1,35 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
2
 
3
- class OverrideBlamerTest < Test::Unit::TestCase
4
-
3
+ class OverrideBlameTest < Test::Unit::TestCase
4
+
5
5
  # Override the default userstamp_object method
6
6
  class Sprocket < ActiveRecord::Base
7
7
  def userstamp_object
8
8
  Monkey.banana
9
9
  end
10
10
  end
11
-
11
+
12
12
  def setup
13
- @monkey1 = Monkey.create
14
- @monkey2 = Monkey.create
13
+ @monkey1 = Monkey.create!
14
+ @monkey2 = Monkey.create!
15
15
  Monkey.banana = @monkey1
16
- @sprocket = Sprocket.create :name => 'One'
16
+ @sprocket = Sprocket.create! :name => 'One'
17
17
  end
18
-
18
+
19
19
  def test_create
20
+ assert_equal 'One', @sprocket.name
20
21
  assert_equal @monkey1.id, @sprocket.created_by
21
22
  assert_equal @monkey1.id, @sprocket.updated_by
22
23
  end
23
-
24
+
24
25
  def test_update
25
26
  Monkey.banana = @monkey2
26
27
  @sprocket.update_attribute(:name, 'Two')
28
+
29
+ @sprocket.reload
30
+ assert_equal 'Two', @sprocket.name
27
31
  assert_equal @monkey1.id, @sprocket.created_by
28
32
  assert_equal @monkey2.id, @sprocket.updated_by
29
33
  end
30
-
31
- end
34
+
35
+ end
@@ -1,28 +1,27 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
2
 
3
- class PartialBlamerTest < Test::Unit::TestCase
3
+ class PartialBlameTest < Test::Unit::TestCase
4
4
  def setup
5
- ActiveRecord::Base.partial_updates = true
6
- @user1 = User.create
7
- @user2 = User.create
5
+ @user1 = User.create!
6
+ @user2 = User.create!
8
7
  User.current_user = @user1
9
- @widget = Widget.create :name => 'One'
8
+ @widget = Widget.create! :name => 'One'
10
9
  end
11
-
12
- def test_partial_updates_enabled
13
- assert ActiveRecord::Base.partial_updates
14
- end
15
-
10
+
16
11
  def test_create
12
+ assert_equal 'One', @widget.name
17
13
  assert_equal @user1.id, @widget.created_by
18
14
  assert_equal @user1.id, @widget.updated_by
19
15
  end
20
-
16
+
21
17
  def test_update
22
18
  User.current_user = @user2
23
19
  @widget.update_attribute(:name, 'Two')
20
+
21
+ @widget.reload
22
+ assert_equal 'Two', @widget.name
24
23
  assert_equal @user1.id, @widget.created_by
25
24
  assert_equal @user2.id, @widget.updated_by
26
25
  end
27
-
28
- end
26
+
27
+ end
metadata CHANGED
@@ -1,36 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blamer
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
5
- prerelease:
4
+ version: 4.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Keith Morrison
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-02-05 00:00:00.000000000 Z
11
+ date: 2015-02-01 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>'
20
- - !ruby/object:Gem::Version
21
- version: 2.3.0
22
- - - <
17
+ - - ! '>='
23
18
  - !ruby/object:Gem::Version
24
19
  version: 4.0.0
25
20
  type: :runtime
26
21
  prerelease: false
27
22
  version_requirements: !ruby/object:Gem::Requirement
28
- none: false
29
23
  requirements:
30
- - - ! '>'
24
+ - - ! '>='
31
25
  - !ruby/object:Gem::Version
32
- version: 2.3.0
33
- - - <
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
34
39
  - !ruby/object:Gem::Version
35
40
  version: 4.0.0
36
41
  description: Automatically userstamps create and update operations if the table has
@@ -47,9 +52,11 @@ files:
47
52
  - Gemfile
48
53
  - Gemfile.lock
49
54
  - LICENSE
50
- - Rakefile
51
55
  - README.md
56
+ - Rakefile
57
+ - blamer.gemspec
52
58
  - lib/blamer.rb
59
+ - lib/blamer/userstamp.rb
53
60
  - test/blame_test.rb
54
61
  - test/models/monkey.rb
55
62
  - test/models/sprocket.rb
@@ -59,31 +66,30 @@ files:
59
66
  - test/partial_blame_test.rb
60
67
  - test/schema.rb
61
68
  - test/test_helper.rb
62
- homepage: http://github.com/infused/blame
69
+ homepage: http://github.com/infused/blamer
63
70
  licenses:
64
71
  - MIT
72
+ metadata: {}
65
73
  post_install_message:
66
74
  rdoc_options:
67
75
  - --charset=UTF-8
68
76
  require_paths:
69
77
  - lib
70
78
  required_ruby_version: !ruby/object:Gem::Requirement
71
- none: false
72
79
  requirements:
73
80
  - - ! '>='
74
81
  - !ruby/object:Gem::Version
75
82
  version: '0'
76
83
  required_rubygems_version: !ruby/object:Gem::Requirement
77
- none: false
78
84
  requirements:
79
85
  - - ! '>='
80
86
  - !ruby/object:Gem::Version
81
87
  version: 1.3.0
82
88
  requirements: []
83
89
  rubyforge_project:
84
- rubygems_version: 1.8.25
90
+ rubygems_version: 2.4.5
85
91
  signing_key:
86
- specification_version: 3
92
+ specification_version: 4
87
93
  summary: Userstamps for ActiveRecord
88
94
  test_files:
89
95
  - test/blame_test.rb