default-url-options-for-mailers 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown ADDED
@@ -0,0 +1,66 @@
1
+ ## Overview
2
+ `default-url-options-for-mailers` allows us to set or infer `ActionController::Base.default_url_options` within the context of a `ActionMailer` deliver event.
3
+
4
+ This functionality is inspired by [How I Learned to Stop Hating and Love Action Mailer](http://pivotallabs.com/users/nick/blog/articles/281-how-i-learned-to-stop-hating-and-love-action-mailer "nick - How I Learned to Stop Hating and Love Action Mailer"). Quoting from that post heavily, `ActionMailer` makes it difficult to generate URL's. It's common enough when sending an email that it includes a link. But `ActionMailer`, by default, gives you no access to `url_for` or named routes. One solution to this is to manually set `ActionController::Base.default_url_options`, but this is a global change and would affect all Controller actions. Also, it is often preferable to have these values be inferred from the local environment. `default-url-options-for-mailers` allows for setting or inferring these values within the context of a mail-sending action.
5
+
6
+ ## Installation
7
+ Install `default-url-options-for-mailers` as a gem.
8
+
9
+ ## Usage
10
+ Here is a sample initializer.
11
+
12
+ # your_rails_app/config/initializers/pivotal_initializers.rb
13
+ PivotalCore::Initializer::DefaultUrlOptionsForMailers.run do |config|
14
+ # *** Use this line to automatically derive protocol/host/port using incoming rails request:
15
+ # PivotalCore::Initializer::DefaultUrlOptionsForMailers.run
16
+ # config.action_controller.default_url_options_for_mailers = :infer_url_options
17
+
18
+ # *** Use this line to explicitly set protocol/host/port:
19
+ # config.action_controller.default_url_options_for_mailers = { :protocol => "http", :host => "example.com", :port => 3333 }
20
+
21
+ # *** Comment out both lines to disable any default URL option functionality for mailers.
22
+
23
+ # *** NOTE: ActionMailer::Base.default_url_options always takes precedence over this facility and if *any* options are
24
+ # *** set there, default_url_options_for_mailers does nothing.
25
+ end
26
+
27
+ ## Requirements
28
+ To initialize properly, this gem requires Rails 2.3.8 or above.
29
+
30
+ ## Running Tests and Build Dependencies
31
+ To run the tests and/or build the gem:
32
+
33
+ gem install jeweler -v1.5.1 --no-rdoc --no-ri
34
+ rake install_test_gems
35
+
36
+ To run tests:
37
+
38
+ rake
39
+ # or
40
+ rake spec
41
+
42
+ ## MIT License
43
+
44
+ Copyright (c) 2010 Pivotal Labs (www.pivotallabs.com)
45
+ Contact email: info@pivotallabs.com
46
+
47
+ Permission is hereby granted, free of charge, to any person
48
+ obtaining a copy of this software and associated documentation
49
+ files (the "Software"), to deal in the Software without
50
+ restriction, including without limitation the rights to use,
51
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
52
+ copies of the Software, and to permit persons to whom the
53
+ Software is furnished to do so, subject to the following
54
+ conditions:
55
+
56
+ The above copyright notice and this permission notice shall be
57
+ included in all copies or substantial portions of the Software.
58
+
59
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
60
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
61
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
62
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
63
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
64
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
65
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
66
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,70 @@
1
+ module PivotalCore
2
+ module RailsCoreExtensions
3
+ module DefaultUrlOptionsForMailers
4
+ module ActionController
5
+ def self.included(ac)
6
+ ac.module_eval do
7
+ include InstanceMethods
8
+ around_filter :set_default_url_options_for_mailers
9
+ end
10
+ end
11
+
12
+ module InstanceMethods
13
+ def set_default_url_options_for_mailers
14
+ save_current_url_options
15
+ begin
16
+ new_url_options = calculate_new_url_options
17
+ ::ActionMailer::Base.class_eval { self.default_url_options = new_url_options if default_url_options.empty? }
18
+
19
+ yield
20
+ ensure
21
+ restore_previous_url_options
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def calculate_new_url_options
28
+ if ::ActionController::Base.default_url_options_for_mailers.is_a?(Hash)
29
+ returning(::ActionController::Base.default_url_options_for_mailers) do |url_options|
30
+ url_options.delete(:port) if standard_port?(self.request, url_options[:port])
31
+ end
32
+ elsif ::ActionController::Base.default_url_options_for_mailers == :infer_url_options
33
+ inferred_url_options_for(self.request)
34
+ else
35
+ raise "Invalid option for default_url_options_for_mailers: #{::ActionController::Base.default_url_options_for_mailers}"
36
+ end
37
+ end
38
+
39
+ def inferred_url_options_for(request)
40
+ returning({ :protocol => request.protocol, :host => request.host }) do |url_options|
41
+ url_options[:port] = request.port unless standard_port?(request, request.port)
42
+ end
43
+ end
44
+
45
+ def standard_port?(request, port)
46
+ port == request.standard_port
47
+ end
48
+
49
+ def save_current_url_options
50
+ ::ActionMailer::Base.class_eval do
51
+ @old_default_url_options = default_url_options.clone
52
+ end
53
+ end
54
+
55
+ def restore_previous_url_options
56
+ ::ActionMailer::Base.class_eval do
57
+ [:host, :port, :protocol].each do |key|
58
+ if @old_default_url_options.key?(key)
59
+ default_url_options[key] = @old_default_url_options[key]
60
+ else
61
+ default_url_options.delete(key)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,44 @@
1
+ module PivotalCore
2
+ class Configuration
3
+ def action_controller
4
+ @action_controller ||= Rails::OrderedOptions.new
5
+ end
6
+
7
+ def active_record
8
+ @active_record ||= Rails::OrderedOptions.new
9
+ end
10
+ end
11
+
12
+ class Initializer
13
+ class DefaultUrlOptionsForMailers
14
+ def self.run
15
+ configuration = Configuration.new
16
+ yield(configuration) if block_given?
17
+
18
+ new(configuration).process
19
+ end
20
+
21
+ def initialize(configuration)
22
+ @configuration = configuration
23
+ end
24
+
25
+ def process
26
+ process_action_controller_configuration(@configuration)
27
+ end
28
+
29
+ private
30
+
31
+ def process_action_controller_configuration(configuration)
32
+ if configuration.action_controller.default_url_options_for_mailers
33
+ ActionController::Base.class_eval do
34
+ include PivotalCore::RailsCoreExtensions::DefaultUrlOptionsForMailers::ActionController
35
+ end
36
+ ActionController::Base.instance_eval do
37
+ cattr_accessor :default_url_options_for_mailers
38
+ self.default_url_options_for_mailers = configuration.action_controller.default_url_options_for_mailers
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,2 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'default_url_options_for_mailers','default_url_options_for_mailers'))
2
+ require File.expand_path(File.join(File.dirname(__FILE__),'default_url_options_for_mailers','initializer'))
@@ -0,0 +1,164 @@
1
+ require File.join(File. dirname(__FILE__), "/spec_helper")
2
+
3
+ class DefaultUrlOptionsForMailersController < ApplicationController
4
+ around_filter :set_default_url_options_for_mailers
5
+
6
+ # def rescue_action(e) ; raise e; end
7
+ def index
8
+ DefaultUrlOptionsForMailersMailer.deliver_mail_with_url
9
+ head :ok
10
+ end
11
+ end
12
+
13
+ class DefaultUrlOptionsForMailersMailer < ActionMailer::Base
14
+ def mail_with_url
15
+ end
16
+ end
17
+
18
+ shared_examples_for "a good URL options citizen" do
19
+ it "should preserve any pre-existing default_url_options which were explicitly set" do
20
+ ActionMailer::Base.default_url_options[:protocol] = "https://"
21
+ ActionMailer::Base.default_url_options[:host] = "mycustomhost"
22
+ ActionMailer::Base.default_url_options[:port] = 1234
23
+ execute_request(true, "NOTmycustomhost", "9999")
24
+ latest_mail_should_include_link("https://mycustomhost:1234/")
25
+ end
26
+
27
+ it "should not overwrite any options when default_url_options are partially defined" do
28
+ ActionMailer::Base.default_url_options[:protocol] = "https://"
29
+ ActionMailer::Base.default_url_options[:host] = "mycustomhost"
30
+ execute_request(true, "NOTmycustomhost", "9999")
31
+ latest_mail_should_include_link("https://mycustomhost/")
32
+ end
33
+
34
+ it "should keep port blank if originally blank" do
35
+ ActionMailer::Base.default_url_options.key?(:port).should be_false
36
+ execute_request(false, "host", "800")
37
+ ActionMailer::Base.default_url_options.key?(:port).should be_false
38
+ end
39
+ end
40
+
41
+ describe "default_url_options_for_mailer" do
42
+ include ActionController::TestProcess
43
+
44
+ before(:each) do
45
+ ActionMailer::Base.default_url_options = {}
46
+ end
47
+
48
+ context "when not used (outside of a request/controller)" do
49
+ it "should default to mailing from existing default_url_options" do
50
+ ActionMailer::Base.default_url_options[:protocol] = "https://"
51
+ ActionMailer::Base.default_url_options[:host] = "mycustomhost"
52
+ ActionMailer::Base.default_url_options[:port] = 1234
53
+ DefaultUrlOptionsForMailersMailer.deliver_mail_with_url
54
+ latest_mail_should_include_link("https://mycustomhost:1234/")
55
+ end
56
+ end
57
+
58
+ context "when explicitly disabled" do
59
+ before(:each) do
60
+ # configure_default_url_options_for_mailers_with(nil)
61
+ PivotalCore::Initializer::DefaultUrlOptionsForMailers.run { |config| config.action_controller.default_url_options_for_mailers = options }
62
+ @controller = DefaultUrlOptionsForMailersController.new
63
+ end
64
+
65
+ it "should default to mailing from existing default_url_options" do
66
+ ActionMailer::Base.default_url_options[:protocol] = "https://"
67
+ ActionMailer::Base.default_url_options[:host] = "mycustomhost"
68
+ ActionMailer::Base.default_url_options[:port] = 1234
69
+ execute_request(false, "host", "800")
70
+ latest_mail_should_include_link("https://mycustomhost:1234/")
71
+ end
72
+ end
73
+
74
+ context "when set to an explicit hash" do
75
+ before(:each) do
76
+ configure_default_url_options_for_mailers_with({ :host => "example.com", :protocol => "http", :port => 4217 })
77
+ end
78
+
79
+ it_should_behave_like "a good URL options citizen"
80
+
81
+ it "should pass the specified host/port/protocols to all associated mailers" do
82
+ mail_sent_from_domain_should_include_link(false, "host", "3333", "http://example.com:4217/")
83
+ end
84
+
85
+ it "should drop default port" do
86
+ ActionController::Base.default_url_options_for_mailers[:port] = 80
87
+ mail_sent_from_domain_should_include_link(false, "host", "80", "http://example.com/")
88
+ end
89
+ end
90
+
91
+ context "when set to infer URL options" do
92
+ before(:each) do
93
+ configure_default_url_options_for_mailers_with(:infer_url_options)
94
+ end
95
+
96
+ it_should_behave_like "a good URL options citizen"
97
+
98
+ it "should pass host/port/protocols from the request to all associated mailers" do
99
+ mail_sent_from_domain_should_include_link(false, "host", "3333", "http://host:3333/")
100
+ end
101
+
102
+ it "should drop default port" do
103
+ mail_sent_from_domain_should_include_link(false, "host", "80", "http://host/")
104
+ end
105
+
106
+ it "should handle SSL" do
107
+ mail_sent_from_domain_should_include_link(true, "host", "3333", "https://host:3333/")
108
+ end
109
+
110
+ it "should handle SSL with default port" do
111
+ mail_sent_from_domain_should_include_link(true, "host", "443", "https://host/")
112
+ end
113
+ end
114
+
115
+ context "when set to some garbage" do
116
+ before(:each) do
117
+ configure_default_url_options_for_mailers_with("bad data here")
118
+ end
119
+
120
+ after(:each) do
121
+ # Clean up so as not to affect later tests. This is a class-level config option, after all.
122
+ configure_default_url_options_for_mailers_with(nil)
123
+ end
124
+
125
+ it "should raise an exception (resulting in a non-successful response)" do
126
+ lambda { execute_request(true, "ahost", "2342") }.should raise_error
127
+ @response.should be_error
128
+ end
129
+ end
130
+
131
+ private
132
+
133
+ def configure_default_url_options_for_mailers_with(options)
134
+ @controller = DefaultUrlOptionsForMailersController.new
135
+ # @controller.class.send(:include, (PivotalCore::RailsCoreExtensions::DefaultUrlOptionsForMailers::ActionController))
136
+ PivotalCore::Initializer::DefaultUrlOptionsForMailers.run { |config| config.action_controller.default_url_options_for_mailers = options }
137
+ end
138
+
139
+ def mail_sent_from_domain_should_include_link(is_ssl, host, port, expected_link)
140
+ execute_request(is_ssl, host, port)
141
+ latest_mail_should_include_link(expected_link)
142
+ end
143
+
144
+ def execute_request(is_ssl, host, port)
145
+ @request = make_request_with(is_ssl, host, port)
146
+ @response = ActionController::TestResponse.new
147
+
148
+ get :index
149
+ @response.should be_success
150
+ end
151
+
152
+ def latest_mail_should_include_link(expected_link)
153
+ mail = ActionMailer::Base.deliveries.last
154
+ mail.body.should include(expected_link)
155
+ end
156
+
157
+ def make_request_with(is_ssl, host, port)
158
+ request = ActionController::TestRequest.new
159
+ request.host = host
160
+ request.env["SERVER_PORT"] = port
161
+ request.env["HTTPS"] = is_ssl ? "on" : "off"
162
+ request
163
+ end
164
+ end
@@ -0,0 +1,10 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class ApplicationController < ActionController::Base
5
+ helper :all # include all helpers, all the time
6
+ protect_from_forgery # See ActionController::RequestForgeryProtection for details
7
+
8
+ # Scrub sensitive parameters from your log
9
+ # filter_parameter_logging :password
10
+ end
@@ -0,0 +1,3 @@
1
+ # Methods added to this helper will be available to all templates in the application.
2
+ module ApplicationHelper
3
+ end
@@ -0,0 +1,110 @@
1
+ # Don't change this file!
2
+ # Configure your app in config/environment.rb and config/environments/*.rb
3
+
4
+ RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
5
+
6
+ module Rails
7
+ class << self
8
+ def boot!
9
+ unless booted?
10
+ preinitialize
11
+ pick_boot.run
12
+ end
13
+ end
14
+
15
+ def booted?
16
+ defined? Rails::Initializer
17
+ end
18
+
19
+ def pick_boot
20
+ (vendor_rails? ? VendorBoot : GemBoot).new
21
+ end
22
+
23
+ def vendor_rails?
24
+ File.exist?("#{RAILS_ROOT}/vendor/rails")
25
+ end
26
+
27
+ def preinitialize
28
+ load(preinitializer_path) if File.exist?(preinitializer_path)
29
+ end
30
+
31
+ def preinitializer_path
32
+ "#{RAILS_ROOT}/config/preinitializer.rb"
33
+ end
34
+ end
35
+
36
+ class Boot
37
+ def run
38
+ load_initializer
39
+ Rails::Initializer.run(:set_load_path)
40
+ end
41
+ end
42
+
43
+ class VendorBoot < Boot
44
+ def load_initializer
45
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
46
+ Rails::Initializer.run(:install_gem_spec_stubs)
47
+ Rails::GemDependency.add_frozen_gem_path
48
+ end
49
+ end
50
+
51
+ class GemBoot < Boot
52
+ def load_initializer
53
+ self.class.load_rubygems
54
+ load_rails_gem
55
+ require 'initializer'
56
+ end
57
+
58
+ def load_rails_gem
59
+ if version = self.class.gem_version
60
+ gem 'rails', version
61
+ else
62
+ gem 'rails'
63
+ end
64
+ rescue Gem::LoadError => load_error
65
+ $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
66
+ exit 1
67
+ end
68
+
69
+ class << self
70
+ def rubygems_version
71
+ Gem::RubyGemsVersion rescue nil
72
+ end
73
+
74
+ def gem_version
75
+ if defined? RAILS_GEM_VERSION
76
+ RAILS_GEM_VERSION
77
+ elsif ENV.include?('RAILS_GEM_VERSION')
78
+ ENV['RAILS_GEM_VERSION']
79
+ else
80
+ parse_gem_version(read_environment_rb)
81
+ end
82
+ end
83
+
84
+ def load_rubygems
85
+ min_version = '1.3.2'
86
+ require 'rubygems'
87
+ unless rubygems_version >= min_version
88
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
89
+ exit 1
90
+ end
91
+
92
+ rescue LoadError
93
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
94
+ exit 1
95
+ end
96
+
97
+ def parse_gem_version(text)
98
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
99
+ end
100
+
101
+ private
102
+ def read_environment_rb
103
+ File.read("#{RAILS_ROOT}/config/environment.rb")
104
+ end
105
+ end
106
+ end
107
+ end
108
+
109
+ # All that for this:
110
+ Rails.boot!
@@ -0,0 +1,41 @@
1
+ # Be sure to restart your server when you modify this file
2
+
3
+ # Specifies gem version of Rails to use when vendor/rails is not present
4
+ RAILS_GEM_VERSION = '2.3.8' unless defined? RAILS_GEM_VERSION
5
+
6
+ # Bootstrap the Rails environment, frameworks, and default configuration
7
+ require File.join(File.dirname(__FILE__), 'boot')
8
+
9
+ Rails::Initializer.run do |config|
10
+ # Settings in config/environments/* take precedence over those specified here.
11
+ # Application configuration should go into files in config/initializers
12
+ # -- all .rb files in that directory are automatically loaded.
13
+
14
+ # Add additional load paths for your own custom dirs
15
+ # config.load_paths += %W( #{RAILS_ROOT}/extras )
16
+
17
+ # Specify gems that this application depends on and have them installed with rake gems:install
18
+ # config.gem "bj"
19
+ # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
20
+ # config.gem "sqlite3-ruby", :lib => "sqlite3"
21
+ # config.gem "aws-s3", :lib => "aws/s3"
22
+
23
+ # Only load the plugins named here, in the order given (default is alphabetical).
24
+ # :all can be used as a placeholder for all plugins not explicitly named
25
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
26
+
27
+ # Skip frameworks you're not going to use. To use Rails without a database,
28
+ # you must remove the Active Record framework.
29
+ # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
30
+
31
+ # Activate observers that should always be running
32
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
33
+
34
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
35
+ # Run "rake -D time" for a list of tasks for finding time zone names.
36
+ config.time_zone = 'UTC'
37
+
38
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
39
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
40
+ # config.i18n.default_locale = :de
41
+ end
@@ -0,0 +1,17 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # In the development environment your application's code is reloaded on
4
+ # every request. This slows down response time but is perfect for development
5
+ # since you don't have to restart the webserver when you make code changes.
6
+ config.cache_classes = false
7
+
8
+ # Log error messages when you accidentally call methods on nil.
9
+ config.whiny_nils = true
10
+
11
+ # Show full error reports and disable caching
12
+ config.action_controller.consider_all_requests_local = true
13
+ config.action_view.debug_rjs = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send
17
+ config.action_mailer.raise_delivery_errors = false
@@ -0,0 +1,28 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # The production environment is meant for finished, "live" apps.
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Full error reports are disabled and caching is turned on
8
+ config.action_controller.consider_all_requests_local = false
9
+ config.action_controller.perform_caching = true
10
+ config.action_view.cache_template_loading = true
11
+
12
+ # See everything in the log (default is :info)
13
+ # config.log_level = :debug
14
+
15
+ # Use a different logger for distributed setups
16
+ # config.logger = SyslogLogger.new
17
+
18
+ # Use a different cache store in production
19
+ # config.cache_store = :mem_cache_store
20
+
21
+ # Enable serving of images, stylesheets, and javascripts from an asset server
22
+ # config.action_controller.asset_host = "http://assets.example.com"
23
+
24
+ # Disable delivery errors, bad email addresses will be ignored
25
+ # config.action_mailer.raise_delivery_errors = false
26
+
27
+ # Enable threaded mode
28
+ # config.threadsafe!
@@ -0,0 +1,28 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # The test environment is used exclusively to run your application's
4
+ # test suite. You never need to work with it otherwise. Remember that
5
+ # your test database is "scratch space" for the test suite and is wiped
6
+ # and recreated between test runs. Don't rely on the data there!
7
+ config.cache_classes = true
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.action_controller.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+ config.action_view.cache_template_loading = true
16
+
17
+ # Disable request forgery protection in test environment
18
+ config.action_controller.allow_forgery_protection = false
19
+
20
+ # Tell Action Mailer not to deliver emails to the real world.
21
+ # The :test delivery method accumulates sent emails in the
22
+ # ActionMailer::Base.deliveries array.
23
+ config.action_mailer.delivery_method = :test
24
+
25
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
26
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
27
+ # like if you have constraints or database-specific column types
28
+ # config.active_record.schema_format = :sql
@@ -0,0 +1 @@
1
+ #ActionController::Base.include()
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying do debug a problem that might steem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ ActionController::Base.cookie_verifier_secret = '0a7eaaad9ea96cb7b789098bb578ecaf8788c6a44d4c0f5b405e12f478136d60832956382e7603e404d529e737ed5dcf2af60d74b5146508b3655ddde944d9fd';
@@ -0,0 +1,10 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,21 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # These settings change the behavior of Rails 2 apps and will be defaults
4
+ # for Rails 3. You can remove this initializer when Rails 3 is released.
5
+
6
+ if defined?(ActiveRecord)
7
+ # Include Active Record class name as root for JSON serialized output.
8
+ ActiveRecord::Base.include_root_in_json = true
9
+
10
+ # Store the full class name (including module namespace) in STI type column.
11
+ ActiveRecord::Base.store_full_sti_class = true
12
+ end
13
+
14
+ ActionController::Routing.generate_best_match = false
15
+
16
+ # Use ISO 8601 format for JSON serialized times and dates.
17
+ ActiveSupport.use_standard_json_time_format = true
18
+
19
+ # Don't escape HTML entities in JSON, leave that for the #json_escape helper.
20
+ # if you're including raw json in an HTML page.
21
+ ActiveSupport.escape_html_entities_in_json = false
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.join(__FILE__, '../../../../../lib/default_url_options_for_mailers'))
2
+
3
+ PivotalCore::Initializer::DefaultUrlOptionsForMailers.run do |config|
4
+ # *** Default URL Options For Mailers ***
5
+ # Use this line to automatically derive protocol/host/port using incoming rails request:
6
+ # PivotalCore::Initializer::DefaultUrlOptionsForMailers.run
7
+ # config.action_controller.default_url_options_for_mailers = :infer_url_options
8
+
9
+ # Use this line to explicitly set protocol/host/port:
10
+ # config.action_controller.default_url_options_for_mailers = { :protocol => "http", :host => "example.com", :port => 3333 }
11
+
12
+ # Comment out both lines to disable any default URL option functionality for mailers.
13
+
14
+ # NOTE: ActionMailer::Base.default_url_options always takes precedence over this facility and if *any* options are
15
+ # set there, default_url_options_for_mailers does nothing.
16
+ end
@@ -0,0 +1,15 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying cookie session data integrity.
4
+ # If you change this key, all old sessions will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ ActionController::Base.session = {
8
+ :key => '_rails_app_session',
9
+ :secret => '80aa4a64add2bc52bf834b29b35be54a5824f3585a051f689a4874e056fa1a505bc3398bac52dfd24e49deec59889847b89076835a58e5edde5b3e659075fd29'
10
+ }
11
+
12
+ # Use the database for sessions instead of the cookie-based default,
13
+ # which shouldn't be used to store highly confidential information
14
+ # (create the session table with "rake db:sessions:create")
15
+ # ActionController::Base.session_store = :active_record_store
@@ -0,0 +1,43 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ # The priority is based upon order of creation: first created -> highest priority.
3
+
4
+ # Sample of regular route:
5
+ # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
6
+ # Keep in mind you can assign values other than :controller and :action
7
+
8
+ # Sample of named route:
9
+ # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
10
+ # This route can be invoked with purchase_url(:id => product.id)
11
+
12
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
13
+ # map.resources :products
14
+
15
+ # Sample resource route with options:
16
+ # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
17
+
18
+ # Sample resource route with sub-resources:
19
+ # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
20
+
21
+ # Sample resource route with more complex sub-resources
22
+ # map.resources :products do |products|
23
+ # products.resources :comments
24
+ # products.resources :sales, :collection => { :recent => :get }
25
+ # end
26
+
27
+ # Sample resource route within a namespace:
28
+ # map.namespace :admin do |admin|
29
+ # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
30
+ # admin.resources :products
31
+ # end
32
+
33
+ # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
34
+ # map.root :controller => "welcome"
35
+
36
+ # See how all your routes lay out with "rake routes"
37
+
38
+ # Install the default routes as the lowest priority.
39
+ # Note: These default routes make all actions in every controller accessible via GET requests. You should
40
+ # consider removing or commenting them out if you're using named routes and resources.
41
+ map.connect ':controller/:action/:id'
42
+ map.connect ':controller/:action/:id.:format'
43
+ end
@@ -0,0 +1,7 @@
1
+ # This file should contain all the record creation needed to seed the database with its default values.
2
+ # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3
+ #
4
+ # Examples:
5
+ #
6
+ # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
7
+ # Major.create(:name => 'Daley', :city => cities.first)
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+ require 'performance_test_help'
3
+
4
+ # Profiling results for each test method are written to tmp/performance.
5
+ class BrowsingTest < ActionController::PerformanceTest
6
+ def test_homepage
7
+ get '/'
8
+ end
9
+ end
@@ -0,0 +1,38 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
3
+ require 'test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ # Transactional fixtures accelerate your tests by wrapping each test method
7
+ # in a transaction that's rolled back on completion. This ensures that the
8
+ # test database remains unchanged so your fixtures don't have to be reloaded
9
+ # between every test method. Fewer database queries means faster tests.
10
+ #
11
+ # Read Mike Clark's excellent walkthrough at
12
+ # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
13
+ #
14
+ # Every Active Record database supports transactions except MyISAM tables
15
+ # in MySQL. Turn off transactional fixtures in this case; however, if you
16
+ # don't care one way or the other, switching from MyISAM to InnoDB tables
17
+ # is recommended.
18
+ #
19
+ # The only drawback to using transactional fixtures is when you actually
20
+ # need to test transactions. Since your test is bracketed by a transaction,
21
+ # any transactions started in your code will be automatically rolled back.
22
+ self.use_transactional_fixtures = true
23
+
24
+ # Instantiated fixtures are slow, but give you @david where otherwise you
25
+ # would need people(:david). If you don't want to migrate your existing
26
+ # test cases which use the @david style and don't mind the speed hit (each
27
+ # instantiated fixtures translates to a database query per test method),
28
+ # then set this back to true.
29
+ self.use_instantiated_fixtures = false
30
+
31
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
32
+ #
33
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
34
+ # -- they do not yet inherit this setting
35
+ fixtures :all
36
+
37
+ # Add more helper methods to be used by all tests here...
38
+ end
@@ -0,0 +1,66 @@
1
+ #ENV["RAILS_ENV"] ||= "test"
2
+ #require(File.join(File.dirname(__FILE__), 'rails_app', 'config', 'environment'))
3
+ #
4
+ #require "spec"
5
+ #require 'spec/rails'
6
+ #
7
+ #Spec::Example::ExampleGroupFactory.register(:functional, Spec::Rails::Example::FunctionalExampleGroup)
8
+ #Spec::Runner.configure do |configuration|
9
+ # configuration.use_transactional_fixtures = true
10
+ # configuration.use_instantiated_fixtures = false
11
+ #end
12
+
13
+ # This file is copied to ~/spec when you run 'ruby script/generate rspec'
14
+ # from the project root directory.
15
+ ENV["RAILS_ENV"] ||= 'test'
16
+ require File.expand_path(File.join(File.dirname(__FILE__),'rails_app','config','environment'))
17
+ require 'spec/autorun'
18
+ require 'spec/rails'
19
+
20
+ # Uncomment the next line to use webrat's matchers
21
+ #require 'webrat/integrations/rspec-rails'
22
+
23
+ # Requires supporting files with custom matchers and macros, etc,
24
+ # in ./support/ and its subdirectories.
25
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
26
+
27
+ Spec::Runner.configure do |config|
28
+ # If you're not using ActiveRecord you should remove these
29
+ # lines, delete config/database.yml and disable :active_record
30
+ # in your config/boot.rb
31
+ config.use_transactional_fixtures = true
32
+ config.use_instantiated_fixtures = false
33
+ # config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
34
+
35
+ # == Fixtures
36
+ #
37
+ # You can declare fixtures for each example_group like this:
38
+ # describe "...." do
39
+ # fixtures :table_a, :table_b
40
+ #
41
+ # Alternatively, if you prefer to declare them only once, you can
42
+ # do so right here. Just uncomment the next line and replace the fixture
43
+ # names with your fixtures.
44
+ #
45
+ # config.global_fixtures = :table_a, :table_b
46
+ #
47
+ # If you declare global fixtures, be aware that they will be declared
48
+ # for all of your examples, even those that don't use them.
49
+ #
50
+ # You can also declare which fixtures to use (for example fixtures for test/fixtures):
51
+ #
52
+ # config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
53
+ #
54
+ # == Mock Framework
55
+ #
56
+ # RSpec uses its own mocking framework by default. If you prefer to
57
+ # use mocha, flexmock or RR, uncomment the appropriate line:
58
+ #
59
+ # config.mock_with :mocha
60
+ # config.mock_with :flexmock
61
+ # config.mock_with :rr
62
+ #
63
+ # == Notes
64
+ #
65
+ # For more information take a look at Spec::Runner::Configuration and Spec::Runner
66
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: default-url-options-for-mailers
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Joe Moore
13
+ - Pivotal Labs
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-24 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rails
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 2
30
+ - 3
31
+ - 8
32
+ version: 2.3.8
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: ""
36
+ email: pivotal-opensource@googlegroups.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README.markdown
43
+ files:
44
+ - lib/default_url_options_for_mailers.rb
45
+ - lib/default_url_options_for_mailers/default_url_options_for_mailers.rb
46
+ - lib/default_url_options_for_mailers/initializer.rb
47
+ - README.markdown
48
+ has_rdoc: true
49
+ homepage: http://github.com/pivotal/default-url-options-for-mailers
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options: []
54
+
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ requirements: []
72
+
73
+ rubyforge_project:
74
+ rubygems_version: 1.3.6
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Default or infer the :protocol, :host, and :port values for ActionMailer
78
+ test_files:
79
+ - spec/default_url_options_for_mailers_spec.rb
80
+ - spec/rails_app/app/controllers/application_controller.rb
81
+ - spec/rails_app/app/helpers/application_helper.rb
82
+ - spec/rails_app/config/boot.rb
83
+ - spec/rails_app/config/environment.rb
84
+ - spec/rails_app/config/environments/development.rb
85
+ - spec/rails_app/config/environments/production.rb
86
+ - spec/rails_app/config/environments/test.rb
87
+ - spec/rails_app/config/initializers/action_controller.rb
88
+ - spec/rails_app/config/initializers/backtrace_silencers.rb
89
+ - spec/rails_app/config/initializers/cookie_verification_secret.rb
90
+ - spec/rails_app/config/initializers/inflections.rb
91
+ - spec/rails_app/config/initializers/mime_types.rb
92
+ - spec/rails_app/config/initializers/new_rails_defaults.rb
93
+ - spec/rails_app/config/initializers/pivotal.rb
94
+ - spec/rails_app/config/initializers/session_store.rb
95
+ - spec/rails_app/config/routes.rb
96
+ - spec/rails_app/db/seeds.rb
97
+ - spec/rails_app/test/performance/browsing_test.rb
98
+ - spec/rails_app/test/test_helper.rb
99
+ - spec/spec_helper.rb