log_book 0.1.7 → 0.6.1

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
- SHA1:
3
- metadata.gz: 844141903822ef7b4da7514701dfb0b3d4463189
4
- data.tar.gz: 6d389d3383574dbe3e676419bf46724f178482d9
2
+ SHA256:
3
+ metadata.gz: 3ba38b6769d1e3ce4158b5c961f87c65561eb3ea49e7dcc1a9232b12dc61378e
4
+ data.tar.gz: 991cd4b51ebd117eca1f61f3bd8083c82dfad477028ce483e79aee48d2bd6334
5
5
  SHA512:
6
- metadata.gz: a375456188f8cb54db495328f8260bd92adadcce1446a8454ae84bfaceedab837520cc475fbd1e7c4d46feab2f7d4748684e5781e5a2ae8201d81150979f27e0
7
- data.tar.gz: a38628f1726647304d3b31ee46fbba09857f71a6cb2e25e686f1a836ed36ddb9539a063fb60d65c8206ce2d307012c264a5d21a0f9731bbfe65f2c3eb20c795e
6
+ metadata.gz: a7a71db90398ef4e9d9c9ae6754a470ec2a0771603f5b1ee53b1cb115c46f92565c236cd12f45f9cad3b05bf1af2765c541c628df9f80bc1add75fb4c71aa8a0
7
+ data.tar.gz: e29d9b47f58ddd2b59a0fa8acffecf00a80313ae5093411b3a99a005f60b069019404a2e6108a3cbbed583d44fce05a8c01549616bc6e48c82419f9d992913ec
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
4
+ - 2.5.1
5
+
6
+ matrix:
7
+ fast_finish: true
8
+ allow_failures:
9
+ - rvm: 2.5.1
data/Gemfile.lock ADDED
@@ -0,0 +1,155 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ log_book (0.5.2)
5
+ acts-as-taggable-on (>= 8.0)
6
+ rails (~> 6.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (6.1.4.1)
12
+ actionpack (= 6.1.4.1)
13
+ activesupport (= 6.1.4.1)
14
+ nio4r (~> 2.0)
15
+ websocket-driver (>= 0.6.1)
16
+ actionmailbox (6.1.4.1)
17
+ actionpack (= 6.1.4.1)
18
+ activejob (= 6.1.4.1)
19
+ activerecord (= 6.1.4.1)
20
+ activestorage (= 6.1.4.1)
21
+ activesupport (= 6.1.4.1)
22
+ mail (>= 2.7.1)
23
+ actionmailer (6.1.4.1)
24
+ actionpack (= 6.1.4.1)
25
+ actionview (= 6.1.4.1)
26
+ activejob (= 6.1.4.1)
27
+ activesupport (= 6.1.4.1)
28
+ mail (~> 2.5, >= 2.5.4)
29
+ rails-dom-testing (~> 2.0)
30
+ actionpack (6.1.4.1)
31
+ actionview (= 6.1.4.1)
32
+ activesupport (= 6.1.4.1)
33
+ rack (~> 2.0, >= 2.0.9)
34
+ rack-test (>= 0.6.3)
35
+ rails-dom-testing (~> 2.0)
36
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
37
+ actiontext (6.1.4.1)
38
+ actionpack (= 6.1.4.1)
39
+ activerecord (= 6.1.4.1)
40
+ activestorage (= 6.1.4.1)
41
+ activesupport (= 6.1.4.1)
42
+ nokogiri (>= 1.8.5)
43
+ actionview (6.1.4.1)
44
+ activesupport (= 6.1.4.1)
45
+ builder (~> 3.1)
46
+ erubi (~> 1.4)
47
+ rails-dom-testing (~> 2.0)
48
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
49
+ activejob (6.1.4.1)
50
+ activesupport (= 6.1.4.1)
51
+ globalid (>= 0.3.6)
52
+ activemodel (6.1.4.1)
53
+ activesupport (= 6.1.4.1)
54
+ activerecord (6.1.4.1)
55
+ activemodel (= 6.1.4.1)
56
+ activesupport (= 6.1.4.1)
57
+ activestorage (6.1.4.1)
58
+ actionpack (= 6.1.4.1)
59
+ activejob (= 6.1.4.1)
60
+ activerecord (= 6.1.4.1)
61
+ activesupport (= 6.1.4.1)
62
+ marcel (~> 1.0.0)
63
+ mini_mime (>= 1.1.0)
64
+ activesupport (6.1.4.1)
65
+ concurrent-ruby (~> 1.0, >= 1.0.2)
66
+ i18n (>= 1.6, < 2)
67
+ minitest (>= 5.1)
68
+ tzinfo (~> 2.0)
69
+ zeitwerk (~> 2.3)
70
+ acts-as-taggable-on (8.1.0)
71
+ activerecord (>= 5.0, < 6.2)
72
+ assert_difference (1.0.0)
73
+ activesupport (>= 3.0.0)
74
+ builder (3.2.4)
75
+ concurrent-ruby (1.1.9)
76
+ crass (1.0.6)
77
+ erubi (1.10.0)
78
+ globalid (0.6.0)
79
+ activesupport (>= 5.0)
80
+ i18n (1.8.11)
81
+ concurrent-ruby (~> 1.0)
82
+ loofah (2.12.0)
83
+ crass (~> 1.0.2)
84
+ nokogiri (>= 1.5.9)
85
+ mail (2.7.1)
86
+ mini_mime (>= 0.1.1)
87
+ marcel (1.0.2)
88
+ method_source (1.0.0)
89
+ mini_mime (1.1.2)
90
+ minitest (5.14.4)
91
+ mocha (1.13.0)
92
+ nio4r (2.5.8)
93
+ nokogiri (1.12.5-x86_64-darwin)
94
+ racc (~> 1.4)
95
+ racc (1.6.0)
96
+ rack (2.2.3)
97
+ rack-test (1.1.0)
98
+ rack (>= 1.0, < 3)
99
+ rails (6.1.4.1)
100
+ actioncable (= 6.1.4.1)
101
+ actionmailbox (= 6.1.4.1)
102
+ actionmailer (= 6.1.4.1)
103
+ actionpack (= 6.1.4.1)
104
+ actiontext (= 6.1.4.1)
105
+ actionview (= 6.1.4.1)
106
+ activejob (= 6.1.4.1)
107
+ activemodel (= 6.1.4.1)
108
+ activerecord (= 6.1.4.1)
109
+ activestorage (= 6.1.4.1)
110
+ activesupport (= 6.1.4.1)
111
+ bundler (>= 1.15.0)
112
+ railties (= 6.1.4.1)
113
+ sprockets-rails (>= 2.0.0)
114
+ rails-dom-testing (2.0.3)
115
+ activesupport (>= 4.2.0)
116
+ nokogiri (>= 1.6)
117
+ rails-html-sanitizer (1.4.2)
118
+ loofah (~> 2.3)
119
+ railties (6.1.4.1)
120
+ actionpack (= 6.1.4.1)
121
+ activesupport (= 6.1.4.1)
122
+ method_source
123
+ rake (>= 0.13)
124
+ thor (~> 1.0)
125
+ rake (13.0.6)
126
+ sprockets (4.0.2)
127
+ concurrent-ruby (~> 1.0)
128
+ rack (> 1, < 3)
129
+ sprockets-rails (3.4.1)
130
+ actionpack (>= 5.2)
131
+ activesupport (>= 5.2)
132
+ sprockets (>= 3.0.0)
133
+ sqlite3 (1.4.2)
134
+ thor (1.1.0)
135
+ tzinfo (2.0.4)
136
+ concurrent-ruby (~> 1.0)
137
+ websocket-driver (0.7.5)
138
+ websocket-extensions (>= 0.1.0)
139
+ websocket-extensions (0.1.5)
140
+ zeitwerk (2.5.1)
141
+
142
+ PLATFORMS
143
+ x86_64-darwin-19
144
+
145
+ DEPENDENCIES
146
+ assert_difference (~> 1.0)
147
+ bundler (>= 2.0)
148
+ log_book!
149
+ minitest (>= 5.1)
150
+ mocha (~> 1.13)
151
+ rake (>= 0.13)
152
+ sqlite3 (~> 1.0)
153
+
154
+ BUNDLED WITH
155
+ 2.2.32
data/README.md CHANGED
@@ -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,41 @@ 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 _ignore_ some fields from the changes Event:
60
+
61
+ class MyModel < ActiveRecord::Base
62
+ log_book :ignore => [:my_counter]
63
+ end
64
+
65
+ my_model.update_atttibtes!(:my_counter => 9) # No LogBook::Event will be generated
66
+
67
+ If you want _LogBook::Events_ to be destroyed on _Model_ destroy:
68
+
69
+ class MyModel < ActiveRecord::Base
70
+ log_book :dependent => :destroy
71
+ end
72
+
73
+ In other case the _LogBook::Events_ will remain after _Model_ destroyed.
74
+
75
+ ## Rails Integration
76
+
77
+ Check this example project to see how LogBook is integrated:
78
+
79
+ - [Skeleton](https://github.com/fguillen/Skeleton)
80
+
53
81
  ## TODO
54
82
 
83
+ Use block configuration instead of `model.log_book_historian` do something like:
84
+
85
+ LogBook.conf(:log_book_historian => user) do
86
+ model.save!
87
+ end
88
+
55
89
 
56
90
  ## Sate of the art
57
91
 
@@ -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 :text, :null => false
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
@@ -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
@@ -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
- LogBook.updated(self.log_book_historian, self) unless changes.empty?
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
@@ -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
- model.changes.reject { |k,v| k == "updated_at" || k =~ /password/ || k == "perishable_token" || k == "persistence_token" }.map do |k,v|
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
- "#{k}[#{old_value} -> #{new_value}]"
12
- end.join( ", " )
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
@@ -1,3 +1,3 @@
1
1
  module LogBook
2
- VERSION = "0.1.7"
2
+ VERSION = "0.6.1"
3
3
  end
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,16 +12,16 @@ module LogBook
13
12
  :destroy => "destroy"
14
13
  }
15
14
 
16
- def self.event(historian, historizable, text, tag_list)
15
+ def self.event(historian, historizable, differences, tag_list)
17
16
  tag_list_composed = []
18
17
  tag_list_composed << scope_tag(historian) if historian
19
18
  tag_list_composed << kind_tag(historizable) if historizable
20
19
  tag_list_composed += [tag_list].flatten if tag_list
21
-
20
+
22
21
  LogBook::Event.create!(
23
22
  :historian => historian,
24
23
  :historizable => historizable,
25
- :text => text,
24
+ :differences => differences,
26
25
  :tag_list => tag_list_composed
27
26
  )
28
27
  end
@@ -30,15 +29,15 @@ module LogBook
30
29
  private
31
30
 
32
31
  def self.created(historian, historizable)
33
- LogBook.event(historian, historizable, "#{historizable.class.name} created", LogBook::OPERATIONS[:create])
32
+ LogBook.event(historian, historizable, nil, LogBook::OPERATIONS[:create])
34
33
  end
35
34
 
36
35
  def self.updated(historian, historizable)
37
- LogBook.event(historian, historizable, "#{historizable.class.name} updated [#{LogBook::Utils.pretty_changes(historizable)}]", LogBook::OPERATIONS[:update])
36
+ LogBook.event(historian, historizable, LogBook::Utils.pretty_changes(historizable), LogBook::OPERATIONS[:update])
38
37
  end
39
38
 
40
39
  def self.destroyed(historian, historizable)
41
- LogBook.event(historian, historizable, "#{historizable.class.name} destroyed", LogBook::OPERATIONS[:destroy])
40
+ LogBook.event(historian, historizable, nil, LogBook::OPERATIONS[:destroy])
42
41
  end
43
42
 
44
43
  def self.scope_tag(historian)
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", "~> 4.1.4"
22
- spec.add_runtime_dependency "protected_attributes"
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", "~> 1.6.3"
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", "~> 5.4.0"
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
@@ -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, "Item wadus", LogBook::OPERATIONS[:create])
15
+ LogBook.event(@user, @item, ["DIFFERENCE"], LogBook::OPERATIONS[:create])
16
16
  end
