Skip to content

Commit

Permalink
accept a string for configuration.user_model and constantize it in an…
Browse files Browse the repository at this point in the history
… accessor fix #8
  • Loading branch information
itkin committed Jun 27, 2017
1 parent 4569c1c commit 2aa41f9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/generators/invitation/install/templates/invitation.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Invitation.configure do |config|
# config.user_model = ::User
# config.user_model = '::User'
# config.user_registration_url = ->(params) { Rails.application.routes.url_helpers.sign_up_url(params) }
# config.mailer_sender = '[email protected]'
# config.routes = true
Expand Down
10 changes: 7 additions & 3 deletions lib/invitation/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,23 @@ class Configuration
attr_accessor :case_sensitive_email

def initialize
@user_model = ::User if defined?(::User)
@user_model = '::User' #if defined?(::User)
@user_registration_url = ->(params) { Rails.application.routes.url_helpers.sign_up_url(params) }
@mailer_sender = '[email protected]'
@routes = true
@case_sensitive_email = true
end

def user_model
@user_model.constantize
end

def user_model_class_name
@user_model.name.to_s
user_model.name.to_s
end

def user_model_instance_var
'@' + @user_model.name.demodulize.underscore
'@' + user_model.name.demodulize.underscore
end

# @return [Boolean] are Invitation's built-in routes enabled?
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/config/initializers/invitation.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Invitation.configure do |config|
config.user_model = User
config.user_model = 'User'
config.user_registration_url = ->(params) { 'this_is_a_fake_user_registration_url' }
end
4 changes: 2 additions & 2 deletions spec/models/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Profile

before(:each) do
@conf = Invitation::Configuration.new
@conf.user_model = Gug::Profile
@conf.user_model = 'Gug::Profile'
end

it 'has a user model class name' do
Expand All @@ -41,7 +41,7 @@ class UserProfile; extend ActiveModel::Naming end

it 'has a user model instance variable name' do
@conf = Invitation::Configuration.new
@conf.user_model = UserProfile
@conf.user_model = 'UserProfile'
expect(@conf.user_model_instance_var).to eq('@user_profile')
end
end
Expand Down

0 comments on commit 2aa41f9

Please sign in to comment.