mongoid-history 0.8.3 → 0.8.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -1
- data/.document +5 -5
- data/.github/workflows/test.yml +72 -0
- data/.gitignore +46 -46
- data/.rspec +2 -2
- data/.rubocop.yml +6 -6
- data/.rubocop_todo.yml +99 -99
- data/CHANGELOG.md +173 -163
- data/CONTRIBUTING.md +117 -118
- data/Dangerfile +1 -1
- data/Gemfile +49 -40
- data/LICENSE.txt +20 -20
- data/README.md +609 -608
- data/RELEASING.md +66 -67
- data/Rakefile +24 -24
- data/UPGRADING.md +53 -53
- data/lib/mongoid/history/attributes/base.rb +72 -72
- data/lib/mongoid/history/attributes/create.rb +45 -45
- data/lib/mongoid/history/attributes/destroy.rb +34 -34
- data/lib/mongoid/history/attributes/update.rb +104 -104
- data/lib/mongoid/history/options.rb +177 -177
- data/lib/mongoid/history/trackable.rb +588 -583
- data/lib/mongoid/history/tracker.rb +247 -247
- data/lib/mongoid/history/version.rb +5 -5
- data/lib/mongoid/history.rb +77 -77
- data/lib/mongoid-history.rb +1 -1
- data/mongoid-history.gemspec +25 -25
- data/perf/benchmark_modified_attributes_for_create.rb +65 -65
- data/perf/gc_suite.rb +21 -21
- data/spec/integration/embedded_in_polymorphic_spec.rb +112 -112
- data/spec/integration/integration_spec.rb +976 -976
- data/spec/integration/multi_relation_spec.rb +47 -47
- data/spec/integration/multiple_trackers_spec.rb +68 -68
- data/spec/integration/nested_embedded_documents_spec.rb +64 -64
- data/spec/integration/nested_embedded_documents_tracked_in_parent_spec.rb +124 -124
- data/spec/integration/nested_embedded_polymorphic_documents_spec.rb +115 -115
- data/spec/integration/subclasses_spec.rb +47 -47
- data/spec/integration/track_history_order_spec.rb +84 -84
- data/spec/integration/validation_failure_spec.rb +76 -76
- data/spec/spec_helper.rb +32 -30
- data/spec/support/error_helpers.rb +7 -0
- data/spec/support/mongoid.rb +11 -11
- data/spec/support/mongoid_history.rb +12 -12
- data/spec/unit/attributes/base_spec.rb +141 -141
- data/spec/unit/attributes/create_spec.rb +342 -342
- data/spec/unit/attributes/destroy_spec.rb +228 -228
- data/spec/unit/attributes/update_spec.rb +342 -342
- data/spec/unit/callback_options_spec.rb +165 -165
- data/spec/unit/embedded_methods_spec.rb +87 -87
- data/spec/unit/history_spec.rb +58 -58
- data/spec/unit/my_instance_methods_spec.rb +555 -555
- data/spec/unit/options_spec.rb +365 -365
- data/spec/unit/singleton_methods_spec.rb +406 -406
- data/spec/unit/store/default_store_spec.rb +11 -11
- data/spec/unit/store/request_store_spec.rb +13 -13
- data/spec/unit/trackable_spec.rb +1057 -987
- data/spec/unit/tracker_spec.rb +190 -190
- metadata +9 -7
- data/.travis.yml +0 -36
@@ -1,165 +1,165 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mongoid::History::Options do
|
4
|
-
describe ':if' do
|
5
|
-
before :each do
|
6
|
-
class DummyModel
|
7
|
-
include Mongoid::Document
|
8
|
-
include Mongoid::History::Trackable
|
9
|
-
|
10
|
-
store_in collection: :model_ones
|
11
|
-
field :foo
|
12
|
-
|
13
|
-
attr_accessor :bar
|
14
|
-
|
15
|
-
track_history modifier_field_optional: true, if: :bar
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
after :each do
|
20
|
-
Object.send(:remove_const, :DummyModel)
|
21
|
-
end
|
22
|
-
|
23
|
-
let(:obj) { DummyModel.new(foo: 'Foo') }
|
24
|
-
|
25
|
-
context 'when condition evaluates to true' do
|
26
|
-
before { obj.bar = true }
|
27
|
-
it 'should create history tracks' do
|
28
|
-
expect { obj.save }.to change(Tracker, :count).by(1)
|
29
|
-
expect do
|
30
|
-
obj.update_attributes(foo: 'Foo-2')
|
31
|
-
end.to change(Tracker, :count).by(1)
|
32
|
-
expect { obj.destroy }.to change(Tracker, :count).by(1)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'when condition evaluates to false' do
|
37
|
-
before { obj.bar = false }
|
38
|
-
it 'should not create history tracks' do
|
39
|
-
expect { obj.save }.to_not change(Tracker, :count)
|
40
|
-
expect do
|
41
|
-
obj.update_attributes(foo: 'Foo-2')
|
42
|
-
end.to_not change(Tracker, :count)
|
43
|
-
expect { obj.destroy }.to_not change(Tracker, :count)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe ':unless' do
|
49
|
-
before :each do
|
50
|
-
class DummyModel
|
51
|
-
include Mongoid::Document
|
52
|
-
include Mongoid::History::Trackable
|
53
|
-
|
54
|
-
store_in collection: :model_ones
|
55
|
-
field :foo
|
56
|
-
|
57
|
-
attr_accessor :bar
|
58
|
-
|
59
|
-
track_history modifier_field_optional: true, unless: ->(obj) { obj.bar }
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
after :each do
|
64
|
-
Object.send(:remove_const, :DummyModel)
|
65
|
-
end
|
66
|
-
|
67
|
-
let(:obj) { DummyModel.new(foo: 'Foo') }
|
68
|
-
|
69
|
-
context 'when condition evaluates to true' do
|
70
|
-
before { obj.bar = true }
|
71
|
-
it 'should not create history tracks' do
|
72
|
-
expect { obj.save }.to_not change(Tracker, :count)
|
73
|
-
expect do
|
74
|
-
obj.update_attributes(foo: 'Foo-2')
|
75
|
-
end.to_not change(Tracker, :count)
|
76
|
-
expect { obj.destroy }.to_not change(Tracker, :count)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
context 'when condition evaluates to false' do
|
81
|
-
before { obj.bar = false }
|
82
|
-
it 'should create history tracks' do
|
83
|
-
expect { obj.save }.to change(Tracker, :count).by(1)
|
84
|
-
expect do
|
85
|
-
obj.update_attributes(foo: 'Foo-2')
|
86
|
-
end.to change(Tracker, :count).by(1)
|
87
|
-
expect { obj.destroy }.to change(Tracker, :count).by(1)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
describe ':if and :unless' do
|
93
|
-
before :each do
|
94
|
-
class DummyModel
|
95
|
-
include Mongoid::Document
|
96
|
-
include Mongoid::History::Trackable
|
97
|
-
|
98
|
-
store_in collection: :model_ones
|
99
|
-
field :foo
|
100
|
-
|
101
|
-
attr_accessor :bar, :baz
|
102
|
-
|
103
|
-
track_history modifier_field_optional: true, if: :bar, unless: ->(obj) { obj.baz }
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
after :each do
|
108
|
-
Object.send(:remove_const, :DummyModel)
|
109
|
-
end
|
110
|
-
|
111
|
-
let(:obj) { DummyModel.new(foo: 'Foo') }
|
112
|
-
|
113
|
-
context 'when :if condition evaluates to true' do
|
114
|
-
before { obj.bar = true }
|
115
|
-
|
116
|
-
context 'and :unless condition evaluates to true' do
|
117
|
-
before { obj.baz = true }
|
118
|
-
it 'should not create history tracks' do
|
119
|
-
expect { obj.save }.to_not change(Tracker, :count)
|
120
|
-
expect do
|
121
|
-
obj.update_attributes(foo: 'Foo-2')
|
122
|
-
end.to_not change(Tracker, :count)
|
123
|
-
expect { obj.destroy }.to_not change(Tracker, :count)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
context 'and :unless condition evaluates to false' do
|
128
|
-
before { obj.baz = false }
|
129
|
-
it 'should create history tracks' do
|
130
|
-
expect { obj.save }.to change(Tracker, :count).by(1)
|
131
|
-
expect do
|
132
|
-
obj.update_attributes(foo: 'Foo-2')
|
133
|
-
end.to change(Tracker, :count).by(1)
|
134
|
-
expect { obj.destroy }.to change(Tracker, :count).by(1)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
context 'when :if condition evaluates to false' do
|
140
|
-
before { obj.bar = false }
|
141
|
-
|
142
|
-
context 'and :unless condition evaluates to true' do
|
143
|
-
before { obj.baz = true }
|
144
|
-
it 'should not create history tracks' do
|
145
|
-
expect { obj.save }.to_not change(Tracker, :count)
|
146
|
-
expect do
|
147
|
-
obj.update_attributes(foo: 'Foo-2')
|
148
|
-
end.to_not change(Tracker, :count)
|
149
|
-
expect { obj.destroy }.to_not change(Tracker, :count)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
context 'and :unless condition evaluates to false' do
|
154
|
-
before { obj.baz = false }
|
155
|
-
it 'should not create history tracks' do
|
156
|
-
expect { obj.save }.to_not change(Tracker, :count)
|
157
|
-
expect do
|
158
|
-
obj.update_attributes(foo: 'Foo-2')
|
159
|
-
end.to_not change(Tracker, :count)
|
160
|
-
expect { obj.destroy }.to_not change(Tracker, :count)
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mongoid::History::Options do
|
4
|
+
describe ':if' do
|
5
|
+
before :each do
|
6
|
+
class DummyModel
|
7
|
+
include Mongoid::Document
|
8
|
+
include Mongoid::History::Trackable
|
9
|
+
|
10
|
+
store_in collection: :model_ones
|
11
|
+
field :foo
|
12
|
+
|
13
|
+
attr_accessor :bar
|
14
|
+
|
15
|
+
track_history modifier_field_optional: true, if: :bar
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
after :each do
|
20
|
+
Object.send(:remove_const, :DummyModel)
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:obj) { DummyModel.new(foo: 'Foo') }
|
24
|
+
|
25
|
+
context 'when condition evaluates to true' do
|
26
|
+
before { obj.bar = true }
|
27
|
+
it 'should create history tracks' do
|
28
|
+
expect { obj.save }.to change(Tracker, :count).by(1)
|
29
|
+
expect do
|
30
|
+
obj.update_attributes(foo: 'Foo-2')
|
31
|
+
end.to change(Tracker, :count).by(1)
|
32
|
+
expect { obj.destroy }.to change(Tracker, :count).by(1)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when condition evaluates to false' do
|
37
|
+
before { obj.bar = false }
|
38
|
+
it 'should not create history tracks' do
|
39
|
+
expect { obj.save }.to_not change(Tracker, :count)
|
40
|
+
expect do
|
41
|
+
obj.update_attributes(foo: 'Foo-2')
|
42
|
+
end.to_not change(Tracker, :count)
|
43
|
+
expect { obj.destroy }.to_not change(Tracker, :count)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe ':unless' do
|
49
|
+
before :each do
|
50
|
+
class DummyModel
|
51
|
+
include Mongoid::Document
|
52
|
+
include Mongoid::History::Trackable
|
53
|
+
|
54
|
+
store_in collection: :model_ones
|
55
|
+
field :foo
|
56
|
+
|
57
|
+
attr_accessor :bar
|
58
|
+
|
59
|
+
track_history modifier_field_optional: true, unless: ->(obj) { obj.bar }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
after :each do
|
64
|
+
Object.send(:remove_const, :DummyModel)
|
65
|
+
end
|
66
|
+
|
67
|
+
let(:obj) { DummyModel.new(foo: 'Foo') }
|
68
|
+
|
69
|
+
context 'when condition evaluates to true' do
|
70
|
+
before { obj.bar = true }
|
71
|
+
it 'should not create history tracks' do
|
72
|
+
expect { obj.save }.to_not change(Tracker, :count)
|
73
|
+
expect do
|
74
|
+
obj.update_attributes(foo: 'Foo-2')
|
75
|
+
end.to_not change(Tracker, :count)
|
76
|
+
expect { obj.destroy }.to_not change(Tracker, :count)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'when condition evaluates to false' do
|
81
|
+
before { obj.bar = false }
|
82
|
+
it 'should create history tracks' do
|
83
|
+
expect { obj.save }.to change(Tracker, :count).by(1)
|
84
|
+
expect do
|
85
|
+
obj.update_attributes(foo: 'Foo-2')
|
86
|
+
end.to change(Tracker, :count).by(1)
|
87
|
+
expect { obj.destroy }.to change(Tracker, :count).by(1)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe ':if and :unless' do
|
93
|
+
before :each do
|
94
|
+
class DummyModel
|
95
|
+
include Mongoid::Document
|
96
|
+
include Mongoid::History::Trackable
|
97
|
+
|
98
|
+
store_in collection: :model_ones
|
99
|
+
field :foo
|
100
|
+
|
101
|
+
attr_accessor :bar, :baz
|
102
|
+
|
103
|
+
track_history modifier_field_optional: true, if: :bar, unless: ->(obj) { obj.baz }
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
after :each do
|
108
|
+
Object.send(:remove_const, :DummyModel)
|
109
|
+
end
|
110
|
+
|
111
|
+
let(:obj) { DummyModel.new(foo: 'Foo') }
|
112
|
+
|
113
|
+
context 'when :if condition evaluates to true' do
|
114
|
+
before { obj.bar = true }
|
115
|
+
|
116
|
+
context 'and :unless condition evaluates to true' do
|
117
|
+
before { obj.baz = true }
|
118
|
+
it 'should not create history tracks' do
|
119
|
+
expect { obj.save }.to_not change(Tracker, :count)
|
120
|
+
expect do
|
121
|
+
obj.update_attributes(foo: 'Foo-2')
|
122
|
+
end.to_not change(Tracker, :count)
|
123
|
+
expect { obj.destroy }.to_not change(Tracker, :count)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'and :unless condition evaluates to false' do
|
128
|
+
before { obj.baz = false }
|
129
|
+
it 'should create history tracks' do
|
130
|
+
expect { obj.save }.to change(Tracker, :count).by(1)
|
131
|
+
expect do
|
132
|
+
obj.update_attributes(foo: 'Foo-2')
|
133
|
+
end.to change(Tracker, :count).by(1)
|
134
|
+
expect { obj.destroy }.to change(Tracker, :count).by(1)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context 'when :if condition evaluates to false' do
|
140
|
+
before { obj.bar = false }
|
141
|
+
|
142
|
+
context 'and :unless condition evaluates to true' do
|
143
|
+
before { obj.baz = true }
|
144
|
+
it 'should not create history tracks' do
|
145
|
+
expect { obj.save }.to_not change(Tracker, :count)
|
146
|
+
expect do
|
147
|
+
obj.update_attributes(foo: 'Foo-2')
|
148
|
+
end.to_not change(Tracker, :count)
|
149
|
+
expect { obj.destroy }.to_not change(Tracker, :count)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'and :unless condition evaluates to false' do
|
154
|
+
before { obj.baz = false }
|
155
|
+
it 'should not create history tracks' do
|
156
|
+
expect { obj.save }.to_not change(Tracker, :count)
|
157
|
+
expect do
|
158
|
+
obj.update_attributes(foo: 'Foo-2')
|
159
|
+
end.to_not change(Tracker, :count)
|
160
|
+
expect { obj.destroy }.to_not change(Tracker, :count)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
@@ -1,87 +1,87 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mongoid::History::Trackable do
|
4
|
-
describe 'EmbeddedMethods' do
|
5
|
-
describe 'relation_class_of' do
|
6
|
-
before :each do
|
7
|
-
class ModelOne
|
8
|
-
include Mongoid::Document
|
9
|
-
include Mongoid::History::Trackable
|
10
|
-
|
11
|
-
if Mongoid::Compatibility::Version.mongoid7_or_newer?
|
12
|
-
embeds_one :emb_one
|
13
|
-
embeds_one :emb_two, store_as: 'emt'
|
14
|
-
else
|
15
|
-
embeds_one :emb_one, inverse_class_name: 'EmbOne'
|
16
|
-
embeds_one :emb_two, store_as: 'emt', inverse_class_name: 'EmbTwo'
|
17
|
-
end
|
18
|
-
|
19
|
-
track_history
|
20
|
-
end
|
21
|
-
|
22
|
-
class EmbOne
|
23
|
-
include Mongoid::Document
|
24
|
-
|
25
|
-
embedded_in :model_one
|
26
|
-
end
|
27
|
-
|
28
|
-
class EmbTwo
|
29
|
-
include Mongoid::Document
|
30
|
-
|
31
|
-
embedded_in :model_one
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
after :each do
|
36
|
-
Object.send(:remove_const, :ModelOne)
|
37
|
-
Object.send(:remove_const, :EmbOne)
|
38
|
-
Object.send(:remove_const, :EmbTwo)
|
39
|
-
end
|
40
|
-
|
41
|
-
it { expect(ModelOne.relation_class_of('emb_one')).to eq EmbOne }
|
42
|
-
it { expect(ModelOne.relation_class_of('emt')).to eq EmbTwo }
|
43
|
-
it { expect(ModelOne.relation_class_of('invalid')).to be_nil }
|
44
|
-
end
|
45
|
-
|
46
|
-
describe 'relation_class_of' do
|
47
|
-
before :each do
|
48
|
-
class ModelOne
|
49
|
-
include Mongoid::Document
|
50
|
-
include Mongoid::History::Trackable
|
51
|
-
|
52
|
-
if Mongoid::Compatibility::Version.mongoid7_or_newer?
|
53
|
-
embeds_many :emb_ones
|
54
|
-
embeds_many :emb_twos, store_as: 'emts'
|
55
|
-
else
|
56
|
-
embeds_many :emb_ones, inverse_class_name: 'EmbOne'
|
57
|
-
embeds_many :emb_twos, store_as: 'emts', inverse_class_name: 'EmbTwo'
|
58
|
-
end
|
59
|
-
|
60
|
-
track_history
|
61
|
-
end
|
62
|
-
|
63
|
-
class EmbOne
|
64
|
-
include Mongoid::Document
|
65
|
-
|
66
|
-
embedded_in :model_one
|
67
|
-
end
|
68
|
-
|
69
|
-
class EmbTwo
|
70
|
-
include Mongoid::Document
|
71
|
-
|
72
|
-
embedded_in :model_one
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
after :each do
|
77
|
-
Object.send(:remove_const, :ModelOne)
|
78
|
-
Object.send(:remove_const, :EmbOne)
|
79
|
-
Object.send(:remove_const, :EmbTwo)
|
80
|
-
end
|
81
|
-
|
82
|
-
it { expect(ModelOne.relation_class_of('emb_ones')).to eq EmbOne }
|
83
|
-
it { expect(ModelOne.relation_class_of('emts')).to eq EmbTwo }
|
84
|
-
it { expect(ModelOne.relation_class_of('invalid')).to be_nil }
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mongoid::History::Trackable do
|
4
|
+
describe 'EmbeddedMethods' do
|
5
|
+
describe 'relation_class_of' do
|
6
|
+
before :each do
|
7
|
+
class ModelOne
|
8
|
+
include Mongoid::Document
|
9
|
+
include Mongoid::History::Trackable
|
10
|
+
|
11
|
+
if Mongoid::Compatibility::Version.mongoid7_or_newer?
|
12
|
+
embeds_one :emb_one
|
13
|
+
embeds_one :emb_two, store_as: 'emt'
|
14
|
+
else
|
15
|
+
embeds_one :emb_one, inverse_class_name: 'EmbOne'
|
16
|
+
embeds_one :emb_two, store_as: 'emt', inverse_class_name: 'EmbTwo'
|
17
|
+
end
|
18
|
+
|
19
|
+
track_history
|
20
|
+
end
|
21
|
+
|
22
|
+
class EmbOne
|
23
|
+
include Mongoid::Document
|
24
|
+
|
25
|
+
embedded_in :model_one
|
26
|
+
end
|
27
|
+
|
28
|
+
class EmbTwo
|
29
|
+
include Mongoid::Document
|
30
|
+
|
31
|
+
embedded_in :model_one
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
after :each do
|
36
|
+
Object.send(:remove_const, :ModelOne)
|
37
|
+
Object.send(:remove_const, :EmbOne)
|
38
|
+
Object.send(:remove_const, :EmbTwo)
|
39
|
+
end
|
40
|
+
|
41
|
+
it { expect(ModelOne.relation_class_of('emb_one')).to eq EmbOne }
|
42
|
+
it { expect(ModelOne.relation_class_of('emt')).to eq EmbTwo }
|
43
|
+
it { expect(ModelOne.relation_class_of('invalid')).to be_nil }
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'relation_class_of' do
|
47
|
+
before :each do
|
48
|
+
class ModelOne
|
49
|
+
include Mongoid::Document
|
50
|
+
include Mongoid::History::Trackable
|
51
|
+
|
52
|
+
if Mongoid::Compatibility::Version.mongoid7_or_newer?
|
53
|
+
embeds_many :emb_ones
|
54
|
+
embeds_many :emb_twos, store_as: 'emts'
|
55
|
+
else
|
56
|
+
embeds_many :emb_ones, inverse_class_name: 'EmbOne'
|
57
|
+
embeds_many :emb_twos, store_as: 'emts', inverse_class_name: 'EmbTwo'
|
58
|
+
end
|
59
|
+
|
60
|
+
track_history
|
61
|
+
end
|
62
|
+
|
63
|
+
class EmbOne
|
64
|
+
include Mongoid::Document
|
65
|
+
|
66
|
+
embedded_in :model_one
|
67
|
+
end
|
68
|
+
|
69
|
+
class EmbTwo
|
70
|
+
include Mongoid::Document
|
71
|
+
|
72
|
+
embedded_in :model_one
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
after :each do
|
77
|
+
Object.send(:remove_const, :ModelOne)
|
78
|
+
Object.send(:remove_const, :EmbOne)
|
79
|
+
Object.send(:remove_const, :EmbTwo)
|
80
|
+
end
|
81
|
+
|
82
|
+
it { expect(ModelOne.relation_class_of('emb_ones')).to eq EmbOne }
|
83
|
+
it { expect(ModelOne.relation_class_of('emts')).to eq EmbTwo }
|
84
|
+
it { expect(ModelOne.relation_class_of('invalid')).to be_nil }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/spec/unit/history_spec.rb
CHANGED
@@ -1,58 +1,58 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mongoid::History do
|
4
|
-
it { is_expected.to respond_to(:trackable_settings) }
|
5
|
-
it { is_expected.to respond_to(:trackable_settings=) }
|
6
|
-
|
7
|
-
describe '#default_settings' do
|
8
|
-
let(:default_settings) { { paranoia_field: 'deleted_at' } }
|
9
|
-
it { expect(described_class.default_settings).to eq(default_settings) }
|
10
|
-
end
|
11
|
-
|
12
|
-
describe '#trackable_class_settings' do
|
13
|
-
before :each do
|
14
|
-
class ModelOne
|
15
|
-
include Mongoid::Document
|
16
|
-
include Mongoid::History::Trackable
|
17
|
-
|
18
|
-
store_in collection: :model_ones
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
after :each do
|
23
|
-
Object.send(:remove_const, :ModelOne)
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'when present' do
|
27
|
-
before :each do
|
28
|
-
ModelOne.history_settings paranoia_field: :annuled_at
|
29
|
-
end
|
30
|
-
it { expect(described_class.trackable_class_settings(ModelOne)).to eq(paranoia_field: 'annuled_at') }
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'when not present' do
|
34
|
-
it { expect(described_class.trackable_class_settings(ModelOne)).to eq(paranoia_field: 'deleted_at') }
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe '#reset!' do
|
39
|
-
before :each do
|
40
|
-
class ModelTwo
|
41
|
-
include Mongoid::Document
|
42
|
-
include Mongoid::History::Trackable
|
43
|
-
|
44
|
-
track_history
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
after :each do
|
49
|
-
Object.send(:remove_const, :ModelTwo)
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'should remove all configurations' do
|
53
|
-
expect(ModelTwo).to have_attributes mongoid_history_options: be_a(Mongoid::History::Options)
|
54
|
-
Mongoid::History.reset!
|
55
|
-
expect(ModelTwo).to_not respond_to :mongoid_history_options
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mongoid::History do
|
4
|
+
it { is_expected.to respond_to(:trackable_settings) }
|
5
|
+
it { is_expected.to respond_to(:trackable_settings=) }
|
6
|
+
|
7
|
+
describe '#default_settings' do
|
8
|
+
let(:default_settings) { { paranoia_field: 'deleted_at' } }
|
9
|
+
it { expect(described_class.default_settings).to eq(default_settings) }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#trackable_class_settings' do
|
13
|
+
before :each do
|
14
|
+
class ModelOne
|
15
|
+
include Mongoid::Document
|
16
|
+
include Mongoid::History::Trackable
|
17
|
+
|
18
|
+
store_in collection: :model_ones
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
after :each do
|
23
|
+
Object.send(:remove_const, :ModelOne)
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when present' do
|
27
|
+
before :each do
|
28
|
+
ModelOne.history_settings paranoia_field: :annuled_at
|
29
|
+
end
|
30
|
+
it { expect(described_class.trackable_class_settings(ModelOne)).to eq(paranoia_field: 'annuled_at') }
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when not present' do
|
34
|
+
it { expect(described_class.trackable_class_settings(ModelOne)).to eq(paranoia_field: 'deleted_at') }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#reset!' do
|
39
|
+
before :each do
|
40
|
+
class ModelTwo
|
41
|
+
include Mongoid::Document
|
42
|
+
include Mongoid::History::Trackable
|
43
|
+
|
44
|
+
track_history
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
after :each do
|
49
|
+
Object.send(:remove_const, :ModelTwo)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should remove all configurations' do
|
53
|
+
expect(ModelTwo).to have_attributes mongoid_history_options: be_a(Mongoid::History::Options)
|
54
|
+
Mongoid::History.reset!
|
55
|
+
expect(ModelTwo).to_not respond_to :mongoid_history_options
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|