17
17
 
18
- log_book = LogBook::Event.last
19
- assert_equal(@user, log_book.historian)
20
- assert_equal(@item, log_book.historizable)
21
- assert_equal("Item wadus", log_book.text)
22
- assert_equal(["user", "item", "create"].sort, log_book.tag_list.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, "Item wadus", nil)
27
+ LogBook.event(nil, nil, ["DIFFERENCE"], nil)
28
28
  end
29
29
 
30
- log_book = LogBook::Event.last
31
- assert_equal(nil, log_book.historian)
32
- assert_equal(nil, log_book.historizable)
33
- assert_equal("Item wadus", log_book.text)
34
- assert_equal([], log_book.tag_list)
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, "Item created", LogBook::OPERATIONS[:create])
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
- LogBook.expects(:event).with(@user, @item, "Item updated [title[Item Title -> Other Title]]", LogBook::OPERATIONS[:update])
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
48
71
 
49
- @item.update_attributes!(:title => "Other Title")
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
+ ]
84
+
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, "Item destroyed", LogBook::OPERATIONS[:destroy])
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, "Item wadus", LogBook::OPERATIONS[:create])
62
- log_book_event_2 = LogBook.event(@user, @item, "Item wadus", LogBook::OPERATIONS[:update])
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, "Item wadus", LogBook::OPERATIONS[:create])
119
+ log_book_event = LogBook.event(@user, @item, nil, LogBook::OPERATIONS[:create])
73
120
 
74
121
  @item.destroy
75
122
 
@@ -77,16 +124,15 @@ 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("Item", log_book_event.historizable_type)
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, "Item wadus", LogBook::OPERATIONS[:create])
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
138
  end
92
-
data/test/models.rb CHANGED
@@ -6,5 +6,5 @@ class Item < ActiveRecord::Base
6
6
  end
7
7
 
8
8
  class ItemWithOpts < Item
9
- log_book(:dependent => :destroy)
9
+ log_book(:dependent => :destroy, :ignore => [:my_counter])
10
10
  end
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.update_attributes(:title => "Other Title")
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/tree/master/db/migrate
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, :polymorphic => true
20
- t.references :tagger, :polymorphic => true
21
- t.string :context, :limit => 128
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
- add_column :tags, :taggings_count, :integer, default: 0
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/setup"
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.7
4
+ version: 0.6.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: 2014-07-15 00:00:00.000000000 Z
11
+ date: 2021-11-25 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: 4.1.4
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: 4.1.4
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: 3.3.0
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: 3.3.0
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: 1.6.3
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: 1.6.3
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: '0'
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: '0'
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.4.0
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.4.0
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
- - .ruby-version
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
- rubyforge_project:
186
- rubygems_version: 2.0.3
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