ar-audit-tracer 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,10 +1,10 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- #gemspec
3
+ gemspec
4
4
 
5
5
  #gem 'activerecord', '~> 3.0.3'
6
6
  #gem 'activerecord', '~> 3.1.0'
7
- gem 'activerecord', '~> 3.2.0'
7
+ #gem 'activerecord', '~> 3.2.0'
8
8
 
9
9
  group :test do
10
10
  gem 'rake'
@@ -1,3 +1,9 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ar-audit-tracer (1.0.2)
5
+ activerecord (~> 3.0)
6
+
1
7
  GEM
2
8
  remote: http://rubygems.org/
3
9
  specs:
@@ -24,6 +30,7 @@ PLATFORMS
24
30
  ruby
25
31
 
26
32
  DEPENDENCIES
27
- activerecord (~> 3.2.0)
33
+ activerecord (~> 3.0)
34
+ ar-audit-tracer!
28
35
  rake
29
36
  sqlite3
@@ -7,7 +7,13 @@
7
7
  <i>ar-audit-tracer</i> patches ActiveRecord so modifiers of a record can be traked on saving (insert/update).
8
8
  It works exactly like 'timestamps' (see usage below).
9
9
 
10
- The new version 1.0.0 works now for Rails 3.0, 3.1 and 3.2 and is tested with Ruby 1.8.7, 1.9.2 and 1.9.3.
10
+ The new version 1.0.2 works now for Rails 3.0, 3.1 and 3.2 and is tested with Ruby 1.8.7, 1.9.2 and 1.9.3.
11
+
12
+
13
+ == Installation
14
+
15
+ Add below to your Gemfile and run the +bundle+ command
16
+ gem 'ar-audit-tracer'
11
17
 
12
18
 
13
19
  == Usage
@@ -16,13 +22,27 @@ The new version 1.0.0 works now for Rails 3.0, 3.1 and 3.2 and is tested with Ru
16
22
 
17
23
  In a models migration add:
18
24
  t.authors
19
-
25
+
20
26
  This will add columns +created_by+ and +updated_by+ of type +:string+ to your model.
21
27
 
22
28
  In case you want to use another type, simply pass the type as argument, e.g.
23
29
  t.authors(:integer)
24
30
 
25
- === Usage
31
+ By default the columns are mandatory (:null => true). If you have existing models you want to change
32
+ you have to pass the option <tt>:null => true</tt>, update the values in the new attributes columns and add another
33
+ migration to change the column to <tt>:null => false</tt> if required.
34
+ Note: If you pass options you have to pass the type as well - sample migration statments:
35
+ add_authors(:your_table_name, :string, :null => true)
36
+ or
37
+ change_table :your_table_name do |t|
38
+ t.authors(:integer, :null => true)
39
+ end
40
+
41
+ ==== Note
42
+ The _authors_ methods are simple conveniance methods (as regular timestamp methods are). You can simply
43
+ add columns named +created_by+ and +updated_by+ using regular migration statements.
44
+
45
+ === Configuration
26
46
 
27
47
  All you need to do is to set the current author such as e.g:
28
48
  Concern::Audit::Author.current="bad_man"
@@ -30,8 +50,13 @@ All you need to do is to set the current author such as e.g:
30
50
  Each ActiveRecord +save+ or +update+ then will set the respetive attributes +created_by+ and +modified_by+ automatically, whereas the modifier is set to the same value as the creator on model creation.
31
51
 
32
52
  In a Rails Application you would set the author as described above in a +before_filter+.
33
- +Concern::Audit::Author+ stores the author in a Thread-Local variable.
53
+ <tt>Concern::Audit::Author</tt> stores the author in a Thread-Local variable.
34
54
 
35
55
  == Additional Notes
36
56
  In case you need associations to a respective Author Model you have to set them up yourselfs.
37
57
 
58
+
59
+ == Changelog
60
+
61
+ === Version 1.0.2
62
+ * Fixed migrations so option can be passed
data/Rakefile CHANGED
@@ -26,7 +26,7 @@ rescue LoadError
26
26
  end
27
27
 
28
28
 
