mandrill_mailer 1.0.4 → 1.1.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: 1f1b23face89c57dcf4a9d63594a1d316adb67e5
4
- data.tar.gz: 5311702dc42f69d2c6718177d6f790da846c56fa
3
+ metadata.gz: 79a6370588ee165bd28e0b2610236fb3bf533417
4
+ data.tar.gz: 52579261a95fc18eb4625cb41f9bb9c10fc09ad5
5
5
  SHA512:
6
- metadata.gz: eda62b4c59aa3d60a60f15f851e5483cc1af155a3304c15ed28ee58ae1bccd59ff804e3af1913d018f451e11fac36ab14a95ebdde2ec6b44af30835060edb5fb
7
- data.tar.gz: 094eed9cb7c1e02c72b9fd040ad2a7a03bb9ae46999601d0e654998d72e984e041383053094cf943e796c75875cd542319f9ec4db68f6d54fab9cb2d6c402990
6
+ metadata.gz: fd9651725cad09ddd52c4c796a14443ac7e91165b8da44be8e965f087989f74966310bd6d3cc72fcabc1bf90d817ed7d306030679804b1061880db80b6808e9f
7
+ data.tar.gz: c281185967f50d1036ba767875e2321afe0ac79e33e42ee4ddd097b9a19075a9d2a892ba62086769696daf36412c7f4dcbe3c5efd9d48eedb490e7b834b4b83c
data/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
+ ## 1.1.0 - 2015-10-02
6
+ ### Added
7
+ - Optional RSpec helper (`MandrillMailer::RSpecHelper`) with custom matchers
8
+ to simplify testing mailers like:
9
+ - `expect(mailer).to be_from("email@example.com")`
10
+ - `expect(mailer).to have_merge_data('USER_EMAIL' => user.email)`
11
+ - `expect(mailer).to include_merge_var_content(user.email)`
12
+ - `expect(mailer).to have_subject("Hello")`
13
+ - `expect(mailer).to use_template('Example')`
14
+ - `expect(mailer).to send_email_to('email@example.com')`
15
+
16
+
5
17
  ## 1.0.4 - 2015-09-24
6
18
  ### Added
7
19
  - Allow default `view_content_link` on Mailer class.
@@ -0,0 +1,41 @@
1
+ # MandrilMailer helper module that requires custom matchers for use in RSpec specs.
2
+ # Example usage:
3
+ #
4
+ # In spec/spec_helper.rb):
5
+ #
6
+ # RSpec.configure do |config|
7
+ # # ...
8
+ # require "mandrill_mailer/rspec_helpers"
9
+ # config.include MandrillMailer::RSpecHelper
10
+ # end
11
+ #
12
+ # In spec/mailers/user_mailer_spec.rb):
13
+ #
14
+ # require "rails_helper"
15
+ #s
16
+ # RSpec.describe UserMailer do
17
+ # let(:user) { create(:user) }
18
+ #
19
+ # context ".welcome" do
20
+ # let(:mailer) { described_class.welcome(user) }
21
+ #
22
+ # subject { mailer }
23
+ #
24
+ # it 'has the correct data' do
25
+ # expect(mailer).to use_template('Welcome')
26
+ # end
27
+ # end
28
+ # end
29
+ #
30
+ #
31
+
32
+ module MandrillMailer
33
+ module RSpecHelper
34
+ require 'mandrill_mailer/rspec_helpers/from_matcher'
35
+ require 'mandrill_mailer/rspec_helpers/merge_var_matcher'
36
+ require 'mandrill_mailer/rspec_helpers/merge_var_content_matcher'
37
+ require 'mandrill_mailer/rspec_helpers/subject_matcher'
38
+ require 'mandrill_mailer/rspec_helpers/template_matcher'
39
+ require 'mandrill_mailer/rspec_helpers/to_email_matcher'
40
+ end
41
+ end
@@ -0,0 +1,47 @@
1
+ # Public: Matcher for asserting from email
2
+ #
3
+ # expected_options - The Hash options used to refine the selection (default: {}):
4
+ # :email - expected from email
5
+ # :name - expected from name
6
+ #
7
+ # WelcomeMailer is an instance of MandrillMailler::TemplateMailer
8
+ #
9
+ # let(:user) { create(:user) }
10
+ # let(:mailer) { WelcomeMailer.welcome_registered(user) }
11
+ # it 'has the correct data' do
12
+ # expect(mailer).to be_from('support@codeschool.com')
13
+ # end
14
+ #
15
+ # Returns true or an error message on failure
16
+ #
17
+ RSpec::Matchers.define :be_from do |expected_options|
18
+ match do |mailer|
19
+ bool_arr = [(mailer_from_email(mailer) == expected_options[:email] if expected_options[:email]),
20
+ (mailer_from_name(mailer) == expected_options[:name] if expected_options[:name])]
21
+ !bool_arr.compact.any? {|i| i == false}
22
+ end
23
+
24
+ failure_message_for_should do |actual|
25
+ <<-MESSAGE.strip_heredoc
26
+ Expected from vars: #{mailer_from_email(mailer).inspect} to be: #{expected_options.inspect}.
27
+ MESSAGE
28
+ end
29
+
30
+ failure_message_for_should_not do |actual|
31
+ <<-MESSAGE.strip_heredoc
32
+ Expected from vars: #{mailer_from_email(mailer).inspect} to not be: #{expected_options.inspect}.
33
+ MESSAGE
34
+ end
35
+
36
+ description do
37
+ "be the same from vars as #{expected_options.inspect}"
38
+ end
39
+
40
+ def mailer_from_email(mailer)
41
+ mailer.message['from_email']
42
+ end
43
+
44
+ def mailer_from_name(mailer)
45
+ mailer.message['from_name']
46
+ end
47
+ end
@@ -0,0 +1,49 @@
1
+ # Public: Matcher for asserting specific merge vars content contains something.
2
+ #
3
+ # expected_data - Data to look for in the specified merge var key.
4
+ #
5
+ # WelcomeMailer is an instance of MandrillMailler::TemplateMailer
6
+ #
7
+ # let(:user) { FactoryGirl.create(:user) }
8
+ # let(:mailer) { WelcomeMailer.welcome_registered(user) }
9
+ # it 'has the correct data' do
10
+ # expect(mailer).to include_merge_var_content(user.email)
11
+ # end
12
+ #
13
+ # Returns true or an error message on failure
14
+ #
15
+ RSpec::Matchers.define :include_merge_var_content do |expected_data|
16
+ match do |actual|
17
+ has_match = false
18
+
19
+ matches = merge_vars_from(actual).find do |hash|
20
+ hash['name'] == 'CONTENT'
21
+ end
22
+
23
+ has_match = matches['content'].include?(expected_data)
24
+
25
+ has_match
26
+ end
27
+
28
+ failure_message do |actual|
29
+ <<-MESSAGE.strip_heredoc
30
+ Expected merge variables: #{merge_vars_from(actual).inspect} to include content: #{expected_data}.
31
+ MESSAGE
32
+ end
33
+
34
+ failure_message_when_negated do |actual|
35
+ <<-MESSAGE.strip_heredoc
36
+ Expected merge variables: #{merge_vars_from(actual).inspect} to not include content: #{expected_data}.
37
+ MESSAGE
38
+ end
39
+
40
+ description do
41
+ "include merge var content: #{expected_data}"
42
+ end
43
+
44
+ def merge_vars_from(mailer)
45
+ # Merge vars are in format:
46
+ # [{"name"=>"USER_EMAIL", "content"=>"zoila@homenick.name"},{"name"=>"USER_NAME", "content"=>"Bob"}]
47
+ mailer.message['global_merge_vars']
48
+ end
49
+ end
@@ -0,0 +1,48 @@
1
+ # Public: Matcher for asserting merge vars have certain data.
2
+ #
3
+ # expected_data - Data to compare to the merge vars
4
+ #
5
+ # WelcomeMailer is an instance of MandrillMailler::TemplateMailer
6
+ #
7
+ # let(:user) { create(:user) }
8
+ # let(:mailer) { WelcomeMailer.welcome_registered(user) }
9
+ # it 'has the correct data' do
10
+ # expect(mailer).to have_merge_data('USER_EMAIL' => user.email)
11
+ # end
12
+ #
13
+ # Returns true or an error message on failure
14
+ #
15
+ RSpec::Matchers.define :have_merge_data do |expected_data|
16
+ match do |actual|
17
+ has_match = false
18
+ expected_data.each_pair do |key, value|
19
+ has_match = merge_vars_from(actual).any? do |obj|
20
+ obj['name'] == key && obj['content'] == value
21
+ end
22
+ break unless has_match
23
+ end
24
+ has_match
25
+ end
26
+
27
+ failure_message_for_should do |actual|
28
+ <<-MESSAGE.strip_heredoc
29
+ Expected merge variables: #{merge_vars_from(actual).inspect} to include data: #{expected_data.inspect} but it does not.
30
+ MESSAGE
31
+ end
32
+
33
+ failure_message_for_should_not do |actual|
34
+ <<-MESSAGE.strip_heredoc
35
+ Expected merge variables: #{merge_vars_from(actual).inspect} to not include data: #{expected_data.inspect} but it does.
36
+ MESSAGE
37
+ end
38
+
39
+ description do
40
+ "be the same data as #{expected_data.inspect}"
41
+ end
42
+
43
+ def merge_vars_from(mailer)
44
+ # Merge vars are in format:
45
+ # [{"name"=>"USER_EMAIL", "content"=>"zoila@homenick.name"},{"name"=>"USER_NAME", "content"=>"Bob"}]
46
+ mailer.message['global_merge_vars']
47
+ end
48
+ end
@@ -0,0 +1,39 @@
1
+ # Public: Matcher for asserting subject
2
+ #
3
+ # expected_subject: - Expected subject of email
4
+ #
5
+ # WelcomeMailer is an instance of MandrillMailler::TemplateMailer
6
+ #
7
+ # let(:user) { create(:user) }
8
+ # let(:mailer) { WelcomeMailer.welcome_registered(user) }
9
+ # it 'has the correct data' do
10
+ # expect(mailer).to have_subject('Welcome Subscriber')
11
+ # end
12
+ #
13
+ # Returns true or an error message on failure
14
+ #
15
+ RSpec::Matchers.define :have_subject do |expected_subject|
16
+ match do |mailer|
17
+ mailer_subject(mailer) == expected_subject
18
+ end
19
+
20
+ failure_message_for_should do |actual|
21
+ <<-MESSAGE.strip_heredoc
22
+ Expected subject: #{mailer_subject(mailer).inspect} to be: #{expected_subject.inspect}.
23
+ MESSAGE
24
+ end
25
+
26
+ failure_message_for_should_not do |actual|
27
+ <<-MESSAGE.strip_heredoc
28
+ Expected subject: #{mailer_subject(mailer).inspect} to not be: #{expected_subject.inspect}.
29
+ MESSAGE
30
+ end
31
+
32
+ description do
33
+ "be the same subject as #{expected_subject.inspect}"
34
+ end
35
+
36
+ def mailer_subject(mailer)
37
+ mailer.message['subject']
38
+ end
39
+ end
@@ -0,0 +1,39 @@
1
+ # Public: Matcher for asserting template
2
+ #
3
+ # template_name: - name of template in mandrill the mailer sends to
4
+ #
5
+ # WelcomeMailer is an instance of MandrillMailler::TemplateMailer
6
+ #
7
+ # let(:user) { create(:user) }
8
+ # let(:mailer) { WelcomeMailer.welcome_registered(user) }
9
+ # it 'has the correct data' do
10
+ # expect(mailer).to use_template('Welcome Subscriber')
11
+ # end
12
+ #
13
+ # Returns true or an error message on failure
14
+ #
15
+ RSpec::Matchers.define :use_template do |expected_template|
16
+ match do |mailer|
17
+ mailer_template(mailer) == expected_template
18
+ end
19
+
20
+ failure_message_for_should do |actual|
21
+ <<-MESSAGE.strip_heredoc
22
+ Expected template: #{mailer_template(mailer).inspect} to be: #{expected_template.inspect}.
23
+ MESSAGE
24
+ end
25
+
26
+ failure_message_for_should_not do |actual|
27
+ <<-MESSAGE.strip_heredoc
28
+ Expected template: #{mailer_template(mailer).inspect} to not be: #{expected_template.inspect}.
29
+ MESSAGE
30
+ end
31
+
32
+ description do
33
+ "be the same template as #{expected_template.inspect}"
34
+ end
35
+
36
+ def mailer_template(mailer)
37
+ mailer.template_name
38
+ end
39
+ end
@@ -0,0 +1,63 @@
1
+ # Public: Matcher for asserting to email
2
+ #
3
+ # expected_to - The Hash options used to designate to whom the email is sent, options are optional (default: {}):
4
+ # :name - Name of reciever
5
+ # :email - email of reciever
6
+ #
7
+ # WelcomeMailer is an instance of MandrillMailler::TemplateMailer
8
+ #
9
+ # let(:user) { create(:user) }
10
+ # let(:mailer) { WelcomeMailer.welcome_registered(user) }
11
+ # it 'has the correct data' do
12
+ # expect(mailer).to send_email_to(email: user.email, name: 'Code School Customer')
13
+ # end
14
+ #
15
+ # it 'has the correct to name' do
16
+ # expect(mailer).to send_email_to(name: 'Code School Customer')
17
+ # end
18
+ #
19
+ # it 'has the correct email' do
20
+ # expect(mailer).to send_email_to(email: user.email')
21
+ # end
22
+ #
23
+ # Returns true or an error message on failure
24
+ #
25
+ RSpec::Matchers.define :send_email_to do |expected_to|
26
+ match do |mailer|
27
+ to_arr = mailer_to_data(mailer)
28
+ opts_found = false
29
+ expected_to.each_pair do |key, value|
30
+ opts_found = to_arr.any? do |to_opt|
31
+ to_opt.symbolize_keys!
32
+ bool_arr = [
33
+ (to_opt[:email] == value if key.to_sym == :email),
34
+ (to_opt[:name] == value if key.to_sym == :name)
35
+ ]
36
+ !bool_arr.compact.any? {|i| i == false}
37
+ end
38
+ break unless opts_found
39
+ end
40
+ opts_found
41
+ end
42
+
43
+ failure_message_for_should do |actual|
44
+ <<-MESSAGE.strip_heredoc
45
+ Expected to variables: #{mailer_to_data(mailer).inspect} to include data: #{expected_to.inspect} but it does not.
46
+ MESSAGE
47
+ end
48
+
49
+ failure_message_for_should_not do |actual|
50
+ <<-MESSAGE.strip_heredoc
51
+ Expected to variables: #{mailer_to_data(mailer).inspect} to not include data: #{expected_to.inspect} but it does.
52
+ MESSAGE
53
+ end
54
+
55
+ description do
56
+ "be the same to data as #{expected_to.inspect}"
57
+ end
58
+
59
+ def mailer_to_data(mailer)
60
+ # {email: 'user@email.com', name: 'larry'}
61
+ mailer.message['to']
62
+ end
63
+ end
@@ -1,3 +1,3 @@
1
1
  module MandrillMailer
