Skip to content

Commit

Permalink
Developers may include debug messages in their application logs (#1)
Browse files Browse the repository at this point in the history
* Developers may include debug messages in their application logs

There were some breaking changes with how the griddler gem was packaged.
This caused rake to fail until we downloaded the photos and updated the spec helper.

* Use Ruby 2.0 compliant syntax for defining protected methods
  • Loading branch information
zspencer authored Jan 15, 2020
1 parent b284e5c commit 7dc3bb0
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/griddler/mandrill.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'griddler'
require 'griddler/mandrill/version'
require 'griddler/mandrill/adapter'
require 'griddler/mandrill/logging'

Griddler.adapter_registry.register(:mandrill, Griddler::Mandrill::Adapter)
Griddler.adapter_registry.register(:mandrill, Griddler::Mandrill::Adapter)
7 changes: 7 additions & 0 deletions lib/griddler/mandrill/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def self.normalize_params(params)
end

def normalize_params
logger.debug(message: "entered #normalize_params", events: events)
events.select do |event|
event[:spf].present? && (event[:spf][:result] == 'pass' || event[:spf][:result] == 'neutral')
end.map do |event|
Expand All @@ -32,6 +33,12 @@ def normalize_params
end
end

protected

def logger
Logging.logger
end

private

attr_reader :params
Expand Down
28 changes: 28 additions & 0 deletions lib/griddler/mandrill/logging.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module Griddler
module Mandrill
module Logging
# The default logger discards all message; as we do not want
# to start clogging up existing users logs.
def self.logger
@logger ||= NullLogger.new(STDOUT)
end

# Set your application's logger
# @example In a Rails initializer:
# Griddler::Mandrill::Logging.logger = Rails.logger
# @example In Rails while logging a different level than the default logger
# Griddler::Mandrill::Logging.logger = ActiveSupport::Logger.new(Rails.logger, level: :debug)
def self.logger=(logger)
@logger = logger
end

# A logger which discards messages
class NullLogger < Logger
# Overload the Logger#add method as this is where the #info/#warn/#error methods
# send their messags to the logging subsystem.
def add(*_arguments)
end
end
end
end
end
Binary file added spec/fixtures/photo1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added spec/fixtures/photo2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'griddler'
require 'griddler/testing'
require 'griddler/mandrill'
require 'action_dispatch'
Expand All @@ -10,6 +11,13 @@
config.include Griddler::Testing
end


class Griddler::Testing::UploadedImage
def fixture_file
cwd = File.expand_path File.dirname(__FILE__)
File.new(File.join(cwd, 'fixtures', @name))
end
end
RSpec::Matchers.define :be_normalized_to do |expected|
failure_message do |actual|
message = ""
Expand Down

0 comments on commit 7dc3bb0

Please sign in to comment.