Commit 6fe4cacdfbbe0012501e3fd5ef21af009c1dd518

Authored by Antonio Terceiro
1 parent f72ac6a9

ActionItem1193: fixing user registration!

app/controllers/public/account_controller.rb
... ... @@ -51,6 +51,7 @@ class AccountController < ApplicationController
51 51 @user.terms_of_use = environment.terms_of_use
52 52 @user.environment = environment
53 53 @terms_of_use = environment.terms_of_use
  54 + @user.person_data = params[:profile_data]
54 55 @person = Person.new(params[:profile_data])
55 56 @person.name = @user.login
56 57 @person.environment = @user.environment
... ...
app/models/user.rb
... ... @@ -29,10 +29,16 @@ class User < ActiveRecord::Base
29 29  
30 30 after_create do |user|
31 31 user.person ||= Person.new
  32 + user.person.attributes = user.person_data
32 33 user.person.name ||= user.login
33 34 user.person.update_attributes(:identifier => user.login, :user_id => user.id, :environment_id => user.environment_id)
34 35 end
35 36  
  37 + attr_writer :person_data
  38 + def person_data
  39 + @person_data || {}
  40 + end
  41 +
36 42 before_update do |user|
37 43 if !User.find(user.id).enable_email and user.enable_email and !user.environment.nil?
38 44 User::Mailer.deliver_activation_email_notify(user)
... ...
test/functional/account_controller_test.rb
... ... @@ -635,6 +635,14 @@ class AccountControllerTest < Test::Unit::TestCase
635 635 end
636 636 end
637 637  
  638 + should 'signup filling in mandatory person fields' do
  639 + Person.any_instance.stubs(:required_fields).returns(['organization_website'])
  640 + assert_difference User, :count do
  641 + post :signup, :user => { :login => 'testuser', :password => '123456', :password_confirmation => '123456', :email => 'testuser@example.com' }, :profile_data => { :organization_website => 'example.com' }
  642 + assert_redirected_to :controller => 'profile_editor', :profile => 'testuser'
  643 + end
  644 + end
  645 +
638 646 protected
639 647 def new_user(options = {}, extra_options ={})
640 648 data = {:profile_data => person_data}
... ...