smtp_url 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -4,4 +4,5 @@ gem 'activesupport'
4
4
 
5
5
  group :test do
6
6
  gem "rspec"
7
+ gem "mocha"
7
8
  end
data/Readme.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # SmtpURL setup
2
2
 
3
3
  This gem allows you to configure your smtp settings for mail and
4
- action mailer using a url. The intention is to keep those settings
5
- out of your code and allow easily setting them with an environment
4
+ action mailer using a url. The intention is to keep those settings
5
+ out of your code and allow easily setting them with an environment
6
6
  variable.
7
7
 
8
8
  ## Installation
@@ -13,7 +13,10 @@ Add to your `Gemfile`:
13
13
 
14
14
  ## Usage
15
15
 
16
- Use a URL like so:
16
+ If you are in Rails it will automatically setup your email settings if
17
+ you have the SMTP_URL enviroment variable set.
18
+
19
+ Use a SMTP_URL that looks like so:
17
20
 
18
21
  smtp://<user>:<password>@<hostname>:<port>/?<options>
19
22
 
@@ -25,7 +28,7 @@ both the domain and authentication options. For example:
25
28
  Only `hostname`, is required. Everything else is optional. It will
26
29
  default to port 25 if it is not specified.
27
30
 
28
- Set the URL in an enviroment variable in your server setup:
31
+ Set SMTP_URL in your server setup like so:
29
32
 
30
33
  export SMTP_URL=smtp://user:secret@mailserver:587/?domain=test.com
31
34
 
@@ -34,7 +37,7 @@ Set the URL in an enviroment variable in your server setup:
34
37
  Can be very useful in development when paired with something like
35
38
  [Mailcatcher](http://mailcatcher.me/):
36
39
 
37
- export SMTP_URL=smtp://127.0.0.1:1025
40
+ export SMTP_URL=smtp://localhost:1025
38
41
 
39
42
 
40
43
  ## License
@@ -1,6 +1,12 @@
1
+ require "smtp_url/parser"
2
+
1
3
  module SmtpURL
2
4
  class Railtie < Rails::Railtie
3
- config.action_mailer.delivery_method = :smtp
4
- config.action_mailer.smtp_settings = SmtpURL::Parser.new(ENV["SMTP_URL"]).parse
5
+ if ENV["SMTP_URL"]
6
+ config.action_mailer.delivery_method = :smtp
7
+ config.action_mailer.smtp_settings = SmtpURL::Parser.new(ENV["SMTP_URL"]).parse
8
+ else
9
+ Rails.logger.warn "SmtpURL did not setup your email delivery because the SMTP_URL env var was missing"
10
+ end
5
11
  end
6
12
  end
@@ -1,3 +1,3 @@
1
1
  module SmtpURL
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -1,3 +1,4 @@
1
+ require 'spec_helper'
1
2
  require 'smtp_url/invalid_url_exception'
2
3
  require 'smtp_url/parser'
3
4
 
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ module Rails
4
+ class Railtie
5
+ def self.config
6
+ Config.new
7
+ end
8
+
9
+ def self.mailer_config
10
+ MailerConfig.new
11
+ end
12
+ end
13
+
14
+ class Config
15
+ def action_mailer
16
+ MailerConfig.new
17
+ end
18
+ end
19
+
20
+ class MailerConfig
21
+ def deliver_method=(method)
22
+ end
23
+
24
+ def smtp_settings=(hash)
25
+ end
26
+ end
27
+
28
+ class Logger
29
+ def warn(message)
30
+ end
31
+ end
32
+
33
+ def self.logger
34
+ Logger.new
35
+ end
36
+ end
37
+
38
+ require 'smtp_url/railtie'
39
+
40
+ describe SmtpURL::Railtie do
41
+
42
+ it "should log a warning if SMTP_URL is not set" do
43
+ Rails::Logger.any_instance.expects(:warn).with('SmtpURL did not setup your email delivery because the SMTP_URL env var was missing')
44
+ load 'smtp_url/railtie.rb'
45
+ end
46
+
47
+ it "should setup action_mailer settings when SMTP_URL is set" do
48
+ ENV['SMTP_URL'] = 'smtp://localhost:1025'
49
+ Rails::MailerConfig.any_instance.expects(:delivery_method=).with(:smtp)
50
+ Rails::MailerConfig.any_instance.expects(:smtp_settings=)
51
+ load 'smtp_url/railtie.rb'
52
+ end
53
+ end
54
+
55
+
56
+
57
+
58
+
@@ -0,0 +1,11 @@
1
+ require "rubygems"
2
+ require "mocha/api"
3
+ require "rspec"
4
+
5
+ RSpec.configure do |config|
6
+ config.treat_symbols_as_metadata_keys_with_true_values = true
7
+ config.run_all_when_everything_filtered = true
8
+ config.filter_run :focus
9
+ config.mock_framework = :mocha
10
+ config.order = 'random'
11
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smtp_url
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-14 00:00:00.000000000 Z
12
+ date: 2012-12-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -45,6 +45,8 @@ files:
45
45
  - lib/smtp_url/version.rb
46
46
  - smtp_url.gemspec
47
47
  - spec/smtp_url/parser_spec.rb
48
+ - spec/smtp_url/railtie_spec.rb
49
+ - spec/spec_helper.rb
48
50
  homepage: https://github.com/danielfarrell/smtp_url
49
51
  licenses: []
50
52
  post_install_message:
@@ -71,3 +73,6 @@ specification_version: 3
71
73
  summary: Convert an smtp url into mail/action mailer friendly hashes
72
74
  test_files:
73
75
  - spec/smtp_url/parser_spec.rb
76
+ - spec/smtp_url/railtie_spec.rb
77
+ - spec/spec_helper.rb
78
+ has_rdoc: