context_logger 0.0.40 → 0.0.41

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
  SHA1:
3
- metadata.gz: f6c022444accec283a9f4dced8de9ba46f36cfaf
4
- data.tar.gz: 801e99264ddba77fd3f3072cefb76a74dc147cbf
3
+ metadata.gz: 9e008c70f4b8407833f42781545288f463f8548c
4
+ data.tar.gz: 5000f4aa5737e905897335d477c5be28c26a581b
5
5
  SHA512:
6
- metadata.gz: 83a7532b211cf9176ba8414b1a24440cf05bc8ac7e34382327081df3d45ee2a35749966c4920593a67bb430d182e69a15efbd34055d97b2b786fdcea15dd3d33
7
- data.tar.gz: f1d529126101a863e929902088d99c0c5dde185fb72c5ad6368ecac4069b3909f2a955207af533f42bfc11294db54e6caba098843206a732dc13afa55c1fbc29
6
+ metadata.gz: 154b8a1a7f637ab0de78dddf8849d5f486693c53fa28acc5bf0f28b9caf8bfeeffed8c3e2bc42a5a6fe411a02590021bdec43889d96f7786280b25df9a1f3b97
7
+ data.tar.gz: 9ea923cca2ed01ed09df2bf33655f23b35225f3967408cd738bd5cf39e62e04c8759c45f66fe90b5d6d9f8efdc8c8f94821f007dc4a4c2a864aac9f3ec1f31cb
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,14 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ context_logger (0.0.37)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ context_logger!
@@ -13,4 +13,4 @@ module Api
13
13
  end
14
14
  end
15
15
  end