29
- require 'rake/rdoctask'
29
+ require 'rdoc/task'
30
30
  require "ar-audit-tracer/version"
31
31
  Rake::RDocTask.new do |rdoc|
32
32
  version = ArAuditTracer::VERSION
@@ -98,9 +98,10 @@ module ActiveRecord
98
98
  # Adds author columns (created_by and updated_by) to the named table.
99
99
  # ===== Examples
100
100
  # add_authors(:suppliers)
101
- def add_authors(table_name, type=:string)
102
- add_column table_name, :created_by, type, :null => false
103
- add_column table_name, :updated_by, type, :null => false
101
+ def add_authors(table_name, type=:string, *args)
102
+ options = {:null => false}.merge(args.extract_options!)
103
+ add_column table_name, :created_by, type, options
104
+ add_column table_name, :updated_by, type, options
104
105
  end
105
106
 
106
107
  # Removes the author columns (created_by and updated_by) from the table definition.
@@ -134,8 +135,9 @@ module ActiveRecord
134
135
  #
135
136
  # @param Symbol type The desired type for the columns, defaults to :string
136
137
  # @see SchemaStatements#add_authors
137
- def authors(type=:string)
138
- @base.add_authors(@table_name, type)
138
+ def authors(type=:string, *args)
139
+ options = {:null => false}.merge(args.extract_options!)
140
+ @base.add_authors(@table_name, type, options)
139
141
  end
140
142
 
141
143
  # Removes the author columns (created_by and updated_by) from the table.
@@ -1,3 +1,3 @@
1
1
  module ArAuditTracer
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  end
@@ -7,7 +7,7 @@ class Concern::Audit::AuthorTest < Test::Unit::TestCase
7
7
  def setup
8
8
  Concern::Audit::Author.current = nil
9
9
  end
10
-
10
+
11
11
  def test_author_setting_in_single_thread
12
12
  Concern::Audit::Author.current
13
13
 
@@ -16,7 +16,7 @@ class Concern::Audit::AuthorTest < Test::Unit::TestCase
16
16
 
17
17
  assert_equal("the_author", Concern::Audit::Author.current)
18
18
  end
19
-
19
+
20
20
  def test_author_setting_in_different_threads
21
21
  Concern::Audit::Author.current="outer_thread"
22
22
 
@@ -0,0 +1,7 @@
1
+ class AddAuthors < ActiveRecord::Migration
2
+
3
+ def up
4
+ add_authors(:blank_twos, :string, :null => true)
5
+ end
6
+
7
+ end
@@ -0,0 +1,11 @@
1
+ class ChangeTableAuthors < ActiveRecord::Migration
2
+
3
+ def up
4
+
5
+ change_table :blank_ones do |t|
6
+ t.authors(:integer, :null => true)
7
+ end
8
+
9
+ end
10
+
11
+ end
@@ -7,3 +7,9 @@ end
7
7
  class WithIntegerAuthor < ActiveRecord::Base
8
8
  end
9
9
 
10
+ class BlankOne < ActiveRecord::Base
11
+ end
12
+
13
+ class BlankTwo < ActiveRecord::Base
14
+ end
15
+
@@ -13,4 +13,12 @@ ActiveRecord::Schema.define(:version => 0) do
13
13
  t.authors(:integer)
14
14
  end
15
15
 
16
+ create_table :blank_ones, :force => true do |t|
17
+ t.string :name
18
+ end
19
+
20
+ create_table :blank_twos, :force => true do |t|
21
+ t.string :name
22
+ end
23
+
16
24
  end
@@ -1,5 +1,8 @@
1
1
  require 'helper'
2
2
 
3
+ require 'resources/migrations/add_authors'
4
+ require 'resources/migrations/change_table_authors'
5
+
3
6
  class TestArAuditTracer < Test::Unit::TestCase
4
7
 
5
8
  def setup
@@ -90,4 +93,27 @@ class TestArAuditTracer < Test::Unit::TestCase
90
93
  assert_equal audited_record.updated_by, 1
91
94
  end
92
95
 
