diff --git a/gold/app/models/mailer.rb b/gold/app/models/mailer.rb new file mode 100644 index 0000000..37c7c19 --- /dev/null +++ b/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 + diff --git a/gold/app/views/mailer/create_confirmation.erb b/gold/app/views/mailer/create_confirmation.erb new file mode 100644 index 0000000..d48f578 --- /dev/null +++ b/gold/app/views/mailer/create_confirmation.erb @@ -0,0 +1 @@ +Welcome! Your confirmation code is <%= @user.perishable_token %>. diff --git a/gold/app/views/mailer/resend_confirmation.erb b/gold/app/views/mailer/resend_confirmation.erb new file mode 100644 index 0000000..ea98968 --- /dev/null +++ b/gold/app/views/mailer/resend_confirmation.erb @@ -0,0 +1 @@ +Your confirmation code is <%= @user.perishable_token %>. diff --git a/gold/app/views/mailer/reset_password.erb b/gold/app/views/mailer/reset_password.erb new file mode 100644 index 0000000..0e63fa2 --- /dev/null +++ b/gold/app/views/mailer/reset_password.erb @@ -0,0 +1 @@ +Your reset password code is <%= @user.perishable_token %>. diff --git a/gold/app/views/mailer/update_confirmation.erb b/gold/app/views/mailer/update_confirmation.erb new file mode 100644 index 0000000..7cbd281 --- /dev/null +++ b/gold/app/views/mailer/update_confirmation.erb @@ -0,0 +1 @@ +Your new confirmation code is <%= @user.perishable_token %>. diff --git a/gold/db/migrate/20090805175804_create_users.rb b/gold/db/migrate/20090805175804_create_users.rb index 5964e0d..df9feba 100644 --- a/gold/db/migrate/20090805175804_create_users.rb +++ b/gold/db/migrate/20090805175804_create_users.rb @@ -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 @@ -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 diff --git a/gold/test/unit/mailer_test.rb b/gold/test/unit/mailer_test.rb new file mode 100644 index 0000000..0099957 --- /dev/null +++ b/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 diff --git a/gold/test/unit/user_test.rb b/gold/test/unit/user_test.rb index d6d2a91..59d68f8 100644 --- a/gold/test/unit/user_test.rb +++ b/gold/test/unit/user_test.rb @@ -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