mongodb_logger 0.4.2 → 0.5.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.
Files changed (94) hide show
  1. data/.gitignore +2 -1
  2. data/.rvmrc +1 -1
  3. data/.travis.yml +5 -4
  4. data/Appraisals +9 -0
  5. data/CHANGELOG.md +20 -3
  6. data/README.md +58 -35
  7. data/Rakefile +33 -96
  8. data/app/assets/javascripts/analytics.js.coffee +5 -4
  9. data/app/assets/javascripts/logs.js.coffee +11 -11
  10. data/app/assets/javascripts/mongodb_logger.js +2 -1
  11. data/app/assets/javascripts/vendors/jquery-1.9.1.min.js +5 -0
  12. data/app/assets/javascripts/vendors/jquery.pjax.min.js +15 -13
  13. data/app/assets/javascripts/vendors/mustache.min.js +10 -0
  14. data/app/assets/stylesheets/layout.css +20 -15
  15. data/app/assets/stylesheets/mongodb_logger.css +0 -3
  16. data/bin/mongodb_logger_web +1 -2
  17. data/features/rails.feature +20 -8
  18. data/features/step_definitions/mongodb_logger_web_steps.rb +2 -3
  19. data/features/step_definitions/rails_application_steps.rb +84 -58
  20. data/features/step_definitions/rake_steps.rb +10 -0
  21. data/features/support/aruba.rb +5 -0
  22. data/features/support/env.rb +11 -5
  23. data/features/support/rails.rb +55 -67
  24. data/gemfiles/rails31.gemfile +8 -0
  25. data/gemfiles/rails32.gemfile +8 -0
  26. data/lib/mongodb_logger.rb +10 -3
  27. data/lib/mongodb_logger/adapters/base.rb +5 -1
  28. data/lib/mongodb_logger/adapters/mongo.rb +17 -13
  29. data/lib/mongodb_logger/adapters/moped.rb +17 -11
  30. data/lib/mongodb_logger/capistrano.rb +8 -0
  31. data/lib/mongodb_logger/logger.rb +13 -26
  32. data/lib/mongodb_logger/rack_middleware.rb +24 -0
  33. data/lib/mongodb_logger/railtie.rb +4 -4
  34. data/lib/mongodb_logger/server.rb +43 -68
  35. data/lib/mongodb_logger/server/helpers.rb +5 -0
  36. data/lib/mongodb_logger/server/{content_for.rb → helpers/content_for.rb} +0 -0
  37. data/lib/mongodb_logger/server/helpers/mustache_helpers.rb +66 -0
  38. data/lib/mongodb_logger/server/{partials.rb → helpers/partials.rb} +0 -0
  39. data/lib/mongodb_logger/server/{sprokets.rb → helpers/sprokets.rb} +4 -4
  40. data/lib/mongodb_logger/server/{view_helpers.rb → helpers/view_helpers.rb} +22 -38
  41. data/lib/mongodb_logger/server/model.rb +4 -0
  42. data/lib/mongodb_logger/server/model/additional_filter.rb +15 -23
  43. data/lib/mongodb_logger/server/model/analytic.rb +24 -32
  44. data/lib/mongodb_logger/server/model/base.rb +21 -0
  45. data/lib/mongodb_logger/server/model/filter.rb +12 -20
  46. data/lib/mongodb_logger/server/mustache/logs/info.rb +15 -0
  47. data/lib/mongodb_logger/server/templates/logs/info.mustache +25 -0
  48. data/lib/mongodb_logger/server/views/layout.erb +28 -26
  49. data/lib/mongodb_logger/server/views/shared/_log.erb +1 -1
  50. data/lib/mongodb_logger/server/views/shared/_tabs.erb +2 -2
  51. data/lib/mongodb_logger/server/views/shared/layout/_mustache.erb +6 -0
  52. data/lib/mongodb_logger/server/views/show_log.erb +2 -2
  53. data/lib/mongodb_logger/server_config.rb +4 -4
  54. data/lib/mongodb_logger/utils/migrate.rb +50 -0
  55. data/lib/mongodb_logger/utils/progressbar.rb +79 -0
  56. data/lib/mongodb_logger/version.rb +1 -1
  57. data/mongodb_logger.gemspec +15 -8
  58. data/{test/config/samples → spec/factories/config}/database.yml +0 -0
  59. data/{test/config/samples → spec/factories/config}/database_no_file_logging.yml +0 -0
  60. data/{test/config/samples → spec/factories/config}/database_replica_set.yml +0 -0
  61. data/{test/config/samples → spec/factories/config}/database_with_auth.yml +0 -0
  62. data/spec/factories/config/database_with_capsize.yml +9 -0
  63. data/{test/config/samples → spec/factories/config}/database_with_collection.yml +0 -0
  64. data/{test/config/samples → spec/factories/config}/database_with_url.yml +0 -0
  65. data/{test/config/samples → spec/factories/config}/mongodb_logger.yml +0 -0
  66. data/{test/config/samples → spec/factories/config}/mongoid.yml +0 -0
  67. data/{test/config/samples → spec/factories/config}/server_config.yml +0 -0
  68. data/spec/javascripts/support/jasmine.yml +1 -5
  69. data/spec/mongodb_logger_spec.rb +257 -0
  70. data/spec/rails_spec/controllers/tests_controller_spec_rails.rb +128 -0
  71. data/spec/rails_spec/spec_helper_rails.rb +13 -0
  72. data/spec/spec_helper.rb +17 -0
  73. data/{test/test_helper.rb → spec/support/mongodb_logger_helper.rb} +44 -63
  74. data/spec/support/mongodb_logger_macros.rb +22 -0
  75. data/spec/support/rails.rb +40 -0
  76. data/spec/utils/migrate_spec.rb +32 -0
  77. data/{lib/tasks → tasks}/mongodb_logger.rake +14 -6
  78. metadata +198 -78
  79. data/SUPPORTED_RAILS_VERSIONS +0 -16
  80. data/TESTING.md +0 -24
  81. data/app/assets/javascripts/vendors/jquery-1.8.3.min.js +0 -2
  82. data/features/support/terminal.rb +0 -95
  83. data/lib/mongodb_logger/server/views/shared/_log_info.erb +0 -27
  84. data/test/Gemfile_tests +0 -9
  85. data/test/active_record.rb +0 -13
  86. data/test/log/.gitkeep +0 -0
  87. data/test/rails.rb +0 -22
  88. data/test/rails/app/controllers/order_controller.rb +0 -23
  89. data/test/rails/test/functional/order_controller_test.rb +0 -116
  90. data/test/rails/test/test_helper.rb +0 -10
  91. data/test/shoulda_macros/log_macros.rb +0 -13
  92. data/test/test.sh +0 -7
  93. data/test/unit/mongodb_logger_replica_test.rb +0 -56
  94. data/test/unit/mongodb_logger_test.rb +0 -307
