Skip to content

Commit

Permalink
Added mailer and fields on user
Browse files Browse the repository at this point in the history
  • Loading branch information
Tammer Saleh committed Oct 20, 2009
1 parent 376163b commit 14b032d
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 0 deletions.
31 changes: 31 additions & 0 deletions gold/app/models/mailer.rb
@@ -0,0 +1,31 @@
class Mailer < ActionMailer::Base
def create_confirmation(user)
@subject = I18n.t 'actionmailer.create_confirmation', :default => 'Create confirmation'
@from = "none@example.com"
@recipients = user.email
@body[:user] = user
end

def update_confirmation(user)
@subject = I18n.t 'actionmailer.update_confirmation', :default => 'Update e-mail confirmation'
@from = "none@example.com"
@recipients = user.email
@body[:user] = user
end

def reset_password(user)
@subject = I18n.t 'actionmailer.reset_password', :default => 'Reset password'
@from = "none@example.com"
@recipients = user.email
@body[:user] = user
end

def resend_confirmation(user)
@subject = I18n.t 'actionmailer.resend_confirmation', :default => 'Confirmation code'
@from = "none@example.com"
@recipients = user.email
@body[:user] = user
end

end

1 change: 1 addition & 0 deletions gold/app/views/mailer/create_confirmation.erb
@@ -0,0 +1 @@
Welcome! Your confirmation code is <%= @user.perishable_token %>.
1 change: 1 addition & 0 deletions gold/app/views/mailer/resend_confirmation.erb
@@ -0,0 +1 @@
Your confirmation code is <%= @user.perishable_token %>.
1 change: 1 addition & 0 deletions gold/app/views/mailer/reset_password.erb
@@ -0,0 +1 @@
Your reset password code is <%= @user.perishable_token %>.
1 change: 1 addition & 0 deletions gold/app/views/mailer/update_confirmation.erb
@@ -0,0 +1 @@
Your new confirmation code is <%= @user.perishable_token %>.
6 changes: 6 additions & 0 deletions gold/db/migrate/20090805175804_create_users.rb
Expand Up @@ -3,10 +3,14 @@ def self.up
create_table :users do |t|
t.string :name
t.string :email

t.string :crypted_password
t.string :password_salt

t.string :persistence_token
t.string :perishable_token
t.boolean :active, :default => true, :null => false

t.string :photo_file_name
t.string :photo_content_type
t.integer :photo_file_size
Expand All @@ -15,6 +19,8 @@ def self.up
end

add_index :users, :active
add_index :users, :email
add_index :users, :perishable_token
end

def self.down
Expand Down
20 changes: 20 additions & 0 deletions gold/test/unit/mailer_test.rb
@@ -0,0 +1,20 @@
require 'test_helper'

class MailerTest < ActionMailer::TestCase
%w(create_confirmation update_confirmation reset_password resend_confirmation).each do |email_type|
context "A #{email_type.humanize} email" do
setup do
@user = Factory(:user, :email => 'recipient@email.com', :perishable_token => '0123456789')
@email = Mailer.send("create_#{email_type}", @user)
end

should "be delivered to the user's email address" do
assert_equal [@user.email], @email.to
end

should "contain the perishable token" do
assert_match(/#{@user.perishable_token}/, @email.body)
end
end
end
end
4 changes: 4 additions & 0 deletions gold/test/unit/user_test.rb
Expand Up @@ -3,6 +3,10 @@
class UserTest < ActiveSupport::TestCase
should_have_db_column :active, :type => :boolean, :default => true

should_have_db_index :email
should_have_db_index :active
should_have_db_index :perishable_token

should_validate_presence_of :email
should_validate_presence_of :password
should_validate_presence_of :name
Expand Down

0 comments on commit 14b032d

Please sign in to comment.