postmaster_general 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm gemset use ree@postmaster_general --create
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+
5
+ gem "actionmailer", "~> 3.0"
6
+ gem "configatron"
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "rspec", "~> 2.1"
12
+ gem "yard", "~> 0.6.0"
13
+ gem "bundler", "~> 1.0.0"
14
+ gem "jeweler", "~> 1.5.1"
15
+ gem "rcov", ">= 0"
16
+ gem "reek", "~> 1.2.8"
17
+ gem "roodi", "~> 2.1.0"
18
+ end
@@ -0,0 +1,87 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.3)
6
+ actionpack (= 3.0.3)
7
+ mail (~> 2.2.9)
8
+ actionpack (3.0.3)
9
+ activemodel (= 3.0.3)
10
+ activesupport (= 3.0.3)
11
+ builder (~> 2.1.2)
12
+ erubis (~> 2.6.6)
13
+ i18n (~> 0.4)
14
+ rack (~> 1.2.1)
15
+ rack-mount (~> 0.6.13)
16
+ rack-test (~> 0.5.6)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.3)
19
+ activesupport (= 3.0.3)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.4)
22
+ activesupport (3.0.3)
23
+ builder (2.1.2)
24
+ configatron (2.6.4)
25
+ yamler (>= 0.1.0)
26
+ diff-lcs (1.1.2)
27
+ erubis (2.6.6)
28
+ abstract (>= 1.0.0)
29
+ git (1.2.5)
30
+ i18n (0.5.0)
31
+ jeweler (1.5.2)
32
+ bundler (~> 1.0.0)
33
+ git (>= 1.2.5)
34
+ rake
35
+ mail (2.2.14)
36
+ activesupport (>= 2.3.6)
37
+ i18n (>= 0.4.0)
38
+ mime-types (~> 1.16)
39
+ treetop (~> 1.4.8)
40
+ mime-types (1.16)
41
+ polyglot (0.3.1)
42
+ rack (1.2.1)
43
+ rack-mount (0.6.13)
44
+ rack (>= 1.0.0)
45
+ rack-test (0.5.7)
46
+ rack (>= 1.0)
47
+ rake (0.8.7)
48
+ rcov (0.9.9)
49
+ reek (1.2.8)
50
+ ruby2ruby (~> 1.2)
51
+ ruby_parser (~> 2.0)
52
+ sexp_processor (~> 3.0)
53
+ roodi (2.1.0)
54
+ ruby_parser
55
+ rspec (2.4.0)
56
+ rspec-core (~> 2.4.0)
57
+ rspec-expectations (~> 2.4.0)
58
+ rspec-mocks (~> 2.4.0)
59
+ rspec-core (2.4.0)
60
+ rspec-expectations (2.4.0)
61
+ diff-lcs (~> 1.1.2)
62
+ rspec-mocks (2.4.0)
63
+ ruby2ruby (1.2.5)
64
+ ruby_parser (~> 2.0)
65
+ sexp_processor (~> 3.0)
66
+ ruby_parser (2.0.5)
67
+ sexp_processor (~> 3.0)
68
+ sexp_processor (3.0.5)
69
+ treetop (1.4.9)
70
+ polyglot (>= 0.3.1)
71
+ tzinfo (0.3.24)
72
+ yamler (0.1.0)
73
+ yard (0.6.4)
74
+
75
+ PLATFORMS
76
+ ruby
77
+
78
+ DEPENDENCIES
79
+ actionmailer (~> 3.0)
80
+ bundler (~> 1.0.0)
81
+ configatron
82
+ jeweler (~> 1.5.1)
83
+ rcov
84
+ reek (~> 1.2.8)
85
+ roodi (~> 2.1.0)
86
+ rspec (~> 2.1)
87
+ yard (~> 0.6.0)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Dan Pickett
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ = postmaster_general
2
+
3
+ A little utility to log emails sent in a block of code (best used in isolation and tests)
4
+
5
+ #set the log directory
6
+ PostmasterGeneral.log_directory = "/some/arbitrary/path"
7
+
8
+ #in a test
9
+ PostmasterGeneral.log_deliveries("a_delivery.txt") do
10
+ UserActivation.notification.deliver
11
+ end
12
+
13
+ The user activation notification email that was sent via the actionmailer class will be logged to
14
+
15
+ /some/arbitrary/path/a_delivery.txt
16
+
17
+ == Installing
18
+
19
+ Add postmaster_general to your Gemfile:
20
+
21
+ gem "postmaster_general"
22
+
23
+ Then run bundle install:
24
+
25
+ bundle install
26
+
27
+ == Contributing to postmaster_general
28
+
29
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
30
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
31
+ * Fork the project
32
+ * Start a feature/bugfix branch
33
+ * Commit and push until you are happy with your contribution
34
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
35
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
36
+
37
+ == Copyright
38
+
39
+ Copyright (c) 2011 Dan Pickett. See LICENSE.txt for
40
+ further details.
41
+
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "postmaster_general"
16
+ gem.homepage = "http://github.com/dpickett/postmaster_general"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{A mail logger for ActionMailer 3.x}
19
+ gem.description = %Q{Logs emails delivered for easy reference}
20
+ gem.email = "dpickett@enlightsolutions.com"
21
+ gem.authors = ["Dan Pickett"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core'
30
+ require 'rspec/core/rake_task'
31
+ RSpec::Core::RakeTask.new(:spec) do |spec|
32
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
+ end
34
+
35
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
36
+ spec.pattern = 'spec/**/*_spec.rb'
37
+ spec.rcov = true
38
+ end
39
+
40
+ require 'reek/rake/task'
41
+ Reek::Rake::Task.new do |t|
42
+ t.fail_on_error = true
43
+ t.verbose = false
44
+ t.source_files = 'lib/**/*.rb'
45
+ end
46
+
47
+ require 'roodi'
48
+ require 'roodi_task'
49
+ RoodiTask.new do |t|
50
+ t.verbose = false
51
+ end
52
+
53
+ task :default => :spec
54
+
55
+ require 'yard'
56
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,37 @@
1
+ require 'action_mailer'
2
+ require 'configatron'
3
+ require 'fileutils'
4
+
5
+ module PostmasterGeneral
6
+ #sets the log directory for actionmailer logging
7
+ def self.log_directory=(path)
8
+ configatron.postmaster_general.log_directory = path
9
+ end
10
+
11
+ #returns the log directory configured previously
12
+ def self.log_directory
13
+ configatron.postmaster_general.log_directory
14
+ end
15
+
16
+ #logs mail deliveries performed within the specified block to the specified path
17
+ #the path is appended to the previously configured log_directory
18
+ def self.log_deliveries(path, &block)
19
+ before_index = ActionMailer::Base.deliveries.size - 1
20
+ before_index = 0 if before_index < 0
21
+
22
+ yield
23
+
24
+ log_path = File.join(log_directory, path)
25
+
26
+ FileUtils.mkdir_p(File.dirname(log_path))
27
+ FileUtils.rm_f(log_path)
28
+
29
+ ActionMailer::Base.deliveries[before_index..-1].each do |mail|
30
+ File.open(log_path, "w+") do |f|
31
+ f << "=================="
32
+ f << mail.encoded
33
+ f << "=================="
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,81 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{postmaster_general}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Dan Pickett"]
12
+ s.date = %q{2011-01-23}
13
+ s.description = %q{Logs emails delivered for easy reference}
14
+ s.email = %q{dpickett@enlightsolutions.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ ".rvmrc",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/postmaster_general.rb",
30
+ "postmaster_general.gemspec",
31
+ "spec/postmaster_general_spec.rb",
32
+ "spec/spec_helper.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/dpickett/postmaster_general}
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.7}
38
+ s.summary = %q{A mail logger for ActionMailer 3.x}
39
+ s.test_files = [
40
+ "spec/postmaster_general_spec.rb",
41
+ "spec/spec_helper.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_runtime_dependency(%q<actionmailer>, ["~> 3.0"])
50
+ s.add_runtime_dependency(%q<configatron>, [">= 0"])
51
+ s.add_development_dependency(%q<rspec>, ["~> 2.1"])
52
+ s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
53
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
54
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
55
+ s.add_development_dependency(%q<rcov>, [">= 0"])
56
+ s.add_development_dependency(%q<reek>, ["~> 1.2.8"])
57
+ s.add_development_dependency(%q<roodi>, ["~> 2.1.0"])
58
+ else
59
+ s.add_dependency(%q<actionmailer>, ["~> 3.0"])
60
+ s.add_dependency(%q<configatron>, [">= 0"])
61
+ s.add_dependency(%q<rspec>, ["~> 2.1"])
62
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
65
+ s.add_dependency(%q<rcov>, [">= 0"])
66
+ s.add_dependency(%q<reek>, ["~> 1.2.8"])
67
+ s.add_dependency(%q<roodi>, ["~> 2.1.0"])
68
+ end
69
+ else
70
+ s.add_dependency(%q<actionmailer>, ["~> 3.0"])
71
+ s.add_dependency(%q<configatron>, [">= 0"])
72
+ s.add_dependency(%q<rspec>, ["~> 2.1"])
73
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
74
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
75
+ s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
76
+ s.add_dependency(%q<rcov>, [">= 0"])
77
+ s.add_dependency(%q<reek>, ["~> 1.2.8"])
78
+ s.add_dependency(%q<roodi>, ["~> 2.1.0"])
79
+ end
80
+ end
81
+
@@ -0,0 +1,54 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "PostmasterGeneral" do
4
+ context "configuration" do
5
+ it "allows the setting of a log directory" do
6
+ path = "/some/path"
7
+ PostmasterGeneral.log_directory = path
8
+ PostmasterGeneral.log_directory.should eql(path)
9
+ end
10
+ end
11
+
12
+ context "logging" do
13
+ TEST_LOG_PATH = File.join(File.dirname(__FILE__), "..", "tmp")
14
+
15
+ let(:log_file_name) { "log.txt" }
16
+ class SillyMailer < ActionMailer::Base
17
+ def logging_is_for_kids
18
+ mail(:to => "user@example.com", :from => "author@example.com") do |format|
19
+ format.text { render :text => "Message" }
20
+ end
21
+ end
22
+ end
23
+
24
+ before do
25
+ PostmasterGeneral.log_directory = TEST_LOG_PATH
26
+ end
27
+
28
+ after do
29
+ FileUtils.rm_rf(TEST_LOG_PATH)
30
+ end
31
+
32
+ it "creates a log file" do
33
+ perform_delivery
34
+
35
+ File.should exist(TEST_LOG_PATH + "/#{log_file_name}")
36
+ end
37
+
38
+ it "fills the log file in with the mail's encoded value" do
39
+ mail = perform_delivery
40
+
41
+ File.read(TEST_LOG_PATH + "/#{log_file_name}").should =~ /#{Regexp.escape(mail.encoded)}/
42
+ end
43
+ end
44
+
45
+ def perform_delivery
46
+ mail = nil
47
+
48
+ PostmasterGeneral.log_deliveries(log_file_name) do
49
+ mail = SillyMailer.logging_is_for_kids.deliver
50
+ end
51
+
52
+ mail
53
+ end
54
+ end
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'postmaster_general'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ ActionMailer::Base.delivery_method = :test
11
+ RSpec.configure do |config|
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,218 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: postmaster_general
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Dan Pickett
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-23 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ type: :runtime
24
+ name: actionmailer
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ hash: 7
31
+ segments:
32
+ - 3
33
+ - 0
34
+ version: "3.0"
35
+ requirement: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ prerelease: false
38
+ type: :runtime
39
+ name: configatron
40
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ requirement: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ prerelease: false
52
+ type: :development
53
+ name: rspec
54
+ version_requirements: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 1
60
+ segments:
61
+ - 2
62
+ - 1
63
+ version: "2.1"
64
+ requirement: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ prerelease: false
67
+ type: :development
68
+ name: yard
69
+ version_requirements: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ hash: 7
75
+ segments:
76
+ - 0
77
+ - 6
78
+ - 0
79
+ version: 0.6.0
80
+ requirement: *id004
81
+ - !ruby/object:Gem::Dependency
82
+ prerelease: false
83
+ type: :development
84
+ name: bundler
85
+ version_requirements: &id005 !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ hash: 23
91
+ segments:
92
+ - 1
93
+ - 0
94
+ - 0
95
+ version: 1.0.0
96
+ requirement: *id005
97
+ - !ruby/object:Gem::Dependency
98
+ prerelease: false
99
+ type: :development
100
+ name: jeweler
101
+ version_requirements: &id006 !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ~>
105
+ - !ruby/object:Gem::Version
106
+ hash: 1
107
+ segments:
108
+ - 1
109
+ - 5
110
+ - 1
111
+ version: 1.5.1
112
+ requirement: *id006
113
+ - !ruby/object:Gem::Dependency
114
+ prerelease: false
115
+ type: :development
116
+ name: rcov
117
+ version_requirements: &id007 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ hash: 3
123
+ segments:
124
+ - 0
125
+ version: "0"
126
+ requirement: *id007
127
+ - !ruby/object:Gem::Dependency
128
+ prerelease: false
129
+ type: :development
130
+ name: reek
131
+ version_requirements: &id008 !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ~>
135
+ - !ruby/object:Gem::Version
136
+ hash: 15
137
+ segments:
138
+ - 1
139
+ - 2
140
+ - 8
141
+ version: 1.2.8
142
+ requirement: *id008
143
+ - !ruby/object:Gem::Dependency
144
+ prerelease: false
145
+ type: :development
146
+ name: roodi
147
+ version_requirements: &id009 !ruby/object:Gem::Requirement
148
+ none: false
149
+ requirements:
150
+ - - ~>
151
+ - !ruby/object:Gem::Version
152
+ hash: 11
153
+ segments:
154
+ - 2
155
+ - 1
156
+ - 0
157
+ version: 2.1.0
158
+ requirement: *id009
159
+ description: Logs emails delivered for easy reference
160
+ email: dpickett@enlightsolutions.com
161
+ executables: []
162
+
163
+ extensions: []
164
+
165
+ extra_rdoc_files:
166
+ - LICENSE.txt
167
+ - README.rdoc
168
+ files:
169
+ - .document
170
+ - .rspec
171
+ - .rvmrc
172
+ - Gemfile
173
+ - Gemfile.lock
174
+ - LICENSE.txt
175
+ - README.rdoc
176
+ - Rakefile
177
+ - VERSION
178
+ - lib/postmaster_general.rb
179
+ - postmaster_general.gemspec
180
+ - spec/postmaster_general_spec.rb
181
+ - spec/spec_helper.rb
182
+ has_rdoc: true
183
+ homepage: http://github.com/dpickett/postmaster_general
184
+ licenses:
185
+ - MIT
186
+ post_install_message:
187
+ rdoc_options: []
188
+
189
+ require_paths:
190
+ - lib
191
+ required_ruby_version: !ruby/object:Gem::Requirement
192
+ none: false
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ hash: 3
197
+ segments:
198
+ - 0
199
+ version: "0"
200
+ required_rubygems_version: !ruby/object:Gem::Requirement
201
+ none: false
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ hash: 3
206
+ segments:
207
+ - 0
208
+ version: "0"
209
+ requirements: []
210
+
211
+ rubyforge_project:
212
+ rubygems_version: 1.3.7
213
+ signing_key:
214
+ specification_version: 3
215
+ summary: A mail logger for ActionMailer 3.x
216
+ test_files:
217
+ - spec/postmaster_general_spec.rb
218
+ - spec/spec_helper.rb