acts_as_audited 1.1.1 → 2.0.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/.yardopts +3 -0
  2. data/Gemfile +8 -0
  3. data/Gemfile.lock +102 -0
  4. data/LICENSE +2 -2
  5. data/README.rdoc +90 -0
  6. data/Rakefile +32 -28
  7. data/acts_as_audited.gemspec +75 -34
  8. data/autotest/discover.rb +1 -0
  9. data/lib/acts_as_audited.rb +18 -212
  10. data/lib/acts_as_audited/audit.rb +58 -40
  11. data/lib/acts_as_audited/audit_sweeper.rb +5 -27
  12. data/lib/acts_as_audited/auditor.rb +263 -0
  13. data/lib/generators/acts_as_audited/install_generator.rb +28 -0
  14. data/lib/generators/acts_as_audited/templates/add_comment_to_audits.rb +9 -0
  15. data/lib/generators/acts_as_audited/templates/add_remote_address_to_audits.rb +10 -0
  16. data/{generators/audited_migration/templates/migration.rb → lib/generators/acts_as_audited/templates/install.rb} +6 -4
  17. data/lib/generators/acts_as_audited/templates/rename_changes_to_audited_changes.rb +9 -0
  18. data/lib/generators/acts_as_audited/upgrade_generator.rb +49 -0
  19. data/spec/acts_as_audited_spec.rb +426 -0
  20. data/spec/audit_spec.rb +190 -0
  21. data/spec/audit_sweeper_spec.rb +74 -0
  22. data/spec/audited_spec_helpers.rb +16 -0
  23. data/{test → spec}/db/schema.rb +8 -5
  24. data/spec/rails_app/config/application.rb +23 -0
  25. data/spec/rails_app/config/boot.rb +13 -0
  26. data/{test/db → spec/rails_app/config}/database.yml +10 -7
  27. data/spec/rails_app/config/environment.rb +5 -0
  28. data/spec/rails_app/config/environments/development.rb +19 -0
  29. data/spec/rails_app/config/environments/production.rb +33 -0
  30. data/spec/rails_app/config/environments/test.rb +33 -0
  31. data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  32. data/spec/rails_app/config/initializers/inflections.rb +2 -0
  33. data/spec/rails_app/config/initializers/secret_token.rb +2 -0
  34. data/spec/rails_app/config/routes.rb +6 -0
  35. data/spec/spec_helper.rb +21 -0
  36. data/spec/spec_models.rb +76 -0
  37. data/test/db/version_1.rb +17 -0
  38. data/test/db/version_2.rb +18 -0
  39. data/test/db/version_3.rb +19 -0
  40. data/test/install_generator_test.rb +17 -0
  41. data/test/test_helper.rb +11 -67
  42. data/test/upgrade_generator_test.rb +43 -0
  43. metadata +179 -41
  44. data/.gitignore +0 -4
  45. data/README +0 -70
  46. data/VERSION +0 -1
  47. data/generators/audited_migration/USAGE +0 -7
  48. data/generators/audited_migration/audited_migration_generator.rb +0 -7
  49. data/init.rb +0 -1
  50. data/rails/init.rb +0 -8
  51. data/test/acts_as_audited_test.rb +0 -374
  52. data/test/audit_sweeper_test.rb +0 -31
  53. data/test/audit_test.rb +0 -179