@@ -0,0 +1,6 @@
1
+ <script type="text/javascript">
2
+ window.MustacheTemplates = {};
3
+ <% Dir["#{File.expand_path(File.join(@main_dir, "server", "templates"))}/**/*.mustache"].each do |template| %>
4
+ window.MustacheTemplates[<%= template.split(File::SEPARATOR).last(2).join("/").gsub(".mustache", "").inspect %>] = Mustache.compile(<%= File.open(template, 'rb').read.inspect %>)
5
+ <% end %>
6
+ </script>
@@ -2,8 +2,8 @@
2
2
 
3
3
  <div class="unit-right">
4
4
  <div class="pam">
5
- <a href="<%=h url_path("overview") %>" data-pjax='#mainPjax' class="button small grey">Back</a>
6
- </div> <!-- pam -->
5
+ <a href="<%=h url_path("overview") %>" data-pjax='true' class="button small grey">Back</a>
6
+ </div> <!-- pam -->
7
7
  </div> <!-- unit-right -->
8
8
  <h1 class="pam">Log #<%=h @log['_id'] %></h1>
9
9
  <ul class="list">
@@ -2,7 +2,7 @@ require 'mongodb_logger/logger'
2
2
 
3
3
  module MongodbLogger
4
4
  class ServerConfig
