mongoid-audit 0.3.2 → 1.0.0.alpha.1

Sign up to get free protection for your applications and to get access to all the features.
data/spec/spec_helper.rb DELETED
@@ -1,28 +0,0 @@
1
- require 'coveralls'
2
- Coveralls.wear!
3
-
4
- ENV["RAILS_ENV"] ||= 'test'
5
-
6
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
-
8
- require 'rubygems'
9
- require 'bundler/setup'
10
- require 'active_support/core_ext'
11
- require 'mongoid'
12
- require 'database_cleaner'
13
-
14
- module RailsAdmin
15
- def self.add_extension(*args); end
16
- end
17
- require "mongoid-audit/rails_admin"
18
-
19
- Bundler.require
20
-
21
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each do |f|
22
- require f
23
- end
24
-
25
- require 'mongoid-audit'
26
- class HistoryTracker
27
- include Mongoid::Audit::Tracker
28
- end
@@ -1,11 +0,0 @@
1
- DatabaseCleaner[:mongoid].strategy = :truncation
2
-
3
- RSpec.configure do |config|
4
- config.before :each do
5
- DatabaseCleaner.start
6
- end
7
-
8
- config.after :each do
9
- DatabaseCleaner.clean
10
- end
11
- end
@@ -1,16 +0,0 @@
1
- Mongoid.configure do |config|
2
- config.connect_to "mongoid-audit-test"
3
- end
4
-
5
- RSpec.configure do |config|
6
- config.before :each do
7
- HistoryTracker.add_observer(::Mongoid::Audit::Sweeper.instance)
8
- end
9
- config.backtrace_exclusion_patterns = [
10
- # /\/lib\d*\/ruby\//,
11
- # /bin\//,
12
- # /gems/,
13
- # /spec\/spec_helper\.rb/,
14
- /lib\/rspec\/(core|expectations|matchers|mocks)/
15
- ]
16
- end
@@ -1,134 +0,0 @@
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
- def compare( option )
16
- option[:except].sort! unless option[:except].nil?
17
- option.should == @expected_option
18
- end
19
-
20
- it "should have #track_history" do
21
- MyModel.should respond_to :track_history
22
- end
23
-
24
- it "should append trackable_class_options ONLY when #track_history is called" do
25
- Mongoid::Audit.trackable_class_options.should be_blank
26
- MyModel.track_history
27
- Mongoid::Audit.trackable_class_options.keys.should == [:my_model]
28
- end
29
-
30
- describe "#track_history" do
31
- before :each do
32
- Object.send(:remove_const, :MyModel) if Object.constants.include?(:MyModel)
33
-
34
- class MyModel
35
- include Mongoid::Document
36
- include Mongoid::Audit::Trackable
37
- track_history
38
- end
39
-
40
- @expected_option = {
41
- :on => :all,
42
- :modifier_field => :modifier,
43
- :version_field => :version,
44
- :scope => :my_model,
45
- :except => ["version", "created_at", "updated_at", "deleted_at", "c_at", "u_at", "modifier_id", "_id", "id"].sort,
46
- :track_create => false,
47
- :track_update => true,
48
- :track_destroy => false,
49
- }
50
- end
51
-
52
- after :each do
53
- Mongoid::Audit.trackable_class_options = nil
54
- end
55
-
56
- it "should have default options" do
57
- compare( Mongoid::Audit.trackable_class_options[:my_model] )
58
- end
59
-
60
- it "should define callback function #track_update" do
61
- MyModel.new.private_methods.collect(&:to_sym).should include(:track_update)
62
- end
63
-
64
- it "should define callback function #track_create" do
65
- MyModel.new.private_methods.collect(&:to_sym).should include(:track_create)
66
- end
67
-
68
- it "should define callback function #track_destroy" do
69
- MyModel.new.private_methods.collect(&:to_sym).should include(:track_destroy)
70
- end
71
-
72
- it "should define #history_trackable_options" do
73
- compare( MyModel.history_trackable_options )
74
- end
75
-
76
- context "sub-model" do
77
- before :each do
78
- Object.send(:remove_const, :MyModel) if Object.constants.include?(:MyModel)
79
- Object.send(:remove_const, :MySubModel) if Object.constants.include?(:MySubModel)
80
-
81
- class MyModel
82
- include Mongoid::Document
83
- include Mongoid::Audit::Trackable
84
- track_history
85
- end
86
- class MySubModel < MyModel
87
- end
88
- end
89
-
90
- it "should have default options" do
91
- compare( Mongoid::Audit.trackable_class_options[:my_model] )
92
- end
93
-
94
- it "should define #history_trackable_options" do
95
- compare( MySubModel.history_trackable_options )
96
- end
97
- end
98
-
99
- context "track_history" do
100
-
101
- it "should be enabled on the current thread" do
102
- MyModel.new.track_history?.should == true
103
- end
104
-
105
- it "should be disabled within disable_tracking" do
106
- MyModel.disable_tracking do
107
- MyModel.new.track_history?.should == false
108
- end
109
- end
110
-
111
- it "should be rescued if an exception occurs" do
112
- begin
113
- MyModel.disable_tracking do
114
- raise "exception"
115
- end
116
- rescue
117
- end
118
- MyModel.new.track_history?.should == true
119
- end
120
-
121
- it "should be disabled only for the class that calls disable_tracking" do
122
- class MyModel2
123
- include Mongoid::Document
124
- include Mongoid::Audit::Trackable
125
- track_history
126
- end
127
-
128
- MyModel.disable_tracking do
129
- MyModel2.new.track_history?.should == true
130
- end
131
- end
132
- end
133
- end
134
- end
data/spec/tracker_spec.rb DELETED
@@ -1,17 +0,0 @@
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