+ user = User.create ({uuid: 'zzzzz-tpzed-abcdefghijklmno', email: 'foo@example.com' })
+
+ assert_equal '', user.full_name
+
+ user.first_name = 'John'
+ user.last_name = 'Smith'
+
+ assert_equal user.first_name + ' ' + user.last_name, user.full_name
+ end
+
+ test "create new user" do
+ Thread.current[:user] = @admin_user # set admin user as the current user
+
+ user = User.new
+ user.first_name = "first_name_for_newly_created_user"
+ user.save
+
+ # verify there is one extra user in the db now
+ assert_equal @all_users.size+1, User.find(:all).size
+
+ user = User.find(user.id) # get the user back
+ assert_equal(user.first_name, 'first_name_for_newly_created_user')
+ assert_not_nil user.uuid, 'uuid should be set for newly created user'
+ assert_nil user.email, 'email should be null for newly created user, because it was not passed in'
+ assert_nil user.identity_url, 'identity_url should be null for newly created user, because it was not passed in'
+
+ user.first_name = 'first_name_for_newly_created_user_updated'
+ user.save
+ user = User.find(user.id) # get the user back
+ assert_equal(user.first_name, 'first_name_for_newly_created_user_updated')
+ end
+
+ test "create new inactive user with new_inactive_user_notification_recipients empty" do
+ Thread.current[:user] = @admin_user # set admin user as the current user
+
+ Rails.configuration.new_inactive_user_notification_recipients = ''
+
+ ActionMailer::Base.deliveries = []
+
+ user = User.new
+ user.first_name = "first_name_for_newly_created_user"
+ user.is_active = false
+ user.save
+
+ assert_equal '', Rails.configuration.new_inactive_user_notification_recipients
+
+ ActionMailer::Base.deliveries.each do |d|
+ assert_not_equal "#{Rails.configuration.email_subject_prefix}New inactive user notification", setup_email.subject
+ end
+
+ end
+
+ test "create new inactive user with new_user_notification_recipients empty" do
+ Thread.current[:user] = @admin_user # set admin user as the current user
+
+ Rails.configuration.new_user_notification_recipients = ''
+
+ ActionMailer::Base.deliveries = []
+
+ user = User.new
+ user.first_name = "first_name_for_newly_created_user"
+ user.is_active = false
+ user.save
+
+ assert_equal '', Rails.configuration.new_user_notification_recipients
+
+ ActionMailer::Base.deliveries.each do |d|
+ assert_not_equal "#{Rails.configuration.email_subject_prefix}New user notification", d.subject
+ end
+
+ end
+
+ test "create new inactive user with new_user_notification_recipients and new_inactive_user_notification_recipients set" do
+ Thread.current[:user] = @admin_user # set admin user as the current user
+
+ Rails.configuration.new_user_notification_recipients = 'foo_new@example.com'
+ Rails.configuration.new_inactive_user_notification_recipients = 'foo_new_inactive@example.com'
+
+ ActionMailer::Base.deliveries = []
+
+ user = User.new
+ user.first_name = "first_name_for_newly_created_user"
+ user.is_active = false
+ user.save
+
+ new_user_email = nil
+ new_inactive_user_email = nil
+ ActionMailer::Base.deliveries.each do |d|
+ if d.subject == "#{Rails.configuration.email_subject_prefix}New inactive user notification" then
+ new_inactive_user_email = d
+ end
+ if d.subject == "#{Rails.configuration.email_subject_prefix}New user notification" then
+ new_user_email = d
+ end
+ end
+
+ assert_not_nil new_inactive_user_email, 'Expected new inactive user email after setup'
+ assert_not_nil new_user_email, 'Expected new user email after setup'
+
+ assert_equal 'foo_new@example.com', Rails.configuration.new_user_notification_recipients
+ assert_equal 'foo_new_inactive@example.com', Rails.configuration.new_inactive_user_notification_recipients
+
+ assert_equal Rails.configuration.user_notifier_email_from, new_inactive_user_email.from[0]
+ assert_equal 'foo_new_inactive@example.com', new_inactive_user_email.to[0]
+ assert_equal "#{Rails.configuration.email_subject_prefix}New inactive user notification", new_inactive_user_email.subject
+
+ assert_equal Rails.configuration.user_notifier_email_from, new_user_email.from[0]
+ assert_equal 'foo_new@example.com', new_user_email.to[0]
+ assert_equal "#{Rails.configuration.email_subject_prefix}New user notification", new_user_email.subject
+ end
+
+ test "create new inactive user with new_user_notification_recipients set" do
+ Thread.current[:user] = @admin_user # set admin user as the current user
+
+ Rails.configuration.new_user_notification_recipients = 'foo@example.com'
+
+ user = User.new
+ user.first_name = "first_name_for_newly_created_user"
+ user.is_active = false
+ user.save
+
+ new_user_email = nil
+
+ ActionMailer::Base.deliveries.each do |d|
+ if d.subject == "#{Rails.configuration.email_subject_prefix}New user notification" then
+ new_user_email = d
+ break
+ end
+ end
+
+ assert_not_nil new_user_email, 'Expected email after setup'
+
+ assert_equal 'foo@example.com', Rails.configuration.new_user_notification_recipients
+
+ assert_equal Rails.configuration.user_notifier_email_from, new_user_email.from[0]
+ assert_equal 'foo@example.com', new_user_email.to[0]
+ assert_equal "#{Rails.configuration.email_subject_prefix}New user notification", new_user_email.subject
+ end
+
+ test "create new active user with new_inactive_user_notification_recipients set" do
+ Thread.current[:user] = @admin_user # set admin user as the current user
+
+ Rails.configuration.new_inactive_user_notification_recipients = 'foo@example.com'
+
+ ActionMailer::Base.deliveries = []
+
+ user = User.new
+ user.first_name = "first_name_for_newly_created_user"
+ user.is_active = true
+ user.save
+
+ assert_equal 'foo@example.com', Rails.configuration.new_inactive_user_notification_recipients
+
+ ActionMailer::Base.deliveries.each do |d|
+ assert_not_equal "#{Rails.configuration.email_subject_prefix}New inactive user notification", setup_email.subject
+ end
+
+ end
+
+
+ test "update existing user" do
+ Thread.current[:user] = @active_user # set active user as current user
+ @active_user.first_name = "first_name_changed"
+ @active_user.save
+
+ @active_user = User.find(@active_user.id) # get the user back
+ assert_equal(@active_user.first_name, 'first_name_changed')
+
+ # admin user also should be able to update the "active" user info
+ Thread.current[:user] = @admin_user # set admin user as current user
+ @active_user.first_name = "first_name_changed_by_admin_for_active_user"
+ @active_user.save
+
+ @active_user = User.find(@active_user.id) # get the user back
+ assert_equal(@active_user.first_name, 'first_name_changed_by_admin_for_active_user')
+ end
+
+ test "delete a user and verify" do
+ active_user_uuid = @active_user.uuid
+
+ Thread.current[:user] = @admin_user
+ @active_user.delete
+
+ found_deleted_user = false
+ User.find(:all).each do |user|
+ if user.uuid == active_user_uuid
+ found_deleted_user = true
+ break
+ end