fusionary-mail_logger 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest CHANGED
@@ -6,8 +6,12 @@ generators/mail_logger/USAGE
6
6
  lib/mail_logger/app/models/mail_log.rb
7
7
  lib/mail_logger/lib/extensions/action_mailer.rb
8
8
  lib/mail_logger.rb
9
+ mail_logger.gemspec
9
10
  Manifest
10
11
  MIT-LICENSE
11
12
  rails/init.rb
12
13
  Rakefile
13
14
  README.textile
15
+ test/test_helper.rb
16
+ test/unit/action_mailer_extension_test.rb
17
+ test/unit/mail_log_test.rb
data/README.textile CHANGED
@@ -16,11 +16,16 @@ Ensure the environment's database is present and then run
16
16
 
17
17
  script/generate mail_logger
18
18
 
19
- This will generate the migration and generate the MailLog AR model.
19
+ This will generate the migration and generate the MailLog ActiveRecord model.
20
+
21
+ The model includes a module that attaches all the necessary code, allowing you to add other code (named scopes, etc) without interference
22
+
23
+ h2. Ultra-Transparent
24
+
25
+ You could install this gem and not notice *anything* different with your application. It sits in the background, dumping all emails that get sent to your database. The to, from, and subject line, as well as created_at, are all indexed for your querying pleasure. Set up named scopes to search fields, or aggregate all common subjects and allow administrator accounts to filter/view them. Whatever the case, the data is yours; whipping together the controller and setting permissions is the easy part.
20
26
 
21
27
  h2. About
22
28
 
23
- The purpose of this is to provide a simple audit trail, specific to ActionMailer, for Rails apps. Without much work, you could write a
24
- controller and some views and then monitor the emails sent out; that's really beyond the scope of this project though.
29
+ The purpose of this is to provide a simple audit trail, specific to ActionMailer, for Rails apps. Without much work, you could write a controller and some views and then monitor the emails sent out; that's really beyond the scope of this project though.
25
30
 
26
31
  Copyright (c) 2009 Fusionary Media, released under the MIT license
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rake'
3
3
  require 'rake/testtask'
4
4
  require 'echoe'
5
5
 
6
- Echoe.new("mail_logger", "0.1.1") do |p|
6
+ Echoe.new("mail_logger", "0.1.2") do |p|
7
7
  p.description = "Braindead-simple email logger for ActionMailer using ActiveRecord"
8
8
  p.url = "http://github.com/fusionary/mail_logger"
9
9
  p.author = ["Fusionary Media", "Josh Clayton"]
@@ -9,7 +9,11 @@ module MailLogger
9
9
  module ClassMethods
10
10
  def create_from_mail(email)
11
11
  [:to, :from, :subject, :quoted_body, :encoded].each do |att|
12
- return unless email.respond_to?(att)
12
+ raise(ArgumentError, "object is not an email") unless email.respond_to?(att)
13
+ end
14
+
15
+ [:to, :from].each do |required_att|
16
+ raise(ArgumentError, "email does not have attribute '#{required_att}' assigned") if email.send(required_att).blank?
13
17
  end
14
18
 
15
19
  self.create(:to => email.to.join(", "), :from => email.from.join(", "), :subject => email.subject, :body => email.quoted_body, :message => email.encoded)
@@ -5,13 +5,14 @@ module MailLogger
5
5
  def self.included(base)
6
6
  base.class_eval do
7
7
  def deliver_with_hooks!(*args)
8
+ logger ||= nil
8
9
  mail = args.first || @mail # depend on ActionMailer::Base's @mail ivar is pretty nasty but has to be done
9
10
  if !mail.nil?
10
11
  begin
11
- logger.info "MailLogger logged #{mail.encoded}" unless logger.nil?
12
+ logger.info "MailLogger logged #{mail.encoded}" if logger
12
13
  MailLog.create_from_mail(mail)
13
14
  rescue
14
- logger.info "MailLogger failed" unless logger.nil?
15
+ logger.info "MailLogger failed" if logger
15
16
  end
16
17
  end
17
18
 
