idlemailer 2.0.0.rc1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 026e7c3207e3a4d68ad8788514da4df57fb38c7c
4
- data.tar.gz: 1ba8967dd1cea7dbb1615083c542dc75371220c5
3
+ metadata.gz: cc834e63c8ea6672e0994a01d0443523dafd5f27
4
+ data.tar.gz: 756db93875c86f865d330f1eee5c6a1a1724f337
5
5
  SHA512:
6
- metadata.gz: 33eabc8cf62e1a2854b56d330150b2e7f5525ea04640e03455eecc256140af4dfa999f30b714e171875db1a2fc2bc7c350da0869445b455389e4e118817356d6
7
- data.tar.gz: '0294ef2f3f64dce15c02c787f0b1fb0234ca7c902c85a1f5162d4236c2ccf59f1dca1bdce1c96f7b2900c610d04bc4f9d33e2513221c066f33ddf164bdf1b15e'
6
+ metadata.gz: 4726efb741bd15359ec79c3ae8825f05cfcf6cb5a0b3abac25e1bb05a78186725688479f1bc4d18ffb5d7f9a46dc9e90729e7718ca776ea1409788c44548e174
7
+ data.tar.gz: 89679a1c6df53140a4e7e21011c8dd9d20cddab9ea641addfd21d92434b83e9d0c89faa6270e07324ca81c6dc240a4d199564c75d54e46ecd7ef7709fc9e5be7
data/README.md CHANGED
@@ -1,15 +1,16 @@
1
1
  # IdleMailer
2
2
 
