| 1 |
require File.dirname(__FILE__) + '/../spec_helper' |
| 2 |
|
| 3 |
describe Mailer do |
| 4 |
URL_BASE = "#{Mailer.default_url_options[:protocol]||'http'}://#{Mailer.default_url_options[:host]}" |
| 5 |
|
| 6 |
before(:each) do |
| 7 |
Mailer.deliveries = [] |
| 8 |
end |
| 9 |
|
| 10 |
it "send new_repository_clone" do |
| 11 |
repos = repositories(:johans2) |
| 12 |
url = "#{URL_BASE}/projects/#{repos.project.slug}/repos/#{repos.name}" |
| 13 |
mail = Mailer.create_new_repository_clone(repos) |
| 14 |
|
| 15 |
mail.to.should == [repos.project.user.email] |
| 16 |
mail.subject.should == %Q{[Gitorious] #{repos.user.login} has cloned #{repos.project.slug}/#{repos.parent.name}} |
| 17 |
mail.body.should match(/#{repos.user.login} recently created a clone/) |
| 18 |
mail.body.should include(url) |
| 19 |
|
| 20 |
Mailer.deliver(mail) |
| 21 |
Mailer.deliveries.should == [mail] |
| 22 |
end |
| 23 |
|
| 24 |
it "sends signup_notification" do |
| 25 |
user = users(:johan) |
| 26 |
user.password = "fubar" |
| 27 |
url = "#{URL_BASE}/users/activate/#{user.activation_code}" |
| 28 |
mail = Mailer.create_signup_notification(user) |
| 29 |
|
| 30 |
mail.to.should == [user.email] |
| 31 |
mail.subject.should == "[Gitorious] Please activate your new account" |
| 32 |
mail.body.should match(/username is #{user.login}$/) |
| 33 |
mail.body.should include(url) |
| 34 |
|
| 35 |
Mailer.deliver(mail) |
| 36 |
Mailer.deliveries.should == [mail] |
| 37 |
end |
| 38 |
|
| 39 |
it "sends activation" do |
| 40 |
user = users(:johan) |
| 41 |
mail = Mailer.create_activation(user) |
| 42 |
|
| 43 |
mail.to.should == [user.email] |
| 44 |
mail.subject.should == "[Gitorious] Your account has been activated!" |
| 45 |
mail.body.should match(/your account has been activated/) |
| 46 |
|
| 47 |
Mailer.deliver(mail) |
| 48 |
Mailer.deliveries.should == [mail] |
| 49 |
end |
| 50 |
|
| 51 |
it "sends merge_request_notification" do |
| 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}" |
| 54 |
mail = Mailer.create_merge_request_notification(merge_request) |
| 55 |
|
| 56 |
mail.to.should == [merge_request.target_repository.user.email] |
| 57 |
mail.subject.should == "[Gitorious] moe has requested a merge in johans project" |
| 58 |
mail.body.should match(/moe has requested that you merge #{merge_request.source_repository.name} with #{merge_request.target_repository.name}/) |
| 59 |
mail.body.should match(/in the #{merge_request.target_repository.project.title} project/) |
| 60 |
mail.body.should include(merge_request.proposal) |
| 61 |
mail.body.should include(url) |
| 62 |
|
| 63 |
Mailer.deliver(mail) |
| 64 |
Mailer.deliveries.should == [mail] |
| 65 |
end |
| 66 |
|
| 67 |
it "sends forgotten_password" do |
| 68 |
user = users(:johan) |
| 69 |
mail = Mailer.create_forgotten_password(user, "newpassword") |
| 70 |
|
| 71 |
mail.to.should == [user.email] |
| 72 |
mail.subject.should == "[Gitorious] Your new password" |
| 73 |
mail.body.should match(/your new password is: newpassword/i) |
| 74 |
|
| 75 |
Mailer.deliver(mail) |
| 76 |
Mailer.deliveries.should == [mail] |
| 77 |
end |
| 78 |
|
| 79 |
end |