thoth 1.0.1 → 3.0.0

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: 36a0fea0a7c3866ead79fbc02e70ff5ae5002e3b
4
- data.tar.gz: a2f1581036daafdf21c24d981059e40be9bc2702
2
+ SHA256:
3
+ metadata.gz: bc4c495e0e43df12a9feac3c87b8dd8048b92fa85b0888fe7625dc7e2baa313a
4
+ data.tar.gz: b0e4f5196a85f87a9c4b4460cf0aa5acaf93e5d175d16551c370c57f55c6d0ca
5
5
  SHA512:
6
- metadata.gz: 3ecb32050cca7bd0cc0e57ff4fdc4367e8833424976bb0d700ae0666be860733611d2b98a7417315eabb1fb669928c158966c95b9f3b5e4e3fe3d9c9c236ff72
7
- data.tar.gz: 22bbef5466d1b538531df83eb3e0a7ea6b09e586acba72802f2fef4b5c87ba0dd2f111b04422b1ab00f58731b633583691b9c7d59e4f5ca5d3932505dc3c424e
6
+ metadata.gz: c3c8206712f6c30272a25ad2328385555bddd8fda18e9787a872add736fe1bbbc4a3a445399eb8447393fb1c6b0fc5384f28e880a2a3248b4c5f7e96f550bd12
7
+ data.tar.gz: 29ea47f712c88d147b6ed47b56ea944f49b3888cf8895815f7b13210b24c6276b396c9043e991842ed1ab01878c19c9d8db9431827f01935566354ca1654fc49
data/README.md CHANGED
@@ -68,6 +68,14 @@ file = File.open(Rails.root.join(*%w[log checkout_events.log]), 'a')
68
68
  Thoth.logger = Thoth::Logger.new(Thoth::Output::Json.new(file))
