Commit c668a3249b8ac651705ebd70dbdb89809e1d65da

Authored by Carlos Purificação
1 parent 8c6a28dd

Fix user creation pt-br messages

app/models/user.rb
... ... @@ -104,18 +104,18 @@ class User < ActiveRecord::Base
104 104  
105 105 validates_presence_of :login
106 106 validates_presence_of :email
107   - validates_format_of :login, :message => _('incorrect login format'), :with => Profile::IDENTIFIER_FORMAT, :if => (lambda {|user| !user.login.blank?})
  107 + validates_format_of :login, :message => :login_format, :with => Profile::IDENTIFIER_FORMAT, :if => (lambda {|user| !user.login.blank?})
108 108 validates_presence_of :password, :if => :password_required?
109 109 validates_presence_of :password_confirmation, :if => :password_required?
110   - validates_length_of :password, :message => _('length must be within 4 to 40 characters'), :within => 4..40, :if => :password_required?
  110 + validates_length_of :password, :within => 4..40, :if => :password_required?
111 111 validates_confirmation_of :password, :if => :password_required?
112   - validates_length_of :login, :message => _('length must be within 2 to 40 characters'), :within => 2..40, :if => (lambda {|user| !user.login.blank?})
113   - validates_length_of :email, :message => _('length must be within 3 to 100 characters'),:within => 3..100, :if => (lambda {|user| !user.email.blank?})
  112 + validates_length_of :login, :within => 2..40, :if => (lambda {|user| !user.login.blank?})
  113 + validates_length_of :email, :within => 3..100, :if => (lambda {|user| !user.email.blank?})
114 114 validates_uniqueness_of :login, :case_sensitive => false, :scope => :environment_id
115 115 validates_uniqueness_of :email, :case_sensitive => false, :scope => :environment_id
116 116 before_save :encrypt_password
117 117 before_save :normalize_email, if: proc{ |u| u.email.present? }
118   - validates_format_of :email, :message => _('incorrect email format'), :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda {|user| !user.email.blank?})
  118 + validates_format_of :email, :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda {|user| !user.email.blank?})
119 119  
120 120 validates_inclusion_of :terms_accepted, :in => [ '1' ], :if => lambda { |u| ! u.terms_of_use.blank? }, :message => N_('{fn} must be checked in order to signup.').fix_i18n
121 121  
... ...
config/locales/en-US.yml
... ... @@ -221,6 +221,9 @@
221 221 <<: *errors_template
222 222 full_messages:
223 223 format: "%{attribute} %{message}"
  224 + models:
  225 + user:
  226 + login_format: "with invalid format. It must contain only lowercase letters, digits, '_' and '-', and must begin with a letter or a digit."
224 227  
225 228 en:
226 229 <<: *en-US
... ...
config/locales/pt-BR.yml
... ... @@ -229,9 +229,11 @@
229 229 <<: *errors_messages
230 230 template:
231 231 <<: *errors_template
232   -
233 232 full_messages:
234 233 format: "%{attribute} %{message}"
  234 + models:
  235 + user:
  236 + login_format: "com formato inválido. Só pode conter letras minúsculas não acentudadas, dígitos, '_' e '-', e deve iniciar com uma letra ou um dígito."
235 237  
236 238 pt:
237 239 <<: *pt-BR
... ...
config/locales/pt-PT.yml
... ... @@ -229,3 +229,4 @@
229 229  
230 230 full_messages:
231 231 format: "%{attribute} %{message}"
  232 +
... ...
db/schema.rb
... ... @@ -11,7 +11,7 @@
11 11 #
12 12 # It's strongly recommended to check this file into your version control system.
13 13  
14   -ActiveRecord::Schema.define(:version => 20150712194411) do
  14 +ActiveRecord::Schema.define(:version => 20150722042714) do
