mongoid-audit 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ require 'active_support/core_ext'
6
+ require 'mongoid'
7
+ require 'database_cleaner'
8
+
9
+ Bundler.require
10
+
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each do |f|
12
+ require f
13
+ end
14
+
15
+ require 'mongoid-audit'
16
+
@@ -0,0 +1,9 @@
1
+ RSpec.configure do |config|
2
+ config.before :suite do
3
+ DatabaseCleaner.strategy = :truncation
4
+ end
5
+ config.after :each do
6
+ DatabaseCleaner.clean
7
+ end
8
+ end
9
+
@@ -0,0 +1,17 @@
1
+ ENV["MONGOID_ENV"] = "test"
2
+ Mongoid.load!("config/mongoid.yml")
3
+
4
+ RSpec.configure do |config|
5
+ config.before :each do
6
+ Mongoid.observers = Mongoid::Audit::Sweeper
7
+ end
8
+ config.backtrace_clean_patterns = [
9
+ # /\/lib\d*\/ruby\//,
10
+ # /bin\//,
11
+ # /gems/,
12
+ # /spec\/spec_helper\.rb/,
13
+ /lib\/rspec\/(core|expectations|matchers|mocks)/
14
+ ]
15
+ end
16
+
17
+
@@ -0,0 +1,121 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Mongoid::Audit::Trackable do
4
+ before :each do
5
+ class MyModel
6
+ include Mongoid::Document
7
+ include Mongoid::Audit::Trackable
8
+ end
9
+ end
10
+
11
+ after :each do
12
+ Mongoid::Audit.trackable_class_options = nil
13
+ end
14
+
15
+ it "should have #track_history" do
16
+ MyModel.should respond_to :track_history
17
+ end
18
+
19
+ it "should append trackable_class_options ONLY when #track_history is called" do
20
+ Mongoid::Audit.trackable_class_options.should be_blank
21
+ MyModel.track_history
22
+ Mongoid::Audit.trackable_class_options.keys.should == [:my_model]
23
+ end
24
+
25
+ describe "#track_history" do
26
+ before :each do
27
+ class MyModel
28
+ include Mongoid::Document
29
+ include Mongoid::Audit::Trackable
30
+ track_history
31
+ end
32
+
33
+ @expected_option = {
34
+ :on => :all,
35
+ :modifier_field => :modifier,
36
+ :version_field => :version,
37
+ :scope => :my_model,
38
+ :except => ["created_at", "updated_at", "version", "modifier_id", "_id", "id"],
39
+ :track_create => false,
40
+ :track_update => true,
41
+ :track_destroy => false,
42
+ }
43
+ end
44
+
45
+ after :each do
46
+ Mongoid::Audit.trackable_class_options = nil
47
+ end
48
+
49
+ it "should have default options" do
50
+ Mongoid::Audit.trackable_class_options[:my_model].should == @expected_option
51
+ end
52
+
53
+ it "should define callback function #track_update" do
54
+ MyModel.new.private_methods.collect(&:to_sym).should include(:track_update)
55
+ end
56
+
57
+ it "should define callback function #track_create" do
58
+ MyModel.new.private_methods.collect(&:to_sym).should include(:track_create)
59
+ end
60
+
61
+ it "should define callback function #track_destroy" do
62
+ MyModel.new.private_methods.collect(&:to_sym).should include(:track_destroy)
63
+ end
64
+
65
+ it "should define #history_trackable_options" do
66
+ MyModel.history_trackable_options.should == @expected_option
67
+ end
68
+
69
+ context "sub-model" do
70
+ before :each do
71
+ class MySubModel < MyModel
72
+ end
73
+ end
74
+
75
+ it "should have default options" do
76
+ Mongoid::Audit.trackable_class_options[:my_model].should == @expected_option
77
+ end
78
+
79
+ it "should define #history_trackable_options" do
80
+ MySubModel.history_trackable_options.should == @expected_option
81
+ end
82
+ end
83
+
84
+ context "track_history" do
85
+
86
+ it "should be enabled on the current thread" do
87
+ MyModel.new.track_history?.should == true
88
+ end
89
+
90
+ it "should be disabled within disable_tracking" do
91
+ MyModel.disable_tracking do
92
+ MyModel.new.track_history?.should == false
93
+ end
94
+ end
95
+
96
+ it "should be rescued if an exception occurs" do
97
+ begin
98
+ MyModel.disable_tracking do
99
+ raise "exception"
100
+ end
101
+ rescue
102
+ end
103
+ MyModel.new.track_history?.should == true
104
+ end
105
+
106
+ it "should be disabled only for the class that calls disable_tracking" do
107
+ class MyModel2
108
+ include Mongoid::Document
109
+ include Mongoid::Audit::Trackable
110
+ track_history
111
+ end
112
+
113
+ MyModel.disable_tracking do
114
+ MyModel2.new.track_history?.should == true
115
+ end
116
+ end
117
+
118
+ end
119
+
120
+ end
121
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Mongoid::Audit::Tracker do
4
+ before :each do
5
+ class MyTracker
6
+ include Mongoid::Audit::Tracker
7
+ end
8
+ end
9
+
10
+ after :each do
11
+ Mongoid::Audit.tracker_class_name = nil
12
+ end
13
+
14
+ it "should set tracker_class_name when included" do
15
+ Mongoid::Audit.tracker_class_name.should == :my_tracker
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid-audit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gleb Tv
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: easy_diff
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: mongoid
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 3.0.4
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 3.0.4
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.12.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.12.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 1.0.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 1.0.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: database_cleaner
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 0.8.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 0.8.0
94
+ - !ruby/object:Gem::Dependency
95
+ name: activesupport
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 3.2.11
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 3.2.11
110
+ description: Mongoid Audit
111
+ email:
112
+ - glebtv@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - .rspec
119
+ - .travis.yml
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - config/mongoid.yml
125
+ - lib/mongoid-audit.rb
126
+ - lib/mongoid-audit/sweeper.rb
127
+ - lib/mongoid-audit/trackable.rb
128
+ - lib/mongoid-audit/tracker.rb
129
+ - lib/mongoid-audit/version.rb
130
+ - mongoid-audit.gemspec
131
+ - spec/integration/integration_spec.rb
132
+ - spec/spec_helper.rb
133
+ - spec/support/database_cleaner.rb
134
+ - spec/support/mongoid.rb
135
+ - spec/trackable_spec.rb
136
+ - spec/tracker_spec.rb
137
+ homepage: https://github.com/rs-pro/mongoid-audit
138
+ licenses: []
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ! '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ! '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 1.8.22
158
+ signing_key:
159
+ specification_version: 3
160
+ summary: Easily track model change history and mantain audit log with mongoid
161
+ test_files:
162
+ - spec/integration/integration_spec.rb
163
+ - spec/spec_helper.rb
164
+ - spec/support/database_cleaner.rb
165
+ - spec/support/mongoid.rb
166
+ - spec/trackable_spec.rb
167
+ - spec/tracker_spec.rb
168
+ has_rdoc: