bjornblomqvist-emailer 0.1.13 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.13
1
+ 0.1.15
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{emailer}
8
- s.version = "0.1.13"
8
+ s.version = "0.1.15"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Erik Hansson", "Bjorn Blomqvist"]
@@ -31,12 +31,14 @@ Gem::Specification.new do |s|
31
31
  "lib/emailer/mock_smtp_facade.rb",
32
32
  "lib/emailer/smtp_facade.rb",
33
33
  "lib/emailer/string_utilities.rb",
34
+ "lib/emailer/testing_middleware.rb",
34
35
  "lib/emailer/tofile_smtp_facade.rb",
35
36
  "spec/emailer/authsmtp_facade_spec.rb",
36
37
  "spec/emailer/logger_smtp_facade_spec.rb",
37
38
  "spec/emailer/mail_queue_spec.rb",
38
39
  "spec/emailer/mock_smtp_facade_spec.rb",
39
40
  "spec/emailer/smtp_facade_spec.rb",
41
+ "spec/emailer/testing_middlerware_spec.rb",
40
42
  "spec/emailer/tofile_smtp_facade_spec.rb",
41
43
  "spec/spec.opts",
42
44
  "spec/spec_helper.rb"
@@ -53,6 +55,7 @@ Gem::Specification.new do |s|
53
55
  "spec/emailer/mail_queue_spec.rb",
54
56
  "spec/emailer/mock_smtp_facade_spec.rb",
55
57
  "spec/emailer/smtp_facade_spec.rb",
58
+ "spec/emailer/testing_middlerware_spec.rb",
56
59
  "spec/emailer/tofile_smtp_facade_spec.rb",
57
60
  "spec/spec_helper.rb"
58
61
  ]
@@ -5,4 +5,6 @@ require File.join File.dirname(__FILE__), 'emailer/mail_queue'
5
5
  require File.join File.dirname(__FILE__), 'emailer/string_utilities'
6
6
  require File.join File.dirname(__FILE__), 'emailer/mock_smtp_facade'
7
7
  require File.join File.dirname(__FILE__), 'emailer/logger_smtp_facade'
8
- require File.join File.dirname(__FILE__), 'emailer/tofile_smtp_facade'
8
+ require File.join File.dirname(__FILE__), 'emailer/tofile_smtp_facade'
9
+ require File.join File.dirname(__FILE__), 'emailer/testing_middleware'
10
+
@@ -49,33 +49,10 @@ module Emailer
49
49
  end
50
50
 
51
51
  def get_url_for uuidString
52
- return "/getemail/"+uuidString
52
+ TestingMiddleware.testing_path+uuidString
53
53
  end
54
54
  end
55
55
 
56
- class TestingMiddleware
57
-
58
- def initialize(app)
59
- @app = app
60
- end
61
-
62
- def call(env)
63
- if env["PATH_INFO"].index("/getemail/")
64
-
65
- uuid = env["PATH_INFO"].sub("/getemail/".length)
66
-
67
- return [200, {"Content-Type" => "text/plain"},['Emailer::SmtpFacade.default is not a MockSmtpFacade']] unless
68
- Emailer::SmtpFacade.default.instance_of? Emailer::MockSmtpFacade
69
-
70
- return [200, {"Content-Type" => "text/plain"},['No email sent']] if Emailer::SmtpFacade.default.sent.count == 0
71
-
72
- return [200, {"Content-Type" => "text/html"}, [Emailer::SmtpFacade.default.sent[uuid][:body].to_s]]
73
- else
74
- @app.call env
75
- end
76
- end
77
-
78
- end
79
56
  end
80
57
 
81
58
 
@@ -0,0 +1,38 @@
1
+ module Emailer
2
+
3
+
4
+ class TestingMiddleware
5
+
6
+ class << self
7
+ attr_accessor :testing_path
8
+ def testing_path
9
+ @testing_path ||= "/get_email_just_for_test/"
10
+ end
11
+ end
12
+
13
+
14
+ def initialize(app)
15
+ @app = app
16
+ end
17
+
18
+ def call(env)
19
+ if env["PATH_INFO"].index(TestingMiddleware.testing_path)
20
+
21
+ uuid = env["PATH_INFO"][TestingMiddleware.testing_path.length..-1]
22
+
23
+ return [200, {"Content-Type" => "text/plain"},['Emailer::SmtpFacade.default is not a MockSmtpFacade']] unless
24
+ Emailer::SmtpFacade.default.instance_of? Emailer::MockSmtpFacade
25
+
26
+ return [200, {"Content-Type" => "text/plain"},['No email sent']] unless Emailer::SmtpFacade.default.sent.count > 0
27
+
28
+ return [200, {"Content-Type" => "text/plain"},['No email with that ID']] unless Emailer::SmtpFacade.default.sent[uuid]
29
+
30
+ return [200, {"Content-Type" => "text/html"}, [Emailer::SmtpFacade.default.sent[uuid][:body].to_s]]
31
+ end
32
+
33
+ @app.call env
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -70,26 +70,6 @@ module Emailer
70
70
 
71
71
  end
72
72
  end
