diff --git a/lib/generators/invitation/install/templates/invitation.rb b/lib/generators/invitation/install/templates/invitation.rb index 2ec7075..d0adf5e 100644 --- a/lib/generators/invitation/install/templates/invitation.rb +++ b/lib/generators/invitation/install/templates/invitation.rb @@ -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 = 'reply@example.com' # config.routes = true diff --git a/lib/invitation/configuration.rb b/lib/invitation/configuration.rb index b426529..24f345e 100644 --- a/lib/invitation/configuration.rb +++ b/lib/invitation/configuration.rb @@ -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 = 'reply@example.com' @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? diff --git a/spec/dummy/config/initializers/invitation.rb b/spec/dummy/config/initializers/invitation.rb index 768f629..6e1d4ae 100644 --- a/spec/dummy/config/initializers/invitation.rb +++ b/spec/dummy/config/initializers/invitation.rb @@ -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 diff --git a/spec/models/configuration_spec.rb b/spec/models/configuration_spec.rb index 770e547..207be26 100644 --- a/spec/models/configuration_spec.rb +++ b/spec/models/configuration_spec.rb @@ -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 @@ -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