96
+ def test_migration_add_authors
97
+ assert !BlankTwo.attribute_names.include?(:created_by)
98
+ assert !BlankTwo.attribute_names.include?(:updated_by)
99
+
100
+ AddAuthors.new().up
101
+ BlankTwo.reset_column_information
102
+
103
+ assert_equal :string, BlankTwo.columns_hash['created_by'].type
104
+ assert_equal :string, BlankTwo.columns_hash['updated_by'].type
105
+ end
106
+
107
+ def test_migration_change_table_authors
108
+ assert !BlankOne.attribute_names.include?(:created_by)
109
+ assert !BlankOne.attribute_names.include?(:updated_by)
110
+
111
+ ChangeTableAuthors.new().up
112
+ BlankOne.reset_column_information
113
+
114
+ assert_equal :integer, BlankOne.columns_hash['created_by'].type
115
+ assert_equal :integer, BlankOne.columns_hash['updated_by'].type
116
+ end
117
+
118
+
93
119
  end
metadata CHANGED
@@ -1,59 +1,70 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ar-audit-tracer
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
4
5
  prerelease:
5
- version: 1.0.1
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Martin Schweizer
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-02-17 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2012-05-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: activerecord
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
18
+ requirements:
21
19
  - - ~>
22
- - !ruby/object:Gem::Version
23
- version: "3.0"
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
24
22
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: activerecord
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: activerecord
32
+ requirement: !ruby/object:Gem::Requirement
30
33
  none: false
31
- requirements:
34
+ requirements:
32
35
  - - ~>
33
- - !ruby/object:Gem::Version
34
- version: "3.0"
36
+ - !ruby/object:Gem::Version
37
+ version: '3.0'
35
38
  type: :development
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: sqlite3
39
39
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- version: "0"
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: sqlite3
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
46
54
  type: :development
47
- version_requirements: *id003
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
48
62
  description: Handles ActiveRecord authors in the same way as timstamps.
49
63
  email: martin@verticonaut.me
50
64
  executables: []
51
-
52
65
  extensions: []
53
-
54
66
  extra_rdoc_files: []
55
-
56
- files:
67
+ files:
57
68
  - .document
58
69
  - .gitignore
59
70
  - .rvmrc
@@ -72,41 +83,43 @@ files:
72
83
  - lib/concern/audit/author.rb
73
84
  - test/concern/audit/author_test.rb
74
85
  - test/helper.rb
86
+ - test/resources/migrations/add_authors.rb
87
+ - test/resources/migrations/change_table_authors.rb
75
88
  - test/resources/models.rb
76
89
  - test/resources/schema.rb
77
90
  - test/test_ar-audit-tracer.rb
78
91
  homepage: http://github.com/verticonaut/ar-audit-tracer
79
92
  licenses: []
80
-
81
93
  post_install_message:
82
- rdoc_options:
94
+ rdoc_options:
83
95
  - --charset
84
96
  - UTF-8
85
97
  - --line-numbers
86
- require_paths:
98
+ require_paths:
87
99
  - lib
88
- required_ruby_version: !ruby/object:Gem::Requirement
100
+ required_ruby_version: !ruby/object:Gem::Requirement
89
101
  none: false
90
- requirements:
91
- - - ">="
92
- - !ruby/object:Gem::Version
93
- version: "0"
94
- required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
107
  none: false
96
- requirements:
97
- - - ">="
98
- - !ruby/object:Gem::Version
99
- version: "0"
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
100
112
  requirements: []
101
-
102
113
  rubyforge_project:
103
- rubygems_version: 1.8.15
114
+ rubygems_version: 1.8.21
104
115
  signing_key:
105
116
  specification_version: 3
106
117
  summary: Track creator/modifiers of you AR Models similar to timestamps.
107
- test_files:
118
+ test_files:
108
119
  - test/concern/audit/author_test.rb
109
120
  - test/helper.rb
121
+ - test/resources/migrations/add_authors.rb
122
+ - test/resources/migrations/change_table_authors.rb
110
123
  - test/resources/models.rb
111
124
  - test/resources/schema.rb
112
125
  - test/test_ar-audit-tracer.rb