69
69
  ```
70
70
 
71
+ ## Running Specs
72
+ ```
73
+ cd spec/dummy
74
+ bundle exec rake db:setup
75
+ cd ../..
76
+ bundle exec rspec
77
+ ```
78
+
71
79
 
72
80
  ## Contributing
73
81
 
data/lib/thoth/logger.rb CHANGED
@@ -9,6 +9,11 @@ module Thoth
9
9
  @timestamp_key = options.fetch(:timestamp_key, :time)
10
10
  end
11
11
 
12
+ #lazy load this since this class is initialized before rails' filter_parameters is set
13
+ def param_filter
14
+ @param_filter ||= ::ActiveSupport::ParameterFilter.new(::Rails.application.config.filter_parameters)
15
+ end
16
+
12
17
  def log(event_name, details={}, context={})
13
18
  event_data = marshal_event(event_name, details, context)
14
19
 
@@ -21,12 +26,12 @@ module Thoth
21
26
  private
22
27
 
23
28
  def marshal_event(event_name, details, context)
24
- {
29
+ param_filter.filter({
25
30
  event: event_name,
26
31
  timestamp_key => Time.now.utc.strftime(timestamp_format),
27
32
  context: context.reverse_merge(Thoth.context),
28
33
  details: details
29
- }
34
+ })
30
35
  end
31
36
  end
32
37
  end
@@ -37,7 +37,7 @@ module Thoth
37
37
  self.class.thoth_options[:only]
38
38
  end
39
39
 
40
- if only_options.empty? || !(only_options.map(&:to_s) & changes.keys).empty?
40
+ if only_options.empty? || !(only_options.map(&:to_s) & changed_attribute_names_to_save).empty?
41
41
  thoth_log_model(:update)
42
42
  end
43
43
  end
@@ -48,7 +48,11 @@ module Thoth
48
48
  end
49
49
 
50
50
  def thoth_log_model(action)
51
- Thoth.logger.log("#{self.class.name} #{action}", changes: changes, attributes: attributes)
51
+ Thoth.logger.log("#{self.class.name} #{action}", changes: changes_to_log, attributes: attributes)
52
+ end
53
+
54
+ def changes_to_log
55
+ has_changes_to_save? ? changes_to_save : saved_changes
52
56
  end
53
57
  end
54
58
  end
@@ -5,7 +5,7 @@ module Thoth
5
5
  class Railtie < ::Rails::Railtie
6
6
  initializer "thoth.configure_rails_initialization" do
7
7
  Thoth.logger ||= (
8
- file = File.open(::Rails.root.join(*%W[log events_#{ENV['RAILS_ENV']}.log]), 'a')
8
+ file = File.open(::Rails.root.join(*%W[log events_#{::Rails.env}.log]), 'a')
9
9
  file.sync = true
10
10
  Logger.new(Output::Json.new(file))
11
11
  )
data/lib/thoth/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Thoth
2
- VERSION = "1.0.1"
2
+ VERSION = "3.0.0"
3
3
  end
data/spec/dummy/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'rails', '3.2.18'
3
+ gem 'rails', '6.0.4.6'
4
4
 
5
5
  # Bundle edge Rails instead:
6
6
  # gem 'rails', :git => 'git://github.com/rails/rails.git'
@@ -10,17 +10,17 @@ gem 'sqlite3'
10
10
 
11
11
  # Gems used only for assets and not required
12
12
  # in production environments by default.
13
- group :assets do
14
- gem 'sass-rails', '~> 3.2.3'
15
- gem 'coffee-rails', '~> 3.2.1'
13
+ # group :assets do
14
+ # gem 'sass-rails', '~> 3.2.3'
15
+ # gem 'coffee-rails', '~> 3.2.1'
16
16
 
17
- # See https://github.com/sstephenson/execjs#readme for more supported runtimes
18
- # gem 'therubyracer', :platforms => :ruby
17
+ # # See https://github.com/sstephenson/execjs#readme for more supported runtimes
18
+ # # gem 'therubyracer', :platforms => :ruby
19
19
 
20
- gem 'uglifier', '>= 1.0.3'
21
- end
20
+ # gem 'uglifier', '>= 1.0.3'
21
+ # end
22
22
 
23
- gem 'jquery-rails'
23
+ # gem 'jquery-rails'
24
24
 
25
25
  gem 'thoth', path: File.join(File.dirname(__FILE__), %w[.. ..])
26
26
 
@@ -0,0 +1,3 @@
1
+ //= link_tree ../images
2
+ //= link_directory ../javascripts .js
3
+ //= link_directory ../stylesheets .css
@@ -1,3 +1,3 @@
1
1
  class Car < ActiveRecord::Base
2
- attr_accessible :make, :model, :year
2
+ # attr_accessible :make, :model, :year
3
3
  end
@@ -1,5 +1,5 @@
1
1
  class Cat < ActiveRecord::Base
2
- attr_accessible :name, :breed
2
+ # attr_accessible :name, :breed
3
3
 
4
4
  def evil?
5
5
  true
@@ -1,3 +1,3 @@
1
1
  class Person < ActiveRecord::Base
2
- attr_accessible :name, :food, :color
2
+ # attr_accessible :name, :food, :color
3
3
  end
@@ -51,12 +51,14 @@ module Dummy
51
51
  # This will create an empty whitelist of attributes available for mass-assignment for all models
52
52
  # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
53
53
  # parameters by using an attr_accessible or attr_protected declaration.
54
- config.active_record.whitelist_attributes = true
54
+ # config.active_record.whitelist_attributes = true
55
55
 
56
56
  # Enable the asset pipeline
57
57
  config.assets.enabled = true
58
58
 
59
59
  # Version of your assets, change this if you want to expire all your assets
60
60
  config.assets.version = '1.0'
61
+
62
+ config.eager_load = false
61
63
  end
62
64
  end
@@ -23,11 +23,11 @@ Dummy::Application.configure do
23
23
  config.action_dispatch.best_standards_support = :builtin
24
24
 
25
25
  # Raise exception on mass assignment protection for Active Record models
26
- config.active_record.mass_assignment_sanitizer = :strict
26
+ # config.active_record.mass_assignment_sanitizer = :strict
27
27
 
28
28
  # Log the query plan for queries taking more than this (works
29
29
  # with SQLite, MySQL, and PostgreSQL)
30
- config.active_record.auto_explain_threshold_in_seconds = 0.5
30
+ # config.active_record.auto_explain_threshold_in_seconds = 0.5
31
31
 
32
32
  # Do not compress assets
33
33
  config.assets.compress = false
@@ -30,7 +30,7 @@ Dummy::Application.configure do
30
30
  config.action_mailer.delivery_method = :test
31
31
 
32
32
  # Raise exception on mass assignment protection for Active Record models
33
- config.active_record.mass_assignment_sanitizer = :strict
33
+ # config.active_record.mass_assignment_sanitizer = :strict
34
34
 
35
35
  # Print deprecation notices to the stderr
36
36
  config.active_support.deprecation = :stderr
@@ -0,0 +1,17 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key is used for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+
6
+ # Make sure the secret is at least 30 characters and all random,
7
+ # no regular words or you'll be exposed to dictionary attacks.
8
+ # You can use `rails secret` to generate a secure secret key.
9
+
10
+ # Make sure the secrets in this file are kept private
11
+ # if you're sharing your code publicly.
12
+
13
+ development:
14
+ secret_key_base: a9fd55a1a5f8cceaa3e268109e1eaaff039f583d1c181285972943ecc50f7db1304482f74eecf6e03cb96eac1cb785b0115935050b76474dc02d8035de68fd96
15
+
16
+ test:
17
+ secret_key_base: 420f66fbeefc13c18e9850d3a1b1e27500d0a802619a8731de312ed7faffa419f5b76fa1d2b5b81d335f787f4e100ba2cef315a02a23026e33a2c940ad7fb0a2
@@ -23,7 +23,7 @@ describe ControllerWithThothContextController, type: :controller do
23
23
  context "on any action" do
24
24
  it "stores params in the Thoth.context" do
25
25
  get :show
26
- expect(assigns(:context)).to eq({"controller"=>"controller_with_thoth_context", "action"=>"show", "current_user"=>1})
26
+ expect(controller.view_context.assigns['context']).to eq({"controller"=>"controller_with_thoth_context", "action"=>"show", "current_user"=>1})
27
27
  end
28
28
  end
29
- end
29
+ end
@@ -32,7 +32,7 @@ describe Thoth::Rails::Model do
32
32
  end
33
33
 
34
34
  context "on destroy" do
35
- let!(:person) { Person.create(name: 'Lee') }
35
+ let!(:person) { Person.create(name: 'Lee').reload }
36
36
 
37
37
  it "records the destroy event" do
38
38
  expect(Thoth).to receive(:logger).and_return(double(log: true))
@@ -45,7 +45,7 @@ describe Thoth::Rails::Model do
45
45
  log_events on: :update
46
46
  end
47
47
 
48
- let!(:cat) { Cat.create }
48
+ let!(:cat) { Cat.create.reload }
49
49
 
50
50
  it "does not record anything" do
51
51
  expect(Thoth).not_to receive(:logger)
@@ -55,11 +55,11 @@ describe Thoth::Rails::Model do
55
55
  end
56
56
 
57
57
  context "on update" do
58
- let!(:person) { Person.create(name: 'Lee') }
58
+ let!(:person) { Person.create(name: 'Lee').reload }
59
59
 
60
60
  it "records the update event" do
61
61
  expect(Thoth).to receive(:logger).and_return(double(log: true))
62
- person.update_attributes!(name: 'Smith')
62
+ person.update!(name: 'Smith')
63
63
  end
64
64
 
65
65
  context "when logging only changes to certain attribute" do
@@ -68,20 +68,20 @@ describe Thoth::Rails::Model do
68
68
  log_events only: :name
69
69
  end
70
70
 
71
- let!(:person) { PersonWithOnly.create(name: 'Lee') }
71
+ let!(:person) { PersonWithOnly.create(name: 'Lee').reload }
72
72
 
73
73
 
74
74
  context "and a watched attribute changes" do
75
75
  it "records the update event" do
76
76
  expect(Thoth).to receive(:logger).and_return(double(log: true))
77
- person.update_attributes!(name: 'Smith', color: :blue)
77
+ person.update!(name: 'Smith', color: :blue)
78
78
  end
79
79
  end
80
80
 
81
81
  context "and a watched attribute does not change" do
82
82
  it "does not record anything" do
83
83
  expect(Thoth).not_to receive(:logger)
84
- person.update_attributes!(color: :blue)
84
+ person.update!(color: :blue)
85
85
  end
86
86
  end
87
87
  end
@@ -92,11 +92,11 @@ describe Thoth::Rails::Model do
92
92
  log_events on: :destroy
93
93
  end
94
94
 
95
- let!(:car) { Car.create(make: 'Tesla', model: 'S') }
95
+ let!(:car) { Car.create(make: 'Tesla', model: 'S').reload }
96
96
 
97
97
  it "does not record anything" do
98
98
  expect(Thoth).not_to receive(:logger)
99
- car.update_attributes!(model: 'X')
99
+ car.update!(model: 'X')
100
100
  end
101
101
  end
102
102
  end
data/thoth.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Philippe Huibonhoa"]
10
10
  spec.email = ["phuibonhoa@gmail.com"]
11
11
  spec.summary = %q{Easy event logging for rails.}
12
- spec.homepage = "https://github.com/bkr/thoth"
12
+ spec.homepage = "https://github.com/phuibonhoa/thoth"
13
13
  spec.license = "MIT"
14
14
 
15
15
  spec.files = `git ls-files -z`.split("\x0")
@@ -17,13 +17,13 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_dependency 'activesupport', ['>= 3.0']
20
+ spec.add_dependency 'activesupport', ['>= 6.0']
21
21
  spec.add_dependency 'request_store'
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "bundler"
24
24
  spec.add_development_dependency "rake"
25
- spec.add_development_dependency 'rails', '~> 3.2.18'
26
- spec.add_development_dependency 'rspec-rails', '~> 2.14'
25
+ spec.add_development_dependency 'rails', '>= 6.0'
26
+ spec.add_development_dependency 'rspec-rails', '>= 4.1.2'
27
27
  spec.add_development_dependency 'sqlite3'
28
28
  spec.add_development_dependency 'pry-remote'
29
29
  spec.add_development_dependency 'timecop'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thoth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philippe Huibonhoa
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-10 00:00:00.000000000 Z
11
+ date: 2022-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
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: '3.0'
26
+ version: '6.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: request_store
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.6'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '1.6'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -70,30 +70,30 @@ dependencies:
70
70
  name: rails
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 3.2.18
75
+ version: '6.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 3.2.18
82
+ version: '6.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec-rails
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '2.14'
89
+ version: 4.1.2
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '2.14'
96
+ version: 4.1.2
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: sqlite3
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -136,7 +136,7 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
- description:
139
+ description:
140
140
  email:
141
141
  - phuibonhoa@gmail.com
142
142
  executables: []
@@ -161,6 +161,7 @@ files:
161
161
  - spec/dummy/Gemfile
162
162
  - spec/dummy/README.rdoc
163
163
  - spec/dummy/Rakefile
164
+ - spec/dummy/app/assets/config/manifest.js
164
165
  - spec/dummy/app/assets/images/rails.png
165
166
  - spec/dummy/app/assets/javascripts/application.js
166
167
  - spec/dummy/app/assets/stylesheets/application.css
@@ -188,6 +189,7 @@ files:
188
189
  - spec/dummy/config/initializers/wrap_parameters.rb
189
190
  - spec/dummy/config/locales/en.yml
190
191
  - spec/dummy/config/routes.rb
192
+ - spec/dummy/config/secrets.yml
191
193
  - spec/dummy/db/migrate/20140926015139_create_people.rb
192
194
  - spec/dummy/db/migrate/20140926022006_create_cars.rb
193
195
  - spec/dummy/db/migrate/20140926022112_create_cats.rb
@@ -223,11 +225,11 @@ files:
223
225
  - spec/thoth/rails/controller_context_spec.rb
224
226
  - spec/thoth/rails/model_spec.rb
225
227
  - thoth.gemspec
226
- homepage: https://github.com/bkr/thoth
228
+ homepage: https://github.com/phuibonhoa/thoth
227
229
  licenses:
228
230
  - MIT
229
231
  metadata: {}
230
- post_install_message:
232
+ post_install_message:
231
233
  rdoc_options: []
232
234
  require_paths:
233
235
  - lib
@@ -242,9 +244,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
242
244
  - !ruby/object:Gem::Version
243
245
  version: '0'
244
246
  requirements: []
245
- rubyforge_project:
246
- rubygems_version: 2.2.2
247
- signing_key:
247
+ rubygems_version: 3.0.3
248
+ signing_key:
248
249
  specification_version: 4
249
250
  summary: Easy event logging for rails.
250
251
  test_files:
@@ -252,6 +253,7 @@ test_files:
252
253
  - spec/dummy/Gemfile
253
254
  - spec/dummy/README.rdoc
254
255
  - spec/dummy/Rakefile
256
+ - spec/dummy/app/assets/config/manifest.js
255
257
  - spec/dummy/app/assets/images/rails.png
256
258
  - spec/dummy/app/assets/javascripts/application.js
257
259
  - spec/dummy/app/assets/stylesheets/application.css
@@ -279,6 +281,7 @@ test_files:
279
281
  - spec/dummy/config/initializers/wrap_parameters.rb
280
282
  - spec/dummy/config/locales/en.yml
281
283
  - spec/dummy/config/routes.rb
284
+ - spec/dummy/config/secrets.yml
282
285
  - spec/dummy/db/migrate/20140926015139_create_people.rb
283
286
  - spec/dummy/db/migrate/20140926022006_create_cars.rb
284
287
  - spec/dummy/db/migrate/20140926022112_create_cats.rb