2
- VERSION = "1.0.4"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mandrill_mailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Rensel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-25 00:00:00.000000000 Z
11
+ date: 2015-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -100,6 +100,13 @@ files:
100
100
  - lib/mandrill_mailer/mock.rb
101
101
  - lib/mandrill_mailer/offline.rb
102
102
  - lib/mandrill_mailer/railtie.rb
103
+ - lib/mandrill_mailer/rspec_helper.rb
104
+ - lib/mandrill_mailer/rspec_helpers/from_matcher.rb
105
+ - lib/mandrill_mailer/rspec_helpers/merge_var_content_matcher.rb
106
+ - lib/mandrill_mailer/rspec_helpers/merge_var_matcher.rb
107
+ - lib/mandrill_mailer/rspec_helpers/subject_matcher.rb
108
+ - lib/mandrill_mailer/rspec_helpers/template_matcher.rb
109
+ - lib/mandrill_mailer/rspec_helpers/to_email_matcher.rb
103
110
  - lib/mandrill_mailer/template_mailer.rb
104
111
  - lib/mandrill_mailer/version.rb
105
112
  - mandrill_mailer.gemspec
@@ -130,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
137
  version: '0'
131
138
  requirements: []
132
139
  rubyforge_project:
133
- rubygems_version: 2.4.8
140
+ rubygems_version: 2.4.6
134
141
  signing_key:
135
142
  specification_version: 4
136
143
  summary: Transactional Mailer for Mandrill