track_changes 0.5.1 → 1.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +46 -32
- data/TODO +1 -1
- data/VERSION.yml +4 -4
- data/lib/generators/track_changes/templates/initializer.rb +1 -0
- data/lib/generators/track_changes/templates/migration.rb +18 -0
- data/lib/generators/track_changes/templates/stylesheet.css +12 -0
- data/lib/generators/track_changes/track_changes_generator.rb +30 -0
- data/lib/track_changes/action_controller.rb +31 -0
- data/lib/track_changes/active_record.rb +26 -0
- data/lib/track_changes/around_save.rb +9 -0
- data/lib/track_changes/changes.rb +15 -0
- data/lib/track_changes/configuration.rb +3 -32
- data/lib/track_changes/current_user.rb +5 -0
- data/lib/track_changes/current_user_filter.rb +12 -0
- data/lib/track_changes/engine.rb +7 -0
- data/lib/track_changes.rb +11 -10
- data/test/functional/posts_controller_test.rb +39 -10
- data/test/railsapp/Gemfile +12 -0
- data/test/railsapp/Gemfile.lock +84 -0
- data/test/railsapp/Rakefile +4 -0
- data/test/{rails_root → railsapp}/app/controllers/application_controller.rb +1 -0
- data/test/railsapp/app/controllers/posts_controller.rb +40 -0
- data/test/railsapp/app/models/post.rb +3 -0
- data/test/railsapp/app/models/user.rb +3 -0
- data/test/railsapp/app/views/layouts/application.html.erb +12 -0
- data/test/railsapp/app/views/posts/_form.html.erb +13 -0
- data/test/railsapp/app/views/posts/_post.html.erb +3 -0
- data/test/railsapp/app/views/posts/edit.html.erb +5 -0
- data/test/railsapp/app/views/posts/index.html.erb +2 -0
- data/test/railsapp/config/application.rb +12 -0
- data/test/railsapp/config/boot.rb +13 -0
- data/test/railsapp/config/database.yml +5 -0
- data/test/railsapp/config/environment.rb +5 -0
- data/test/railsapp/config/environments/test.rb +10 -0
- data/test/railsapp/config/routes.rb +3 -0
- data/test/railsapp/config.ru +2 -0
- data/test/railsapp/db/test.sqlite3 +0 -0
- data/test/railsapp/log/test.log +6385 -0
- data/test/railsapp/script/rails +6 -0
- data/test/schema.rb +19 -0
- data/test/test_helper.rb +4 -26
- data/test/track_changes_test.rb +34 -0
- metadata +124 -88
- data/lib/track_changes/audit_filter.rb +0 -69
- data/lib/track_changes/base.rb +0 -9
- data/lib/track_changes/class_methods.rb +0 -74
- data/lib/track_changes/filter.rb +0 -43
- data/lib/track_changes/initializer.rb +0 -18
- data/lib/track_changes/instance_methods.rb +0 -5
- data/lib/track_changes/result.rb +0 -36
- data/test/base_test.rb +0 -20
- data/test/class_methods_test.rb +0 -29
- data/test/filter_test.rb +0 -73
- data/test/rails_root/app/controllers/posts_controller.rb +0 -36
- data/test/rails_root/app/models/audit.rb +0 -4
- data/test/rails_root/app/models/post.rb +0 -3
- data/test/rails_root/config/boot.rb +0 -110
- data/test/rails_root/config/database.yml +0 -3
- data/test/rails_root/config/environment.rb +0 -7
- data/test/rails_root/config/environments/test.rb +0 -7
- data/test/rails_root/config/initializers/new_rails_defaults.rb +0 -7
- data/test/rails_root/config/initializers/session_store.rb +0 -4
- data/test/rails_root/config/initializers/track_changes_setup.rb +0 -8
- data/test/rails_root/config/routes.rb +0 -3
- data/test/rails_root/db/migrate/20100115021125_create_audits.rb +0 -16
- data/test/rails_root/db/migrate/20100115021151_create_posts.rb +0 -15
- data/test/rails_root/log/test.log +0 -543
- data/test/rails_root/script/console +0 -3
- data/test/rails_root/script/generate +0 -3
- data/test/result_test.rb +0 -35
- data/test/track_changes/audit_filter_test.rb +0 -154
- data/test/track_changes/configuration_test.rb +0 -36
- data/test/track_changes/initializer_test.rb +0 -37
@@ -1,154 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module TrackChanges
|
4
|
-
class AuditFilterTest < Test::Unit::TestCase
|
5
|
-
should "accept a single model" do
|
6
|
-
assert TrackChanges::AuditFilter.new(:model)
|
7
|
-
end
|
8
|
-
|
9
|
-
should "accept multiple models" do
|
10
|
-
assert TrackChanges::AuditFilter.new(:model_a, :model_b)
|
11
|
-
end
|
12
|
-
|
13
|
-
should "respond to #before" do
|
14
|
-
assert TrackChanges::AuditFilter.new.respond_to?(:before)
|
15
|
-
end
|
16
|
-
|
17
|
-
should "respond to #after" do
|
18
|
-
assert TrackChanges::AuditFilter.new.respond_to?(:after)
|
19
|
-
end
|
20
|
-
|
21
|
-
should "create an audit when before and after called" do
|
22
|
-
expected_change_set = {"value" => ["old", "new"]}
|
23
|
-
expected_user = "current user"
|
24
|
-
|
25
|
-
audit = mock('audit')
|
26
|
-
|
27
|
-
model = mock('model')
|
28
|
-
model.stubs(:attributes=).returns({})
|
29
|
-
model.stubs(:changes).returns(expected_change_set)
|
30
|
-
|
31
|
-
modified_model = mock('modified model')
|
32
|
-
modified_model.stubs(:changed?).returns(false)
|
33
|
-
modified_model.stubs(:attributes).returns({})
|
34
|
-
modified_model.stubs(:audits).returns(audit)
|
35
|
-
|
36
|
-
controller = mock('controller')
|
37
|
-
controller.stubs(:instance_variable_get).returns(model, modified_model)
|
38
|
-
controller.stubs(:current_user).returns(expected_user)
|
39
|
-
|
40
|
-
audit_filter = AuditFilter.new(:model)
|
41
|
-
audit_filter.before(controller)
|
42
|
-
|
43
|
-
audit.expects(:create!).with(has_entries(:user => expected_user, :change_set => expected_change_set)).returns(true)
|
44
|
-
audit_filter.after(controller)
|
45
|
-
end
|
46
|
-
|
47
|
-
should "ignore nil models" do
|
48
|
-
controller = mock('controller')
|
49
|
-
controller.expects(:instance_variable_get).returns(nil)
|
50
|
-
|
51
|
-
audit_filter = AuditFilter.new(:model)
|
52
|
-
assert_nothing_raised do
|
53
|
-
audit_filter.before(controller)
|
54
|
-
audit_filter.after(controller)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
should "respect ignore_nil option" do
|
59
|
-
controller = mock('controller')
|
60
|
-
controller.stubs(:instance_variable_get).returns(nil)
|
61
|
-
|
62
|
-
audit_filter = AuditFilter.new(:model, :ignore_nil => false)
|
63
|
-
assert_raises TypeError do
|
64
|
-
audit_filter.before(controller)
|
65
|
-
audit_filter.after(controller)
|
66
|
-
end
|
67
|
-
|
68
|
-
audit_filter = AuditFilter.new(:model, :ignore_nil => true)
|
69
|
-
assert_nothing_raised do
|
70
|
-
audit_filter.before(controller)
|
71
|
-
audit_filter.after(controller)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
should "respect audit_accessor option" do
|
76
|
-
change = mock('change')
|
77
|
-
change.stubs(:create!).returns(true)
|
78
|
-
|
79
|
-
model = mock('model')
|
80
|
-
model.stubs(:attributes=).returns({})
|
81
|
-
model.stubs(:changes).returns({:not => :empty})
|
82
|
-
|
83
|
-
modified_model = mock('modified model')
|
84
|
-
modified_model.stubs(:changed?).returns(false)
|
85
|
-
modified_model.stubs(:attributes).returns({})
|
86
|
-
modified_model.stubs(:changes).returns(change)
|
87
|
-
|
88
|
-
controller = mock('controller')
|
89
|
-
controller.stubs(:instance_variable_get).returns(model, modified_model)
|
90
|
-
controller.stubs(:current_user).returns("user")
|
91
|
-
|
92
|
-
audit_filter = AuditFilter.new(:model, :audit_accessor => :changes)
|
93
|
-
audit_filter.before(controller)
|
94
|
-
|
95
|
-
# Test call to :changes
|
96
|
-
audit_filter.after(controller)
|
97
|
-
|
98
|
-
audit = mock('audit')
|
99
|
-
audit.stubs(:create!).returns(true)
|
100
|
-
modified_model.stubs(:audits).returns(audit)
|
101
|
-
|
102
|
-
# Test call to :audits
|
103
|
-
audit_filter.after(controller)
|
104
|
-
end
|
105
|
-
|
106
|
-
should "respect :current_user option with :user" do
|
107
|
-
audit = mock('audit')
|
108
|
-
audit.stubs(:create!).returns(true)
|
109
|
-
|
110
|
-
model = mock('model')
|
111
|
-
model.stubs(:attributes=).returns({})
|
112
|
-
model.stubs(:changes).returns({:not => :empty})
|
113
|
-
|
114
|
-
modified_model = mock('modified model')
|
115
|
-
modified_model.stubs(:changed?).returns(false)
|
116
|
-
modified_model.stubs(:attributes).returns({})
|
117
|
-
modified_model.stubs(:audits).returns(audit)
|
118
|
-
|
119
|
-
controller = mock('controller')
|
120
|
-
controller.stubs(:instance_variable_get).returns(model, modified_model)
|
121
|
-
controller.stubs(:user).returns("configured user")
|
122
|
-
|
123
|
-
audit_filter = AuditFilter.new(:model, :current_user => :user)
|
124
|
-
audit_filter.before(controller)
|
125
|
-
|
126
|
-
# Test call to :user
|
127
|
-
audit_filter.after(controller)
|
128
|
-
end
|
129
|
-
|
130
|
-
should "respect :current_user option with :current_user" do
|
131
|
-
audit = mock('audit')
|
132
|
-
audit.stubs(:create!).returns(true)
|
133
|
-
|
134
|
-
model = mock('model')
|
135
|
-
model.stubs(:attributes=).returns({})
|
136
|
-
model.stubs(:changes).returns({:not => :empty})
|
137
|
-
|
138
|
-
modified_model = mock('modified model')
|
139
|
-
modified_model.stubs(:changed?).returns(false)
|
140
|
-
modified_model.stubs(:attributes).returns({})
|
141
|
-
modified_model.stubs(:audits).returns(audit)
|
142
|
-
|
143
|
-
controller = mock('controller')
|
144
|
-
controller.stubs(:instance_variable_get).returns(model, modified_model)
|
145
|
-
controller.stubs(:current_user).returns("configured user")
|
146
|
-
|
147
|
-
audit_filter = AuditFilter.new(:model, :current_user => :current_user)
|
148
|
-
audit_filter.before(controller)
|
149
|
-
|
150
|
-
# Test call to :current_user
|
151
|
-
audit_filter.after(controller)
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module TrackChanges
|
4
|
-
class ConfigurationTest < ActiveSupport::TestCase
|
5
|
-
def setup
|
6
|
-
@configuration = TrackChanges::Configuration.new
|
7
|
-
end
|
8
|
-
|
9
|
-
should "have audit_association accessor" do
|
10
|
-
assert @configuration.respond_to?(:audit_association)
|
11
|
-
assert @configuration.respond_to?(:audit_association=)
|
12
|
-
end
|
13
|
-
|
14
|
-
should "have current_user accessor" do
|
15
|
-
assert @configuration.respond_to?(:current_user)
|
16
|
-
assert @configuration.respond_to?(:current_user=)
|
17
|
-
end
|
18
|
-
|
19
|
-
should "have ignore_nil accessor" do
|
20
|
-
assert @configuration.respond_to?(:ignore_nil)
|
21
|
-
assert @configuration.respond_to?(:ignore_nil=)
|
22
|
-
end
|
23
|
-
|
24
|
-
should "set default audit_association to Audit" do
|
25
|
-
assert_equal :audits, @configuration.audit_association
|
26
|
-
end
|
27
|
-
|
28
|
-
should "set default current user association" do
|
29
|
-
assert_equal :current_user, @configuration.current_user
|
30
|
-
end
|
31
|
-
|
32
|
-
should "set default ignore_nil" do
|
33
|
-
assert_equal true, @configuration.ignore_nil
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module TrackChanges
|
4
|
-
class InitializerTest < ActiveSupport::TestCase
|
5
|
-
should "be a singleton" do
|
6
|
-
first_instance = Initializer.instance
|
7
|
-
second_instance = Initializer.instance
|
8
|
-
assert_equal first_instance, second_instance
|
9
|
-
end
|
10
|
-
|
11
|
-
should "have an accessor for configuration" do
|
12
|
-
initializer = Initializer.instance
|
13
|
-
|
14
|
-
assert initializer.respond_to?(:configuration)
|
15
|
-
end
|
16
|
-
|
17
|
-
should "yield configuration on call to instance" do
|
18
|
-
block_executed = false
|
19
|
-
initializer = Initializer.instance do |configuration|
|
20
|
-
block_executed = true
|
21
|
-
assert configuration.kind_of?(TrackChanges::Configuration)
|
22
|
-
end
|
23
|
-
|
24
|
-
assert block_executed, "block wasn't executed"
|
25
|
-
end
|
26
|
-
|
27
|
-
should "set global configuration" do
|
28
|
-
initializer = Initializer.instance do |configuration|
|
29
|
-
configuration.audit_association = :test_audit_association
|
30
|
-
end
|
31
|
-
|
32
|
-
initializer = Initializer.instance
|
33
|
-
configuration = initializer.configuration
|
34
|
-
assert_equal :test_audit_association, configuration.audit_association
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|