Commit 24c796645557b7e1f50ad3b4c80310a68b3ba3b9

Authored by tallys
Committed by Tallys Martins
1 parent d9a22bdf

Refactoring "perform" method on CreateUser task and "signup" method on AccountController

Signed-off-by: André Bernardes <andrebsguedes@gmail.com>
Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
app/controllers/public/account_controller.rb
... ... @@ -87,7 +87,7 @@ class AccountController &lt; ApplicationController
87 87 @person.environment = @user.environment
88 88 unless @user.environment.enabled?('admin_must_approve_new_users')
89 89 if request.post?
90   - @person.update_attributes(params[:profile_data])
  90 + @person.attributes = params[:profile_data]
91 91 if may_be_a_bot
92 92 set_signup_start_time_for_now
93 93 @block_bot = true
... ...
app/models/create_user.rb
... ... @@ -26,17 +26,12 @@ class CreateUser &lt; Task
26 26 end
27 27  
28 28 def perform
29   - user = User.new
30   - person = Person.new(person_data)
  29 + user = User.new(user_data)
  30 + user.person = Person.new(person_data)
31 31 author_name = user.name
32   - user_data = self.data.reject do |key, value|
33   - ! DATA_FIELDS.include?(key.to_s)
34   - end
35   - person.update_attributes(@person)
36   - user.update_attributes(user_data)
37 32 user.environment = self.environment
38   - person.environment = user.environment
39   - user.save!
  33 + user.person.environment = user.environment
  34 + user.signup!
40 35 end
41 36  
42 37 def title
... ... @@ -69,4 +64,14 @@ class CreateUser &lt; Task
69 64 def target_notification_message
70 65 _("User \"%{user}\" just requested to register. You have to approve or reject it through the \"Pending Validations\" section in your control panel.\n") % { :user => self.name }
71 66 end
  67 +
  68 + protected
  69 +
  70 + def user_data
  71 + user_data = self.data.reject do |key, value|
  72 + !DATA_FIELDS.include?(key.to_s)
  73 + end
  74 +
  75 + user_data
  76 + end
72 77 end
73 78 \ No newline at end of file
... ...
features/signup.feature
... ... @@ -312,8 +312,8 @@ Feature: signup
312 312 And feature "skip_new_user_email_confirmation" is enabled on environment
313 313 And I go to /account/signup
314 314 And I fill in "Username" with "teste"
315   - And I fill in "Password" with "1234"
316   - And I fill in "Password confirmation" with "1234"
  315 + And I fill in "Password" with "123456"
  316 + And I fill in "Password confirmation" with "123456"
317 317 And I fill in "e-Mail" with "teste@teste.com"
318 318 And I fill in "Full name" with "Teste da Silva"
319 319 And I press "Create my account"
... ... @@ -325,7 +325,7 @@ Feature: signup
325 325 And I follow "Logout"
326 326 And I follow "Login"
327 327 And I fill in "Username / Email" with "teste"
328   - And I fill in "Password" with "1234"
  328 + And I fill in "Password" with "123456"
329 329 And I press "Log in"
330 330 Then I should see "teste"
331 331  
... ...