5
-
5
+
6
6
  class ServerLogger < MongodbLogger::Logger
7
7
  private
8
8
  def resolve_config
@@ -12,14 +12,14 @@ module MongodbLogger
12
12
  config
13
13
  end
14
14
  end
15
-
15
+
16
16
  class << self
17
17
  def set_config(config_path)
18
18
  ENV['MONGODBLOGGERCONFIG'] = config_path
19
- @logger = ServerLogger.new(:path => "server.log")
19
+ @logger = ServerLogger.new(path: "server.log")
20
20
  @logger.mongo_adapter
21
21
  end
22
-
22
+
23
23
  def mongo_adapter
24
24
  @logger.mongo_adapter if @logger
25
25
  end
@@ -0,0 +1,50 @@
1
+ require 'mongodb_logger/logger'
2
+ require 'mongodb_logger/utils/progressbar'
3
+
4
+ module MongodbLogger
5
+ module Utils
6
+ class Migrate
7
+
8
+ def initialize
9
+ raise "this task work only in Rails app" unless defined?(Rails)
10
+ Progressbar.new.show("Importing data to new capped collection") do
11
+ mongodb_logger = Rails.logger
12
+ collection_name = mongodb_logger.db_configuration['collection'].dup
13
+ @mongo_adapter = mongodb_logger.mongo_adapter
14
+ @migrate_logger = create_migration_collection(mongodb_logger.db_configuration)
15
+
16
+ iterator = 0
17
+ all_count = @mongo_adapter.collection.find.count
18
+ @mongo_adapter.collection.find.each do |row|
19
+ @migrate_logger.mongo_adapter.collection.insert(row)
20
+ iterator += 1
21
+ progress ((iterator.to_f / all_count.to_f) * 100).round
22
+ end if all_count > 0
23
+ progress 100
24
+ @migrate_logger.mongo_adapter.rename_collection(collection_name, true)
25
+ end
26
+ end
27
+
28
+ def create_migration_collection(configuration)
29
+ configuration.merge!({ 'collection' => "#{configuration['collection']}_copy_#{rand(100)}" })
30
+ migrate_logger = MongoMigrateLogger.new(configuration)
31
+ migrate_logger.mongo_adapter.reset_collection
32
+ migrate_logger
33
+ end
34
+
35
+ class MongoMigrateLogger < MongodbLogger::Logger
36
+ def initialize(config = {})
37
+ @static_config = config
38
+ super(path: "/dev/null")
39
+ end
40
+
41
+ private
42
+ def resolve_config
43
+ @static_config
44
+ end
45
+ end
46
+
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,79 @@
1
+ # https://github.com/bitboxer/simple_progressbar
2
+ module MongodbLogger
3
+ module Utils
4
+ class Progressbar
5
+ def initialize
6
+ @last_length = 0
7
+ @title = ""
8
+ @progress = 0
9
+ end
10
+
11
+ def show(title, &block)
12
+ @title = title
13
+ print @title + " "
14
+ start_progress
15
+ # thanks to http://www.dcmanges.com/blog/ruby-dsls-instance-eval-with-delegation
16
+ @self_before_instance_eval = eval "self", block.binding
17
+ instance_eval(&block)
18
+ finish_progress
19
+ end
20
+
21
+ def interrupt
22
+ # TODO: Make some of the strings constants so we don't have to use a magic number here.
23
+ progressbar_length = 16 + @last_length + @title.length
24
+ move_cursor = "\e[#{progressbar_length}D"
25
+ print move_cursor + (" " * progressbar_length) + move_cursor
26
+ STDOUT.flush
27
+ yield
28
+ puts
29
+ print @title + " "
30
+ render_progress(@progress)
31
+ end
32
+
33
+ def progress(percent)
34
+ print "\e[#{15 + @last_length}D"
35
+ render_progress(percent)
36
+ end
37
+
38
+ def method_missing(method, *args, &block)
39
+ @self_before_instance_eval.send method, *args, &block
40
+ end
41
+
42
+ private
43
+
44
+ def render_progress(percent)
45
+ @progress = percent
46
+ print "["
47
+
48
+ print "*" * [(percent/10).to_i, 10].min
49
+ print " " * [10 - (percent/10).to_i, 0].max
50
+
51
+ if percent.class != Float
52
+ printable_percent = "%3s" % percent
53
+ else
54
+ non_decimal_digits = (Math.log(percent) / Math.log(10)).truncate + 1
55
+ printable_percent = (non_decimal_digits < 3 ? " " * (3 - non_decimal_digits) : "") + percent.to_s
56
+ end
57
+
58
+ print "]\e[32m #{printable_percent}\e[0m %"
59
+
60
+ new_length = printable_percent.length
61
+ if @last_length > new_length
62
+ print " " * (@last_length - new_length)
63
+ print "\e[#{@last_length - new_length}D"
64
+ end
65
+ @last_length = new_length
66
+
67
+ STDOUT.flush
68
+ end
69
+
70
+ def start_progress
71
+ render_progress(0)
72
+ end
73
+
74
+ def finish_progress
75
+ puts
76
+ end
77
+ end
78
+ end
79
+ end
@@ -1,3 +1,3 @@
1
1
  module MongodbLogger
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -1,35 +1,42 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/mongodb_logger/version', __FILE__)
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mongodb_logger/version'
3
5
 