73
-
74
-
75
- describe :last_email_sent_url do
76
- it 'Should return url to last email sent' do
77
- smtp = LoggerSmtpFacade.new :log_file => TEST_LOG_FILE
78
-
79
- email = {
80
- :to => "test@bits2life.com",
81
- :from => "test2@bits2life.com",
82
- :subject => "This is a test 4",
83
- :body => "Test body"
84
- }
85
-
86
- smtp.open do
87
- smtp.send_mail email
88
- end
89
-
90
- smtp.last_email_sent_url.should == "/getemail/"+smtp.sent.keys.last
91
- end
92
- end
93
73
 
94
74
 
95
75
 
@@ -23,6 +23,26 @@ module Emailer
23
23
 
24
24
  end
25
25
  end
26
+
27
+ describe :last_email_sent_url do
28
+ it 'Should return url to last email sent' do
29
+ smtp = MockSmtpFacade.new
30
+
31
+ email = {
32
+ :to => "test@bits2life.com",
33
+ :from => "test2@bits2life.com",
34
+ :subject => "This is a test 4",
35
+ :body => "Test body"
36
+ }
37
+
38
+ smtp.open do
39
+ smtp.send_mail email
40
+ end
41
+
42
+ smtp.last_email_sent_url.should == TestingMiddleware.testing_path+smtp.sent.keys.last
43
+ end
44
+ end
26
45
 
27
46
  end
47
+
28
48
  end
@@ -0,0 +1,72 @@
1
+ require File.join(File.dirname(__FILE__), "../spec_helper")
2
+
3
+
4
+ class Temp
5
+
6
+ def call bla
7
+ "Temp was called"
8
+ end
9
+ end
10
+
11
+
12
+ module Emailer
13
+ describe TestingMiddleware do
14
+
15
+ EMAIL = {
16
+ :to => "test@test.se",
17
+ :from => "test@test.se",
18
+ :subject => "What subjcet ?",
19
+ :body => "<html>"
20
+ }
21
+
22
+ before :each do
23
+ Emailer::SmtpFacade.default = Emailer::MockSmtpFacade.new
24
+ end
25
+
26
+ describe :call do
27
+
28
+ it 'Should return an email when given the correct enviorment url' do
29
+
30
+ Emailer::SmtpFacade.default.open do |smtp|
31
+ smtp.send_html(
32
+ EMAIL
33
+ )
34
+ end
35
+
36
+ tm = TestingMiddleware.new(Temp.new)
37
+ tm.call("PATH_INFO" => Emailer::SmtpFacade.default.last_email_sent_url)[2][0].should == EMAIL[:body]
38
+
39
+ end
40
+
41
+ it 'Should return "No email sent" if we havent sent any emails yet' do
42
+
43
+ tm = TestingMiddleware.new(Temp.new)
44
+ tm.call("PATH_INFO" => Emailer::TestingMiddleware.testing_path)[2][0].should == "No email sent"
45
+
46
+ end
47
+
48
+ it 'Should return "No email with that ID" if we supplie the wrong id' do
49
+
50
+ Emailer::SmtpFacade.default.open do |smtp|
51
+ smtp.send_html(
52
+ EMAIL
53
+ )
54
+ end
55
+
56
+ tm = TestingMiddleware.new(Temp.new)
57
+ tm.call("PATH_INFO" => Emailer::SmtpFacade.default.get_url_for("ueoueo"))[2][0].should == "No email with that ID"
58
+
59
+ end
60
+
61
+ it 'Should pass on the call if the url dosent match' do
62
+ tm = TestingMiddleware.new(Temp.new)
63
+ tm.call("PATH_INFO" => "/").should == "Temp was called"
64
+ end
65
+
66
+ end
67
+
68
+
69
+
70
+ end
71
+ end
72
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bjornblomqvist-emailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Hansson
@@ -67,12 +67,14 @@ files:
67
67
  - lib/emailer/mock_smtp_facade.rb
68
68
  - lib/emailer/smtp_facade.rb
69
69
  - lib/emailer/string_utilities.rb
70
+ - lib/emailer/testing_middleware.rb
70
71
  - lib/emailer/tofile_smtp_facade.rb
71
72
  - spec/emailer/authsmtp_facade_spec.rb
72
73
  - spec/emailer/logger_smtp_facade_spec.rb
73
74
  - spec/emailer/mail_queue_spec.rb
74
75
  - spec/emailer/mock_smtp_facade_spec.rb
75
76
  - spec/emailer/smtp_facade_spec.rb
77
+ - spec/emailer/testing_middlerware_spec.rb
76
78
  - spec/emailer/tofile_smtp_facade_spec.rb
77
79
  - spec/spec.opts
78
80
  - spec/spec_helper.rb
@@ -109,5 +111,6 @@ test_files:
109
111
  - spec/emailer/mail_queue_spec.rb
110
112
  - spec/emailer/mock_smtp_facade_spec.rb
111
113
  - spec/emailer/smtp_facade_spec.rb
114
+ - spec/emailer/testing_middlerware_spec.rb
112
115
  - spec/emailer/tofile_smtp_facade_spec.rb
113
116
  - spec/spec_helper.rb