16
- end
16
+ end
@@ -0,0 +1,21 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'context_logger'
3
+ s.version = '0.0.41'
4
+ s.date = '2015-11-11'
5
+ s.summary = 'writes log to db and log file and exposes it via http'
6
+ s.description = 'writes log to db and log file and exposes it via http'
7
+ s.authors = ['Alexander Libster']
8
+ s.email = '012alex012@gmail.com'
9
+ s.files = `git ls-files`.split($/)
10
+ # s.files = %w(lib/context_logger.rb lib/context_logger/engine.rb db/migrate/20151112164817_create_context_logs.rb
11
+ # app/models/context_log.rb app/controllers/api/v1/resources/context_logger_controller.rb config/routes.rb)
12
+ s.homepage = ''
13
+ s.license = 'MIT'
14
+
15
+
16
+ # s.add_development_dependency 'bundler'
17
+ # s.add_development_dependency 'rails'
18
+ # s.add_development_dependency 'rspec', '~> 3.0'
19
+ # s.add_development_dependency 'rspec-rails'
20
+ # s.add_development_dependency 'faker'
21
+ end
@@ -0,0 +1,10 @@
1
+ class ContextLog
2
+ def self.columns
3
+ [
4
+ OpenStruct.new(name: :context),
5
+ OpenStruct.new(name: :severity),
6
+ OpenStruct.new(name: :action_id),
7
+ OpenStruct.new(name: :message)
8
+ ]
9
+ end
10
+ end
@@ -0,0 +1,23 @@
1
+ # require 'spec_helper'
2
+ # require 'rails/all'
3
+ #
4
+ # require 'rspec/rails'
5
+ #
6
+ # require './app/controllers/api/v1/resources/context_logger_controller.rb'
7
+ #
8
+ # describe Api::V1::Resources::ContextLoggerController do
9
+ # let (:connection) { mock("connection") }
10
+ # before(:each) do
11
+ # ::ActiveRecord::Base.stub!(:connection).and_return(connection)
12
+ # ConnectionPool.any_instance.stub(:retrieve_connection).and_return({lala: 1})
13
+ # end
14
+ #
15
+ # context 'index' do
16
+ # it 'ContextLoggerController' do
17
+ # response_body = 'response_body'
18
+ #
19
+ # get :index
20
+ # expect(response.body).to eq(response_body)
21
+ # end
22
+ # end
23
+ # end
@@ -0,0 +1,137 @@
1
+ require 'spec_helper'
2
+ # require 'rails/all'
3
+ # require 'rspec/rails'
4
+
5
+ require './spec/rails_stub.rb'
6
+ require './spec/logger_stub.rb'
7
+ require './spec/context_log_stub.rb'
8
+
9
+
10
+ require './lib/context_logger.rb'
11
+
12
+ require 'active_support/core_ext/hash'
13
+ require 'ostruct'
14
+
15
+ describe ContextLogger do
16
+ context 'self.options' do
17
+ it 'expect options to be equal described_class::DEFAULTS' do
18
+ expect(described_class.options).to eq(described_class::DEFAULTS)
19
+ end
20
+ end
21
+
22
+ context 'self.setup' do
23
+ it 'expect modify options' do
24
+ described_class.setup(context: :publish)
25
+ expect(described_class.options).to eq(described_class::DEFAULTS.merge(context: :publish))
26
+
27
+ described_class.setup(context: :not_publish, another_key: :another_value)
28
+ expect(described_class.options).to eq(described_class::DEFAULTS.merge(context: :not_publish, another_key: :another_value))
29
+ end
30
+ end
31
+
32
+
33
+ context 'self.set_destinations' do
34
+ it 'ALL_DESTINATIONS' do
35
+ described_class.set_destinations(:all)
36
+ expect(described_class.destinations).to eq(described_class::ALL_DESTINATIONS)
37
+ end
38
+
39
+ it 'write_rails_log and write_context_log' do
40
+ described_class.set_destinations(write_rails_log: true, write_context_log: true)
41
+ expect(described_class.destinations).to eq(write_rails_log: true, write_context_log: true)
42
+ end
43
+
44
+ it 'write_db_log' do
45
+ described_class.set_destinations(write_db_log: true, write_context_log: false)
46
+ expect(described_class.destinations).to eq(write_db_log: true)
47
+ end
48
+
49
+ it 'with illegal destination - should be ignored' do
50
+ described_class.set_destinations(write_db_log: true, illegal_destination_should_be_ignored: true)
51
+ expect(described_class.destinations).to eq(write_db_log: true)
52
+ end
53
+ end
54
+
55
+ context 'self.logs_folder' do
56
+ it 'should build logs\' folder properly' do
57
+ expect(described_class.logs_folder).to eq('root_directory/log')
58
+ end
59
+ end
60
+
61
+ context 'self.log_file_path' do
62
+ it 'should build log_file_path properly with legal filename based on context' do
63
+ expect(described_class.log_file_path(:publish)).to eq('root_directory/log/publish.log')
64
+ expect(described_class.log_file_path('publish context')).to eq('root_directory/log/publish_context.log')
65
+ expect(described_class.log_file_path('@publish $context')).to eq('root_directory/log/publish_context.log')
66
+ expect(described_class.log_file_path('@publish $context123')).to eq('root_directory/log/publish_context123.log')
67
+ end
68
+ end
69
+
70
+ context 'self.log' do
71
+ it 'all destinations - should call methods to write to all destinations' do
72
+ params = {context: :publish, severity: :info}
73
+ params_with_defaults = described_class.options.merge(params.reject{|_, v| v.nil?})
74
+ described_class.set_destinations({
75
+ write_rails_log: true,
76
+ write_context_log: true,
77
+ write_db_log: true
78
+ })
79
+
80
+ expect(described_class).to receive(:write_rails_log).with(params_with_defaults)
81
+ expect(described_class).to receive(:write_context_log).with(params_with_defaults)
82
+ expect(described_class).to receive(:write_db_log).with(params_with_defaults)
83
+
84
+ described_class.log(params_with_defaults)
85
+ end
86
+
87
+ it 'partial destinations - should call methods to write to part of destinations' do
88
+ params = {context: :publish, severity: :info}
89
+ params_with_defaults = described_class.options.merge(params.reject{|_, v| v.nil?})
90
+ described_class.set_destinations({
91
+ write_context_log: true,
92
+ write_db_log: true
93
+ })
94
+
95
+ expect(described_class).to_not receive(:write_rails_log).with(params_with_defaults)
96
+ expect(described_class).to receive(:write_context_log).with(params_with_defaults)
97
+ expect(described_class).to receive(:write_db_log).with(params_with_defaults)
98
+
99
+ described_class.log(params_with_defaults)
100
+ end
101
+ end
102
+
103
+ context 'self.write_rails_log' do
104
+ it 'expects call the proper Rails.logger method with the proper params' do
105
+ params = {context: :publish, severity: :info}
106
+ params_with_defaults = described_class.options.merge(params.reject{|_, v| v.nil?})
107
+
108
+
109
+ expect(Rails.logger). to receive(:info).with(params_with_defaults.except(:severity))
110
+ described_class.write_rails_log(params_with_defaults)
111
+ end
112
+ end
113
+
114
+ context 'self.write_context_log' do
115
+ it 'expects call the proper Logger method with the proper params' do
116
+ params = {context: :publish, severity: :info, action_id: 123}
117
+ params_with_defaults = described_class.options.merge(params.reject{|_, v| v.nil?})
118
+
119
+ expect_any_instance_of(Logger).to receive(:info).with(params_with_defaults.except(:severity, :context))
120
+ described_class.write_context_log(params_with_defaults)
121
+ end
122
+ end
123
+
124
+ context 'self.write_db_log' do
125
+ it 'expects call the create method of ::ContextLog with the proper params' do
126
+
127
+ params = {context: :publish, severity: :info, action_id: 123}
128
+ params_with_defaults = described_class.options.merge(params.reject{|_, v| v.nil?})
129
+
130
+ column_names = ContextLog.columns.map(&:name)
131
+ expected_params = described_class.options.merge(params_with_defaults).select{|k, _| column_names.include?(k)}
132
+ expect(::ContextLog).to receive(:create).with(expected_params)
133
+ described_class.write_db_log(params_with_defaults)
134
+ end
135
+ end
136
+
137
+ end
@@ -0,0 +1,4 @@
1
+ class Logger
2
+ def initialize(file_name)
3
+ end
4
+ end
@@ -0,0 +1,15 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require 'rails/all'
4
+
5
+ require 'rspec/rails'
6
+ #require "/Users/elia.gilad/work/boost_rules/spec/../lib/boost_rules/assets_provider.rb"
7
+
8
+ require './app/controllers/api/v1/resources/context_logger_controller.rb'
9
+ #Dir[File.dirname(__FILE__) + "/../**/*.rb"].each {|file| require file }
10
+
11
+ require 'spec_helper'
12
+
13
+ RSpec.configure do |config|
14
+
15
+ end
@@ -0,0 +1,16 @@
1
+ class Rails
2
+ class Engine
3
+ def self.isolate_namespace(arg)
4
+ end
5
+
6
+ def self.initializer(arg)
7
+ end
8
+ end
9
+
10
+ def self.root
11
+ 'root_directory'
12
+ end
13
+
14
+ def self.logger
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ # require 'rubygems'
2
+ # require 'bundler'
3
+ # Bundler.setup
4
+
5
+ RSpec.configure do |config|
6
+ # some (optional) config here
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: context_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.40
4
+ version: 0.0.41
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Libster
@@ -16,12 +16,22 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
+ - Gemfile
20
+ - Gemfile.lock
19
21
  - app/controllers/api/v1/resources/context_logger_controller.rb
20
22
  - app/models/context_log.rb
21
23
  - config/routes.rb
24
+ - context_logger.gemspec
22
25
  - db/migrate/20151112164817_create_context_logs.rb
23
26
  - lib/context_logger.rb
24
27
  - lib/context_logger/engine.rb
28
+ - spec/context_log_stub.rb
29
+ - spec/controllers/context_logger_spec.rb
30
+ - spec/lib/context_logger_spec.rb
31
+ - spec/logger_stub.rb
32
+ - spec/rails_helper.rb
33
+ - spec/rails_stub.rb
34
+ - spec/spec_helper.rb
25
35
  homepage: ''
26
36
  licenses:
27
37
  - MIT