Skip to content

Commit

Permalink
use Clearance.configure block to set mailer sender instead of DO_NOT_…
Browse files Browse the repository at this point in the history
…REPLY constant
  • Loading branch information
Dan Croak committed Jan 20, 2010
1 parent e516323 commit c858032
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 38 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.textile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
h2. 0.8.5 (01/18/2010)
h2. 0.8.5

* replaced routing hack with Clearance::Routes.draw(map) to give
* replaced routing hack with Clearance::Routes.draw(map) to give
more control to the application developer. (Dan Croak)
* removed attr_accessible from Clearance::User. (Dan Croak)
* fixed bug in password reset feature. (Dan Croak)
* use Jeweler for gemming. (Dan Croak)
* remove dependency on root_path, use '/' instead. (Dan Croak)
* use Clearance.configure block to set mailer sender instead of
DO_NOT_REPLY constant. (Dan Croak)

h2. 0.8.4 (10/08/2009)

Expand Down
19 changes: 4 additions & 15 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,40 +37,29 @@ generators = %w(clearance clearance_features clearance_views)
namespace :generator do
desc "Cleans up the test app before running the generator"
task :cleanup do
generators.each do |generator|
FileList["generators/#{generator}/templates/**/*.*"].each do |each|
file = "test/rails_root/#{each.gsub("generators/#{generator}/templates/",'')}"
File.delete(file) if File.exists?(file)
end
end

FileList["test/rails_root/db/**/*"].each do |each|
FileList["test/rails_root/db/**/*"].each do |each|
FileUtils.rm_rf(each)
end

FileUtils.rm_rf("test/rails_root/vendor/plugins/clearance")
FileUtils.mkdir_p("test/rails_root/vendor/plugins")
clearance_root = File.expand_path(File.dirname(__FILE__))
system("ln -s #{clearance_root} test/rails_root/vendor/plugins/clearance")

FileUtils.rm_rf("test/rails_root/app/views/passwords")
FileUtils.rm_rf("test/rails_root/app/views/sessions")
FileUtils.rm_rf("test/rails_root/app/views/users")
end

desc "Run the clearance generator"
task :clearance do
system "cd test/rails_root && ./script/generate clearance && rake db:migrate db:test:prepare"
system "cd test/rails_root && ./script/generate clearance -f && rake db:migrate db:test:prepare"
end

desc "Run the clearance features generator"
task :clearance_features do
system "cd test/rails_root && ./script/generate clearance_features"
system "cd test/rails_root && ./script/generate clearance_features -f"
end

desc "Run the clearance views generator"
task :clearance_views do
system "cd test/rails_root && ./script/generate clearance_views"
system "cd test/rails_root && ./script/generate clearance_views -f"
end
end

Expand Down
6 changes: 2 additions & 4 deletions app/models/clearance_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
class ClearanceMailer < ActionMailer::Base

default_url_options[:host] = HOST

def change_password(user)
from DO_NOT_REPLY
from Clearance.configuration.mailer_sender
recipients user.email
subject I18n.t(:change_password,
:scope => [:clearance, :models, :clearance_mailer],
Expand All @@ -12,7 +10,7 @@ def change_password(user)
end

def confirmation(user)
from DO_NOT_REPLY
from Clearance.configuration.mailer_sender
recipients user.email
subject I18n.t(:confirmation,
:scope => [:clearance, :models, :clearance_mailer],
Expand Down
3 changes: 3 additions & 0 deletions generators/clearance/clearance_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ class ClearanceGenerator < Rails::Generator::Base

def manifest
record do |m|
m.directory File.join("config", "initializers")
m.file "clearance.rb", "config/initializers/clearance.rb"

m.insert_into "app/controllers/application_controller.rb",
"include Clearance::Authentication"

Expand Down
6 changes: 3 additions & 3 deletions generators/clearance/templates/clearance.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Clearance.configure do |config|
# config.mailer_sender 'donotreply@example.com'
# end
Clearance.configure do |config|
config.mailer_sender = 'donotreply@example.com'
end
1 change: 1 addition & 0 deletions lib/clearance.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'clearance/extensions/errors'
require 'clearance/extensions/rescue'

require 'clearance/configuration'
require 'clearance/routes'
require 'clearance/authentication'
require 'clearance/user'
25 changes: 25 additions & 0 deletions lib/clearance/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Clearance
class Configuration
attr_accessor :mailer_sender

def initialize
@mailer_sender = 'donotreply@example.com'
end
end

class << self
attr_accessor :configuration
end

# Configure Clearance someplace sensible,
# like config/initializers/clearance.rb
#
# @example
# Clearance.configure do |config|
# config.mailer_sender = 'donotreply@example.com'
# end
def self.configure
self.configuration ||= Configuration.new
yield(configuration)
end
end
4 changes: 2 additions & 2 deletions test/models/clearance_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ClearanceMailerTest < ActiveSupport::TestCase
end

should "be from DO_NOT_REPLY" do
assert_match /#{@email.from[0]}/i, DO_NOT_REPLY
assert_match /#{@email.from[0]}/i, Clearance.configuration.mailer_sender
end

should "be sent to user" do
Expand All @@ -34,7 +34,7 @@ class ClearanceMailerTest < ActiveSupport::TestCase
end

should "be from DO_NOT_REPLY" do
assert_match /#{@email.from[0]}/i, DO_NOT_REPLY
assert_match /#{@email.from[0]}/i, Clearance.configuration.mailer_sender
end

should "be sent to user" do
Expand Down
5 changes: 3 additions & 2 deletions test/rails_root/config/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
:session_key => "_clearance_session",
:secret => ['clearance', 'random', 'words', 'here'].map {|k| Digest::MD5.hexdigest(k) }.join
}

config.gem "justinfrench-formtastic",
:lib => 'formtastic',
:source => 'http://gems.github.com'
end

DO_NOT_REPLY = "donotreply@example.com"
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
end
2 changes: 0 additions & 2 deletions test/rails_root/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test

HOST = "localhost"

config.gem 'shoulda',
:source => "http://gemcutter.org",
:version => '>= 2.9.1'
Expand Down
11 changes: 3 additions & 8 deletions test/rails_root/config/initializers/clearance.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# This simulates loading the clearance gem, but without relying on
# vendor/gems

clearance_path = File.join(File.dirname(__FILE__), *%w(.. .. .. ..))
clearance_lib_path = File.join(clearance_path, "lib")

$LOAD_PATH.unshift(clearance_lib_path)
load File.join(clearance_path, 'rails', 'init.rb')
Clearance.configure do |config|
config.mailer_sender = 'donotreply@example.com'
end

0 comments on commit c858032

Please sign in to comment.