Commit c1fd590056d4d094b16d5717c4bb20b7fc88cf2d
1 parent
29966d34
Exists in
master
and in
5 other branches
Add user registration tests
Signed-off-by: Gustavo Jaruga <darksshades@gmail.com> Signed-off-by: Parley Martins <parley@outlook.com>
Showing
1 changed file
with
65 additions
and
22 deletions
Show diff stats
test/functional/account_controller_test.rb
| ... | ... | @@ -10,8 +10,8 @@ class AccountControllerTest < ActionController::TestCase |
| 10 | 10 | environment.enabled_plugins = ['MpogSoftwarePlugin'] |
| 11 | 11 | environment.save |
| 12 | 12 | |
| 13 | - @govPower = GovernmentalPower.create(:name=>"Some Gov Power") | |
| 14 | - @govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | |
| 13 | + @gov_power = GovernmentalPower.create(:name=>"Some Gov Power") | |
| 14 | + @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | |
| 15 | 15 | @juridical_nature = JuridicalNature.create(:name => "Autarquia") |
| 16 | 16 | |
| 17 | 17 | @controller = AccountController.new |
| ... | ... | @@ -19,8 +19,8 @@ class AccountControllerTest < ActionController::TestCase |
| 19 | 19 | @response = ActionController::TestResponse.new |
| 20 | 20 | |
| 21 | 21 | @institution_list = [] |
| 22 | - @institution_list << create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @govPower, @govSphere) | |
| 23 | - @institution_list << create_public_institution("Tribunal Regional da Uniao", "TRU", "BR", "DF", "Brasilia", @juridical_nature, @govPower, @govSphere) | |
| 22 | + @institution_list << create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @gov_power, @gov_sphere) | |
| 23 | + @institution_list << create_public_institution("Tribunal Regional da Uniao", "TRU", "BR", "DF", "Brasilia", @juridical_nature, @gov_power, @gov_sphere) | |
| 24 | 24 | @user_info = { |
| 25 | 25 | :login=>"novo_usuario", |
| 26 | 26 | :password=>"nova_senha", |
| ... | ... | @@ -30,11 +30,24 @@ class AccountControllerTest < ActionController::TestCase |
| 30 | 30 | :institution_ids=>[@institution_list.last.id] |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | + @second_user_info = { | |
| 34 | + :login=>"outro_usuario", | |
| 35 | + :password=>"nova_senha", | |
| 36 | + :password_confirmation=>"nova_senha", | |
| 37 | + :email=>"um_outro@novo.usuario", | |
| 38 | + :secondary_email=>"outro2@email.com", | |
| 39 | + :institution_ids=>[@institution_list.last.id] | |
| 40 | + } | |
| 41 | + | |
| 33 | 42 | @profile_data_info = { |
| 34 | 43 | :name=>"Um novo usuario", |
| 35 | 44 | :area_interest=>"uma area ai" |
| 36 | 45 | } |
| 37 | 46 | |
| 47 | + @second_profile_data_info = { | |
| 48 | + :name=>"Um outro usuario", | |
| 49 | + :area_interest=>"uma area ai" | |
| 50 | + } | |
| 38 | 51 | disable_signup_bot_check |
| 39 | 52 | end |
| 40 | 53 | |
| ... | ... | @@ -89,6 +102,36 @@ class AccountControllerTest < ActionController::TestCase |
| 89 | 102 | assert last_user.institutions.include?(@institution_list.last) |
| 90 | 103 | end |
| 91 | 104 | |
| 105 | + should "not create a user with secondary email as someone's primary email" do | |
| 106 | + @second_user_info[:secondary_email] = @user_info[:email] | |
| 107 | + | |
| 108 | + post :signup, :user => @user_info, :profile_data => @profile_data_info | |
| 109 | + post :signup, :user => @second_user_info, :profile_data => @second_profile_data_info | |
| 110 | + assert !assigns(:user).save, "This should not have been saved." | |
| 111 | + end | |
| 112 | + | |
| 113 | + should "not create a user with secondary email as someone's secondary email" do | |
| 114 | + @second_user_info[:secondary_email] = @user_info[:secondary_email] | |
| 115 | + | |
| 116 | + post :signup, :user => @user_info, :profile_data => @profile_data_info | |
| 117 | + post :signup, :user => @second_user_info, :profile_data => @second_profile_data_info | |
| 118 | + assert !assigns(:user).save, "This should not have been saved." | |
| 119 | + end | |
| 120 | + | |
| 121 | + should "not create a user with equal emails" do | |
| 122 | + @user_info[:email] = @user_info[:secondary_email] | |
| 123 | + | |
| 124 | + post :signup, :user => @user_info, :profile_data => @profile_data_info | |
| 125 | + assert !assigns(:user).save, "This should not have been saved." | |
| 126 | + end | |
| 127 | + | |
| 128 | + should "not create a user with governmental secondary email" do | |
| 129 | + @user_info[:secondary_email] = "email@gov.br" | |
| 130 | + | |
| 131 | + post :signup, :user => @user_info, :profile_data => @profile_data_info | |
| 132 | + assert !assigns(:user).save, "This should not have been saved." | |
| 133 | + end | |
| 134 | + | |
| 92 | 135 | private |
| 93 | 136 | |
| 94 | 137 | def create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s |
| ... | ... | @@ -110,24 +153,24 @@ class AccountControllerTest < ActionController::TestCase |
| 110 | 153 | institution |
| 111 | 154 | end |
| 112 | 155 | |
| 113 | - def form_params | |
| 114 | - user = { | |
| 115 | - :login=>"novo_usuario", | |
| 116 | - :password=>"nova_senha", | |
| 117 | - :password_confirmation=>"nova_senha", | |
| 118 | - :email=>"um@novo.usuario", | |
| 119 | - :secondary_email=>"outro@email.com", | |
| 120 | - :institution_ids=>[@institution_list.last.id] | |
| 121 | - } | |
| 122 | - | |
| 123 | - profile_data = { | |
| 124 | - :name=>"Um novo usuario", | |
| 125 | - :area_interest=>"uma area ai" | |
| 126 | - } | |
| 127 | - | |
| 128 | - user["profile_data"] = profile_data | |
| 129 | - user | |
| 130 | - end | |
| 156 | + # def form_params | |
| 157 | + # user = { | |
| 158 | + # :login=>"novo_usuario", | |
| 159 | + # :password=>"nova_senha", | |
| 160 | + # :password_confirmation=>"nova_senha", | |
| 161 | + # :email=>"um@novo.usuario", | |
| 162 | + # :secondary_email=>"outro@email.com", | |
| 163 | + # :institution_ids=>[@institution_list.last.id] | |
| 164 | + # } | |
| 165 | + | |
| 166 | + # profile_data = { | |
| 167 | + # :name=>"Um novo usuario", | |
| 168 | + # :area_interest=>"uma area ai" | |
| 169 | + # } | |
| 170 | + | |
| 171 | + # user["profile_data"] = profile_data | |
| 172 | + # user | |
| 173 | + # end | |
| 131 | 174 | |
| 132 | 175 | def disable_signup_bot_check(environment = Environment.default) |
| 133 | 176 | environment.min_signup_delay = 0 | ... | ... |