Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Defer user_model load so it can be a constant

  • Loading branch information...
commit a582eec8d9a791051d9f16c5ef82ec539445af0c 1 parent fc6af70
@danhodge danhodge authored
Showing with 6 additions and 13 deletions.
  1. +3 −9 lib/clearance/configuration.rb
  2. +3 −4 spec/configuration_spec.rb
View
12 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
View
7 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
Please sign in to comment.
Something went wrong with that request. Please try again.