| |   |
| 2 | 2 | def signup_notification(user) |
| 3 | 3 | setup_email(user) |
| 4 | 4 | @subject += 'Please activate your new account' |
| 5 | | @body[:url] = "http://#{GitoriousConfig['gitorious_host']}/users/activate/#{user.activation_code}" |
| 6 | | |
| 5 | @body[:url] = url_for( |
| 6 | :controller => 'users', |
| 7 | :action => 'activate', |
| 8 | :activation_code => user.activation_code |
| 9 | ) |
| 7 | 10 | end |
| 8 | | |
| 11 | |
| 9 | 12 | def activation(user) |
| 10 | 13 | setup_email(user) |
| 11 | 14 | @subject += 'Your account has been activated!' |
| 12 | 15 | end |
| 13 | | |
| 16 | |
| 14 | 17 | def new_repository_clone(repository) |
| 15 | 18 | setup_email(repository.project.user) |
| 16 | 19 | @subject += %Q{#{repository.user.login} has cloned #{repository.project.slug}/#{repository.parent.name}} |
| … | … | |
| 21 | 21 | @body[:cloner] = repository.user |
| 22 | 22 | @body[:project] = repository.project |
| 23 | 23 | @body[:repository] = repository |
| 24 | | @body[:url] = "http://#{GitoriousConfig['gitorious_host']}/p/#{repository.project.slug}/repos/#{repository.name}" |
| 24 | @body[:url] = project_repository_url(repository.project, repository) |
| 25 | 25 | end |
| 26 | | |
| 26 | |
| 27 | 27 | def merge_request_notification(merge_request) |
| 28 | 28 | setup_email(merge_request.target_repository.user) |
| 29 | 29 | @subject += %Q{#{merge_request.source_repository.user.login} has requested a merge in #{merge_request.target_repository.project.title}} |
| 30 | 30 | @body[:merge_request] = merge_request |
| 31 | 31 | @body[:project] = merge_request.target_repository.project |
| 32 | | url = "http://#{GitoriousConfig['gitorious_host']}/p/#{merge_request.target_repository.project.slug}" |
| 33 | | url << "/repos/#{merge_request.target_repository.name}" |
| 34 | | url << "/merge_requests/#{merge_request.id}" |
| 35 | | @body[:url] = url |
| 32 | @body[:url] = |
| 33 | project_repository_merge_request_url( |
| 34 | merge_request.target_repository.project, |
| 35 | merge_request.target_repository, |
| 36 | merge_request |
| 37 | ) |
| 36 | 38 | end |
| 37 | | |
| 39 | |
| 38 | 40 | def forgotten_password(user, password) |
| 39 | 41 | setup_email(user) |
| 40 | 42 | @subject += "Your new password" |
| 41 | 43 | @body[:password] = password |
| 42 | 44 | end |
| 43 | | |
| 45 | |
| 44 | 46 | protected |
| 45 | 47 | def setup_email(user) |
| 46 | 48 | @recipients = "#{user.email}" |
| toggle raw diff |
--- a/app/models/mailer.rb
+++ b/app/models/mailer.rb
@@ -2,15 +2,18 @@ class Mailer < ActionMailer::Base
def signup_notification(user)
setup_email(user)
@subject += 'Please activate your new account'
- @body[:url] = "http://#{GitoriousConfig['gitorious_host']}/users/activate/#{user.activation_code}"
-
+ @body[:url] = url_for(
+ :controller => 'users',
+ :action => 'activate',
+ :activation_code => user.activation_code
+ )
end
-
+
def activation(user)
setup_email(user)
@subject += 'Your account has been activated!'
end
-
+
def new_repository_clone(repository)
setup_email(repository.project.user)
@subject += %Q{#{repository.user.login} has cloned #{repository.project.slug}/#{repository.parent.name}}
@@ -18,26 +21,28 @@ class Mailer < ActionMailer::Base
@body[:cloner] = repository.user
@body[:project] = repository.project
@body[:repository] = repository
- @body[:url] = "http://#{GitoriousConfig['gitorious_host']}/p/#{repository.project.slug}/repos/#{repository.name}"
+ @body[:url] = project_repository_url(repository.project, repository)
end
-
+
def merge_request_notification(merge_request)
setup_email(merge_request.target_repository.user)
@subject += %Q{#{merge_request.source_repository.user.login} has requested a merge in #{merge_request.target_repository.project.title}}
@body[:merge_request] = merge_request
@body[:project] = merge_request.target_repository.project
- url = "http://#{GitoriousConfig['gitorious_host']}/p/#{merge_request.target_repository.project.slug}"
- url << "/repos/#{merge_request.target_repository.name}"
- url << "/merge_requests/#{merge_request.id}"
- @body[:url] = url
+ @body[:url] =
+ project_repository_merge_request_url(
+ merge_request.target_repository.project,
+ merge_request.target_repository,
+ merge_request
+ )
end
-
+
def forgotten_password(user, password)
setup_email(user)
@subject += "Your new password"
@body[:password] = password
end
-
+
protected
def setup_email(user)
@recipients = "#{user.email}" |
| |   |
| 14 | 14 | config.action_view.cache_template_extensions = false |
| 15 | 15 | config.action_view.debug_rjs = true |
| 16 | 16 | |
| 17 | | # Don't care if the mailer can't send |
| 17 | # ActionMailer::Base.default_url_options[:protocol] = 'https' |
| 18 | ActionMailer::Base.default_url_options[:host] = |
| 19 | YAML.load_file(File.join(RAILS_ROOT, "config/gitorious.yml"))["gitorious_host"] |
| 18 | 20 | config.action_mailer.raise_delivery_errors = false |
| 19 | 21 | config.action_mailer.delivery_method = :test |
| 20 | | ExceptionNotifier.exception_recipients = YAML.load_file(File.join(RAILS_ROOT, |
| 21 | | "config/gitorious.yml"))["exception_notification_emails"] |
| 22 | ExceptionNotifier.exception_recipients = YAML.load_file(File.join(RAILS_ROOT, |
| 23 | "config/gitorious.yml"))["exception_notification_emails"] |
| toggle raw diff |
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -14,8 +14,10 @@ config.action_controller.perform_caching = false
config.action_view.cache_template_extensions = false
config.action_view.debug_rjs = true
-# Don't care if the mailer can't send
+# ActionMailer::Base.default_url_options[:protocol] = 'https'
+ActionMailer::Base.default_url_options[:host] =
+ YAML.load_file(File.join(RAILS_ROOT, "config/gitorious.yml"))["gitorious_host"]
config.action_mailer.raise_delivery_errors = false
config.action_mailer.delivery_method = :test
-ExceptionNotifier.exception_recipients = YAML.load_file(File.join(RAILS_ROOT,
- "config/gitorious.yml"))["exception_notification_emails"]
\ No newline at end of file
+ExceptionNotifier.exception_recipients = YAML.load_file(File.join(RAILS_ROOT,
+ "config/gitorious.yml"))["exception_notification_emails"] |
| |   |
| 23 | 23 | # Enable serving of images, stylesheets, and javascripts from an asset server |
| 24 | 24 | # config.action_controller.asset_host = "http://assets.example.com" |
| 25 | 25 | |
| 26 | # ActionMailer::Base.default_url_options[:protocol] = 'https' |
| 27 | ActionMailer::Base.default_url_options[:host] = |
| 28 | YAML.load_file(File.join(RAILS_ROOT, "config/gitorious.yml"))["gitorious_host"] |
| 26 | 29 | # Disable delivery errors, bad email addresses will be ignored |
| 27 | 30 | # config.action_mailer.raise_delivery_errors = false |
| 28 | | |
| 29 | | ExceptionNotifier.exception_recipients = YAML.load_file(File.join(RAILS_ROOT, |
| 31 | ExceptionNotifier.exception_recipients = YAML.load_file(File.join(RAILS_ROOT, |
| 30 | 32 | "config/gitorious.yml"))["exception_notification_emails"] |
| 31 | | ExceptionNotifier.class_eval do |
| 32 | | remove_method :template_root |
| 33 | | ExceptionNotifier.template_root = "#{RAILS_ROOT}/vendor/plugins/exception_notification/lib/../views" |
| 33 | ExceptionNotifier.class_eval do |
| 34 | remove_method :template_root |
| 35 | ExceptionNotifier.template_root = "#{RAILS_ROOT}/vendor/plugins/exception_notification/lib/../views" |
| 34 | 36 | end |
| toggle raw diff |
--- a/config/environments/production.rb
+++ b/config/environments/production.rb
@@ -23,12 +23,14 @@ config.action_controller.fragment_cache_store = :file_store, File.join(cache_dir
# Enable serving of images, stylesheets, and javascripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
+# ActionMailer::Base.default_url_options[:protocol] = 'https'
+ActionMailer::Base.default_url_options[:host] =
+ YAML.load_file(File.join(RAILS_ROOT, "config/gitorious.yml"))["gitorious_host"]
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
-
-ExceptionNotifier.exception_recipients = YAML.load_file(File.join(RAILS_ROOT,
+ExceptionNotifier.exception_recipients = YAML.load_file(File.join(RAILS_ROOT,
"config/gitorious.yml"))["exception_notification_emails"]
-ExceptionNotifier.class_eval do
- remove_method :template_root
- ExceptionNotifier.template_root = "#{RAILS_ROOT}/vendor/plugins/exception_notification/lib/../views"
+ExceptionNotifier.class_eval do
+ remove_method :template_root
+ ExceptionNotifier.template_root = "#{RAILS_ROOT}/vendor/plugins/exception_notification/lib/../views"
end
\ No newline at end of file |
| |   |
| 16 | 16 | # Disable request forgery protection in test environment |
| 17 | 17 | config.action_controller.allow_forgery_protection = false |
| 18 | 18 | |
| 19 | # ActionMailer::Base.default_url_options[:protocol] = 'https' |
| 20 | ActionMailer::Base.default_url_options[:host] = |
| 21 | YAML.load_file(File.join(RAILS_ROOT, "config/gitorious.yml"))["gitorious_host"] |
| 19 | 22 | # Tell ActionMailer not to deliver emails to the real world. |
| 20 | 23 | # The :test delivery method accumulates sent emails in the |
| 21 | 24 | # ActionMailer::Base.deliveries array. |
| toggle raw diff |
--- a/config/environments/test.rb
+++ b/config/environments/test.rb
@@ -16,6 +16,9 @@ config.action_controller.perform_caching = false
# Disable request forgery protection in test environment
config.action_controller.allow_forgery_protection = false
+# ActionMailer::Base.default_url_options[:protocol] = 'https'
+ActionMailer::Base.default_url_options[:host] =
+ YAML.load_file(File.join(RAILS_ROOT, "config/gitorious.yml"))["gitorious_host"]
# Tell ActionMailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array. |
| |   |
| 1 | 1 | require File.dirname(__FILE__) + '/../spec_helper' |
| 2 | 2 | |
| 3 | 3 | describe Mailer do |
| 4 | URL_BASE = "#{Mailer.default_url_options[:protocol]||'http'}://#{Mailer.default_url_options[:host]}" |
| 5 | |
| 4 | 6 | before(:each) do |
| 5 | 7 | Mailer.deliveries = [] |
| 6 | 8 | end |
| 7 | | |
| 9 | |
| 8 | 10 | it "send new_repository_clone" do |
| 9 | 11 | repos = repositories(:johans2) |
| 12 | url = "#{URL_BASE}/projects/#{repos.project.slug}/repos/#{repos.name}" |
| 10 | 13 | mail = Mailer.create_new_repository_clone(repos) |
| 11 | | |
| 14 | |
| 12 | 15 | mail.to.should == [repos.project.user.email] |
| 13 | 16 | mail.subject.should == %Q{[Gitorious] #{repos.user.login} has cloned #{repos.project.slug}/#{repos.parent.name}} |
| 14 | 17 | mail.body.should match(/#{repos.user.login} recently created a clone/) |
| 15 | | mail.body.should match(/\/p\/#{repos.project.slug}\/repos\/#{repos.name}/) |
| 16 | | |
| 18 | mail.body.should include(url) |
| 19 | |
| 17 | 20 | Mailer.deliver(mail) |
| 18 | 21 | Mailer.deliveries.should == [mail] |
| 19 | 22 | end |
| 20 | | |
| 23 | |
| 21 | 24 | it "sends signup_notification" do |
| 22 | 25 | user = users(:johan) |
| 23 | 26 | user.password = "fubar" |
| 27 | url = "#{URL_BASE}/users/activate/#{user.activation_code}" |
| 24 | 28 | mail = Mailer.create_signup_notification(user) |
| 25 | | |
| 29 | |
| 26 | 30 | mail.to.should == [user.email] |
| 27 | 31 | mail.subject.should == "[Gitorious] Please activate your new account" |
| 28 | | mail.body.should match(/users\/activate\/#{user.activation_code}/) |
| 29 | 32 | mail.body.should match(/username is #{user.login}$/) |
| 30 | | |
| 33 | mail.body.should include(url) |
| 34 | |
| 31 | 35 | Mailer.deliver(mail) |
| 32 | 36 | Mailer.deliveries.should == [mail] |
| 33 | 37 | end |
| 34 | | |
| 38 | |
| 35 | 39 | it "sends activation" do |
| 36 | 40 | user = users(:johan) |
| 37 | 41 | mail = Mailer.create_activation(user) |
| 38 | | |
| 42 | |
| 39 | 43 | mail.to.should == [user.email] |
| 40 | 44 | mail.subject.should == "[Gitorious] Your account has been activated!" |
| 41 | 45 | mail.body.should match(/your account has been activated/) |
| 42 | | |
| 46 | |
| 43 | 47 | Mailer.deliver(mail) |
| 44 | 48 | Mailer.deliveries.should == [mail] |
| 45 | 49 | end |
| 46 | | |
| 50 | |
| 47 | 51 | it "sends merge_request_notification" do |
| 48 | 52 | merge_request = merge_requests(:moes_to_johans) |
| 53 | url = "#{URL_BASE}/projects/#{merge_request.target_repository.project.slug}/repos/#{merge_request.target_repository.name}/merge_requests/#{merge_request.id}" |
| 49 | 54 | mail = Mailer.create_merge_request_notification(merge_request) |
| 50 | | |
| 55 | |
| 51 | 56 | mail.to.should == [merge_request.target_repository.user.email] |
| 52 | 57 | mail.subject.should == "[Gitorious] moe has requested a merge in johans project" |
| 53 | 58 | mail.body.should match(/moe has requested that you merge #{merge_request.source_repository.name} with #{merge_request.target_repository.name}/) |
| 54 | 59 | mail.body.should match(/in the #{merge_request.target_repository.project.title} project/) |
| 55 | 60 | mail.body.should include(merge_request.proposal) |
| 56 | | |
| 61 | mail.body.should include(url) |
| 62 | |
| 57 | 63 | Mailer.deliver(mail) |
| 58 | 64 | Mailer.deliveries.should == [mail] |
| 59 | 65 | end |
| toggle raw diff |
--- a/spec/models/mailer_spec.rb
+++ b/spec/models/mailer_spec.rb
@@ -1,59 +1,65 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe Mailer do
+ URL_BASE = "#{Mailer.default_url_options[:protocol]||'http'}://#{Mailer.default_url_options[:host]}"
+
before(:each) do
Mailer.deliveries = []
end
-
+
it "send new_repository_clone" do
repos = repositories(:johans2)
+ url = "#{URL_BASE}/projects/#{repos.project.slug}/repos/#{repos.name}"
mail = Mailer.create_new_repository_clone(repos)
-
+
mail.to.should == [repos.project.user.email]
mail.subject.should == %Q{[Gitorious] #{repos.user.login} has cloned #{repos.project.slug}/#{repos.parent.name}}
mail.body.should match(/#{repos.user.login} recently created a clone/)
- mail.body.should match(/\/p\/#{repos.project.slug}\/repos\/#{repos.name}/)
-
+ mail.body.should include(url)
+
Mailer.deliver(mail)
Mailer.deliveries.should == [mail]
end
-
+
it "sends signup_notification" do
user = users(:johan)
user.password = "fubar"
+ url = "#{URL_BASE}/users/activate/#{user.activation_code}"
mail = Mailer.create_signup_notification(user)
-
+
mail.to.should == [user.email]
mail.subject.should == "[Gitorious] Please activate your new account"
- mail.body.should match(/users\/activate\/#{user.activation_code}/)
mail.body.should match(/username is #{user.login}$/)
-
+ mail.body.should include(url)
+
Mailer.deliver(mail)
Mailer.deliveries.should == [mail]
end
-
+
it "sends activation" do
user = users(:johan)
mail = Mailer.create_activation(user)
-
+
mail.to.should == [user.email]
mail.subject.should == "[Gitorious] Your account has been activated!"
mail.body.should match(/your account has been activated/)
-
+
Mailer.deliver(mail)
Mailer.deliveries.should == [mail]
end
-
+
it "sends merge_request_notification" do
merge_request = merge_requests(:moes_to_johans)
+ url = "#{URL_BASE}/projects/#{merge_request.target_repository.project.slug}/repos/#{merge_request.target_repository.name}/merge_requests/#{merge_request.id}"
mail = Mailer.create_merge_request_notification(merge_request)
-
+
mail.to.should == [merge_request.target_repository.user.email]
mail.subject.should == "[Gitorious] moe has requested a merge in johans project"
mail.body.should match(/moe has requested that you merge #{merge_request.source_repository.name} with #{merge_request.target_repository.name}/)
mail.body.should match(/in the #{merge_request.target_repository.project.title} project/)
mail.body.should include(merge_request.proposal)
-
+ mail.body.should include(url)
+
Mailer.deliver(mail)
Mailer.deliveries.should == [mail]
end |