15 15  
16 16 create_table "abuse_reports", :force => true do |t|
17 17 t.integer "reporter_id"
... ... @@ -163,8 +163,6 @@ ActiveRecord::Schema.define(:version =&gt; 20150712194411) do
163 163 t.integer "author_id"
164 164 t.integer "created_by_id"
165 165 t.boolean "show_to_followers", :default => true
166   - t.integer "sash_id"
167   - t.integer "level", :default => 0
168 166 end
169 167  
170 168 add_index "articles", ["comments_count"], :name => "index_articles_on_comments_count"
... ... @@ -191,17 +189,6 @@ ActiveRecord::Schema.define(:version =&gt; 20150712194411) do
191 189 add_index "articles_categories", ["article_id"], :name => "index_articles_categories_on_article_id"
192 190 add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id"
193 191  
194   - create_table "badges_sashes", :force => true do |t|
195   - t.integer "badge_id"
196   - t.integer "sash_id"
197   - t.boolean "notified_user", :default => false
198   - t.datetime "created_at"
199   - end
200   -
201   - add_index "badges_sashes", ["badge_id", "sash_id"], :name => "index_badges_sashes_on_badge_id_and_sash_id"
202   - add_index "badges_sashes", ["badge_id"], :name => "index_badges_sashes_on_badge_id"
203   - add_index "badges_sashes", ["sash_id"], :name => "index_badges_sashes_on_sash_id"
204   -
205 192 create_table "blocks", :force => true do |t|
206 193 t.string "title"
207 194 t.integer "box_id"
... ... @@ -297,10 +284,8 @@ ActiveRecord::Schema.define(:version =&gt; 20150712194411) do
297 284 t.string "referrer"
298 285 t.text "settings"
299 286 t.integer "paragraph_id"
300   - t.string "paragraph_uuid"
301 287 end
302 288  
303   - add_index "comments", ["paragraph_uuid"], :name => "index_comments_on_paragraph_uuid"
304 289 add_index "comments", ["source_id", "spam"], :name => "index_comments_on_source_id_and_spam"
305 290  
306 291 create_table "contact_lists", :force => true do |t|
... ... @@ -370,7 +355,6 @@ ActiveRecord::Schema.define(:version =&gt; 20150712194411) do
370 355 t.string "default_language"
371 356 t.string "noreply_email"
372 357 t.string "redirection_after_signup", :default => "keep_on_same_page"
373   - t.text "send_email_plugin_allow_to"
374 358 t.string "date_format", :default => "month_name_with_year"
375 359 end
376 360  
... ... @@ -407,17 +391,6 @@ ActiveRecord::Schema.define(:version =&gt; 20150712194411) do
407 391 add_index "friendships", ["person_id", "friend_id"], :name => "index_friendships_on_person_id_and_friend_id"
408 392 add_index "friendships", ["person_id"], :name => "index_friendships_on_person_id"
409 393  
410   - create_table "gamification_plugin_badges", :force => true do |t|
411   - t.string "name"
412   - t.integer "level"
413   - t.string "description"
414   - t.string "custom_fields"
415   - t.integer "owner_id"
416   - t.string "owner_type"
417   - t.datetime "created_at", :null => false
418   - t.datetime "updated_at", :null => false
419   - end
420   -
421 394 create_table "images", :force => true do |t|
422 395 t.integer "parent_id"
423 396 t.string "content_type"
... ... @@ -474,46 +447,6 @@ ActiveRecord::Schema.define(:version =&gt; 20150712194411) do
474 447 t.datetime "updated_at"
475 448 end
476 449  
477   - create_table "mark_comment_as_read_plugin", :force => true do |t|
478   - t.integer "comment_id"
479   - t.integer "person_id"
480   - end
481   -
482   - add_index "mark_comment_as_read_plugin", ["comment_id", "person_id"], :name => "index_mark_comment_as_read_plugin_on_comment_id_and_person_id", :unique => true
483   -
484   - create_table "merit_actions", :force => true do |t|
485   - t.integer "user_id"
486   - t.string "action_method"
487   - t.integer "action_value"
488   - t.boolean "had_errors", :default => false
489   - t.string "target_model"
490   - t.integer "target_id"
491   - t.text "target_data"
492   - t.boolean "processed", :default => false
493   - t.datetime "created_at", :null => false
494   - t.datetime "updated_at", :null => false
495   - end
496   -
497   - create_table "merit_activity_logs", :force => true do |t|
498   - t.integer "action_id"
499   - t.string "related_change_type"
500   - t.integer "related_change_id"
501   - t.string "description"
502   - t.datetime "created_at"
503   - end
504   -
505   - create_table "merit_score_points", :force => true do |t|
506   - t.integer "score_id"
507   - t.integer "num_points", :default => 0
508   - t.string "log"
509   - t.datetime "created_at"
510   - end
511   -
512   - create_table "merit_scores", :force => true do |t|
513   - t.integer "sash_id"
514   - t.string "category", :default => "default"
515   - end
516   -
517 450 create_table "national_region_types", :force => true do |t|
518 451 t.string "name"
519 452 end
... ... @@ -530,15 +463,6 @@ ActiveRecord::Schema.define(:version =&gt; 20150712194411) do
530 463 add_index "national_regions", ["name"], :name => "name_index"
531 464 add_index "national_regions", ["national_region_code"], :name => "code_index"
532 465  
533   - create_table "pairwise_plugin_choices_related", :force => true do |t|
534   - t.integer "choice_id"
535   - t.integer "parent_choice_id"
536   - t.integer "question_id"
537   - t.integer "user_id"
538   - t.datetime "created_at", :null => false
539   - t.datetime "updated_at", :null => false
540   - end
541   -
542 466 create_table "price_details", :force => true do |t|
543 467 t.decimal "price", :default => 0.0
544 468 t.integer "product_id"
... ... @@ -646,21 +570,15 @@ ActiveRecord::Schema.define(:version =&gt; 20150712194411) do
646 570 t.boolean "allow_members_to_invite", :default => true
647 571 t.boolean "invite_friends_only", :default => false
648 572 t.boolean "secret", :default => false
649   - t.integer "sash_id"
650   - t.integer "level", :default => 0
651 573 end
652 574  
653 575 add_index "profiles", ["activities_count"], :name => "index_profiles_on_activities_count"
654 576 add_index "profiles", ["created_at"], :name => "index_profiles_on_created_at"
655   - add_index "profiles", ["enabled"], :name => "index_profiles_on_enabled"
656 577 add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id"
657 578 add_index "profiles", ["friends_count"], :name => "index_profiles_on_friends_count"
658 579 add_index "profiles", ["identifier"], :name => "index_profiles_on_identifier"
659 580 add_index "profiles", ["members_count"], :name => "index_profiles_on_members_count"
660 581 add_index "profiles", ["region_id"], :name => "index_profiles_on_region_id"
661   - add_index "profiles", ["type"], :name => "index_profiles_on_type"
662   - add_index "profiles", ["validated"], :name => "index_profiles_on_validated"
663   - add_index "profiles", ["visible"], :name => "index_profiles_on_visible"
664 582  
665 583 create_table "proposals_discussion_plugin_proposal_evaluations", :force => true do |t|
666 584 t.integer "proposal_task_id"
... ... @@ -718,12 +636,6 @@ ActiveRecord::Schema.define(:version =&gt; 20150712194411) do
718 636 t.boolean "is_global"
719 637 end
720 638  
721   - add_index "role_assignments", ["accessor_id", "accessor_type", "resource_id", "resource_type"], :name => "index_on_role_assigments_accessor_resource_role"
722   - add_index "role_assignments", ["accessor_id", "accessor_type", "role_id"], :name => "index_on_role_assigments_accessor_role"
723   - add_index "role_assignments", ["accessor_id", "accessor_type"], :name => "index_role_assignments_on_accessor_id_and_accessor_type"
724   - add_index "role_assignments", ["resource_id", "resource_type", "role_id"], :name => "index_on_role_assigments_resource_role"
725   - add_index "role_assignments", ["resource_id", "resource_type"], :name => "index_role_assignments_on_resource_id_and_resource_type"
726   -
727 639 create_table "roles", :force => true do |t|
728 640 t.string "name"
729 641 t.string "key"
... ... @@ -733,11 +645,6 @@ ActiveRecord::Schema.define(:version =&gt; 20150712194411) do
733 645 t.integer "profile_id"
734 646 end
735 647  
736   - create_table "sashes", :force => true do |t|
737   - t.datetime "created_at", :null => false
738   - t.datetime "updated_at", :null => false
739   - end
740   -
741 648 create_table "scraps", :force => true do |t|
742 649 t.text "content"
743 650 t.integer "sender_id"
... ...
script/updatepo/data/pt.upo
... ... @@ -128,8 +128,3 @@ msgid &quot;Saved with success!&quot;# msgstr &quot;Salvo com sucesso!&quot;
128 128 msgid "Select at least one category"# msgstr "Selecione pelo menos uma categoria"
129 129 msgid "Task Acceptance"# msgstr "Aceitar Tarefa"
130 130 msgid "Select an acceptance email template:"# msgstr "Selecionar modelo de email para aceitar:"
131   -msgid "incorrect email format"# msgstr "formato do email inválido. O mesmo só pode ser composto por letras minúsculas, números, '_' e '-'. Adicionalmente não é permitido usar acentuação nem começar com '_' ou '-'"
132   -msgid "incorrect login format"# msgstr "formato do login inválido. O mesmo só pode ser composto por letras minúsculas, números, '_' e '-'. Adicionalmente não é permitido usar acentuação nem começar com '_' ou '-'"
133   -msgid "length must be within 4 to 40 characters"# msgstr "o tamanho do campo deve ser entre 4 e 40 caracteres"
134   -msgid "length must be within 2 to 40 characters"# msgstr "o tamanho do campo deve ser entre 2 e 40 caracteres"
135   -msgid "length must be within 3 to 100 characters"# msgstr "o tamanho do campo deve ser entre 3 e 100 caracteres"
... ...
test/unit/api/session_test.rb
... ... @@ -39,7 +39,32 @@ class SessionTest &lt; ActiveSupport::TestCase
39 39 assert json['private_token'].blank?
40 40 end
41 41  
42   - should 'do not register a user without email' do
  42 + should 'not register a user with invalid login' do
  43 + params = {:login => "c", :password => "newuserapi", :password_confirmation => "newuserapi", :email => "newuserapi@email.com" }
  44 + post "/api/v1/register?#{params.to_query}"
  45 + assert_equal 400, last_response.status
  46 + json = JSON.parse(last_response.body)
  47 + msg = json['message'].split(':')
  48 + key = msg[0][2, 5]
  49 + val = msg[1][2, 38]
  50 + assert_equal "login", key
  51 + assert_equal "is too short (minimum is 2 characters)", val
  52 + end
  53 +
  54 + should 'not register a user with invalid login pt' do
  55 + I18n.locale = "pt-BR"
  56 + params = {:lang => "pt-BR", :login => "c", :password => "newuserapi", :password_confirmation => "newuserapi", :email => "newuserapi@email.com" }
  57 + post "/api/v1/register?#{params.to_query}"
  58 + assert_equal 400, last_response.status
  59 + json = JSON.parse(last_response.body)
  60 + msg = json['message'].split(':')
  61 + key = msg[0][2, 5]
  62 + val = msg[1][2, 35]
  63 + assert_equal "login", key
  64 + assert val.include? "muito curto"
  65 + end
  66 +
  67 + should 'not register a user without email' do
43 68 params = {:login => "newuserapi", :password => "newuserapi", :password_confirmation => "newuserapi", :email => nil }
44 69 post "/api/v1/register?#{params.to_query}"
45 70 assert_equal 400, last_response.status
... ...