4
6
  Gem::Specification.new do |gem|
5
7
  gem.authors = ["Alexey Vasiliev"]
6
8
  gem.email = ["leopard.not.a@gmail.com"]
7
- gem.description = %q{MongoDB logger for Rails 3}
8
- gem.summary = %q{MongoDB logger for Rails 3}
9
+ gem.description = %q{MongoDB logger for Rails}
10
+ gem.summary = %q{MongoDB logger for Rails}
9
11
  gem.homepage = "http://mongodb-logger.catware.org"
10
12
 
11
13
  gem.extra_rdoc_files = [ "LICENSE", "README.md" ]
12
14
  gem.rdoc_options = ["--charset=UTF-8"]
13
15
 
14
16
  gem.add_development_dependency "rspec"
17
+ gem.add_development_dependency "rspec-rails"
15
18
  gem.add_development_dependency "shoulda"
16
19
  gem.add_development_dependency "mocha"
17
20
  gem.add_development_dependency "cucumber"
21
+ gem.add_development_dependency "cucumber-rails"
18
22
  gem.add_development_dependency "capybara"
19
23
  gem.add_development_dependency "coffee-script"
20
24
  gem.add_development_dependency "uglifier"
21
25
  gem.add_development_dependency "jasmine"
26
+ gem.add_development_dependency "appraisal"
27
+ gem.add_development_dependency "aruba"
22
28
  # adapters
23
29
  gem.add_development_dependency "mongo"
24
30
  gem.add_development_dependency "moped"
25
-
31
+
26
32
  gem.add_dependency "rake", ">= 0.9.0"
27
- gem.add_dependency "json", "~> 1.7.0"
33
+ gem.add_dependency "multi_json", ">= 1.6.0"
28
34
  gem.add_dependency "activesupport", ">= 3.1.0"
29
35
  gem.add_dependency "actionpack", ">= 3.1.0"
30
36
  gem.add_dependency "sprockets", ">= 2.0.0"