3
- A lightweight (~150 line) alternative to ActionMailer for hipsters who use Ruby but not Rails. Powered by [mail](http://www.rubydoc.info/gems/mail). Great for API-only backends that need to send email.
3
+ A lightweight (~150 line) alternative to ActionMailer for Rubyists who are too cool for Rails. Powered by the [mail](http://www.rubydoc.info/gems/mail) gem. Great for API-only backends that need to send email.
4
4
 
5
5
  ## Installation
6
6
 
7
- $ [sudo] gem install idlemailer
8
- # Or add "idlemailer" to your Gemfile
7
+ Add to your Gemfile.
8
+
9
+ gem 'idlemailer'
9
10
 
10
11
  ## Use
11
12
 
12
- IdleMailer is all about providing mailer classes and templates. But [the mail gem](http://www.rubydoc.info/gems/mail) has a great API, so you have unfettered access to it in your mailers through the "mail" object.
13
+ IdleMailer provides mailer classes and templates on top of the [mail](http://www.rubydoc.info/gems/mail) gem. `mail` has a great API, so you have unfettered access to it in your mailers.
13
14
 
14
15
  ```ruby
15
16
  # Define your mailer class
@@ -17,18 +18,17 @@ class WidgetMailer
17
18
  include IdleMailer::Mailer
18
19
 
19
20
  def initialize(user, widget)
21
+ @widget = widget
20
22
  mail.to = user.email
21
23
  mail.subject = "Widget #{widget.sku}"
22
- @widget = widget
23
24
  end
24
25
  end
25
26
 
26
- # Create widget.html.erb and/or widget.text.erb templates.
27
+ # Create widget.html.erb and/or widget.text.erb in your templates directory.
27
28
  # They'll have access to instance variables like @widget above.
28
29
 
29
30
  # Send your mail
30
- mailer = WidgetMailer.new(current_user, widget)
31
- mailer.deliver
31
+ WidgetMailer.new(current_user, widget).deliver
32
32
  ```
33
33
 
34
34
  ### Inline templates
@@ -40,9 +40,9 @@ class WidgetMailer
40
40
  include IdleMailer::Mailer
41
41
 
42
42
  def initialize(user, widget)
43
+ @widget = widget
43
44
  mail.to = user.email
44
45
  mail.subject = "Widget #{widget.sku}"
45
- @widget = widget
46
46
  end
47
47
 
48
48
  text %(
@@ -104,7 +104,7 @@ end
104
104
 
105
105
  ## Testing
106
106
 
107
- Put the mailer in testing mode:
107
+ Put the mailer into testing mode:
108
108
 
109
109
  ```ruby
110
110
  IdleMailer.config do |config|
@@ -112,10 +112,44 @@ IdleMailer.config do |config|
112
112
  end
113
113
  ```
114
114
 
115
- Then use mail gem's built in testing helpers in your specs:
115
+ Then configure your test runner. Here's an example with RSpec:
116
+
117
+ ```ruby
118
+ RSpec.configure do |config|
119
+ # Clear sent mail after every test
120
+ config.after :each do
121
+ IdleMailer::Testing.clear_mail!
122
+ end
123
+
124
+ # Include the test helpers in your specs
125
+ config.include IdleMailer::Testing::Helpers
126
+ end
127
+ ```
128
+
129
+ Your tests will have access to these helper methods. (Note you can also call them directly on `IdleMailer::Testing` as well)
116
130
 
117
131
  ```ruby
118
- sent = Mail::TestMailer.deliveries.any? { |mail| mail.to.include? @user.email }
132
+ # quick boolean checks
133
+ sent_mail_to? 'user@example.com'
134
+ sent_mail_to? 'user@example.com', /subject/
135
+ sent_mail_to? 'user@example.com', /subject/, /body/
136
+ sent_mail_with_subject? /Foo/
137
+ sent_mail_with_body? /Bar/
138
+ sent_mail_from? 'user@example.com'
139
+
140
+ # get arrays of matching sent mail (Mail::Message objects)
141
+ mail_to 'user@example.com'
142
+ mail_to 'user@example.com', /subject/
143
+ mail_to 'user@example.com', /subject/, /body/
144
+ mail_with_subject /Foo/
145
+ mail_with_body /Bar/
146
+ mail_from 'user@example.com'
147
+
148
+ # get an array of all sent mail
149
+ sent_mail
150
+
151
+ # clear all sent mail
152
+ clear_mail!
119
153
  ```
120
154
 
121
155
  ## License
@@ -1,4 +1,5 @@
1
1
  module IdleMailer
2
+ # Loads a mailer's templates and layouts
2
3
  module TemplateManager
3
4
  def self.extended(klass)
4
5
  klass.class_eval do
@@ -11,19 +12,19 @@ module IdleMailer
11
12
  end
12
13
 
13
14
  def text(str)
14
- templates['text'] = ERB.new str
15
+ templates['text'] = ERB.new str.chomp
15
16
  end
16
17
 
17
18
  def html(str)
18
- templates['html'] = ERB.new str
19
+ templates['html'] = ERB.new str.chomp
19
20
  end
20
21
 
21
22
  def template(type)
22
- templates[type] || ERB.new(template_path(template_name, type).read)
23
+ templates[type] || ERB.new(template_path(template_name, type).read.chomp)
23
24
  end
24
25
 
25
26
  def layout(type)
26
- layouts[type] || ERB.new(template_path(IdleMailer.config.layout, type).read)
27
+ layouts[type] || ERB.new(template_path(IdleMailer.config.layout, type).read.chomp)
27
28
  end
28
29
 
29
30
  def has_template?(type)
@@ -0,0 +1,60 @@
1
+ module IdleMailer
2
+ # Module for testing. You can call all IdleMailer::Testing::Helpers methods directly on this module if you want.
3
+ module Testing
4
+ # Helpers for your tests
5
+ module Helpers
6
+ # Returns true if any mail was sent from the given email address.
7
+ def sent_mail_from?(addr)
8
+ mail_from(addr).any?
9
+ end
10
+
11
+ # Returns true if any mail was sent to the given email address. You may pass subject and body patterns to get more specific (String or Regexp).
12
+ def sent_mail_to?(addr, subject = nil, body = nil)
13
+ mail_to(addr, subject, body).any?
14
+ end
15
+
16
+ # Returns true if any mail was sent matching the given subject (String or Regexp).
17
+ def sent_mail_with_subject?(pattern)
18
+ mail_with_subject(pattern).any?
19
+ end
20
+
21
+ # Returns true if any mail was sent matching the given body (Regexp).
22
+ def sent_mail_with_body?(pattern)
23
+ mail_with_body(pattern).any?
24
+ end
25
+
26
+ # Returns all mail sent from the given email address.
27
+ def mail_from(addr)
28
+ sent_mail.select { |m| m.from.include? addr }
29
+ end
30
+
31
+ # Returns all mail sent to the given email address. You may pass subject and body patterns to get more specific (String or Regexp).
32
+ def mail_to(addr, subject = nil, body = nil)
33
+ sent_mail.select { |m|
34
+ m.to.include?(addr) && (subject.nil? || subject === m.subject) && (body.nil? || body === m.to_s)
35
+ }
36
+ end
37
+
38
+ # Returns all mail sent matching the given subject (String or Regexp).
39
+ def mail_with_subject(pattern)
40
+ sent_mail.select { |m| pattern === m.subject }
41
+ end
42
+
43
+ # Returns all mail sent matching the given body (Regexp).
44
+ def mail_with_body(pattern)
45
+ sent_mail.select { |m| pattern === m.to_s }
46
+ end
47
+
48
+ # Returns all sent mail.
49
+ def sent_mail
50
+ Mail::TestMailer.deliveries
51
+ end
52
+
53
+ # Clears sent mail.
54
+ def clear_mail!
55
+ Mail::TestMailer.deliveries.clear
56
+ end
57
+ end
58
+ extend Helpers
59
+ end
60
+ end
@@ -1,5 +1,5 @@
1
1
  # IdleMailer module
2
2
  module IdleMailer
3
3
  # Version number
4
- VERSION = '2.0.0.rc1'
4
+ VERSION = '2.0.0'
5
5
  end
data/lib/idlemailer.rb CHANGED
@@ -1,9 +1,14 @@
1
1
  require 'erb'
2
2
  require 'pathname'
3
3
  require 'mail'
4
+
4
5
  require 'idlemailer/config'
5
6
  require 'idlemailer/defaults'
6
7
  require 'idlemailer/message'
7
8
  require 'idlemailer/mailer'
8
9
  require 'idlemailer/template_manager'
9
10
  require 'idlemailer/version'
11
+
12
+ module IdleMailer
13
+ autoload :Testing, 'idlemailer/testing'
14
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: idlemailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.rc1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Hollinger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-28 00:00:00.000000000 Z
11
+ date: 2017-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mail
@@ -39,6 +39,7 @@ files:
39
39
  - lib/idlemailer/mailer.rb
40
40
  - lib/idlemailer/message.rb
41
41
  - lib/idlemailer/template_manager.rb
42
+ - lib/idlemailer/testing.rb
42
43
  - lib/idlemailer/version.rb
43
44
  homepage: https://github.com/jhollinger/idlemailer
44
45
  licenses: []
@@ -51,12 +52,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
52
  requirements:
52
53
  - - ">="
53
54
  - !ruby/object:Gem::Version
54
- version: '0'
55
+ version: 2.0.0
55
56
  required_rubygems_version: !ruby/object:Gem::Requirement
56
57
  requirements:
57
- - - ">"
58
+ - - ">="
58
59
  - !ruby/object:Gem::Version
59
- version: 1.3.1
60
+ version: '0'
60
61
  requirements: []
61
62
  rubyforge_project:
62
63
  rubygems_version: 2.5.2