Commit 24c796645557b7e1f50ad3b4c80310a68b3ba3b9
Committed by
Tallys Martins
1 parent
d9a22bdf
Exists in
master
and in
29 other branches
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>
Showing
3 changed files
with
18 additions
and
13 deletions
Show diff stats
app/controllers/public/account_controller.rb
@@ -87,7 +87,7 @@ class AccountController < ApplicationController | @@ -87,7 +87,7 @@ class AccountController < ApplicationController | ||
87 | @person.environment = @user.environment | 87 | @person.environment = @user.environment |
88 | unless @user.environment.enabled?('admin_must_approve_new_users') | 88 | unless @user.environment.enabled?('admin_must_approve_new_users') |
89 | if request.post? | 89 | if request.post? |
90 | - @person.update_attributes(params[:profile_data]) | 90 | + @person.attributes = params[:profile_data] |
91 | if may_be_a_bot | 91 | if may_be_a_bot |
92 | set_signup_start_time_for_now | 92 | set_signup_start_time_for_now |
93 | @block_bot = true | 93 | @block_bot = true |
app/models/create_user.rb
@@ -26,17 +26,12 @@ class CreateUser < Task | @@ -26,17 +26,12 @@ class CreateUser < Task | ||
26 | end | 26 | end |
27 | 27 | ||
28 | def perform | 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 | author_name = user.name | 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 | user.environment = self.environment | 32 | user.environment = self.environment |
38 | - person.environment = user.environment | ||
39 | - user.save! | 33 | + user.person.environment = user.environment |
34 | + user.signup! | ||
40 | end | 35 | end |
41 | 36 | ||
42 | def title | 37 | def title |
@@ -69,4 +64,14 @@ class CreateUser < Task | @@ -69,4 +64,14 @@ class CreateUser < Task | ||
69 | def target_notification_message | 64 | def target_notification_message |
70 | _("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 } | 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 | end | 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 | end | 77 | end |
73 | \ No newline at end of file | 78 | \ No newline at end of file |
features/signup.feature
@@ -312,8 +312,8 @@ Feature: signup | @@ -312,8 +312,8 @@ Feature: signup | ||
312 | And feature "skip_new_user_email_confirmation" is enabled on environment | 312 | And feature "skip_new_user_email_confirmation" is enabled on environment |
313 | And I go to /account/signup | 313 | And I go to /account/signup |
314 | And I fill in "Username" with "teste" | 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 | And I fill in "e-Mail" with "teste@teste.com" | 317 | And I fill in "e-Mail" with "teste@teste.com" |
318 | And I fill in "Full name" with "Teste da Silva" | 318 | And I fill in "Full name" with "Teste da Silva" |
319 | And I press "Create my account" | 319 | And I press "Create my account" |
@@ -325,7 +325,7 @@ Feature: signup | @@ -325,7 +325,7 @@ Feature: signup | ||
325 | And I follow "Logout" | 325 | And I follow "Logout" |
326 | And I follow "Login" | 326 | And I follow "Login" |
327 | And I fill in "Username / Email" with "teste" | 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 | And I press "Log in" | 329 | And I press "Log in" |
330 | Then I should see "teste" | 330 | Then I should see "teste" |
331 | 331 |