track_changes 0.5.0 → 0.5.1
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.
- data/LICENSE +20 -20
- data/README.rdoc +87 -87
- data/TODO +4 -4
- data/VERSION.yml +5 -5
- data/lib/track_changes/audit_filter.rb +69 -69
- data/lib/track_changes/base.rb +9 -9
- data/lib/track_changes/class_methods.rb +74 -74
- data/lib/track_changes/configuration.rb +38 -38
- data/lib/track_changes/filter.rb +43 -43
- data/lib/track_changes/initializer.rb +18 -18
- data/lib/track_changes/instance_methods.rb +5 -5
- data/lib/track_changes/result.rb +36 -36
- data/lib/track_changes.rb +12 -12
- data/test/base_test.rb +20 -20
- data/test/class_methods_test.rb +29 -29
- data/test/filter_test.rb +73 -73
- data/test/functional/posts_controller_test.rb +16 -16
- data/test/rails_root/app/controllers/application_controller.rb +2 -2
- data/test/rails_root/app/controllers/posts_controller.rb +36 -36
- data/test/rails_root/app/models/audit.rb +4 -4
- data/test/rails_root/app/models/post.rb +3 -3
- data/test/rails_root/config/boot.rb +110 -110
- data/test/rails_root/config/database.yml +3 -3
- data/test/rails_root/config/environment.rb +7 -7
- data/test/rails_root/config/environments/test.rb +7 -7
- data/test/rails_root/config/initializers/new_rails_defaults.rb +7 -7
- data/test/rails_root/config/initializers/session_store.rb +4 -4
- data/test/rails_root/config/initializers/track_changes_setup.rb +8 -8
- data/test/rails_root/config/routes.rb +3 -3
- data/test/rails_root/db/migrate/20100115021125_create_audits.rb +16 -16
- data/test/rails_root/db/migrate/20100115021151_create_posts.rb +15 -15
- data/test/rails_root/log/test.log +377 -2494
- data/test/rails_root/script/console +3 -3
- data/test/rails_root/script/generate +3 -3
- data/test/result_test.rb +35 -35
- data/test/test_helper.rb +29 -29
- data/test/track_changes/audit_filter_test.rb +154 -154
- data/test/track_changes/configuration_test.rb +36 -36
- data/test/track_changes/initializer_test.rb +37 -37
- metadata +31 -19
@@ -1,3 +1,3 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require File.expand_path('../../config/boot', __FILE__)
|
3
|
-
require 'commands/console'
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require File.expand_path('../../config/boot', __FILE__)
|
3
|
+
require 'commands/console'
|
@@ -1,3 +1,3 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require File.expand_path('../../config/boot', __FILE__)
|
3
|
-
require 'commands/generate'
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require File.expand_path('../../config/boot', __FILE__)
|
3
|
+
require 'commands/generate'
|
data/test/result_test.rb
CHANGED
@@ -1,35 +1,35 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
class ResultTest < Test::Unit::TestCase
|
4
|
-
context "a Result instance" do
|
5
|
-
setup do
|
6
|
-
@controller = mock()
|
7
|
-
@changes = { "attr" => ["old", "new"] }
|
8
|
-
|
9
|
-
@filter = TrackChanges::Result.new(:model, @controller, @changes)
|
10
|
-
end
|
11
|
-
|
12
|
-
should "define given symbol as method" do
|
13
|
-
@controller.expects(:instance_variable_get).with() {|v| v == "@model"}.returns(:ivar_result)
|
14
|
-
assert_equal :ivar_result, @filter.model
|
15
|
-
end
|
16
|
-
|
17
|
-
should "send method_missing calls to controller" do
|
18
|
-
@controller.expects(:bogus_method).returns(:got_it)
|
19
|
-
assert_equal :got_it, @filter.bogus_method
|
20
|
-
end
|
21
|
-
|
22
|
-
should "get @current_user from controller" do
|
23
|
-
@controller.expects(:instance_variable_get).with() {|v| v == "@current_user"}.returns(:ivar_result)
|
24
|
-
assert_equal :ivar_result, @filter.current_user
|
25
|
-
end
|
26
|
-
|
27
|
-
should "return changes" do
|
28
|
-
assert_equal @changes, @filter.changes
|
29
|
-
end
|
30
|
-
|
31
|
-
should "return controller" do
|
32
|
-
assert_equal @controller, @filter.controller
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class ResultTest < Test::Unit::TestCase
|
4
|
+
context "a Result instance" do
|
5
|
+
setup do
|
6
|
+
@controller = mock()
|
7
|
+
@changes = { "attr" => ["old", "new"] }
|
8
|
+
|
9
|
+
@filter = TrackChanges::Result.new(:model, @controller, @changes)
|
10
|
+
end
|
11
|
+
|
12
|
+
should "define given symbol as method" do
|
13
|
+
@controller.expects(:instance_variable_get).with() {|v| v == "@model"}.returns(:ivar_result)
|
14
|
+
assert_equal :ivar_result, @filter.model
|
15
|
+
end
|
16
|
+
|
17
|
+
should "send method_missing calls to controller" do
|
18
|
+
@controller.expects(:bogus_method).returns(:got_it)
|
19
|
+
assert_equal :got_it, @filter.bogus_method
|
20
|
+
end
|
21
|
+
|
22
|
+
should "get @current_user from controller" do
|
23
|
+
@controller.expects(:instance_variable_get).with() {|v| v == "@current_user"}.returns(:ivar_result)
|
24
|
+
assert_equal :ivar_result, @filter.current_user
|
25
|
+
end
|
26
|
+
|
27
|
+
should "return changes" do
|
28
|
+
assert_equal @changes, @filter.changes
|
29
|
+
end
|
30
|
+
|
31
|
+
should "return controller" do
|
32
|
+
assert_equal @controller, @filter.controller
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
# Copied from the shoulda library
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
# Load the environment
|
5
|
-
ENV['RAILS_ENV'] = 'test'
|
6
|
-
|
7
|
-
rails_root = File.dirname(__FILE__) + '/rails_root'
|
8
|
-
|
9
|
-
require "#{rails_root}/config/environment.rb"
|
10
|
-
|
11
|
-
# Load the testing framework
|
12
|
-
require 'test_help'
|
13
|
-
silence_warnings { RAILS_ENV = ENV['RAILS_ENV'] }
|
14
|
-
|
15
|
-
# Run the migrations
|
16
|
-
ActiveRecord::Migration.verbose = false
|
17
|
-
ActiveRecord::Migrator.migrate("#{RAILS_ROOT}/db/migrate")
|
18
|
-
|
19
|
-
# Setup the fixtures path
|
20
|
-
ActiveSupport::TestCase.fixture_path =
|
21
|
-
File.join(File.dirname(__FILE__), "fixtures")
|
22
|
-
|
23
|
-
class ActiveSupport::TestCase #:nodoc:
|
24
|
-
self.use_transactional_fixtures = false
|
25
|
-
self.use_instantiated_fixtures = false
|
26
|
-
end
|
27
|
-
|
28
|
-
require 'track_changes'
|
29
|
-
require 'shoulda'
|
1
|
+
# Copied from the shoulda library
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
# Load the environment
|
5
|
+
ENV['RAILS_ENV'] = 'test'
|
6
|
+
|
7
|
+
rails_root = File.dirname(__FILE__) + '/rails_root'
|
8
|
+
|
9
|
+
require "#{rails_root}/config/environment.rb"
|
10
|
+
|
11
|
+
# Load the testing framework
|
12
|
+
require 'test_help'
|
13
|
+
silence_warnings { RAILS_ENV = ENV['RAILS_ENV'] }
|
14
|
+
|
15
|
+
# Run the migrations
|
16
|
+
ActiveRecord::Migration.verbose = false
|
17
|
+
ActiveRecord::Migrator.migrate("#{RAILS_ROOT}/db/migrate")
|
18
|
+
|
19
|
+
# Setup the fixtures path
|
20
|
+
ActiveSupport::TestCase.fixture_path =
|
21
|
+
File.join(File.dirname(__FILE__), "fixtures")
|
22
|
+
|
23
|
+
class ActiveSupport::TestCase #:nodoc:
|
24
|
+
self.use_transactional_fixtures = false
|
25
|
+
self.use_instantiated_fixtures = false
|
26
|
+
end
|
27
|
+
|
28
|
+
require 'track_changes'
|
29
|
+
require 'shoulda'
|
@@ -1,154 +1,154 @@
|
|
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
|
+
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 +1,36 @@
|
|
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
|
+
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 +1,37 @@
|
|
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
|
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
|