data/mail_logger.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{mail_logger}
5
- s.version = "0.1.1"
5
+ s.version = "0.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Fusionary Media, Josh Clayton"]
9
- s.date = %q{2009-04-14}
9
+ s.date = %q{2009-04-17}
10
10
  s.description = %q{Braindead-simple email logger for ActionMailer using ActiveRecord}
11
11
  s.email = %q{joshua.clayton@gmail.com}
12
12
  s.extra_rdoc_files = ["lib/mail_logger/app/models/mail_log.rb", "lib/mail_logger/lib/extensions/action_mailer.rb", "lib/mail_logger.rb", "README.textile"]
13
- s.files = ["generators/mail_logger/lib/rake_commands.rb", "generators/mail_logger/mail_logger_generator.rb", "generators/mail_logger/templates/app/models/mail_log.rb", "generators/mail_logger/templates/db/migrate/create_mail_logs.rb", "generators/mail_logger/USAGE", "lib/mail_logger/app/models/mail_log.rb", "lib/mail_logger/lib/extensions/action_mailer.rb", "lib/mail_logger.rb", "Manifest", "MIT-LICENSE", "rails/init.rb", "Rakefile", "README.textile", "mail_logger.gemspec"]
13
+ s.files = ["generators/mail_logger/lib/rake_commands.rb", "generators/mail_logger/mail_logger_generator.rb", "generators/mail_logger/templates/app/models/mail_log.rb", "generators/mail_logger/templates/db/migrate/create_mail_logs.rb", "generators/mail_logger/USAGE", "lib/mail_logger/app/models/mail_log.rb", "lib/mail_logger/lib/extensions/action_mailer.rb", "lib/mail_logger.rb", "mail_logger.gemspec", "Manifest", "MIT-LICENSE", "rails/init.rb", "Rakefile", "README.textile", "test/test_helper.rb", "test/unit/action_mailer_extension_test.rb", "test/unit/mail_log_test.rb"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://github.com/fusionary/mail_logger}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Mail_logger", "--main", "README.textile"]
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.rubyforge_project = %q{mail_logger}
19
19
  s.rubygems_version = %q{1.3.1}
20
20
  s.summary = %q{Braindead-simple email logger for ActionMailer using ActiveRecord}
21
+ s.test_files = ["test/test_helper.rb", "test/unit/action_mailer_extension_test.rb", "test/unit/mail_log_test.rb"]
21
22
 
22
23
  if s.respond_to? :specification_version then
23
24
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
data/rails/init.rb CHANGED
@@ -1 +1,2 @@
1
+ require "action_mailer"
1
2
  require "mail_logger"
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'active_support'
4
+ require 'active_support/test_case'
5
+
6
+ require File.join(File.dirname(__FILE__), "../rails/init")
7
+
8
+ require 'redgreen'
9
+ require 'shoulda'
10
+
11
+ class MailLog
12
+ include MailLogger::App::Models::MailLog
13
+ end
14
+
15
+ class FakeMailer
16
+ def initialize(email)
17
+ @mail = email
18
+ end
19
+
20
+ def deliver!(*args)
21
+ "sent email"
22
+ end
23
+ end
24
+
25
+ FakeMailer.send :include, MailLogger::Lib::Extensions::ActionMailer
26
+
27
+ class ValidEmail
28
+ attr_accessor :to, :from, :subject, :quoted_body, :encoded
29
+ end
@@ -0,0 +1,30 @@
1
+ require File.join(File.dirname(__FILE__), "../test_helper")
2
+
3
+ class ActionMailerExtensionTest < ActiveSupport::TestCase
4
+ context "sending a valid email" do
5
+ should "trigger the default #deliver!" do
6
+ mailer = FakeMailer.new(nil)
7
+ assert_equal "sent email", mailer.deliver!
8
+ end
9
+
10
+ should "not attempt to create a new mail log if mail is nil" do
11
+ mailer = FakeMailer.new(nil)
12
+ MailLog.expects(:create_from_mail).never
13
+ assert_equal "sent email", mailer.deliver!
14
+ end
15
+
16
+ should "attempt to create a new mail log if email if present" do
17
+ email = ValidEmail.new
18
+ email.to = email.from = ["user@example.com"]
19
+ mailer = FakeMailer.new(email)
20
+ MailLog.expects(:create_from_mail).with(email)
21
+ assert_equal "sent email", mailer.deliver!
22
+ end
23
+
24
+ should "proceed even if MailLog raises an error" do
25
+ mailer = FakeMailer.new("my email")
26
+ MailLog.expects(:create_from_mail).with("my email").raises("an error")
27
+ assert_equal "sent email", mailer.deliver!
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,49 @@
1
+ require File.join(File.dirname(__FILE__), "../test_helper")
2
+
3
+ class MailLogTest < ActiveSupport::TestCase
4
+ context "Mail log creation" do
5
+ setup { MailLog.stubs(:create) }
6
+
7
+ should "ensure the email responds to the correct methods" do
8
+ email = ValidEmail.new
9
+ email.to = email.from = ["user@example.com"]
10
+
11
+ [:to, :from, :subject, :quoted_body, :encoded].each do |att|
12
+ email.expects(:respond_to?).with(att).returns(true)
13
+ end
14
+
15
+ MailLog.create_from_mail(email)
16
+ end
17
+
18
+ should "raise an error if the object is not an email" do
19
+ assert_raise ArgumentError, "object is not an email" do
20
+ MailLog.create_from_mail("not an email")
21
+ end
22
+ end
23
+
24
+ should "raise an error if to or from is not set" do
25
+ email = ValidEmail.new
26
+ email.to = ["user@example.com"]
27
+ assert_raise ArgumentError, "email does not have attribute 'from' assigned" do
28
+ MailLog.create_from_mail(email)
29
+ end
30
+
31
+ email.from, email.to = ["user@example.com"]
32
+ assert_raise ArgumentError, "email does not have attribute 'to' assigned" do
33
+ MailLog.create_from_mail(email)
34
+ end
35
+ end
36
+
37
+ should "pass all attributes when creating a new mail log" do
38
+ email = ValidEmail.new
39
+ email.from = ["user-1@example.com", "user-2@example.com"]
40
+ email.to = ["user-3@example.com", "user-4@example.com"]
41
+ email.subject = "Subject line"
42
+ email.quoted_body = "This is a quoted body"
43
+ email.encoded = "Encoded message"
44
+
45
+ MailLog.expects(:create).with({:from => "user-1@example.com, user-2@example.com", :to => "user-3@example.com, user-4@example.com", :subject => "Subject line", :body => "This is a quoted body", :message => "Encoded message"})
46
+ MailLog.create_from_mail(email)
47
+ end
48
+ end
49
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fusionary-mail_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fusionary Media, Josh Clayton
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-14 00:00:00 -07:00
12
+ date: 2009-04-17 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -45,12 +45,15 @@ files:
45
45
  - lib/mail_logger/app/models/mail_log.rb
46
46
  - lib/mail_logger/lib/extensions/action_mailer.rb
47
47
  - lib/mail_logger.rb
48
+ - mail_logger.gemspec
48
49
  - Manifest
49
50
  - MIT-LICENSE
50
51
  - rails/init.rb
51
52
  - Rakefile
52
53
  - README.textile
53
- - mail_logger.gemspec
54
+ - test/test_helper.rb
55
+ - test/unit/action_mailer_extension_test.rb
56
+ - test/unit/mail_log_test.rb
54
57
  has_rdoc: true
55
58
  homepage: http://github.com/fusionary/mail_logger
56
59
  post_install_message:
@@ -82,5 +85,7 @@ rubygems_version: 1.2.0
82
85
  signing_key:
83
86
  specification_version: 2
84
87
  summary: Braindead-simple email logger for ActionMailer using ActiveRecord
85
- test_files: []
86
-
88
+ test_files:
89
+ - test/test_helper.rb
90
+ - test/unit/action_mailer_extension_test.rb
91
+ - test/unit/mail_log_test.rb