@@ -1,31 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
-
3
- class AuditsController < ActionController::Base
4
- def audit
5
- @company = Company.create
6
- render :nothing => true
7
- end
8
-
9
- def update_user
10
- current_user.update_attributes({:password => 'foo'})
11
- render :nothing => true
12
- end
13
-
14
- private
15
- attr_accessor :current_user
16
- end
17
- AuditsController.view_paths = [File.dirname(__FILE__)]
18
- ActionController::Routing::Routes.draw {|m| m.connect ':controller/:action/:id' }
19
-
20
- class AuditsControllerTest < ActionController::TestCase
21
- should "audit user" do
22
- user = @controller.send(:current_user=, create_user)
23
- lambda { post :audit }.should change { Audit.count }
24
- assigns(:company).audits.last.user.should == user
25
- end
26
-
27
- should "not save blank audits" do
28
- user = @controller.send(:current_user=, create_user)
29
- lambda { post :update_user }.should_not change { Audit.count }
30
- end
31
- end
data/test/audit_test.rb DELETED
@@ -1,179 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
-
3
- class AuditTest < Test::Unit::TestCase
4
- def setup
5
- @user = User.new :name => "testing"
6
- @audit = Audit.new
7
- end
8
-
9
- context "user=" do
10
- should "be able to set the user to a model object" do
11
- @audit.user = @user
12
- @audit.user.should == @user
13
- end
14
-
15
- should "be able to set the user to nil" do
16
- @audit.user_id = 1
17
- @audit.user_type = 'User'
18
- @audit.username = 'joe'
19
-
20
- @audit.user = nil
21
-
22
- @audit.user.should == nil
23
- @audit.user_id.should == nil
24
- @audit.user_type.should == nil
25
- @audit.username.should == nil
26
- end
27
-
28
- should "be able to set the user to a string" do
29
- @audit.user = 'testing'
30
- @audit.user.should == 'testing'
31
- end
32
-
33
- should "clear model when setting to a string" do
34
- @audit.user = @user
35
- @audit.user = 'testing'
36
- @audit.user_id.should be(nil)
37
- @audit.user_type.should be(nil)
38
- end
39
-
40
- should "clear the username when setting to a model" do
41
- @audit.username = 'testing'
42
- @audit.user = @user
43
- @audit.username.should be(nil)
44
- end
45
-
46
- end
47
-
48
- context "revision" do
49
- should "recreate attributes" do
50
- user = User.create :name => "1"
51
- 5.times {|i| user.update_attribute :name, (i + 2).to_s }
52
- user.audits.each do |audit|
53
- audit.revision.name.should == audit.version.to_s
54
- end
55
- end
56
-
57
- should "set protected attributes" do
58
- u = User.create(:name => 'Brandon')
59
- u.update_attribute :logins, 1
60
- u.update_attribute :logins, 2
61
-
62
- u.audits[2].revision.logins.should == 2
63
- u.audits[1].revision.logins.should == 1
64
- u.audits[0].revision.logins.should == 0
65
- end
66
-
67
- should "bypass attribute assignment wrappers" do
68
- u = User.create(:name => '<Joe>')
69
- u.audits.first.revision.name.should == '&lt;Joe&gt;'
70
- end
71
-
72
- should "work for deleted records" do
73
- user = User.create :name => "1"
74
- user.destroy
75
- revision = user.audits.last.revision
76
- revision.name.should == user.name
77
- revision.new_record?.should be(true)
78
- end
79
- end
80
-
81
- should "set the version number on create" do
82
- user = User.create! :name => "Set Version Number"
83
- user.audits.first.version.should == 1
84
- user.update_attribute :name, "Set to 2"
85
- user.audits(true).first.version.should == 1
86
- user.audits(true).last.version.should == 2
87
- user.destroy
88
- user.audits(true).last.version.should == 3
89
- end
90
-
91
- context "reconstruct_attributes" do
92
- should "work with with old way of storing just the new value" do
93
- audits = Audit.reconstruct_attributes([Audit.new(:changes => {'attribute' => 'value'})])
94
- audits['attribute'].should == 'value'
95
- end
96
- end
97
-
98
- context "audited_classes" do
99
- class CustomUser < ActiveRecord::Base
100
- end
101
- class CustomUserSubclass < CustomUser
102
- acts_as_audited
103
- end
104
-
105
- should "include audited classes" do
106
- Audit.audited_classes.should include(User)
107
- end
108
-
109
- should "include subclasses" do
110
- Audit.audited_classes.should include(CustomUserSubclass)
111
- end
112
- end
113
-
114
- context "new_attributes" do
115
- should "return a hash of the new values" do
116
- Audit.new(:changes => {:a => [1, 2], :b => [3, 4]}).new_attributes.should == {'a' => 2, 'b' => 4}
117
- end
118
- end
119
-
120
- context "old_attributes" do
121
- should "return a hash of the old values" do
122
- Audit.new(:changes => {:a => [1, 2], :b => [3, 4]}).old_attributes.should == {'a' => 1, 'b' => 3}
123
- end
124
- end
125
-
126
- context "as_user" do
127
- setup do
128
- @user = User.create :name => 'testing'
129
- end
130
-
131
- should "record user objects" do
132
- Audit.as_user(@user) do
133
- company = Company.create :name => 'The auditors'
134
- company.name = 'The Auditors, Inc'
135
- company.save
136
-
137
- company.audits.each do |audit|
138
- audit.user.should == @user
139
- end
140
- end
141
- end
142
-
143
- should "record usernames" do
144
- Audit.as_user(@user.name) do
145
- company = Company.create :name => 'The auditors'
146
- company.name = 'The Auditors, Inc'
147
- company.save
148
-
149
- company.audits.each do |audit|
150
- audit.username.should == @user.name
151
- end
152
- end
153
- end
154
-
155
- should "be thread safe" do
156
- begin
157
- t1 = Thread.new do
158
- Audit.as_user(@user) do
159
- sleep 1
160
- Company.create(:name => 'The Auditors, Inc').audits.first.user.should == @user
161
- end
162
- end
163
-
164
- t2 = Thread.new do
165
- Audit.as_user(@user.name) do
166
- Company.create(:name => 'The Competing Auditors, LLC').audits.first.username.should == @user.name
167
- sleep 0.5
168
- end
169
- end
170
-
171
- t1.join
172
- t2.join
173
- rescue ActiveRecord::StatementInvalid
174
- STDERR.puts "Thread safety tests cannot be run with SQLite"
175
- end
176
- end
177
- end
178
-
179
- end