mongoid-history 0.8.3 → 0.8.5
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.
- 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
data/spec/spec_helper.rb
CHANGED
@@ -1,30 +1,32 @@
|
|
1
|
-
require 'coveralls'
|
2
|
-
Coveralls.wear!
|
3
|
-
|
4
|
-
$LOAD_PATH.push File.expand_path('../../lib', __FILE__)
|
5
|
-
|
6
|
-
require 'active_support/all'
|
7
|
-
require 'mongoid'
|
8
|
-
require 'request_store'
|
9
|
-
|
10
|
-
# Undefine RequestStore so that it may be stubbed in specific tests
|
11
|
-
RequestStoreTemp = RequestStore
|
12
|
-
Object.send(:remove_const, :RequestStore)
|
13
|
-
|
14
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
15
|
-
|
16
|
-
require 'mongoid/history'
|
17
|
-
|
18
|
-
RSpec.configure do |config|
|
19
|
-
config.raise_errors_for_deprecations!
|
20
|
-
|
21
|
-
config.before :all do
|
22
|
-
Mongoid.logger.level = Logger::INFO
|
23
|
-
Mongo::Logger.logger.level = Logger::INFO if Mongoid::Compatibility::Version.mongoid5_or_newer?
|
24
|
-
Mongoid.belongs_to_required_by_default = false if Mongoid::Compatibility::Version.mongoid6?
|
25
|
-
end
|
26
|
-
|
27
|
-
config.before :each do
|
28
|
-
Mongoid::History.reset!
|
29
|
-
end
|
30
|
-
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear!
|
3
|
+
|
4
|
+
$LOAD_PATH.push File.expand_path('../../lib', __FILE__)
|
5
|
+
|
6
|
+
require 'active_support/all'
|
7
|
+
require 'mongoid'
|
8
|
+
require 'request_store'
|
9
|
+
|
10
|
+
# Undefine RequestStore so that it may be stubbed in specific tests
|
11
|
+
RequestStoreTemp = RequestStore
|
12
|
+
Object.send(:remove_const, :RequestStore)
|
13
|
+
|
14
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
15
|
+
|
16
|
+
require 'mongoid/history'
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
config.raise_errors_for_deprecations!
|
20
|
+
|
21
|
+
config.before :all do
|
22
|
+
Mongoid.logger.level = Logger::INFO
|
23
|
+
Mongo::Logger.logger.level = Logger::INFO if Mongoid::Compatibility::Version.mongoid5_or_newer?
|
24
|
+
Mongoid.belongs_to_required_by_default = false if Mongoid::Compatibility::Version.mongoid6?
|
25
|
+
end
|
26
|
+
|
27
|
+
config.before :each do
|
28
|
+
Mongoid::History.reset!
|
29
|
+
end
|
30
|
+
|
31
|
+
config.include ErrorHelpers
|
32
|
+
end
|
data/spec/support/mongoid.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
Mongoid.configure do |config|
|
2
|
-
config.connect_to('mongoid_history_test')
|
3
|
-
end
|
4
|
-
|
5
|
-
RSpec.configure do |config|
|
6
|
-
config.after(:each) do
|
7
|
-
Mongoid.purge!
|
8
|
-
end
|
9
|
-
|
10
|
-
config.backtrace_exclusion_patterns = [%r{lib\/rspec\/(core|expectations|matchers|mocks)}]
|
11
|
-
end
|
1
|
+
Mongoid.configure do |config|
|
2
|
+
config.connect_to('mongoid_history_test')
|
3
|
+
end
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.after(:each) do
|
7
|
+
Mongoid.purge!
|
8
|
+
end
|
9
|
+
|
10
|
+
config.backtrace_exclusion_patterns = [%r{lib\/rspec\/(core|expectations|matchers|mocks)}]
|
11
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
RSpec.configure do |config|
|
2
|
-
config.before :each do
|
3
|
-
class Tracker
|
4
|
-
include Mongoid::History::Tracker
|
5
|
-
end
|
6
|
-
Mongoid::History.tracker_class_name = 'Tracker'
|
7
|
-
Mongoid::History.modifier_class_name = 'User'
|
8
|
-
end
|
9
|
-
config.after :each do
|
10
|
-
Mongoid::History.tracker_class_name = nil
|
11
|
-
end
|
12
|
-
end
|
1
|
+
RSpec.configure do |config|
|
2
|
+
config.before :each do
|
3
|
+
class Tracker
|
4
|
+
include Mongoid::History::Tracker
|
5
|
+
end
|
6
|
+
Mongoid::History.tracker_class_name = 'Tracker'
|
7
|
+
Mongoid::History.modifier_class_name = 'User'
|
8
|
+
end
|
9
|
+
config.after :each do
|
10
|
+
Mongoid::History.tracker_class_name = nil
|
11
|
+
end
|
12
|
+
end
|
@@ -1,141 +1,141 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mongoid::History::Attributes::Base do
|
4
|
-
before :each do
|
5
|
-
class ModelOne
|
6
|
-
include Mongoid::Document
|
7
|
-
include Mongoid::History::Trackable
|
8
|
-
|
9
|
-
field :foo
|
10
|
-
field :b, as: :bar
|
11
|
-
end
|
12
|
-
|
13
|
-
class ModelTwo
|
14
|
-
include Mongoid::Document
|
15
|
-
|
16
|
-
field :foo
|
17
|
-
field :goo
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
after :each do
|
22
|
-
Object.send(:remove_const, :ModelOne)
|
23
|
-
Object.send(:remove_const, :ModelTwo)
|
24
|
-
end
|
25
|
-
|
26
|
-
let(:obj_one) { ModelOne.new }
|
27
|
-
let(:base) { described_class.new(obj_one) }
|
28
|
-
subject { base }
|
29
|
-
|
30
|
-
it { is_expected.to respond_to(:trackable) }
|
31
|
-
|
32
|
-
describe '#initialize' do
|
33
|
-
it { expect(base.instance_variable_get(:@trackable)).to eq obj_one }
|
34
|
-
end
|
35
|
-
|
36
|
-
describe '#trackable_class' do
|
37
|
-
subject { base.send(:trackable_class) }
|
38
|
-
it { is_expected.to eq ModelOne }
|
39
|
-
end
|
40
|
-
|
41
|
-
describe '#aliased_fields' do
|
42
|
-
subject { base.send(:aliased_fields) }
|
43
|
-
it { is_expected.to eq('id' => '_id', 'bar' => 'b') }
|
44
|
-
end
|
45
|
-
|
46
|
-
describe '#changes_method' do
|
47
|
-
before(:each) do
|
48
|
-
ModelOne.track_history changes_method: :my_changes
|
49
|
-
end
|
50
|
-
subject { base.send(:changes_method) }
|
51
|
-
it { is_expected.to eq :my_changes }
|
52
|
-
end
|
53
|
-
|
54
|
-
describe '#changes' do
|
55
|
-
before(:each) do
|
56
|
-
ModelOne.track_history
|
57
|
-
allow(obj_one).to receive(:changes) { { 'foo' => ['Foo', 'Foo-new'] } }
|
58
|
-
end
|
59
|
-
subject { base.send(:changes) }
|
60
|
-
it { is_expected.to eq('foo' => ['Foo', 'Foo-new']) }
|
61
|
-
end
|
62
|
-
|
63
|
-
describe '#format_field' do
|
64
|
-
subject { base.send(:format_field, :bar, 'foo') }
|
65
|
-
|
66
|
-
context 'when formatted via string' do
|
67
|
-
before do
|
68
|
-
ModelOne.track_history format: { bar: '*%s*' }
|
69
|
-
end
|
70
|
-
|
71
|
-
it { is_expected.to eq '*foo*' }
|
72
|
-
end
|
73
|
-
|
74
|
-
context 'when formatted via proc' do
|
75
|
-
before do
|
76
|
-
ModelOne.track_history format: { bar: ->(v) { v * 2 } }
|
77
|
-
end
|
78
|
-
|
79
|
-
it { is_expected.to eq 'foofoo' }
|
80
|
-
end
|
81
|
-
|
82
|
-
context 'when not formatted' do
|
83
|
-
before do
|
84
|
-
ModelOne.track_history
|
85
|
-
end
|
86
|
-
|
87
|
-
it { is_expected.to eq 'foo' }
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
shared_examples 'formats embedded relation' do |relation_type|
|
92
|
-
let(:model_two) { ModelTwo.new(foo: :bar, goo: :baz) }
|
93
|
-
|
94
|
-
before :each do
|
95
|
-
ModelOne.send(relation_type, :model_two)
|
96
|
-
end
|
97
|
-
|
98
|
-
subject { base.send("format_#{relation_type}_relation", :model_two, model_two.attributes) }
|
99
|
-
|
100
|
-
context 'with permitted attributes' do
|
101
|
-
before do
|
102
|
-
ModelOne.track_history on: { model_two: %i[foo] }
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'should select only permitted attributes' do
|
106
|
-
is_expected.to include('foo' => :bar)
|
107
|
-
is_expected.to_not include('goo')
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context 'with attributes formatted via string' do
|
112
|
-
before do
|
113
|
-
ModelOne.track_history on: { model_two: %i[foo] }, format: { model_two: { foo: '&%s&' } }
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'should select obfuscate permitted attributes' do
|
117
|
-
is_expected.to include('foo' => '&bar&')
|
118
|
-
is_expected.to_not include('goo')
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
context 'with attributes formatted via proc' do
|
123
|
-
before do
|
124
|
-
ModelOne.track_history on: { model_two: %i[foo] }, format: { model_two: { foo: ->(v) { v.to_s * 2 } } }
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'should select obfuscate permitted attributes' do
|
128
|
-
is_expected.to include('foo' => 'barbar')
|
129
|
-
is_expected.to_not include('goo')
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
describe '#format_embeds_one_relation' do
|
135
|
-
include_examples 'formats embedded relation', :embeds_one
|
136
|
-
end
|
137
|
-
|
138
|
-
describe '#format_embeds_many_relation' do
|
139
|
-
include_examples 'formats embedded relation', :embeds_many
|
140
|
-
end
|
141
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mongoid::History::Attributes::Base do
|
4
|
+
before :each do
|
5
|
+
class ModelOne
|
6
|
+
include Mongoid::Document
|
7
|
+
include Mongoid::History::Trackable
|
8
|
+
|
9
|
+
field :foo
|
10
|
+
field :b, as: :bar
|
11
|
+
end
|
12
|
+
|
13
|
+
class ModelTwo
|
14
|
+
include Mongoid::Document
|
15
|
+
|
16
|
+
field :foo
|
17
|
+
field :goo
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
after :each do
|
22
|
+
Object.send(:remove_const, :ModelOne)
|
23
|
+
Object.send(:remove_const, :ModelTwo)
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:obj_one) { ModelOne.new }
|
27
|
+
let(:base) { described_class.new(obj_one) }
|
28
|
+
subject { base }
|
29
|
+
|
30
|
+
it { is_expected.to respond_to(:trackable) }
|
31
|
+
|
32
|
+
describe '#initialize' do
|
33
|
+
it { expect(base.instance_variable_get(:@trackable)).to eq obj_one }
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#trackable_class' do
|
37
|
+
subject { base.send(:trackable_class) }
|
38
|
+
it { is_expected.to eq ModelOne }
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#aliased_fields' do
|
42
|
+
subject { base.send(:aliased_fields) }
|
43
|
+
it { is_expected.to eq('id' => '_id', 'bar' => 'b') }
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#changes_method' do
|
47
|
+
before(:each) do
|
48
|
+
ModelOne.track_history changes_method: :my_changes
|
49
|
+
end
|
50
|
+
subject { base.send(:changes_method) }
|
51
|
+
it { is_expected.to eq :my_changes }
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#changes' do
|
55
|
+
before(:each) do
|
56
|
+
ModelOne.track_history
|
57
|
+
allow(obj_one).to receive(:changes) { { 'foo' => ['Foo', 'Foo-new'] } }
|
58
|
+
end
|
59
|
+
subject { base.send(:changes) }
|
60
|
+
it { is_expected.to eq('foo' => ['Foo', 'Foo-new']) }
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#format_field' do
|
64
|
+
subject { base.send(:format_field, :bar, 'foo') }
|
65
|
+
|
66
|
+
context 'when formatted via string' do
|
67
|
+
before do
|
68
|
+
ModelOne.track_history format: { bar: '*%s*' }
|
69
|
+
end
|
70
|
+
|
71
|
+
it { is_expected.to eq '*foo*' }
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'when formatted via proc' do
|
75
|
+
before do
|
76
|
+
ModelOne.track_history format: { bar: ->(v) { v * 2 } }
|
77
|
+
end
|
78
|
+
|
79
|
+
it { is_expected.to eq 'foofoo' }
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'when not formatted' do
|
83
|
+
before do
|
84
|
+
ModelOne.track_history
|
85
|
+
end
|
86
|
+
|
87
|
+
it { is_expected.to eq 'foo' }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
shared_examples 'formats embedded relation' do |relation_type|
|
92
|
+
let(:model_two) { ModelTwo.new(foo: :bar, goo: :baz) }
|
93
|
+
|
94
|
+
before :each do
|
95
|
+
ModelOne.send(relation_type, :model_two)
|
96
|
+
end
|
97
|
+
|
98
|
+
subject { base.send("format_#{relation_type}_relation", :model_two, model_two.attributes) }
|
99
|
+
|
100
|
+
context 'with permitted attributes' do
|
101
|
+
before do
|
102
|
+
ModelOne.track_history on: { model_two: %i[foo] }
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should select only permitted attributes' do
|
106
|
+
is_expected.to include('foo' => :bar)
|
107
|
+
is_expected.to_not include('goo')
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'with attributes formatted via string' do
|
112
|
+
before do
|
113
|
+
ModelOne.track_history on: { model_two: %i[foo] }, format: { model_two: { foo: '&%s&' } }
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should select obfuscate permitted attributes' do
|
117
|
+
is_expected.to include('foo' => '&bar&')
|
118
|
+
is_expected.to_not include('goo')
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context 'with attributes formatted via proc' do
|
123
|
+
before do
|
124
|
+
ModelOne.track_history on: { model_two: %i[foo] }, format: { model_two: { foo: ->(v) { v.to_s * 2 } } }
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should select obfuscate permitted attributes' do
|
128
|
+
is_expected.to include('foo' => 'barbar')
|
129
|
+
is_expected.to_not include('goo')
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe '#format_embeds_one_relation' do
|
135
|
+
include_examples 'formats embedded relation', :embeds_one
|
136
|
+
end
|
137
|
+
|
138
|
+
describe '#format_embeds_many_relation' do
|
139
|
+
include_examples 'formats embedded relation', :embeds_many
|
140
|
+
end
|
141
|
+
end
|