mongoid_activity_tracker 0.2.4 → 0.2.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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b723478a7ba1e99b77eb60fb255cfde76de5e80382a25e4945b3a54b6517aee4
|
|
4
|
+
data.tar.gz: c3eefa74402cdf148777d0d42ae9f546a88b82c1fd2df1450c6930ead3e64d13
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 47c1e0fcf15676c2c64994507c483bf649c5776925c137cf79cc6f3ca38e71d8ace2d0a35ab36d149da19168dcf70140b633f6091c2b434e639aa374e154b11e
|
|
7
|
+
data.tar.gz: b25734e19e8e241d39d146ff7d68c8e5e15ad94b28de791e9c3cb7bfc9c9d0ecc5e385fc124f7932b1e4b8d990de0f2d7caccff149b81015513d9f5879189512
|
data/CHANGELOG.md
CHANGED
|
@@ -14,9 +14,7 @@ module MongoidActivityTracker
|
|
|
14
14
|
create!({ action: action, actor: actor }.merge(options))
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def tracks(relation_name, cache_methods: %i(to_s))
|
|
17
|
+
def tracks(relation_name, cache_methods: %i[to_s])
|
|
20
18
|
field_name = [relation_name, 'cache'].join('_')
|
|
21
19
|
accessor_name = [relation_name, 'cache_methods'].join('_')
|
|
22
20
|
instance_variable_name = ['@', accessor_name].join
|
|
@@ -36,12 +34,10 @@ module MongoidActivityTracker
|
|
|
36
34
|
OpenStruct.new(send(field_name))
|
|
37
35
|
end
|
|
38
36
|
|
|
39
|
-
|
|
37
|
+
before_validation -> { set_cache(relation_name) }
|
|
40
38
|
end
|
|
41
39
|
end
|
|
42
40
|
|
|
43
|
-
# ---------------------------------------------------------------------
|
|
44
|
-
|
|
45
41
|
def self.included(base)
|
|
46
42
|
base.extend ClassMethods
|
|
47
43
|
base.class_eval do
|
|
@@ -51,18 +47,16 @@ module MongoidActivityTracker
|
|
|
51
47
|
|
|
52
48
|
tracks :actor
|
|
53
49
|
|
|
54
|
-
validates :actor, presence: true
|
|
50
|
+
validates :actor, presence: true, unless: -> { actor_cache && actor_cache[:to_s].present? }
|
|
55
51
|
validates :action, presence: true
|
|
56
52
|
end
|
|
57
53
|
end
|
|
58
54
|
|
|
59
|
-
# =====================================================================
|
|
60
|
-
|
|
61
55
|
def created_at
|
|
62
56
|
id.generation_time.in_time_zone(Time.zone)
|
|
63
57
|
end
|
|
64
58
|
|
|
65
|
-
private
|
|
59
|
+
private
|
|
66
60
|
|
|
67
61
|
def set_cache(relation_name)
|
|
68
62
|
accessor_name = [relation_name, 'cache_methods'].join('_')
|
|
@@ -73,6 +67,7 @@ module MongoidActivityTracker
|
|
|
73
67
|
|
|
74
68
|
send(accessor_name).each do |m|
|
|
75
69
|
next if send(field_name)[m].present?
|
|
70
|
+
|
|
76
71
|
send(field_name)[m] = send(relation_name).send(m) if send(relation_name).respond_to?(m)
|
|
77
72
|
end
|
|
78
73
|
end
|
|
@@ -1,112 +1,103 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
describe MongoidActivityTracker::Tracker do
|
|
4
|
+
subject { TestTracker.new }
|
|
5
|
+
|
|
6
|
+
let(:actor) { TestActor.new }
|
|
7
|
+
let(:sub) { TestSubject.new }
|
|
8
|
+
|
|
9
|
+
describe 'associations' do
|
|
10
|
+
it { subject.must_respond_to :actor }
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe 'validations' do
|
|
14
|
+
describe 'by default' do
|
|
15
|
+
before { subject.valid? }
|
|
16
|
+
|
|
17
|
+
it { subject.errors.messages.keys.must_include :actor }
|
|
18
|
+
it { subject.errors.messages.keys.must_include :action }
|
|
13
19
|
end
|
|
14
20
|
|
|
15
|
-
describe '
|
|
16
|
-
|
|
17
|
-
subject.
|
|
18
|
-
|
|
19
|
-
it 'has :actor_cache' do
|
|
20
|
-
subject.must_respond_to :actor_cache
|
|
21
|
-
subject.actor_cache.must_be_kind_of Hash
|
|
21
|
+
describe 'accepts to_s stored in actor_cache' do
|
|
22
|
+
before do
|
|
23
|
+
subject.actor_cache[:to_s] = 'John Doe'
|
|
24
|
+
subject.valid?
|
|
22
25
|
end
|
|
26
|
+
|
|
27
|
+
it { subject.errors.messages.keys.wont_include :actor }
|
|
23
28
|
end
|
|
29
|
+
end
|
|
24
30
|
|
|
25
|
-
|
|
31
|
+
describe 'fields' do
|
|
32
|
+
it { subject.must_respond_to :action }
|
|
33
|
+
it { subject.must_respond_to :actor_cache }
|
|
34
|
+
it { subject.actor_cache.must_be_kind_of Hash }
|
|
35
|
+
end
|
|
26
36
|
|
|
27
|
-
|
|
28
|
-
|
|
37
|
+
describe '.track' do
|
|
38
|
+
let(:result) { TestTracker.track(actor, :create, subject: sub) }
|
|
29
39
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
it 'sets the :actor_cache with :to_s by default' do
|
|
37
|
-
result.actor_cache.must_equal(to_s: actor.to_s)
|
|
38
|
-
end
|
|
39
|
-
it 'sets the :action' do
|
|
40
|
-
result.action.must_equal :create
|
|
41
|
-
end
|
|
42
|
-
it 'sets any other attributes' do
|
|
43
|
-
result.subject.must_equal sub
|
|
44
|
-
end
|
|
45
|
-
end
|
|
40
|
+
it { result.must_be_kind_of TestTracker }
|
|
41
|
+
it { result.actor.must_equal actor }
|
|
42
|
+
it { result.actor_cache.must_equal(to_s: actor.to_s) }
|
|
43
|
+
it { result.action.must_equal :create }
|
|
44
|
+
it { result.subject.must_equal sub }
|
|
45
|
+
end
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
describe '.tracks' do
|
|
48
|
+
it { subject.must_respond_to :subject }
|
|
49
|
+
it { subject.must_respond_to :subject_cache }
|
|
50
|
+
it { subject.subject_cache.must_be_kind_of Hash }
|
|
51
|
+
it { subject.must_respond_to :subject_cache_methods }
|
|
52
|
+
it { subject.subject_cache_methods.must_equal %i[to_s] }
|
|
53
|
+
it { subject.subject_cache_object.must_respond_to :to_s }
|
|
48
54
|
|
|
49
|
-
describe
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
subject.
|
|
55
|
-
subject.subject_cache.must_be_kind_of Hash
|
|
56
|
-
end
|
|
57
|
-
it 'defines the :subject_cache_methods accessor' do
|
|
58
|
-
subject.must_respond_to :subject_cache_methods
|
|
59
|
-
end
|
|
60
|
-
it 'sets :to_s as a default for the :subject_cache_methods' do
|
|
61
|
-
subject.subject_cache_methods.must_equal %i(to_s)
|
|
62
|
-
end
|
|
63
|
-
it 'adds the :subject_cache_object wrapper' do
|
|
64
|
-
subject.subject_cache_object.must_respond_to :to_s
|
|
65
|
-
end
|
|
66
|
-
it 'sets the cache before :save' do
|
|
67
|
-
test_subject = TestSubject.new
|
|
68
|
-
subject.subject = test_subject
|
|
69
|
-
subject.run_callbacks(:save)
|
|
70
|
-
subject.subject_cache.fetch(:to_s).must_equal test_subject.to_s
|
|
55
|
+
describe TestSubject do
|
|
56
|
+
let(:tsubject) { TestSubject.new }
|
|
57
|
+
|
|
58
|
+
before do
|
|
59
|
+
subject.subject = tsubject
|
|
60
|
+
subject.run_callbacks(:validation)
|
|
71
61
|
end
|
|
62
|
+
|
|
63
|
+
it { subject.subject_cache.fetch(:to_s).must_equal tsubject.to_s }
|
|
72
64
|
end
|
|
65
|
+
end
|
|
73
66
|
|
|
74
|
-
|
|
67
|
+
describe ':created_at' do
|
|
68
|
+
it { subject.must_respond_to :created_at }
|
|
69
|
+
it { subject.created_at.must_be_kind_of Time }
|
|
70
|
+
end
|
|
75
71
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
end
|
|
72
|
+
describe ':actor_cache' do
|
|
73
|
+
before do
|
|
74
|
+
subject.actor = actor
|
|
75
|
+
subject.run_callbacks(:validation)
|
|
81
76
|
end
|
|
82
77
|
|
|
83
|
-
|
|
78
|
+
it { subject.actor_cache.fetch(:to_s).must_equal actor.to_s }
|
|
79
|
+
|
|
80
|
+
describe ':to_s' do
|
|
84
81
|
before do
|
|
85
|
-
subject.actor = actor
|
|
86
|
-
end
|
|
87
|
-
it 'sets :actor_cache on save' do
|
|
88
|
-
subject.run_callbacks(:save)
|
|
89
|
-
subject.actor_cache.fetch(:to_s).must_equal actor.to_s
|
|
90
|
-
end
|
|
91
|
-
it 'allows preset cache manually' do
|
|
92
82
|
subject.actor_cache[:to_s] = 'foo-bar'
|
|
93
|
-
subject.run_callbacks(:
|
|
94
|
-
subject.actor_cache.fetch(:to_s).must_equal 'foo-bar'
|
|
95
|
-
end
|
|
96
|
-
it 'allows to override the default cache methods' do
|
|
97
|
-
subject.actor_cache_methods = %i(class)
|
|
98
|
-
subject.run_callbacks(:save)
|
|
99
|
-
subject.actor_cache.fetch(:class).must_equal TestActor
|
|
83
|
+
subject.run_callbacks(:validation)
|
|
100
84
|
end
|
|
85
|
+
|
|
86
|
+
it { subject.actor_cache.fetch(:to_s).must_equal 'foo-bar' }
|
|
101
87
|
end
|
|
102
88
|
|
|
103
|
-
describe '
|
|
104
|
-
|
|
105
|
-
subject.
|
|
106
|
-
|
|
107
|
-
it 'converts keys to methods' do
|
|
108
|
-
subject.actor_cache_object.must_respond_to :to_s
|
|
89
|
+
describe '#actor_cache_methods' do
|
|
90
|
+
before do
|
|
91
|
+
subject.actor_cache_methods = %i[class]
|
|
92
|
+
subject.run_callbacks(:validation)
|
|
109
93
|
end
|
|
94
|
+
|
|
95
|
+
it { subject.actor_cache.fetch(:class).must_equal TestActor }
|
|
110
96
|
end
|
|
111
97
|
end
|
|
98
|
+
|
|
99
|
+
describe ':actor_cache_object' do
|
|
100
|
+
it { subject.actor_cache_object.must_be_kind_of OpenStruct }
|
|
101
|
+
it { subject.actor_cache_object.must_respond_to :to_s }
|
|
102
|
+
end
|
|
112
103
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mongoid_activity_tracker
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tomas Celizna
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2019-01-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: mongoid
|
|
@@ -168,8 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
168
168
|
- !ruby/object:Gem::Version
|
|
169
169
|
version: '0'
|
|
170
170
|
requirements: []
|
|
171
|
-
|
|
172
|
-
rubygems_version: 2.7.3
|
|
171
|
+
rubygems_version: 3.0.1
|
|
173
172
|
signing_key:
|
|
174
173
|
specification_version: 4
|
|
175
174
|
summary: Minimal set of classes and modules to help with activity tracking.
|