31
- gem.add_dependency "sinatra", "~> 1.3.0"
32
- gem.add_dependency "erubis", "~> 2.7.0"
37
+ gem.add_dependency "sinatra", ">= 1.3.0"
38
+ gem.add_dependency "erubis", ">= 2.7.0"
39
+ gem.add_dependency "mustache", ">= 0.99.0"
33
40
  gem.add_dependency "vegas", "~> 0.1.0"
34
41
 
35
42
  gem.rubyforge_project = "mongodb_logger"
@@ -0,0 +1,9 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: db/test.sqlite3
4
+ pool: 5
5
+ timeout: 5000
6
+ mongodb_logger:
7
+ database: system_log
8
+ application_name: mongo_foo
9
+ capsize: <%= 50.megabytes %>
@@ -11,11 +11,7 @@
11
11
  # - dist/**/*.js
12
12
  #
13
13
  src_files:
14
- - app/assets/javascripts/vendors/jquery-1.8.3.min.js
15
- - app/assets/javascripts/vendors/jquery-ui-1.9.2.min.js
16
- - app/assets/javascripts/vendors/jquery.pjax.min.js
17
- - app/assets/javascripts/vendors/highlight.pack.js
18
- - app/assets/javascripts/logs.js
14
+ - app/assets/javascripts/mongodb_logger.js
19
15
 
20
16
  # stylesheets
21
17
  #
