log_book 0.1.7 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +0 -1
- data/.travis.yml +9 -0
- data/Gemfile.lock +173 -0
- data/README.md +44 -1
- data/lib/generators/log_book/templates/create_log_book_events.rb +7 -4
- data/lib/log_book/event.rb +3 -5
- data/lib/log_book/plugin.rb +16 -5
- data/lib/log_book/utils.rb +15 -4
- data/lib/log_book/version.rb +1 -1
- data/lib/log_book.rb +18 -8
- data/log_book.gemspec +8 -9
- data/test/log_book_test.rb +79 -22
- data/test/models.rb +1 -1
- data/test/plugin_test.rb +1 -2
- data/test/schema.rb +13 -8
- data/test/test_helper.rb +5 -1
- metadata +43 -57
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3df7903b6702205b16c36791b7f8ebcfc1612f3dcb0042bfbc77bbde66050ff0
|
4
|
+
data.tar.gz: fdbdd4bdb6424a69ba602a0233e7611a2c3a53aeea65368ee0974f3b6e66275a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88f94471b1bb9b83c11abd1b6ba3cc7c5f0c6b440a7d49014a033ada08b87945be21c15a3f41bfef9e2fc8ea145dc9941aa21ed2cdcf311167dee4dcca2a96eb
|
7
|
+
data.tar.gz: 6931310a5f20887d3936b14d8a59836dda15366e5a046c7be0ac9ebda5802c2650ef944bd1e217e1a303b51af294c39fc5feaf654d7f497614fdf1cf374e07e7
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
log_book (0.6.3)
|
5
|
+
acts-as-taggable-on (>= 8.0)
|
6
|
+
rails (>= 6.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actioncable (7.0.2.2)
|
12
|
+
actionpack (= 7.0.2.2)
|
13
|
+
activesupport (= 7.0.2.2)
|
14
|
+
nio4r (~> 2.0)
|
15
|
+
websocket-driver (>= 0.6.1)
|
16
|
+
actionmailbox (7.0.2.2)
|
17
|
+
actionpack (= 7.0.2.2)
|
18
|
+
activejob (= 7.0.2.2)
|
19
|
+
activerecord (= 7.0.2.2)
|
20
|
+
activestorage (= 7.0.2.2)
|
21
|
+
activesupport (= 7.0.2.2)
|
22
|
+
mail (>= 2.7.1)
|
23
|
+
net-imap
|
24
|
+
net-pop
|
25
|
+
net-smtp
|
26
|
+
actionmailer (7.0.2.2)
|
27
|
+
actionpack (= 7.0.2.2)
|
28
|
+
actionview (= 7.0.2.2)
|
29
|
+
activejob (= 7.0.2.2)
|
30
|
+
activesupport (= 7.0.2.2)
|
31
|
+
mail (~> 2.5, >= 2.5.4)
|
32
|
+
net-imap
|
33
|
+
net-pop
|
34
|
+
net-smtp
|
35
|
+
rails-dom-testing (~> 2.0)
|
36
|
+
actionpack (7.0.2.2)
|
37
|
+
actionview (= 7.0.2.2)
|
38
|
+
activesupport (= 7.0.2.2)
|
39
|
+
rack (~> 2.0, >= 2.2.0)
|
40
|
+
rack-test (>= 0.6.3)
|
41
|
+
rails-dom-testing (~> 2.0)
|
42
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
43
|
+
actiontext (7.0.2.2)
|
44
|
+
actionpack (= 7.0.2.2)
|
45
|
+
activerecord (= 7.0.2.2)
|
46
|
+
activestorage (= 7.0.2.2)
|
47
|
+
activesupport (= 7.0.2.2)
|
48
|
+
globalid (>= 0.6.0)
|
49
|
+
nokogiri (>= 1.8.5)
|
50
|
+
actionview (7.0.2.2)
|
51
|
+
activesupport (= 7.0.2.2)
|
52
|
+
builder (~> 3.1)
|
53
|
+
erubi (~> 1.4)
|
54
|
+
rails-dom-testing (~> 2.0)
|
55
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
56
|
+
activejob (7.0.2.2)
|
57
|
+
activesupport (= 7.0.2.2)
|
58
|
+
globalid (>= 0.3.6)
|
59
|
+
activemodel (7.0.2.2)
|
60
|
+
activesupport (= 7.0.2.2)
|
61
|
+
activerecord (7.0.2.2)
|
62
|
+
activemodel (= 7.0.2.2)
|
63
|
+
activesupport (= 7.0.2.2)
|
64
|
+
activestorage (7.0.2.2)
|
65
|
+
actionpack (= 7.0.2.2)
|
66
|
+
activejob (= 7.0.2.2)
|
67
|
+
activerecord (= 7.0.2.2)
|
68
|
+
activesupport (= 7.0.2.2)
|
69
|
+
marcel (~> 1.0)
|
70
|
+
mini_mime (>= 1.1.0)
|
71
|
+
activesupport (7.0.2.2)
|
72
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
73
|
+
i18n (>= 1.6, < 2)
|
74
|
+
minitest (>= 5.1)
|
75
|
+
tzinfo (~> 2.0)
|
76
|
+
acts-as-taggable-on (9.0.1)
|
77
|
+
activerecord (>= 6.0, < 7.1)
|
78
|
+
assert_difference (1.0.0)
|
79
|
+
activesupport (>= 3.0.0)
|
80
|
+
builder (3.2.4)
|
81
|
+
concurrent-ruby (1.1.9)
|
82
|
+
crass (1.0.6)
|
83
|
+
digest (3.1.0)
|
84
|
+
erubi (1.10.0)
|
85
|
+
globalid (1.0.0)
|
86
|
+
activesupport (>= 5.0)
|
87
|
+
i18n (1.10.0)
|
88
|
+
concurrent-ruby (~> 1.0)
|
89
|
+
io-wait (0.2.1)
|
90
|
+
loofah (2.14.0)
|
91
|
+
crass (~> 1.0.2)
|
92
|
+
nokogiri (>= 1.5.9)
|
93
|
+
mail (2.7.1)
|
94
|
+
mini_mime (>= 0.1.1)
|
95
|
+
marcel (1.0.2)
|
96
|
+
method_source (1.0.0)
|
97
|
+
mini_mime (1.1.2)
|
98
|
+
minitest (5.15.0)
|
99
|
+
mocha (1.13.0)
|
100
|
+
net-imap (0.2.3)
|
101
|
+
digest
|
102
|
+
net-protocol
|
103
|
+
strscan
|
104
|
+
net-pop (0.1.1)
|
105
|
+
digest
|
106
|
+
net-protocol
|
107
|
+
timeout
|
108
|
+
net-protocol (0.1.2)
|
109
|
+
io-wait
|
110
|
+
timeout
|
111
|
+
net-smtp (0.3.1)
|
112
|
+
digest
|
113
|
+
net-protocol
|
114
|
+
timeout
|
115
|
+
nio4r (2.5.8)
|
116
|
+
nokogiri (1.13.3-x86_64-darwin)
|
117
|
+
racc (~> 1.4)
|
118
|
+
racc (1.6.0)
|
119
|
+
rack (2.2.3)
|
120
|
+
rack-test (1.1.0)
|
121
|
+
rack (>= 1.0, < 3)
|
122
|
+
rails (7.0.2.2)
|
123
|
+
actioncable (= 7.0.2.2)
|
124
|
+
actionmailbox (= 7.0.2.2)
|
125
|
+
actionmailer (= 7.0.2.2)
|
126
|
+
actionpack (= 7.0.2.2)
|
127
|
+
actiontext (= 7.0.2.2)
|
128
|
+
actionview (= 7.0.2.2)
|
129
|
+
activejob (= 7.0.2.2)
|
130
|
+
activemodel (= 7.0.2.2)
|
131
|
+
activerecord (= 7.0.2.2)
|
132
|
+
activestorage (= 7.0.2.2)
|
133
|
+
activesupport (= 7.0.2.2)
|
134
|
+
bundler (>= 1.15.0)
|
135
|
+
railties (= 7.0.2.2)
|
136
|
+
rails-dom-testing (2.0.3)
|
137
|
+
activesupport (>= 4.2.0)
|
138
|
+
nokogiri (>= 1.6)
|
139
|
+
rails-html-sanitizer (1.4.2)
|
140
|
+
loofah (~> 2.3)
|
141
|
+
railties (7.0.2.2)
|
142
|
+
actionpack (= 7.0.2.2)
|
143
|
+
activesupport (= 7.0.2.2)
|
144
|
+
method_source
|
145
|
+
rake (>= 12.2)
|
146
|
+
thor (~> 1.0)
|
147
|
+
zeitwerk (~> 2.5)
|
148
|
+
rake (13.0.6)
|
149
|
+
sqlite3 (1.4.2)
|
150
|
+
strscan (3.0.1)
|
151
|
+
thor (1.2.1)
|
152
|
+
timeout (0.2.0)
|
153
|
+
tzinfo (2.0.4)
|
154
|
+
concurrent-ruby (~> 1.0)
|
155
|
+
websocket-driver (0.7.5)
|
156
|
+
websocket-extensions (>= 0.1.0)
|
157
|
+
websocket-extensions (0.1.5)
|
158
|
+
zeitwerk (2.5.4)
|
159
|
+
|
160
|
+
PLATFORMS
|
161
|
+
x86_64-darwin-19
|
162
|
+
|
163
|
+
DEPENDENCIES
|
164
|
+
assert_difference (>= 1.0)
|
165
|
+
bundler (>= 2.0)
|
166
|
+
log_book!
|
167
|
+
minitest (>= 5.1)
|
168
|
+
mocha (>= 1.13)
|
169
|
+
rake (>= 0.13)
|
170
|
+
sqlite3 (>= 1.0)
|
171
|
+
|
172
|
+
BUNDLED WITH
|
173
|
+
2.2.32
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# LogBook
|
2
2
|
|
3
|
-
|
3
|
+
Ruby on Rails, Automatically keeping record of all Model Changes
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -23,6 +23,7 @@ As the Model should be loaded after ActiveReccord has established the connection
|
|
23
23
|
### ActsOnTaggableOn dependency
|
24
24
|
|
25
25
|
rails generate acts_as_taggable_on:migration
|
26
|
+
# rake acts_as_taggable_on_engine:install:migrations # for version '~> 4.0' or superior
|
26
27
|
rake db:migrate
|
27
28
|
|
28
29
|
## Usage
|
@@ -50,8 +51,50 @@ If you want to include _who executes the action_ use the special attribute `log_
|
|
50
51
|
my_model.log_book_historian = current_user
|
51
52
|
my_model.save!
|
52
53
|
|
54
|
+
If you want to _mute_ a model change:
|
55
|
+
|
56
|
+
my_model.log_book_mute = true
|
57
|
+
my_model.save! # No LogBook::Event will be generated
|
58
|
+
|
59
|
+
If you want to _mute_ LogBook globally:
|
60
|
+
|
61
|
+
LogBook.mute = true
|
62
|
+
my_model.save! # No LogBook::Event will be generated
|
63
|
+
|
64
|
+
If you want to _ignore_ some fields from the changes Event:
|
65
|
+
|
66
|
+
class MyModel < ActiveRecord::Base
|
67
|
+
log_book :ignore => [:my_counter]
|
68
|
+
end
|
69
|
+
|
70
|
+
my_model.update_atttibtes!(:my_counter => 9) # No LogBook::Event will be generated
|
71
|
+
|
72
|
+
If you want _LogBook::Events_ to be destroyed on _Model_ destroy:
|
73
|
+
|
74
|
+
class MyModel < ActiveRecord::Base
|
75
|
+
log_book :dependent => :destroy
|
76
|
+
end
|
77
|
+
|
78
|
+
In other case the _LogBook::Events_ will remain after _Model_ destroyed.
|
79
|
+
|
80
|
+
## Rails Integration
|
81
|
+
|
82
|
+
Check this example project to see how LogBook is integrated:
|
83
|
+
|
84
|
+
- [Skeleton](https://github.com/fguillen/Skeleton)
|
85
|
+
|
86
|
+
Or this commit in a more modern Rails project:
|
87
|
+
|
88
|
+
- [RailsSkeleton](https://github.com/fguillen/RailsSkeleton/commit/4c16c6402254bf4c44b7589b404fc22c746bae15)
|
89
|
+
|
53
90
|
## TODO
|
54
91
|
|
92
|
+
Use block configuration instead of `model.log_book_historian` do something like:
|
93
|
+
|
94
|
+
LogBook.conf(:log_book_historian => user) do
|
95
|
+
model.save!
|
96
|
+
end
|
97
|
+
|
55
98
|
|
56
99
|
## Sate of the art
|
57
100
|
|
@@ -1,17 +1,20 @@
|
|
1
|
-
class CreateLogBookEvents < ActiveRecord::Migration
|
1
|
+
class CreateLogBookEvents < ActiveRecord::Migration[4.2]
|
2
2
|
def self.up
|
3
3
|
create_table :log_book_events do |t|
|
4
4
|
t.integer :historian_id
|
5
5
|
t.string :historian_type
|
6
6
|
t.integer :historizable_id
|
7
7
|
t.string :historizable_type
|
8
|
-
t.text :
|
8
|
+
t.text :differences, :limit => 16777215 # mediumtext
|
9
9
|
|
10
|
-
t.timestamps
|
10
|
+
t.timestamps :null => false
|
11
11
|
end
|
12
|
+
|
13
|
+
add_index :log_book_events, [:historizable_id, :historizable_type, :created_at], :name => "index_log_book_events_on_historizable_and_created_at"
|
14
|
+
add_index :log_book_events, [:created_at]
|
12
15
|
end
|
13
16
|
|
14
17
|
def self.down
|
15
18
|
drop_table :log_book_events
|
16
19
|
end
|
17
|
-
end
|
20
|
+
end
|
data/lib/log_book/event.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
class LogBook::Event < ::ActiveRecord::Base
|
2
2
|
self.table_name = "log_book_events"
|
3
3
|
|
4
|
-
attr_accessible :historian, :historizable, :text, :tag_list
|
5
|
-
|
6
4
|
acts_as_taggable
|
7
5
|
|
8
|
-
belongs_to :historian, :polymorphic => true
|
6
|
+
belongs_to :historian, :polymorphic => true, :optional => true
|
9
7
|
belongs_to :historizable, :polymorphic => true
|
10
8
|
|
11
|
-
validates :text, :presence => true
|
12
|
-
|
13
9
|
scope :by_recent, -> { order("id desc") }
|
10
|
+
|
11
|
+
serialize :differences, JSON
|
14
12
|
end
|
data/lib/log_book/plugin.rb
CHANGED
@@ -5,7 +5,6 @@ module LogBook::Plugin
|
|
5
5
|
end
|
6
6
|
|
7
7
|
module ClassMethods
|
8
|
-
|
9
8
|
def log_book(opts = {})
|
10
9
|
after_create :log_book_event_on_create
|
11
10
|
after_update :log_book_event_on_update
|
@@ -14,24 +13,36 @@ module LogBook::Plugin
|
|
14
13
|
has_many :log_book_events, :class_name => "LogBook::Event", :as => :historizable, :dependent => (opts[:dependent] || :nullify)
|
15
14
|
|
16
15
|
attr_accessor :log_book_historian
|
16
|
+
attr_accessor :log_book_mute
|
17
|
+
cattr_accessor :log_book_options
|
18
|
+
|
19
|
+
self.log_book_options = opts
|
20
|
+
self.log_book_options[:ignore] ||= []
|
21
|
+
self.log_book_options[:ignore] << :updated_at # ignoring noisy field
|
17
22
|
end
|
18
23
|
end
|
19
24
|
|
20
25
|
module InstanceMethods
|
21
26
|
def log_book_event_on_create
|
22
|
-
LogBook.created(self.log_book_historian, self)
|
27
|
+
LogBook.created(self.log_book_historian, self) if !self.log_book_mute
|
23
28
|
end
|
24
29
|
|
25
30
|
def log_book_event_on_update
|
26
|
-
|
31
|
+
# TODO: this line of code is duplicated
|
32
|
+
if ActiveRecord::VERSION::STRING.to_f >= 5.1
|
33
|
+
clean_changes = saved_changes.select { |k,v| !self.log_book_options[:ignore].include? k.to_sym }
|
34
|
+
else
|
35
|
+
clean_changes = changes.select { |k,v| !self.log_book_options[:ignore].include? k.to_sym }
|
36
|
+
end
|
37
|
+
LogBook.updated(self.log_book_historian, self) if !clean_changes.empty? and !self.log_book_mute
|
27
38
|
end
|
28
39
|
|
29
40
|
def log_book_event_on_destroy
|
30
|
-
LogBook.destroyed(self.log_book_historian, self)
|
41
|
+
LogBook.destroyed(self.log_book_historian, self) if !self.log_book_mute
|
31
42
|
end
|
32
43
|
end
|
33
44
|
end
|
34
45
|
|
35
46
|
ActiveSupport.on_load(:active_record) do
|
36
47
|
include LogBook::Plugin
|
37
|
-
end
|
48
|
+
end
|
data/lib/log_book/utils.rb
CHANGED
@@ -1,16 +1,27 @@
|
|
1
1
|
module LogBook::Utils
|
2
2
|
def self.pretty_changes(model)
|
3
|
+
# TODO: this line of code is duplicated
|
4
|
+
if ActiveRecord::VERSION::STRING.to_f >= 5.1
|
5
|
+
clean_changes = model.saved_changes.select { |k,v| !model.log_book_options[:ignore].include? k.to_sym }
|
6
|
+
else
|
7
|
+
clean_changes = model.changes.select { |k,v| !model.log_book_options[:ignore].include? k.to_sym }
|
8
|
+
end
|
9
|
+
|
3
10
|
result =
|
4
|
-
|
11
|
+
clean_changes.map do |k,v|
|
5
12
|
old_value = v[0]
|
6
13
|
new_value = v[1]
|
7
14
|
|
8
15
|
old_value = old_value.to_s( :localdb ) if old_value.instance_of? ActiveSupport::TimeWithZone
|
9
16
|
new_value = new_value.to_s( :localdb ) if new_value.instance_of? ActiveSupport::TimeWithZone
|
10
17
|
|
11
|
-
|
12
|
-
|
18
|
+
{
|
19
|
+
"key" => k,
|
20
|
+
"before" => old_value,
|
21
|
+
"after" => new_value
|
22
|
+
}
|
23
|
+
end
|
13
24
|
|
14
25
|
result
|
15
26
|
end
|
16
|
-
end
|
27
|
+
end
|
data/lib/log_book/version.rb
CHANGED
data/lib/log_book.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require "active_record"
|
2
2
|
require "active_support/core_ext/module"
|
3
|
-
require "protected_attributes"
|
4
3
|
require "acts-as-taggable-on"
|
5
4
|
require_relative "log_book/version"
|
6
5
|
require_relative "log_book/plugin"
|
@@ -13,32 +12,44 @@ module LogBook
|
|
13
12
|
:destroy => "destroy"
|
14
13
|
}
|
15
14
|
|
16
|
-
|
15
|
+
@@muted = false
|
16
|
+
|
17
|
+
def self.event(historian, historizable, differences, tag_list)
|
18
|
+
return if @@muted
|
19
|
+
|
17
20
|
tag_list_composed = []
|
18
21
|
tag_list_composed << scope_tag(historian) if historian
|
19
22
|
tag_list_composed << kind_tag(historizable) if historizable
|
20
23
|
tag_list_composed += [tag_list].flatten if tag_list
|
21
|
-
|
24
|
+
|
22
25
|
LogBook::Event.create!(
|
23
26
|
:historian => historian,
|
24
27
|
:historizable => historizable,
|
25
|
-
:
|
28
|
+
:differences => differences,
|
26
29
|
:tag_list => tag_list_composed
|
27
30
|
)
|
28
31
|
end
|
29
32
|
|
33
|
+
def self.muted=(value)
|
34
|
+
@@muted = value
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.muted
|
38
|
+
@@muted
|
39
|
+
end
|
40
|
+
|
30
41
|
private
|
31
42
|
|
32
43
|
def self.created(historian, historizable)
|
33
|
-
LogBook.event(historian, historizable,
|
44
|
+
LogBook.event(historian, historizable, nil, LogBook::OPERATIONS[:create])
|
34
45
|
end
|
35
46
|
|
36
47
|
def self.updated(historian, historizable)
|
37
|
-
LogBook.event(historian, historizable,
|
48
|
+
LogBook.event(historian, historizable, LogBook::Utils.pretty_changes(historizable), LogBook::OPERATIONS[:update])
|
38
49
|
end
|
39
50
|
|
40
51
|
def self.destroyed(historian, historizable)
|
41
|
-
LogBook.event(historian, historizable,
|
52
|
+
LogBook.event(historian, historizable, nil, LogBook::OPERATIONS[:destroy])
|
42
53
|
end
|
43
54
|
|
44
55
|
def self.scope_tag(historian)
|
@@ -49,4 +60,3 @@ module LogBook
|
|
49
60
|
historizable.class.name.underscore
|
50
61
|
end
|
51
62
|
end
|
52
|
-
|
data/log_book.gemspec
CHANGED
@@ -18,14 +18,13 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_runtime_dependency "rails", "
|
22
|
-
spec.add_runtime_dependency "
|
23
|
-
spec.add_runtime_dependency "acts-as-taggable-on", "3.3.0"
|
21
|
+
spec.add_runtime_dependency "rails", ">= 6.0"
|
22
|
+
spec.add_runtime_dependency "acts-as-taggable-on", ">= 8.0"
|
24
23
|
|
25
|
-
spec.add_development_dependency "bundler", "
|
26
|
-
spec.add_development_dependency "rake"
|
27
|
-
spec.add_development_dependency "mocha"
|
28
|
-
spec.add_development_dependency "sqlite3"
|
29
|
-
spec.add_development_dependency "assert_difference"
|
30
|
-
spec.add_development_dependency "minitest", "
|
24
|
+
spec.add_development_dependency "bundler", ">= 2.0"
|
25
|
+
spec.add_development_dependency "rake", ">= 0.13"
|
26
|
+
spec.add_development_dependency "mocha", ">= 1.13"
|
27
|
+
spec.add_development_dependency "sqlite3", ">= 1.0"
|
28
|
+
spec.add_development_dependency "assert_difference", ">= 1.0"
|
29
|
+
spec.add_development_dependency "minitest", ">= 5.1"
|
31
30
|
end
|
data/test/log_book_test.rb
CHANGED
@@ -12,54 +12,101 @@ class LogBookTest < MiniTest::Test
|
|
12
12
|
|
13
13
|
def test_event
|
14
14
|
assert_difference "LogBook::Event.count", 1 do
|
15
|
-
LogBook.event(@user, @item, "
|
15
|
+
LogBook.event(@user, @item, ["DIFFERENCE"], LogBook::OPERATIONS[:create])
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
assert_equal(@user,
|
20
|
-
assert_equal(@item,
|
21
|
-
assert_equal("
|
22
|
-
assert_equal(["user", "item", "create"].sort,
|
18
|
+
log_book_event = LogBook::Event.last
|
19
|
+
assert_equal(@user, log_book_event.historian)
|
20
|
+
assert_equal(@item, log_book_event.historizable)
|
21
|
+
assert_equal(["DIFFERENCE"], log_book_event.differences)
|
22
|
+
assert_equal(["user", "item", "create"].sort, log_book_event.tag_list.sort)
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_event_with_nils
|
26
26
|
assert_difference "LogBook::Event.count", 1 do
|
27
|
-
LogBook.event(nil, nil, "
|
27
|
+
LogBook.event(nil, nil, ["DIFFERENCE"], nil)
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
assert_equal("
|
34
|
-
assert_equal([],
|
30
|
+
log_book_event = LogBook::Event.last
|
31
|
+
assert_nil(log_book_event.historian)
|
32
|
+
assert_nil(log_book_event.historizable)
|
33
|
+
assert_equal(["DIFFERENCE"], log_book_event.differences)
|
34
|
+
assert_equal([], log_book_event.tag_list)
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_created
|
38
38
|
item = Item.new(:title => "Item Title")
|
39
39
|
item.log_book_historian = @user
|
40
40
|
|
41
|
-
LogBook.expects(:event).with(@user, item,
|
41
|
+
LogBook.expects(:event).with(@user, item, nil, LogBook::OPERATIONS[:create])
|
42
|
+
|
43
|
+
item.save!
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_created_when_muted
|
47
|
+
item = Item.new(:title => "Item Title")
|
48
|
+
item.log_book_mute = true
|
49
|
+
|
50
|
+
LogBook.expects(:event).never
|
42
51
|
|
43
52
|
item.save!
|
44
53
|
end
|
45
54
|
|
46
55
|
def test_updated
|
47
|
-
|
56
|
+
differences = [
|
57
|
+
{
|
58
|
+
"key" => "title",
|
59
|
+
"before" => "Item Title",
|
60
|
+
"after" => "Other Title"
|
61
|
+
}
|
62
|
+
]
|
63
|
+
|
64
|
+
LogBook.expects(:event).with(@user, @item, differences, LogBook::OPERATIONS[:update])
|
65
|
+
|
66
|
+
@item.update!(:title => "Other Title")
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_updated_when_muted
|
70
|
+
LogBook.expects(:event).never
|
71
|
+
|
72
|
+
@item.log_book_mute = true
|
73
|
+
@item.update!(:title => "Other Title")
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_updated_with_ignore_fields
|
77
|
+
differences = [
|
78
|
+
{
|
79
|
+
"key" => "title",
|
80
|
+
"before" => "Item Title",
|
81
|
+
"after" => "Other Title"
|
82
|
+
}
|
83
|
+
]
|
48
84
|
|
49
|
-
|
85
|
+
item_with_opts = ItemWithOpts.create!(:title => "Item Title", :my_counter => 0)
|
86
|
+
LogBook.expects(:event).with(@user, item_with_opts, differences, LogBook::OPERATIONS[:update])
|
87
|
+
|
88
|
+
item_with_opts.log_book_historian = @user
|
89
|
+
item_with_opts.update!(:title => "Other Title", :my_counter => 10)
|
50
90
|
end
|
51
91
|
|
52
92
|
def test_item_destroyed
|
53
|
-
LogBook.expects(:event).with(@user, @item,
|
93
|
+
LogBook.expects(:event).with(@user, @item, nil, LogBook::OPERATIONS[:destroy])
|
54
94
|
|
55
95
|
@item.destroy
|
56
96
|
end
|
57
97
|
|
98
|
+
def test_item_destroyed_when_muted
|
99
|
+
LogBook.expects(:event).never
|
100
|
+
|
101
|
+
@item.log_book_mute = true
|
102
|
+
@item.destroy
|
103
|
+
end
|
104
|
+
|
58
105
|
def test_has_many_log_book_events
|
59
106
|
LogBook::Event.destroy_all
|
60
107
|
|
61
|
-
log_book_event_1 = LogBook.event(@user, @item,
|
62
|
-
log_book_event_2 = LogBook.event(@user, @item,
|
108
|
+
log_book_event_1 = LogBook.event(@user, @item, nil, LogBook::OPERATIONS[:create])
|
109
|
+
log_book_event_2 = LogBook.event(@user, @item, nil, LogBook::OPERATIONS[:update])
|
63
110
|
|
64
111
|
@item.reload
|
65
112
|
|
@@ -69,7 +116,7 @@ class LogBookTest < MiniTest::Test
|
|
69
116
|
end
|
70
117
|
|
71
118
|
def test_log_book_events_nullify_on_historizable_destroy
|
72
|
-
log_book_event = LogBook.event(@user, @item,
|
119
|
+
log_book_event = LogBook.event(@user, @item, nil, LogBook::OPERATIONS[:create])
|
73
120
|
|
74
121
|
@item.destroy
|
75
122
|
|
@@ -77,16 +124,26 @@ class LogBookTest < MiniTest::Test
|
|
77
124
|
|
78
125
|
assert_equal(true, log_book_event.historizable_id.nil?)
|
79
126
|
assert_equal(true, log_book_event.historizable.nil?)
|
80
|
-
assert_equal(
|
127
|
+
assert_equal(true, log_book_event.historizable_type.nil?)
|
81
128
|
end
|
82
129
|
|
83
130
|
def test_log_book_events_destroy_on_historizable_destroy
|
84
131
|
item_with_opts = ItemWithOpts.new
|
85
|
-
log_book_event = LogBook.event(@user, item_with_opts,
|
132
|
+
log_book_event = LogBook.event(@user, item_with_opts, nil, LogBook::OPERATIONS[:create])
|
86
133
|
|
87
134
|
item_with_opts.destroy
|
88
135
|
|
89
136
|
assert_equal(false, LogBook::Event.exists?(log_book_event.id))
|
90
137
|
end
|
91
|
-
end
|
92
138
|
|
139
|
+
def test_created_when_global_muted
|
140
|
+
item = Item.new(:title => "Item Title")
|
141
|
+
LogBook.muted = true
|
142
|
+
|
143
|
+
LogBook::Event.expects(:create!).never
|
144
|
+
|
145
|
+
item.save!
|
146
|
+
|
147
|
+
LogBook.muted = false
|
148
|
+
end
|
149
|
+
end
|
data/test/models.rb
CHANGED
data/test/plugin_test.rb
CHANGED
@@ -19,7 +19,7 @@ class PluginTest < MiniTest::Test
|
|
19
19
|
def test_event_on_update
|
20
20
|
@item.log_book_historian = @user
|
21
21
|
LogBook.expects(:updated).with(@user, @item)
|
22
|
-
@item.
|
22
|
+
@item.update!(:title => "Other Title")
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_event_on_destroy
|
@@ -28,4 +28,3 @@ class PluginTest < MiniTest::Test
|
|
28
28
|
@item.destroy
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
data/test/schema.rb
CHANGED
@@ -5,23 +5,28 @@ ActiveRecord::Schema.define :version => 0 do
|
|
5
5
|
|
6
6
|
create_table :items, :force => true do |t|
|
7
7
|
t.string :title
|
8
|
+
t.integer :my_counter
|
8
9
|
end
|
9
10
|
|
10
11
|
# acts-as-taggable-on
|
11
|
-
# https://github.com/mbleigh/acts-as-taggable-on/
|
12
|
-
|
13
|
-
create_table :tags do |t|
|
12
|
+
# https://github.com/mbleigh/acts-as-taggable-on/blob/6e1837762f0d60edc9b6c2d92b5a9435f404173f/spec/internal/db/schema.rb
|
13
|
+
create_table :tags, force: true do |t|
|
14
14
|
t.string :name
|
15
|
+
t.integer :taggings_count, default: 0
|
16
|
+
t.string :type
|
15
17
|
end
|
18
|
+
add_index 'tags', ['name'], name: 'index_tags_on_name', unique: true
|
16
19
|
|
17
|
-
create_table :taggings do |t|
|
20
|
+
create_table :taggings, force: true do |t|
|
18
21
|
t.references :tag
|
19
|
-
t.references :taggable, :
|
20
|
-
t.references :tagger, :
|
21
|
-
t.string :context, :
|
22
|
+
t.references :taggable, polymorphic: true
|
23
|
+
t.references :tagger, polymorphic: true
|
24
|
+
t.string :context, limit: 128
|
22
25
|
|
23
26
|
t.datetime :created_at
|
24
27
|
end
|
25
28
|
|
26
|
-
|
29
|
+
add_index 'taggings',
|
30
|
+
['tag_id', 'taggable_id', 'taggable_type', 'context', 'tagger_id', 'tagger_type'],
|
31
|
+
unique: true, name: 'taggings_idx'
|
27
32
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
+
|
1
2
|
require "active_record"
|
2
3
|
require "active_support/core_ext/module"
|
3
4
|
require "assert_difference"
|
4
5
|
require "acts-as-taggable-on"
|
6
|
+
|
7
|
+
# require "minitest/unit"
|
5
8
|
require "minitest/autorun"
|
6
|
-
require "mocha/
|
9
|
+
require "mocha/mini_test"
|
10
|
+
|
7
11
|
require_relative "../lib/log_book"
|
8
12
|
|
9
13
|
FileUtils.rm("#{File.dirname(__FILE__)}/db/log_book.sqlite", :force => true)
|
metadata
CHANGED
@@ -1,141 +1,127 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: log_book
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fernando Guillen
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '6.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: protected_attributes
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - '>='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - '>='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
26
|
+
version: '6.0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: acts-as-taggable-on
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
|
-
- -
|
31
|
+
- - ">="
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
33
|
+
version: '8.0'
|
48
34
|
type: :runtime
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
|
-
- -
|
38
|
+
- - ">="
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
40
|
+
version: '8.0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: bundler
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
|
-
- -
|
45
|
+
- - ">="
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
47
|
+
version: '2.0'
|
62
48
|
type: :development
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
|
-
- -
|
52
|
+
- - ">="
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
54
|
+
version: '2.0'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: rake
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
|
-
- -
|
59
|
+
- - ">="
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
61
|
+
version: '0.13'
|
76
62
|
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
|
-
- -
|
66
|
+
- - ">="
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
68
|
+
version: '0.13'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: mocha
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
|
-
- -
|
73
|
+
- - ">="
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
75
|
+
version: '1.13'
|
90
76
|
type: :development
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
|
-
- -
|
80
|
+
- - ">="
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
82
|
+
version: '1.13'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: sqlite3
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
|
-
- -
|
87
|
+
- - ">="
|
102
88
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
89
|
+
version: '1.0'
|
104
90
|
type: :development
|
105
91
|
prerelease: false
|
106
92
|
version_requirements: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
108
|
-
- -
|
94
|
+
- - ">="
|
109
95
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
96
|
+
version: '1.0'
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
98
|
name: assert_difference
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
114
100
|
requirements:
|
115
|
-
- -
|
101
|
+
- - ">="
|
116
102
|
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
103
|
+
version: '1.0'
|
118
104
|
type: :development
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
107
|
requirements:
|
122
|
-
- -
|
108
|
+
- - ">="
|
123
109
|
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
110
|
+
version: '1.0'
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
112
|
name: minitest
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
128
114
|
requirements:
|
129
|
-
- -
|
115
|
+
- - ">="
|
130
116
|
- !ruby/object:Gem::Version
|
131
|
-
version: 5.
|
117
|
+
version: '5.1'
|
132
118
|
type: :development
|
133
119
|
prerelease: false
|
134
120
|
version_requirements: !ruby/object:Gem::Requirement
|
135
121
|
requirements:
|
136
|
-
- -
|
122
|
+
- - ">="
|
137
123
|
- !ruby/object:Gem::Version
|
138
|
-
version: 5.
|
124
|
+
version: '5.1'
|
139
125
|
description: Storing an events log book
|
140
126
|
email:
|
141
127
|
- fguillen.mail@gmail.com
|
@@ -143,9 +129,10 @@ executables: []
|
|
143
129
|
extensions: []
|
144
130
|
extra_rdoc_files: []
|
145
131
|
files:
|
146
|
-
- .gitignore
|
147
|
-
- .
|
132
|
+
- ".gitignore"
|
133
|
+
- ".travis.yml"
|
148
134
|
- Gemfile
|
135
|
+
- Gemfile.lock
|
149
136
|
- LICENSE.txt
|
150
137
|
- README.md
|
151
138
|
- Rakefile
|
@@ -167,24 +154,23 @@ homepage: https://github.com/fguillen/LogBook
|
|
167
154
|
licenses:
|
168
155
|
- MIT
|
169
156
|
metadata: {}
|
170
|
-
post_install_message:
|
157
|
+
post_install_message:
|
171
158
|
rdoc_options: []
|
172
159
|
require_paths:
|
173
160
|
- lib
|
174
161
|
required_ruby_version: !ruby/object:Gem::Requirement
|
175
162
|
requirements:
|
176
|
-
- -
|
163
|
+
- - ">="
|
177
164
|
- !ruby/object:Gem::Version
|
178
165
|
version: '0'
|
179
166
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
180
167
|
requirements:
|
181
|
-
- -
|
168
|
+
- - ">="
|
182
169
|
- !ruby/object:Gem::Version
|
183
170
|
version: '0'
|
184
171
|
requirements: []
|
185
|
-
|
186
|
-
|
187
|
-
signing_key:
|
172
|
+
rubygems_version: 3.2.22
|
173
|
+
signing_key:
|
188
174
|
specification_version: 4
|
189
175
|
summary: Storing an events log book
|
190
176
|
test_files:
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.0.0-p247
|