From a582eec8d9a791051d9f16c5ef82ec539445af0c Mon Sep 17 00:00:00 2001 From: danhodge Date: Thu, 1 Dec 2011 17:31:22 -0500 Subject: [PATCH] Defer user_model load so it can be a constant --- lib/clearance/configuration.rb | 12 +++--------- spec/configuration_spec.rb | 7 +++---- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/lib/clearance/configuration.rb b/lib/clearance/configuration.rb index 896cf3549..3d17ae0b8 100644 --- a/lib/clearance/configuration.rb +++ b/lib/clearance/configuration.rb @@ -1,20 +1,14 @@ module Clearance class Configuration - attr_accessor :mailer_sender, :cookie_expiration, :password_strategy, :user_model_name + attr_accessor :mailer_sender, :cookie_expiration, :password_strategy, :user_model def initialize @mailer_sender = 'donotreply@example.com' @cookie_expiration = lambda { 1.year.from_now.utc } - @user_model_name = '::User' - end - - def user_model_name=(model_name) - @user_model_name = model_name - @user_model = nil end def user_model - @user_model ||= @user_model_name.constantize + @user_model || ::User end end @@ -35,7 +29,7 @@ class << self # config.mailer_sender = 'me@example.com' # config.cookie_expiration = lambda { 2.weeks.from_now.utc } # config.password_strategy = MyPasswordStrategy - # config.user_model_name = 'MyNamespace::MyUser' + # config.user_model = MyNamespace::MyUser # end def self.configure self.configuration ||= Configuration.new diff --git a/spec/configuration_spec.rb b/spec/configuration_spec.rb index bfcc9cefd..e1caac4b1 100644 --- a/spec/configuration_spec.rb +++ b/spec/configuration_spec.rb @@ -14,16 +14,15 @@ describe "when a custom user_model_name is specified" do before do + MyUser = Class.new Clearance.configure do |config| - config.user_model_name = 'MyUser' + config.user_model = MyUser end - - MyUser = Class.new end after do Clearance.configure do |config| - config.user_model_name = '::User' + config.user_model = ::User end end