Commit 37d8ade76cb34951b74c4adb9e92fafba7c0cb0c
Committed by
Gabriela Navarro
1 parent
cda90bda
Exists in
master
and in
5 other branches
fix_institution: Fix functional tests
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Showing
3 changed files
with
15 additions
and
285 deletions
Show diff stats
test/functional/account_controller_test.rb
| @@ -1,185 +0,0 @@ | @@ -1,185 +0,0 @@ | ||
| 1 | -require File.dirname(__FILE__) + '/../../../../test/test_helper' | ||
| 2 | -require File.dirname(__FILE__) + '/../../controllers/mpog_software_plugin_controller' | ||
| 3 | - | ||
| 4 | -class AccountController; def rescue_action(e) raise e end; end | ||
| 5 | - | ||
| 6 | -class AccountControllerTest < ActionController::TestCase | ||
| 7 | - | ||
| 8 | - def setup | ||
| 9 | - environment = Environment.default | ||
| 10 | - environment.enabled_plugins = ['MpogSoftwarePlugin'] | ||
| 11 | - environment.save | ||
| 12 | - | ||
| 13 | - @gov_power = GovernmentalPower.create(:name=>"Some Gov Power") | ||
| 14 | - @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | ||
| 15 | - @juridical_nature = JuridicalNature.create(:name => "Autarquia") | ||
| 16 | - | ||
| 17 | - @controller = AccountController.new | ||
| 18 | - @request = ActionController::TestRequest.new | ||
| 19 | - @response = ActionController::TestResponse.new | ||
| 20 | - | ||
| 21 | - @institution_list = [] | ||
| 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 | - @user_info = { | ||
| 25 | - :login=>"novo_usuario", | ||
| 26 | - :password=>"nova_senha", | ||
| 27 | - :password_confirmation=>"nova_senha", | ||
| 28 | - :email=>"um@novo.usuario", | ||
| 29 | - :secondary_email=>"outro@email.com", | ||
| 30 | - :institution_ids=>[@institution_list.last.id] | ||
| 31 | - } | ||
| 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 | - | ||
| 42 | - @profile_data_info = { | ||
| 43 | - :name=>"Um Novo Usuario", | ||
| 44 | - } | ||
| 45 | - | ||
| 46 | - @second_profile_data_info = { | ||
| 47 | - :name=>"Um Outro Usuario", | ||
| 48 | - } | ||
| 49 | - disable_signup_bot_check | ||
| 50 | - end | ||
| 51 | - | ||
| 52 | - should "Create a user without gov email and institution" do | ||
| 53 | - @user_info[:institution_ids] = nil | ||
| 54 | - | ||
| 55 | - post :signup, :user => @user_info, :profile_data => @profile_data_info | ||
| 56 | - | ||
| 57 | - assert_equal assigns(:user).login, @user_info[:login] | ||
| 58 | - assert assigns(:user).save | ||
| 59 | - end | ||
| 60 | - | ||
| 61 | - should "Create a user with gov email and institution" do | ||
| 62 | - @user_info[:email] = "email@gov.br" | ||
| 63 | - | ||
| 64 | - post :signup, :user => @user_info, :profile_data => @profile_data_info | ||
| 65 | - | ||
| 66 | - assert_equal assigns(:user).login, @user_info[:login] | ||
| 67 | - assert assigns(:user).save | ||
| 68 | - end | ||
| 69 | - | ||
| 70 | - should "Do not create a user with gov email without institution" do | ||
| 71 | - @user_info[:email] = "email@gov.br" | ||
| 72 | - @user_info[:institution_ids] = nil | ||
| 73 | - | ||
| 74 | - post :signup, :user => @user_info, :profile_data => @profile_data_info | ||
| 75 | - | ||
| 76 | - assert_equal assigns(:user).login, @user_info[:login] | ||
| 77 | - assert !assigns(:user).save | ||
| 78 | - end | ||
| 79 | - | ||
| 80 | - should "user become a member of its institution community on registration" do | ||
| 81 | - post :signup, :user => @user_info, :profile_data => @profile_data_info | ||
| 82 | - | ||
| 83 | - last_user = User.last | ||
| 84 | - last_community = Community.last | ||
| 85 | - | ||
| 86 | - assert_equal @user_info[:secondary_email], last_user.secondary_email | ||
| 87 | - assert_equal true, last_community.members.include?(last_user.person) | ||
| 88 | - assert_response :success | ||
| 89 | - end | ||
| 90 | - | ||
| 91 | - | ||
| 92 | - should "user can become a member of more than one institution" do | ||
| 93 | - @user_info[:institution_ids] = [@institution_list.first.id, @institution_list.last.id] | ||
| 94 | - | ||
| 95 | - post :signup, :user => @user_info, :profile_data => @profile_data_info | ||
| 96 | - | ||
| 97 | - last_user = User.last | ||
| 98 | - | ||
| 99 | - assert last_user.institutions.include?(@institution_list.first) | ||
| 100 | - assert last_user.institutions.include?(@institution_list.last) | ||
| 101 | - end | ||
| 102 | - | ||
| 103 | - should "not create a user with secondary email as someone's primary email" do | ||
| 104 | - @second_user_info[:secondary_email] = @user_info[:email] | ||
| 105 | - | ||
| 106 | - post :signup, :user => @user_info, :profile_data => @profile_data_info | ||
| 107 | - post :signup, :user => @second_user_info, :profile_data => @second_profile_data_info | ||
| 108 | - assert !assigns(:user).save, "This should not have been saved." | ||
| 109 | - end | ||
| 110 | - | ||
| 111 | - should "not create a user with secondary email as someone's secondary email" do | ||
| 112 | - @second_user_info[:secondary_email] = @user_info[:secondary_email] | ||
| 113 | - | ||
| 114 | - post :signup, :user => @user_info, :profile_data => @profile_data_info | ||
| 115 | - post :signup, :user => @second_user_info, :profile_data => @second_profile_data_info | ||
| 116 | - assert !assigns(:user).save, "This should not have been saved." | ||
| 117 | - end | ||
| 118 | - | ||
| 119 | - should "not create a user with equal emails" do | ||
| 120 | - @user_info[:email] = @user_info[:secondary_email] | ||
| 121 | - | ||
| 122 | - post :signup, :user => @user_info, :profile_data => @profile_data_info | ||
| 123 | - assert !assigns(:user).save, "This should not have been saved." | ||
| 124 | - end | ||
| 125 | - | ||
| 126 | - should "not create a user with governmental secondary email" do | ||
| 127 | - @user_info[:secondary_email] = "email@gov.br" | ||
| 128 | - | ||
| 129 | - post :signup, :user => @user_info, :profile_data => @profile_data_info | ||
| 130 | - assert !assigns(:user).save, "This should not have been saved." | ||
| 131 | - end | ||
| 132 | - | ||
| 133 | - should "user can register without secondary_email" do | ||
| 134 | - @user_info[:secondary_email] = "" | ||
| 135 | - | ||
| 136 | - post :signup, :user => @user_info, :profile_data => @profile_data_info | ||
| 137 | - | ||
| 138 | - assert_equal assigns(:user).login, @user_info[:login] | ||
| 139 | - assert assigns(:user).save | ||
| 140 | - end | ||
| 141 | - | ||
| 142 | - private | ||
| 143 | - | ||
| 144 | - def create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s | ||
| 145 | - institution_community = fast_create(Community) | ||
| 146 | - institution_community.name = name | ||
| 147 | - institution_community.country = country | ||
| 148 | - institution_community.state = state | ||
| 149 | - institution_community.city = city | ||
| 150 | - institution_community.save! | ||
| 151 | - | ||
| 152 | - institution = PublicInstitution.new | ||
| 153 | - institution.community = institution_community | ||
| 154 | - institution.name = name | ||
| 155 | - institution.juridical_nature = juridical_nature | ||
| 156 | - institution.acronym = acronym | ||
| 157 | - institution.governmental_power = gov_p | ||
| 158 | - institution.governmental_sphere = gov_s | ||
| 159 | - institution.save! | ||
| 160 | - institution | ||
| 161 | - end | ||
| 162 | - | ||
| 163 | - def form_params | ||
| 164 | - user = { | ||
| 165 | - :login=>"novo_usuario", | ||
| 166 | - :password=>"nova_senha", | ||
| 167 | - :password_confirmation=>"nova_senha", | ||
| 168 | - :email=>"um@novo.usuario", | ||
| 169 | - :secondary_email=>"outro@email.com", | ||
| 170 | - :institution_ids=>[@institution_list.last.id] | ||
| 171 | - } | ||
| 172 | - | ||
| 173 | - profile_data = { | ||
| 174 | - :name=>"Um novo usuario", | ||
| 175 | - } | ||
| 176 | - | ||
| 177 | - user["profile_data"] = profile_data | ||
| 178 | - user | ||
| 179 | - end | ||
| 180 | - | ||
| 181 | - def disable_signup_bot_check(environment = Environment.default) | ||
| 182 | - environment.min_signup_delay = 0 | ||
| 183 | - environment.save! | ||
| 184 | - end | ||
| 185 | -end |
test/functional/institution_editor_test.rb
| @@ -1,68 +0,0 @@ | @@ -1,68 +0,0 @@ | ||
| 1 | -require File.dirname(__FILE__) + '/../../../../test/test_helper' | ||
| 2 | -require File.dirname(__FILE__) + '/../../controllers/mpog_software_plugin_controller' | ||
| 3 | - | ||
| 4 | - | ||
| 5 | -class InstitutionEditorTest < ActionController::TestCase | ||
| 6 | - | ||
| 7 | - def setup | ||
| 8 | - @controller = ProfileEditorController.new | ||
| 9 | - @request = ActionController::TestRequest.new | ||
| 10 | - @response = ActionController::TestResponse.new | ||
| 11 | - | ||
| 12 | - @environment = Environment.default | ||
| 13 | - @environment.enabled_plugins = ['MpogSoftwarePlugin'] | ||
| 14 | - @environment.save | ||
| 15 | - | ||
| 16 | - @govPower = GovernmentalPower.create(:name=>"Some Gov Power") | ||
| 17 | - @govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | ||
| 18 | - @juridical_nature = JuridicalNature.create(:name => "Autarquia") | ||
| 19 | - | ||
| 20 | - | ||
| 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) | ||
| 24 | - end | ||
| 25 | - | ||
| 26 | - | ||
| 27 | - should ' enable edition of sisp field for enviroment admin' do | ||
| 28 | - admin = create_user("adminuser").person | ||
| 29 | - admin.stubs(:has_permission?).returns("true") | ||
| 30 | - login_as('adminuser') | ||
| 31 | - @environment.add_admin(admin) | ||
| 32 | - get :edit, :profile => @institution_list[0].community.identifier, :id => @institution_list[0].community.id | ||
| 33 | - assert_tag :tag => 'span', :descendant => {:tag => "input", :attributes => { :type => 'radio', :name => "institution[sisp]"}} | ||
| 34 | - end | ||
| 35 | - | ||
| 36 | - should 'enable only visulization of sisp field for institution admin' do | ||
| 37 | - ze = create_user("ze").person | ||
| 38 | - login_as('ze') | ||
| 39 | - @institution_list[0].community.add_admin(ze) | ||
| 40 | - get :edit, :profile => @institution_list[0].community.identifier, :id => @institution_list[0].community.id | ||
| 41 | - assert_tag :tag => 'span', :descendant => {:tag => "label", :attributes => {:for => "SISP"}} | ||
| 42 | - end | ||
| 43 | - | ||
| 44 | - | ||
| 45 | - private | ||
| 46 | - | ||
| 47 | - def create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s | ||
| 48 | - institution_community = fast_create(Community) | ||
| 49 | - institution_community.name = name | ||
| 50 | - institution_community.country = country | ||
| 51 | - institution_community.state = state | ||
| 52 | - institution_community.city = city | ||
| 53 | - institution_community.save! | ||
| 54 | - | ||
| 55 | - institution = PublicInstitution.new | ||
| 56 | - institution.community = institution_community | ||
| 57 | - institution.name = name | ||
| 58 | - institution.juridical_nature = juridical_nature | ||
| 59 | - institution.sisp = false | ||
| 60 | - institution.acronym = acronym | ||
| 61 | - institution.governmental_power = gov_p | ||
| 62 | - institution.governmental_sphere = gov_s | ||
| 63 | - institution.save! | ||
| 64 | - | ||
| 65 | - institution | ||
| 66 | - end | ||
| 67 | - | ||
| 68 | -end |
test/functional/profile_editor_controller_test.rb
| 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
| 2 | +require File.dirname(__FILE__) + '/institution_test_helper' | ||
| 2 | require File.dirname(__FILE__) + '/../../../../app/controllers/my_profile/profile_editor_controller' | 3 | require File.dirname(__FILE__) + '/../../../../app/controllers/my_profile/profile_editor_controller' |
| 3 | 4 | ||
| 4 | class ProfileEditorController; def rescue_action(e) raise e end; end | 5 | class ProfileEditorController; def rescue_action(e) raise e end; end |
| @@ -19,14 +20,17 @@ class ProfileEditorControllerTest < ActionController::TestCase | @@ -19,14 +20,17 @@ class ProfileEditorControllerTest < ActionController::TestCase | ||
| 19 | @environment.add_admin(admin) | 20 | @environment.add_admin(admin) |
| 20 | @environment.save | 21 | @environment.save |
| 21 | 22 | ||
| 22 | - @govPower = GovernmentalPower.create(:name => "Some Gov Power") | ||
| 23 | - @govSphere = GovernmentalSphere.create(:name => "Some Gov Sphere") | 23 | + @govPower = GovernmentalPower.create(:name=>"Some Gov Power") |
| 24 | + @govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | ||
| 24 | @juridical_nature = JuridicalNature.create(:name => "Autarquia") | 25 | @juridical_nature = JuridicalNature.create(:name => "Autarquia") |
| 25 | 26 | ||
| 27 | + @institution_list = [] | ||
| 28 | + @institution_list << InstitutionTestHelper.create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @govPower, @govSphere, "12.345.678/9012-45") | ||
| 29 | + @institution_list << InstitutionTestHelper.create_public_institution("Tribunal Regional da Uniao", "TRU", "BR", "DF", "Brasilia", @juridical_nature, @govPower, @govSphere, "12.345.678/9012-90") | ||
| 26 | end | 30 | end |
| 27 | 31 | ||
| 28 | should "update institution date_modification when edit profile" do | 32 | should "update institution date_modification when edit profile" do |
| 29 | - create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @govPower, @govSphere) | 33 | + InstitutionTestHelper.create_public_institution("Just a test name", "JTN", "BR", "DF", "Gama", @juridical_nature, @govPower, @govSphere, "12.345.678/9055-33") |
| 30 | 34 | ||
| 31 | post :edit, :profile => Institution.last.community.identifier, :profile_data => {:name => "Ministerio da Saude"}, :institution => Institution.last | 35 | post :edit, :profile => Institution.last.community.identifier, :profile_data => {:name => "Ministerio da Saude"}, :institution => Institution.last |
| 32 | 36 | ||
| @@ -35,9 +39,6 @@ class ProfileEditorControllerTest < ActionController::TestCase | @@ -35,9 +39,6 @@ class ProfileEditorControllerTest < ActionController::TestCase | ||
| 35 | end | 39 | end |
| 36 | 40 | ||
| 37 | should "add new institution for user into edit profile" do | 41 | should "add new institution for user into edit profile" do |
| 38 | - institutions = [] | ||
| 39 | - institutions << create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @govPower, @govSphere) | ||
| 40 | - institutions << create_public_institution("Nova Instituicao", "NIN", "BR", "GO", "Goiania", @juridical_nature, @govPower, @govSphere) | ||
| 41 | user = fast_create(User) | 42 | user = fast_create(User) |
| 42 | user.person = fast_create(Person) | 43 | user.person = fast_create(Person) |
| 43 | user.person.user = user | 44 | user.person.user = user |
| @@ -46,21 +47,23 @@ class ProfileEditorControllerTest < ActionController::TestCase | @@ -46,21 +47,23 @@ class ProfileEditorControllerTest < ActionController::TestCase | ||
| 46 | 47 | ||
| 47 | params_user = Hash.new | 48 | params_user = Hash.new |
| 48 | params_user[:institution_ids] = [] | 49 | params_user[:institution_ids] = [] |
| 49 | - institutions.each do |institution| | 50 | + |
| 51 | + @institution_list.each do |institution| | ||
| 50 | params_user[:institution_ids] << institution.id | 52 | params_user[:institution_ids] << institution.id |
| 51 | end | 53 | end |
| 52 | 54 | ||
| 53 | post :edit, :profile => User.last.person.identifier, :user => params_user | 55 | post :edit, :profile => User.last.person.identifier, :user => params_user |
| 54 | 56 | ||
| 55 | - assert_equal institutions.count, User.last.institutions.count | 57 | + assert_equal @institution_list.count, User.last.institutions.count |
| 56 | end | 58 | end |
| 57 | 59 | ||
| 58 | should "remove institutions for user into edit profile" do | 60 | should "remove institutions for user into edit profile" do |
| 59 | user = fast_create(User) | 61 | user = fast_create(User) |
| 60 | user.person = fast_create(Person) | 62 | user.person = fast_create(Person) |
| 61 | 63 | ||
| 62 | - user.institutions << create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @govPower, @govSphere) | ||
| 63 | - user.institutions << create_public_institution("Nova Instituicao", "NIN", "BR", "GO", "Goiania", @juridical_nature, @govPower, @govSphere) | 64 | + @institution_list.each do |institution| |
| 65 | + user.institutions << institution | ||
| 66 | + end | ||
| 64 | 67 | ||
| 65 | user.person.user = user | 68 | user.person.user = user |
| 66 | user.save! | 69 | user.save! |
| @@ -69,30 +72,10 @@ class ProfileEditorControllerTest < ActionController::TestCase | @@ -69,30 +72,10 @@ class ProfileEditorControllerTest < ActionController::TestCase | ||
| 69 | params_user = Hash.new | 72 | params_user = Hash.new |
| 70 | params_user[:institution_ids] = [] | 73 | params_user[:institution_ids] = [] |
| 71 | 74 | ||
| 75 | + assert_equal @institution_list.count, User.last.institutions.count | ||
| 76 | + | ||
| 72 | post :edit, :profile => User.last.person.identifier, :user => params_user | 77 | post :edit, :profile => User.last.person.identifier, :user => params_user |
| 73 | 78 | ||
| 74 | assert_equal 0, User.last.institutions.count | 79 | assert_equal 0, User.last.institutions.count |
| 75 | end | 80 | end |
| 76 | - | ||
| 77 | - private | ||
| 78 | - | ||
| 79 | - def create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s | ||
| 80 | - institution_community = fast_create(Community) | ||
| 81 | - institution_community.name = name | ||
| 82 | - institution_community.country = country | ||
| 83 | - institution_community.state = state | ||
| 84 | - institution_community.city = city | ||
| 85 | - institution_community.save! | ||
| 86 | - | ||
| 87 | - institution = PublicInstitution.new | ||
| 88 | - institution.community = institution_community | ||
| 89 | - institution.name = name | ||
| 90 | - institution.juridical_nature = juridical_nature | ||
| 91 | - institution.acronym = acronym | ||
| 92 | - institution.governmental_power = gov_p | ||
| 93 | - institution.governmental_sphere = gov_s | ||
| 94 | - institution.save! | ||
| 95 | - institution | ||
| 96 | - end | ||
| 97 | - | ||
| 98 | end | 81 | end |