@@ -0,0 +1,257 @@
1
+ require 'spec_helper'
2
+
3
+ describe MongodbLogger::Logger do
4
+ extend MongodbLogger::SpecMacros
5
+
6
+ EXCEPTION_MSG = "Foo"
7
+
8
+ before :all do
9
+ create_logs_dir
10
+ end
11
+
12
+ context "in instantiation" do
13
+ before do
14
+ described_class.any_instance.stub(:internal_initialize).and_return(nil)
15
+ described_class.any_instance.stub(:disable_file_logging?).and_return(false)
16
+ @mongodb_logger = described_class.new
17
+ end
18
+
19
+ [MongodbLogger::SpecHelper::LOGGER_CONFIG,
20
+ MongodbLogger::SpecHelper::DEFAULT_CONFIG,
21
+ MongodbLogger::SpecHelper::MONGOID_CONFIG].each do |config|
22
+ context "during configuration when using #{config}" do
23
+ before do
24
+ setup_for_config(config)
25
+ end
26
+ after do
27
+ cleanup_for_config(config)
28
+ end
29
+
30
+ should_use_database_name_in_config
31
+ end
32
+ end
33
+
34
+ context "during configuration when using #{MongodbLogger::SpecHelper::DEFAULT_CONFIG_WITH_URL}" do
35
+ before do
36
+ setup_for_config(MongodbLogger::SpecHelper::DEFAULT_CONFIG_WITH_URL, MongodbLogger::SpecHelper::DEFAULT_CONFIG)
37
+ end
38
+ after do
39
+ cleanup_for_config(MongodbLogger::SpecHelper::DEFAULT_CONFIG)
40
+ end
41
+
42
+ it "authenticated by url" do
43
+ @mongodb_logger.send(:connect)
44
+ @mongodb_logger.mongo_adapter.authenticated?.should be_true
45
+ @mongodb_logger.db_configuration['database'].should == "system_log"
46
+ end
47
+ end
48
+
49
+ context "upon connecting with authentication settings" do
50
+ before do
51
+ setup_for_config(MongodbLogger::SpecHelper::DEFAULT_CONFIG_WITH_AUTH, MongodbLogger::SpecHelper::DEFAULT_CONFIG)
52
+ create_mongo_user
53
+ end
54
+ after do
55
+ remove_mongo_user
56
+ cleanup_for_config(MongodbLogger::SpecHelper::DEFAULT_CONFIG)
57
+ end
58
+
59
+ should_use_database_name_in_config
60
+
61
+ it "authenticate with the credentials in the configuration" do
62
+ @mongodb_logger.send(:connect)
63
+ @mongodb_logger.mongo_adapter.authenticated?.should be_true
64
+ end
65
+ end
66
+
67
+ context "after configuration" do
68
+ before do
69
+ setup_for_config(MongodbLogger::SpecHelper::DEFAULT_CONFIG)
70
+ @mongodb_logger.send(:connect)
71
+ @mongo_adapter = @mongodb_logger.mongo_adapter
72
+ end
73
+
74
+ it "set the default host, port, and capsize if not configured" do
75
+ @mongo_adapter.configuration['host'].should == 'localhost'
76
+ @mongo_adapter.configuration['port'].should == 27017
77
+ @mongo_adapter.configuration['capsize'].should == MongodbLogger::Logger::DEFAULT_COLLECTION_SIZE
78
+ end
79
+
80
+ it "set the mongo collection name depending on the Rails environment" do
81
+ @mongo_adapter.collection_name.should == "#{Rails.env}_log"
82
+ end
83
+
84
+ it "set the application name when specified in the config file" do
85
+ @mongo_adapter.configuration['application_name'].should == "mongo_foo"
86
+ end
87
+
88
+ it "set safe insert when specified in the config file" do
89
+ @mongo_adapter.configuration['write_options'].should be_present
90
+ end
91
+
92
+ it "use the database name in the config file" do
93
+ @mongo_adapter.configuration['database'].should == "system_log"
94
+ end
95
+
96
+ it "not authenticate" do
97
+ @mongo_adapter.authenticated?.should be_false
98
+ end
99
+
100
+ it "create a capped collection in the database with the configured size" do
101
+ @mongodb_logger.send(:check_for_collection)
102
+ @mongo_adapter.connection.collection_names.include?(@mongo_adapter.configuration['collection']).should be_true
103
+ # new capped collections are X MB + 5888 bytes, but don't be too strict in case that changes
104
+ @mongo_adapter.collection_stats[:storageSize].should < MongodbLogger::Logger::DEFAULT_COLLECTION_SIZE + 1.megabyte
105
+ end
106
+
107
+ end
108
+
109
+ end
110
+
111
+ context "after instantiation" do
112
+ before do
113
+ common_mongodb_logger_setup
114
+ end
115
+
116
+ context "upon insertion of a log record when active record is not used" do
117
+ before do
118
+ log_to_mongo("Test")
119
+ end
120
+
121
+ should_contain_one_log_record
122
+
123
+ it "allow recreation of the capped collection to remove all records" do
124
+ @mongo_adapter.reset_collection
125
+ @mongo_adapter.collection.find.count.should == 0
126
+ end
127
+ end
128
+
129
+ context "upon insertion of a colorized log record when ActiveRecord is used" do
130
+ before do
131
+ @log_message = "TESTING"
132
+ log_to_mongo("\e[31m #{@log_message} \e[0m")
133
+ end
134
+
135
+ it "detect logging is colorized" do
136
+ @mongodb_logger.send(:logging_colorized?).should be_true
137
+ end
138
+
139
+ should_contain_one_log_record
140
+
141
+ it "strip out colorization from log messages" do
142
+ @mongo_adapter.collection.find({"messages.debug" => @log_message}).count.should == 1
143
+ end
144
+ end
145
+
146
+ it "add application metadata to the log record" do
147
+ options = { "application" => self.class.name }
148
+ log_metadata_to_mongo(options)
149
+ @mongo_adapter.collection.find({"application" => self.class.name}).count.should == 1
150
+ end
151
+
152
+ it "not raise an exception when bson-unserializable data is logged in the :messages key" do
153
+ log_to_mongo(Tempfile.new("foo"))
154
+ @mongo_adapter.collection.find.count.should == 1
155
+ end
156
+
157
+ it "not raise an exception when bson-unserializable data is logged in the :params key" do
158
+ log_params_to_mongo({:foo => Tempfile.new("bar")})
159
+ @mongo_adapter.collection.find.count.should == 1
160
+ end
161
+
162
+ context "when an exception is raised" do
163
+ it "log the exception" do
164
+ expect { log_exception_to_mongo(EXCEPTION_MSG) }.to raise_error RuntimeError, EXCEPTION_MSG
165
+ @mongo_adapter.collection.find({"messages.error" => /^#{EXCEPTION_MSG}/}).count.should == 1
166
+ @mongo_adapter.collection.find({"is_exception" => true}).count.should == 1
167
+ end
168
+ end
169
+ end
170
+
171
+ context "after configure" do
172
+ before do
173
+ MongodbLogger::Base.configure do |config|
174
+ config.on_log_exception do |mongo_record|
175
+ # do something with error
176
+ end
177
+ end
178
+ common_mongodb_logger_setup
179
+ end
180
+
181
+ it "not call callback function on log" do
182
+ MongodbLogger::Base.should_receive(:on_log_exception).exactly(0)
183
+ log_to_mongo("Test")
184
+ end
185
+
186
+ context "when an exception is raised" do
187
+ it "should call callback function" do
188
+ MongodbLogger::Base.should_receive(:on_log_exception).exactly(1)
189
+ expect { log_exception_to_mongo(EXCEPTION_MSG) }.to raise_error RuntimeError, EXCEPTION_MSG
190
+ end
191
+ end
192
+ end
193
+
194
+ context "logging at INFO level" do
195
+ before do
196
+ common_mongodb_logger_setup(level: MongodbLogger::Logger::INFO)
197
+ log_to_mongo("INFO")
198
+ end
199
+
200
+ should_contain_one_log_record
201
+
202
+ it "not log DEBUG messages" do
203
+ @mongo_adapter.collection.find({"messages.debug" => { "$exists" => true }}).count.should == 0
204
+ end
205
+ end
206
+
207
+ context "without file logging" do
208
+ before do
209
+ setup_for_config(MongodbLogger::SpecHelper::DEFAULT_CONFIG_WITH_NO_FILE_LOGGING, MongodbLogger::SpecHelper::DEFAULT_CONFIG)
210
+ @log_file = Pathname.new('log.out')
211
+ FileUtils.touch(@log_file)
212
+ end
213
+
214
+ after do
215
+ File.delete(@log_file)
216
+ end
217
+
218
+ context "in instantiation" do
219
+ it "not call super in the initialize method" do
220
+ described_class.should_receive(:open).exactly(0)
221
+ MongodbLogger::Logger.new
222
+ end
223
+
224
+ it "set log" do
225
+ MongodbLogger::Logger.new.instance_variable_get(:@log).should be_a_kind_of(Logger)
226
+ end
227
+ end
228
+
229
+ context "after instantiation" do
230
+ context "upon insertion of a log record" do
231
+ before do
232
+ @mongodb_logger = MongodbLogger::Logger.new(path: @log_file)
233
+ log_to_mongo("Test")
234
+ end
235
+
236
+ it "not log the record to a file" do
237
+ File.open(@log_file.to_s, "rb").read.should be_blank
238
+ end
239
+ end
240
+ end
241
+ end
242
+
243
+ context "with custom collection" do
244
+ before do
245
+ config = MongodbLogger::SpecHelper::DEFAULT_CONFIG_WITH_COLLECTION
246
+ common_mongodb_logger_setup({}, config)
247
+ file_path = File.join(MongodbLogger::SpecHelper::SAMPLE_CONFIG_DIR, config)
248
+ @file_config = YAML.load(ERB.new(File.new(file_path).read).result)[Rails.env]['mongodb_logger']
249
+ end
250
+
251
+ it "changed collection name" do
252
+ @mongo_adapter.collection.name.should == @file_config['collection']
253
+ @mongo_adapter.collection_stats[:collection].should == @file_config['collection']
254
+ end
255
+ end
256
+
257
+ end