Commit a25978cd47b5c44d5c9097e4161477eca0db62e7
Committed by
Arthur Esposte
1 parent
e6be3b0c
Exists in
master
and in
5 other branches
Functional test for add and remove institutions for user into edit profile
(institution_fields) Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com>
Showing
1 changed file
with
55 additions
and
11 deletions
Show diff stats
test/functional/profile_editor_controller_test.rb
| ... | ... | @@ -13,37 +13,81 @@ class ProfileEditorControllerTest < ActionController::TestCase |
| 13 | 13 | Environment.default.affiliate(@profile, [Environment::Roles.admin(Environment.default.id)] + Profile::Roles.all_roles(Environment.default.id)) |
| 14 | 14 | @environment = Environment.default |
| 15 | 15 | @environment.enabled_plugins = ['MpogSoftwarePlugin'] |
| 16 | - | |
| 17 | - @govPower = GovernmentalPower.create(:name=>"Some Gov Power") | |
| 18 | - @govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | |
| 19 | - | |
| 20 | 16 | admin = create_user("adminuser").person |
| 21 | 17 | admin.stubs(:has_permission?).returns("true") |
| 22 | 18 | login_as('adminuser') |
| 23 | - | |
| 24 | 19 | @environment.add_admin(admin) |
| 25 | 20 | @environment.save |
| 21 | + | |
| 22 | + @govPower = GovernmentalPower.create(:name => "Some Gov Power") | |
| 23 | + @govSphere = GovernmentalSphere.create(:name => "Some Gov Sphere") | |
| 24 | + @juridical_nature = JuridicalNature.create(:name => "Autarquia") | |
| 25 | + | |
| 26 | 26 | end |
| 27 | 27 | |
| 28 | - should "update institution date_modification in your creation" do | |
| 29 | - institution = create_public_institution("Ministerio Publico da Uniao", "MPU", @govPower, @govSphere) | |
| 30 | - institution.date_modification = "Invalid Date" | |
| 28 | + 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) | |
| 31 | 30 | |
| 32 | - post :edit, :profile => Institution.last.community.identifier, :profile_data => {:name => "Ministerio da Saude"}, :institution => institution | |
| 31 | + post :edit, :profile => Institution.last.community.identifier, :profile_data => {:name => "Ministerio da Saude"}, :institution => Institution.last | |
| 33 | 32 | |
| 34 | 33 | date = Time.now.day.to_s + "/" + Time.now.month.to_s + "/" + Time.now.year.to_s |
| 35 | 34 | assert_equal date, Institution.last.date_modification |
| 36 | 35 | end |
| 37 | 36 | |
| 37 | + 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.person = fast_create(Person) | |
| 43 | + user.person.user = user | |
| 44 | + user.save! | |
| 45 | + user.person.save! | |
| 46 | + | |
| 47 | + params_user = Hash.new | |
| 48 | + params_user[:institution_ids] = [] | |
| 49 | + institutions.each do |institution| | |
| 50 | + params_user[:institution_ids] << institution.id | |
| 51 | + end | |
| 52 | + | |
| 53 | + post :edit, :profile => User.last.person.identifier, :user => params_user | |
| 54 | + | |
| 55 | + assert_equal institutions.count, User.last.institutions.count | |
| 56 | + end | |
| 57 | + | |
| 58 | + should "remove institutions for user into edit profile" do | |
| 59 | + user = fast_create(User) | |
| 60 | + user.person = fast_create(Person) | |
| 61 | + | |
| 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 | + | |
| 65 | + user.person.user = user | |
| 66 | + user.save! | |
| 67 | + user.person.save! | |
| 68 | + | |
| 69 | + params_user = Hash.new | |
| 70 | + params_user[:institution_ids] = [] | |
| 71 | + | |
| 72 | + post :edit, :profile => User.last.person.identifier, :user => params_user | |
| 73 | + | |
| 74 | + assert_equal 0, User.last.institutions.count | |
| 75 | + end | |
| 76 | + | |
| 38 | 77 | private |
| 39 | 78 | |
| 40 | - def create_public_institution name, acronym, gov_p, gov_s | |
| 79 | + def create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s | |
| 41 | 80 | institution_community = fast_create(Community) |
| 42 | 81 | institution_community.name = name |
| 82 | + institution_community.country = country | |
| 83 | + institution_community.state = state | |
| 84 | + institution_community.city = city | |
| 85 | + institution_community.save! | |
| 43 | 86 | |
| 44 | 87 | institution = PublicInstitution.new |
| 45 | 88 | institution.community = institution_community |
| 46 | 89 | institution.name = name |
| 90 | + institution.juridical_nature = juridical_nature | |
| 47 | 91 | institution.acronym = acronym |
| 48 | 92 | institution.governmental_power = gov_p |
| 49 | 93 | institution.governmental_sphere = gov_s |
| ... | ... | @@ -51,4 +95,4 @@ class ProfileEditorControllerTest < ActionController::TestCase |
| 51 | 95 | institution |
| 52 | 96 | end |
| 53 | 97 | |
| 54 | -end | |
| 55 | 98 | \ No newline at end of file |
| 99 | +end | ... | ... |