Commit 71b0d4ea9e3581899eeb09c2ecf1f08047ffb886

Authored by Marcos Pereira
1 parent 2cb76293

Fixing namespaces, requires and tests

Signed-off-by: Alexandre Barbosa <alexandreab@live.com>
Signed-off-by: Arthur Jahn <stutrzbecher@gmail.com>
Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com>
Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
Showing 38 changed files with 574 additions and 566 deletions   Show diff stats
src/noosfero-spb/gov_user/db/migrate/20151019174219_rename_tables_with_plugin_namespace.rb
... ... @@ -1,9 +0,0 @@
1   -class RenameTablesWithPluginNamespace < ActiveRecord::Migration
2   - def change
3   - rename_table :institutions, :gov_user_plugin_institutions
4   - rename_table :governmental_spheres, :gov_user_plugin_governmental_spheres
5   - rename_table :governmental_powers, :gov_user_plugin_governmental_powers
6   - rename_table :juridical_natures, :gov_user_plugin_juridical_natures
7   - rename_table :institutions_users, :gov_user_plugin_institutions_users
8   - end
9   -end
src/noosfero-spb/gov_user/db/migrate/20151029193551_update_namespace_types_on_database.rb
... ... @@ -1,13 +0,0 @@
1   -class UpdateNamespaceTypesOnDatabase < ActiveRecord::Migration
2   - def up
3   - execute("UPDATE blocks SET type = 'GovUserPlugin::InstitutionsBlock' WHERE type = 'InstitutionsBlock'")
4   - execute("UPDATE gov_user_plugin_institutions SET type = 'GovUserPlugin::PublicInstitution' WHERE type = 'PublicInstitution'")
5   - execute("UPDATE gov_user_plugin_institutions SET type = 'GovUserPlugin::PrivateInstitution' WHERE type = 'PrivateInstitution'")
6   - end
7   -
8   - def down
9   - execute("UPDATE blocks SET type = 'InstitutionsBlock' WHERE type = 'GovUserPlugin::InstitutionsBlock'")
10   - execute("UPDATE gov_user_plugin_institutions SET type = 'PublicInstitution' WHERE type = 'GovUserPlugin::PublicInstitution'")
11   - execute("UPDATE gov_user_plugin_institutions SET type = 'PrivateInstitution' WHERE type = 'GovUserPlugin::PrivateInstitution'")
12   - end
13   -end
src/noosfero-spb/gov_user/db/migrate/20151105174601_create_institutions_organization_ratings_table.rb
... ... @@ -1,12 +0,0 @@
1   -class CreateInstitutionsOrganizationRatingsTable < ActiveRecord::Migration
2   - def up
3   - create_table :gov_user_plugin_institutions_organization_ratings, {:id => false, :force => true} do |t|
4   - t.references :institution
5   - t.references :organization_rating
6   - end
7   - end
8   -
9   - def down
10   - drop_table :gov_user_plugin_institutions_organization_ratings
11   - end
12   -end
src/noosfero-spb/gov_user/db/migrate/20151105175611_move_institutions_relation_with_organization_ratings.rb
... ... @@ -1,9 +0,0 @@
1   -class MoveInstitutionsRelationWithOrganizationRatings < ActiveRecord::Migration
2   - def up
3   - execute('INSERT INTO gov_user_plugin_institutions_organization_ratings (institution_id,organization_rating_id) SELECT institution_id, id from organization_ratings where institution_id IS NOT NULL;')
4   - end
5   -
6   - def down
7   - execute('DELETE FROM gov_user_plugin_institutions_organization_ratings;')
8   - end
9   -end
src/noosfero-spb/gov_user/db/migrate/20151105175646_remove_old_institution_relation_from_organization_ratings.rb
... ... @@ -1,10 +0,0 @@
1   -class RemoveOldInstitutionRelationFromOrganizationRatings < ActiveRecord::Migration
2   - def up
3   - remove_column :organization_ratings, :institution_id
4   - end
5   -
6   - def down
7   - add_column :organization_ratings, :institution_id, :integer
8   - execute('UPDATE organization_ratings AS oratings SET institution_id = (SELECT institution_id FROM gov_user_plugin_institutions_organization_ratings AS g WHERE g.organization_rating_id = oratings.id);')
9   - end
10   -end
src/noosfero-spb/gov_user/db/migrate/20160302185631_rename_tables_with_plugin_namespace.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +class RenameTablesWithPluginNamespace < ActiveRecord::Migration
  2 + def change
  3 + rename_table :institutions, :gov_user_plugin_institutions
  4 + rename_table :governmental_spheres, :gov_user_plugin_governmental_spheres
  5 + rename_table :governmental_powers, :gov_user_plugin_governmental_powers
  6 + rename_table :juridical_natures, :gov_user_plugin_juridical_natures
  7 + rename_table :institutions_users, :gov_user_plugin_institutions_users
  8 + end
  9 +end
... ...
src/noosfero-spb/gov_user/db/migrate/20160302185632_update_namespace_types_on_database.rb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +class UpdateNamespaceTypesOnDatabase < ActiveRecord::Migration
  2 + def up
  3 + execute("UPDATE blocks SET type = 'GovUserPlugin::InstitutionsBlock' WHERE type = 'InstitutionsBlock'")
  4 + execute("UPDATE gov_user_plugin_institutions SET type = 'GovUserPlugin::PublicInstitution' WHERE type = 'PublicInstitution'")
  5 + execute("UPDATE gov_user_plugin_institutions SET type = 'GovUserPlugin::PrivateInstitution' WHERE type = 'PrivateInstitution'")
  6 + end
  7 +
  8 + def down
  9 + execute("UPDATE blocks SET type = 'InstitutionsBlock' WHERE type = 'GovUserPlugin::InstitutionsBlock'")
  10 + execute("UPDATE gov_user_plugin_institutions SET type = 'PublicInstitution' WHERE type = 'GovUserPlugin::PublicInstitution'")
  11 + execute("UPDATE gov_user_plugin_institutions SET type = 'PrivateInstitution' WHERE type = 'GovUserPlugin::PrivateInstitution'")
  12 + end
  13 +end
... ...
src/noosfero-spb/gov_user/db/migrate/20160302185634_create_institutions_organization_ratings_table.rb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +class CreateInstitutionsOrganizationRatingsTable < ActiveRecord::Migration
  2 + def up
  3 + create_table :gov_user_plugin_institutions_organization_ratings, {:id => false, :force => true} do |t|
  4 + t.references :institution
  5 + t.references :organization_rating
  6 + end
  7 + end
  8 +
  9 + def down
  10 + drop_table :gov_user_plugin_institutions_organization_ratings
  11 + end
  12 +end
... ...
src/noosfero-spb/gov_user/db/migrate/20160302185635_move_institutions_relation_with_organization_ratings.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +class MoveInstitutionsRelationWithOrganizationRatings < ActiveRecord::Migration
  2 + def up
  3 + execute('INSERT INTO gov_user_plugin_institutions_organization_ratings (institution_id,organization_rating_id) SELECT institution_id, id from organization_ratings where institution_id IS NOT NULL;')
  4 + end
  5 +
  6 + def down
  7 + execute('DELETE FROM gov_user_plugin_institutions_organization_ratings;')
  8 + end
  9 +end
... ...
src/noosfero-spb/gov_user/db/migrate/20160302185636_remove_old_institution_relation_from_organization_ratings.rb 0 → 100644
... ... @@ -0,0 +1,10 @@
  1 +class RemoveOldInstitutionRelationFromOrganizationRatings < ActiveRecord::Migration
  2 + def up
  3 + remove_column :organization_ratings, :institution_id
  4 + end
  5 +
  6 + def down
  7 + add_column :organization_ratings, :institution_id, :integer
  8 + execute('UPDATE organization_ratings AS oratings SET institution_id = (SELECT institution_id FROM gov_user_plugin_institutions_organization_ratings AS g WHERE g.organization_rating_id = oratings.id);')
  9 + end
  10 +end
... ...
src/noosfero-spb/gov_user/lib/gov_user_plugin/governmental_power.rb
1   -class GovUserPlugin::GovernmentalPower < Noosfero::Plugin::ActiveRecord
  1 +class GovUserPlugin::GovernmentalPower < ActiveRecord::Base
2 2 attr_accessible :name
3 3  
4 4 validates :name, :presence=>true, :uniqueness=>true
... ...
src/noosfero-spb/gov_user/lib/gov_user_plugin/governmental_sphere.rb
1   -class GovUserPlugin::GovernmentalSphere < Noosfero::Plugin::ActiveRecord
  1 +class GovUserPlugin::GovernmentalSphere < ActiveRecord::Base
2 2 attr_accessible :name
3 3  
4 4 validates :name, :presence=>true, :uniqueness=>true
... ...
src/noosfero-spb/gov_user/lib/gov_user_plugin/institution.rb
1 1 #encoding: utf-8
2 2  
3   -class GovUserPlugin::Institution < Noosfero::Plugin::ActiveRecord
  3 +class GovUserPlugin::Institution < ActiveRecord::Base
4 4 has_many :comments
5 5  
6 6 SEARCH_FILTERS = {
... ... @@ -35,15 +35,13 @@ class GovUserPlugin::Institution &lt; Noosfero::Plugin::ActiveRecord
35 35 validates :name, :presence=>true, :uniqueness=>true
36 36 validates :cnpj, :length=>{maximum: 18}
37 37  
38   - before_save :verify_institution_type
39   -
40 38 belongs_to :community
41 39  
42 40 scope :search_institution, lambda{ |value, env|
43 41 joins(:community).where("(profiles.name ilike ? OR institutions.acronym ilike ?) AND profiles.environment_id = ?", "%#{value}%", "%#{value}%", env.id)
44 42 }
45   - scope :public, :conditions => { :type => "GovUserPlugin::PublicInstitution" }
46   - scope :private, :conditions => { :type => "GovUserPlugin::PrivateInstitution" }
  43 + scope :public_institutions, :conditions => { :type => "GovUserPlugin::PublicInstitution" }
  44 + scope :private_institutions, :conditions => { :type => "GovUserPlugin::PrivateInstitution" }
47 45  
48 46 validate :validate_country, :validate_state, :validate_city,
49 47 :verify_institution_type
... ...
src/noosfero-spb/gov_user/lib/gov_user_plugin/institutions_organization_ratings.rb
1   -class GovUserPlugin::InstitutionsOrganizationRatings < Noosfero::Plugin::ActiveRecord
  1 +class GovUserPlugin::InstitutionsOrganizationRatings < ActiveRecord::Base
2 2 self.primary_key = :institution_id
3 3  
4 4 attr_accessible :institution, :organization_rating
... ...
src/noosfero-spb/gov_user/lib/gov_user_plugin/institutions_users.rb
1   -class GovUserPlugin::InstitutionsUsers < Noosfero::Plugin::ActiveRecord
  1 +class GovUserPlugin::InstitutionsUsers < ActiveRecord::Base
2 2 belongs_to :user
3 3 belongs_to :institution, :class_name => 'GovUserPlugin::Institution'
4 4 end
... ...
src/noosfero-spb/gov_user/lib/gov_user_plugin/juridical_nature.rb
1   -class GovUserPlugin::JuridicalNature < Noosfero::Plugin::ActiveRecord
  1 +class GovUserPlugin::JuridicalNature < ActiveRecord::Base
2 2 self.record_timestamps = false
3 3  
4 4 attr_accessible :name
... ...
src/noosfero-spb/gov_user/lib/gov_user_plugin/private_institution.rb
1 1 class GovUserPlugin::PrivateInstitution < GovUserPlugin::Institution
  2 + validates :cnpj,
  3 + :format => {with: CNPJ_FORMAT},
  4 + :if => :is_a_brazilian_institution?
  5 +
  6 + validates :cnpj,
  7 + :uniqueness => true, :unless => 'cnpj.blank?'
  8 +
  9 + private
  10 + def is_a_brazilian_institution?
  11 + self.community.country == "BR"
  12 + end
2 13 end
... ...
src/noosfero-spb/gov_user/test/unit/gov_user_person_test.rb 0 → 100644
... ... @@ -0,0 +1,57 @@
  1 +# encoding: utf-8
  2 +
  3 +require_relative '../helpers/plugin_test_helper'
  4 +require 'test_helper'
  5 +
  6 +class SoftwareCommunitiesPluginPersonTest < ActiveSupport::TestCase
  7 + include PluginTestHelper
  8 +
  9 + def setup
  10 + @plugin = GovUserPlugin.new
  11 +
  12 + @user = fast_create(User)
  13 + @person = create_person(
  14 + "My Name",
  15 + "user@email.com",
  16 + "123456",
  17 + "user2@email.com",
  18 + "Any State",
  19 + "Some City"
  20 + )
  21 + end
  22 +
  23 + def teardown
  24 + @plugin = nil
  25 + end
  26 +
  27 + should 'be a noosfero plugin' do
  28 + assert_kind_of Noosfero::Plugin, @plugin
  29 + end
  30 +
  31 + should 'save person with a valid full name' do
  32 + p = Person::new :name=>"S1mpl3 0f N4m3", :identifier=>"simple-name"
  33 + p.user = fast_create(:user)
  34 +
  35 + assert_equal true, p.save
  36 + end
  37 +
  38 + should 'save person with a valid full name with accents' do
  39 + name = 'Jônatàs dâ Sîlvã Jösé'
  40 + identifier = "jonatas-jose-da-silva"
  41 + p = Person::new :name=>name, :identifier=>identifier
  42 + p.user = fast_create(:user)
  43 +
  44 + assert_equal true, p.save
  45 + end
  46 +
  47 + should 'not save person whose name has not capital letter' do
  48 + p = Person::new :name=>"simple name"
  49 + assert !p.save, _("Name Should begin with a capital letter and no special characters")
  50 + end
  51 +
  52 + should 'not save person whose name has special characters' do
  53 + p = Person::new :name=>"Simple N@me"
  54 +
  55 + assert !p.save , _("Name Should begin with a capital letter and no special characters")
  56 + end
  57 +end
... ...
src/noosfero-spb/gov_user/test/unit/gov_user_plugin/gov_user_person_test.rb
... ... @@ -1,57 +0,0 @@
1   -# encoding: utf-8
2   -
3   -require_relative '../../../../../test/test_helper'
4   -require_relative '../../helpers/plugin_test_helper'
5   -
6   -class SoftwareCommunitiesPluginPersonTest < ActiveSupport::TestCase
7   - include PluginTestHelper
8   -
9   - def setup
10   - @plugin = GovUserPlugin.new
11   -
12   - @user = fast_create(User)
13   - @person = create_person(
14   - "My Name",
15   - "user@email.com",
16   - "123456",
17   - "user2@email.com",
18   - "Any State",
19   - "Some City"
20   - )
21   - end
22   -
23   - def teardown
24   - @plugin = nil
25   - end
26   -
27   - should 'be a noosfero plugin' do
28   - assert_kind_of Noosfero::Plugin, @plugin
29   - end
30   -
31   - should 'save person with a valid full name' do
32   - p = Person::new :name=>"S1mpl3 0f N4m3", :identifier=>"simple-name"
33   - p.user = fast_create(:user)
34   -
35   - assert_equal true, p.save
36   - end
37   -
38   - should 'save person with a valid full name with accents' do
39   - name = 'Jônatàs dâ Sîlvã Jösé'
40   - identifier = "jonatas-jose-da-silva"
41   - p = Person::new :name=>name, :identifier=>identifier
42   - p.user = fast_create(:user)
43   -
44   - assert_equal true, p.save
45   - end
46   -
47   - should 'not save person whose name has not capital letter' do
48   - p = Person::new :name=>"simple name"
49   - assert !p.save, _("Name Should begin with a capital letter and no special characters")
50   - end
51   -
52   - should 'not save person whose name has special characters' do
53   - p = Person::new :name=>"Simple N@me"
54   -
55   - assert !p.save , _("Name Should begin with a capital letter and no special characters")
56   - end
57   -end
src/noosfero-spb/gov_user/test/unit/gov_user_plugin/governmental_power_test.rb
... ... @@ -1,33 +0,0 @@
1   -require_relative '../../../../../test/test_helper'
2   -require_relative '../../helpers/institution_test_helper'
3   -
4   -class GovUserPlugin::GovernmentalPowerTest < ActiveSupport::TestCase
5   -
6   - def setup
7   - @gov_sphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere")
8   - @juridical_nature = GovUserPlugin::JuridicalNature.create(:name => "Autarquia")
9   - end
10   -
11   - def teardown
12   - GovUserPlugin::Institution.destroy_all
13   - end
14   -
15   - should "get public institutions" do
16   - inst_name = "Ministerio Publico da Uniao"
17   - inst_cnpj = "12.345.678/9012-45"
18   - gov_power = GovUserPlugin::GovernmentalPower.create(:name=>"Some gov power")
19   - InstitutionTestHelper.create_public_institution(
20   - inst_name,
21   - "MPU",
22   - "BR",
23   - "DF",
24   - "Gama",
25   - @juridical_nature,
26   - gov_power,
27   - @gov_sphere,
28   - inst_cnpj
29   - )
30   -
31   - assert_equal gov_power.institutions.public.count, GovUserPlugin::PublicInstitution.count
32   - end
33   -end
src/noosfero-spb/gov_user/test/unit/gov_user_plugin/institution_test.rb
... ... @@ -1,76 +0,0 @@
1   -require_relative '../../../../../test/test_helper'
2   -require_relative '../../helpers/plugin_test_helper'
3   -
4   -class GovUserPlugin::InstitutionTest < ActiveSupport::TestCase
5   - include PluginTestHelper
6   - def setup
7   - @gov_power = GovUserPlugin::GovernmentalPower.create(:name=>"Some Gov Power")
8   - @gov_sphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere")
9   - @juridical_nature = GovUserPlugin::JuridicalNature.create(:name => "Autarquia")
10   -
11   - @institution = create_public_institution(
12   - "Ministerio Publico da Uniao",
13   - "MPU",
14   - "BR",
15   - "Distrito Federal",
16   - "Gama",
17   - @juridical_nature,
18   - @gov_power,
19   - @gov_sphere,
20   - "11.222.333/4444-55"
21   - )
22   - end
23   -
24   - def teardown
25   - GovUserPlugin::GovernmentalPower.destroy_all
26   - GovUserPlugin::GovernmentalSphere.destroy_all
27   - GovUserPlugin::JuridicalNature.destroy_all
28   - @institution = nil
29   - end
30   -
31   - should "not save institutions without name" do
32   - @institution.name = nil
33   - assert_equal false, @institution.save
34   - assert_equal true, @institution.errors.messages.keys.include?(:name)
35   - end
36   -
37   - should "not save if institution has invalid type" do
38   - invalid_msg = "Type invalid, only public and private institutions are allowed."
39   - @institution.type = "Other type"
40   - assert_equal false, @institution.save
41   - assert_equal true, @institution.errors.messages.keys.include?(:type)
42   - end
43   -
44   - should "not save without country" do
45   - @institution.community.country = nil
46   - assert_equal false, @institution.save
47   - assert_equal true, @institution.errors.messages.keys.include?(:country)
48   - end
49   -
50   - should "not save without state" do
51   - @institution.community.state = nil
52   -
53   - assert_equal false, @institution.save
54   - assert_equal true, @institution.errors.messages.keys.include?(:state)
55   - end
56   -
57   - should "not save without city" do
58   - @institution.community.city = nil
59   - @institution.community.state = "DF"
60   -
61   - assert_equal false, @institution.save
62   - assert_equal true, @institution.errors.messages.keys.include?(:city)
63   - end
64   -
65   - should "only return institutions of a specific environment" do
66   - env1 = Environment.create(:name => "Environment One")
67   - env2 = Environment.create(:name => "Environment Two")
68   -
69   - env1.communities << @institution.community
70   - search_result_env1 = Institution.search_institution("Ministerio", env1).collect{ |i| i.id }
71   - search_result_env2 = Institution.search_institution("Ministerio", env2).collect{ |i| i.id }
72   -
73   - assert_includes search_result_env1, @institution.id
74   - assert_not_includes search_result_env2, @institution.id
75   - end
76   -end
src/noosfero-spb/gov_user/test/unit/gov_user_plugin/institutions_block_test.rb
... ... @@ -1,78 +0,0 @@
1   -require_relative '../../../../../test/test_helper'
2   -require_relative '../../helpers/plugin_test_helper'
3   -
4   -class GovUserPlugin::InstitutionsBlockTest < ActiveSupport::TestCase
5   - def setup
6   - environment = Environment.default
7   - environment.enable_plugin(GovUserPlugin)
8   - end
9   -
10   - include PluginTestHelper
11   - should 'inherit from Block' do
12   - assert_kind_of Block, GovUserPlugin::InstitutionsBlock.new
13   - end
14   -
15   - should 'declare its default title' do
16   - GovUserPlugin::InstitutionsBlock.any_instance.stubs(:profile_count).returns(0)
17   - assert_not_equal Block.new.default_title, GovUserPlugin::InstitutionsBlock.new.default_title
18   - end
19   -
20   - should 'describe itself' do
21   - assert_not_equal Block.description, GovUserPlugin::InstitutionsBlock.description
22   - end
23   -
24   - should 'give empty footer on unsupported owner type' do
25   - block = GovUserPlugin::InstitutionsBlock.new
26   - block.expects(:owner).returns(1)
27   - assert_equal '', block.footer
28   - end
29   -
30   - should 'list institutions' do
31   - Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([GovUserPlugin.new])
32   - user = create_person("Jose_Augusto",
33   - "jose_augusto@email.com",
34   - "aaaaaaa",
35   - "aaaaaaa",
36   - "DF",
37   - "Gama"
38   - )
39   -
40   - institution = create_private_institution(
41   - "inst name",
42   - "IN",
43   - "country",
44   - "state",
45   - "city",
46   - "00.111.222/3333-44"
47   - )
48   - institution.community.add_member(user)
49   -
50   - block = GovUserPlugin::InstitutionsBlock.new
51   - block.expects(:owner).at_least_once.returns(user)
52   -
53   - assert_equivalent [institution.community], block.profiles
54   - end
55   -
56   -
57   - should 'not list communities' do
58   - user = create_person("Jose_Augusto",
59   - "jose_augusto@email.com",
60   - "aaaaaaa",
61   - "aaaaaaa",
62   - 'jose@secondary.com',
63   - "DF",
64   - "Gama"
65   - )
66   - institution = InstitutionTestHelper.create_private_institution("inst name", "IN", "country", "state",
67   - "city", "00.111.222/3333-44")
68   - community = fast_create(Community)
69   - institution.community.add_member(user)
70   - community.add_member(user)
71   -
72   - block = GovUserPlugin::InstitutionsBlock.new
73   - block.expects(:owner).at_least_once.returns(user)
74   -
75   - assert_equivalent block.profiles, [institution.community]
76   - end
77   -
78   -end
src/noosfero-spb/gov_user/test/unit/gov_user_plugin/institutions_organization_ratings_test.rb
... ... @@ -1,50 +0,0 @@
1   -require_relative '../../../../../test/test_helper'
2   -require_relative '../../helpers/plugin_test_helper'
3   -
4   -class GovUserPlugin::InstitutionsOrganizationRatingsTest < ActiveSupport::TestCase
5   - include PluginTestHelper
6   -
7   - def setup
8   - @environment = Environment.default
9   - @environment.enabled_plugins = ['SoftwareCommunitiesPlugin', 'GovUserPlugin']
10   - @environment.save!
11   - end
12   -
13   - should 'validate presence of institution' do
14   - relation = GovUserPlugin::InstitutionsOrganizationRatings.new
15   - relation.valid?
16   - assert relation.errors[:institution].present?
17   - end
18   -
19   - should 'validate presence of organization_rating' do
20   - relation = GovUserPlugin::InstitutionsOrganizationRatings.new
21   - relation.valid?
22   - assert relation.errors[:organization_rating].present?
23   - end
24   -
25   - should "validate institution if there is an institution_id" do
26   - private_institution = build_private_institution "huehue", "hue", "11.222.333/4444-55"
27   - relation = GovUserPlugin::InstitutionsOrganizationRatings.new(:institution => private_institution)
28   - assert !relation.valid?
29   - assert relation.errors[:institution].include?("not found")
30   -
31   - private_institution.save
32   - relation.institution = private_institution
33   - relation.valid?
34   - assert !relation.errors[:institution].include?("not found")
35   - end
36   -
37   - private
38   -
39   - def build_private_institution name, corporate_name, cnpj, country="AR"
40   - community = Community.new :name => name
41   - community.country = country
42   -
43   - institution = GovUserPlugin::PrivateInstitution.new :name=> name
44   - institution.corporate_name = corporate_name
45   - institution.cnpj = cnpj
46   - institution.community = community
47   -
48   - institution
49   - end
50   -end
src/noosfero-spb/gov_user/test/unit/gov_user_plugin/juridical_nature_test.rb
... ... @@ -1,23 +0,0 @@
1   -require_relative '../../../../../test/test_helper'
2   -require_relative '../../helpers/plugin_test_helper'
3   -
4   -class GovUserPlugin::JuridicalNatureTest < ActiveSupport::TestCase
5   -
6   - include PluginTestHelper
7   -
8   - def setup
9   - @govPower = GovUserPlugin::GovernmentalPower.create(:name=>"Some Gov Power")
10   - @govSphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere")
11   - end
12   -
13   - def teardown
14   - GovUserPlugin::Institution.destroy_all
15   - end
16   -
17   - should "get public institutions" do
18   - juridical_nature = GovUserPlugin::JuridicalNature.create(:name => "Autarquia")
19   - create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", juridical_nature, @govPower, @govSphere, "22.333.444/5555-66")
20   - create_public_institution("Tribunal Regional da Uniao", "TRU", "BR", "DF", "Brasilia", juridical_nature, @govPower, @govSphere, "22.333.444/5555-77")
21   - assert juridical_nature.institutions.public.count == GovUserPlugin::PublicInstitution.count
22   - end
23   -end
src/noosfero-spb/gov_user/test/unit/gov_user_plugin/person_test.rb
... ... @@ -1,36 +0,0 @@
1   -require_relative '../../../../../test/test_helper'
2   -require_relative '../../helpers/plugin_test_helper'
3   -
4   -class SoftwareCommunitiesPluginPersonTest < ActiveSupport::TestCase
5   - include PluginTestHelper
6   - def setup
7   - @plugin = GovUserPlugin.new
8   -
9   - @user = fast_create(User)
10   - @person = create_person(
11   - "My Name",
12   - "user@email.com",
13   - "123456",
14   - "123456",
15   - "Any State",
16   - "Some City"
17   - )
18   - end
19   -
20   - should 'calculate the percentege of person incomplete fields' do
21   - @person.cell_phone = "76888919"
22   - @person.contact_phone = "987654321"
23   -
24   - assert_equal(64, @plugin.calc_percentage_registration(@person))
25   -
26   - @person.comercial_phone = "11223344"
27   - @person.country = "I dont know"
28   - @person.state = "I dont know"
29   - @person.city = "I dont know"
30   - @person.organization_website = "www.whatever.com"
31   - @person.image = Image::new :uploaded_data=>fixture_file_upload('/files/rails.png', 'image/png')
32   - @person.save
33   -
34   - assert_equal(100, @plugin.calc_percentage_registration(@person))
35   - end
36   -end
src/noosfero-spb/gov_user/test/unit/gov_user_plugin/private_institution_test.rb
... ... @@ -1,43 +0,0 @@
1   -require_relative '../../../../../test/test_helper'
2   -require_relative '../../helpers/plugin_test_helper'
3   -
4   -class GovUserPlugin::PrivateInstitutionTest < ActiveSupport::TestCase
5   - include PluginTestHelper
6   - def setup
7   - @institution = create_private_institution(
8   - "Simple Private Institution",
9   - "SPI",
10   - "BR",
11   - "Distrito Federal",
12   - "Gama",
13   - "00.000.000/0001-00"
14   - )
15   - end
16   -
17   - def teardown
18   - @institution = nil
19   - GovUserPlugin::Institution.destroy_all
20   - end
21   -
22   - should "not save without a cnpj" do
23   - @institution.cnpj = nil
24   -
25   - assert_equal false, @institution.save
26   -
27   - @institution.cnpj = "11.111.111/1111-11"
28   - assert_equal true, @institution.save
29   - end
30   -
31   - should "save without fantasy name" do
32   - @institution.acronym = nil
33   - @institution.community.save
34   -
35   - assert @institution.save
36   - end
37   -
38   - should "not verify cnpj if it isnt a brazilian institution" do
39   - @institution.cnpj = nil
40   - @institution.community.country = "AR"
41   - assert_equal true, @institution.save
42   - end
43   -end
src/noosfero-spb/gov_user/test/unit/gov_user_plugin/public_institution_test.rb
... ... @@ -1,79 +0,0 @@
1   -require_relative '../../../../../test/test_helper'
2   -require_relative '../../helpers/plugin_test_helper'
3   -
4   -class GovUserPlugin::PublicInstitutionTest < ActiveSupport::TestCase
5   - include PluginTestHelper
6   - def setup
7   - @gov_power = GovUserPlugin::GovernmentalPower.create(:name=>"Some Gov Power")
8   - @gov_sphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere")
9   - @juridical_nature = GovUserPlugin::JuridicalNature.create(:name => "Autarquia")
10   -
11   - @institution = create_public_institution(
12   - "Ministerio Publico da Uniao",
13   - "MPU",
14   - "BR",
15   - "Distrito Federal",
16   - "Gama",
17   - @juridical_nature,
18   - @gov_power,
19   - @gov_sphere,
20   - "11.222.333/4444-55"
21   - )
22   - end
23   -
24   - def teardown
25   - GovUserPlugin::GovernmentalPower.destroy_all
26   - GovUserPlugin::GovernmentalSphere.destroy_all
27   - GovUserPlugin::JuridicalNature.destroy_all
28   - GovUserPlugin::Institution.destroy_all
29   - @gov_power = nil
30   - @gov_sphere = nil
31   - @juridical_nature = nil
32   - @institution = nil
33   - end
34   -
35   - should "save without a cnpj" do
36   - @institution.cnpj = nil
37   - assert @institution.save
38   - end
39   -
40   - should "save institution without an acronym" do
41   - @institution.acronym = nil
42   - assert @institution.save
43   - end
44   -
45   - should "Not save institution without a governmental_power" do
46   - invalid_msg = "Governmental power can't be blank"
47   - @institution.governmental_power = nil
48   -
49   - assert !@institution.save
50   - assert @institution.errors.full_messages.include? invalid_msg
51   - end
52   -
53   - should "Not save institution without a governmental_sphere" do
54   - invalid_msg = "Governmental sphere can't be blank"
55   - @institution.governmental_sphere = nil
56   -
57   - assert !@institution.save
58   - assert @institution.errors.full_messages.include? invalid_msg
59   - end
60   -
61   - should "not save institution without juridical nature" do
62   - invalid_msg = "Juridical nature can't be blank"
63   - @institution.juridical_nature = nil
64   -
65   - assert !@institution.save
66   - assert @institution.errors.full_messages.include? invalid_msg
67   - end
68   -
69   -
70   - should "verify cnpj format if it is filled" do
71   - @institution.cnpj = "123456789"
72   -
73   - assert_equal false, @institution.save
74   -
75   - @institution.cnpj = "11.222.333/4444-55"
76   -
77   - assert_equal true, @institution.save
78   - end
79   -end
src/noosfero-spb/gov_user/test/unit/gov_user_plugin/user_test.rb
... ... @@ -1,25 +0,0 @@
1   -require_relative '../../../../../test/test_helper'
2   -require_relative '../../helpers/plugin_test_helper'
3   -
4   -class UserTest < ActiveSupport::TestCase
5   - include PluginTestHelper
6   -
7   - should 'not save user whose email has already been used' do
8   - user1 = create_default_user
9   - user2 = fast_create(User)
10   -
11   - user2.email = "primary@email.com"
12   - assert !user2.save
13   - end
14   -
15   - private
16   -
17   - def create_default_user
18   - user = fast_create(User)
19   - user.login = "a-login"
20   - user.email = "primary@email.com"
21   - user.save
22   -
23   - return user
24   - end
25   -end
src/noosfero-spb/gov_user/test/unit/gov_user_plugin_api_test.rb
... ... @@ -9,9 +9,9 @@ class GovUserPlugin::ApiTest &lt; ActiveSupport::TestCase
9 9 login_api
10 10 environment = Environment.default
11 11 environment.enable_plugin(GovUserPlugin)
12   - @gov_power = GovernmentalPower.create(:name=>"Some Gov Power")
13   - @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
14   - @juridical_nature = JuridicalNature.create(:name => "Autarquia")
  12 + @gov_power = GovUserPlugin::GovernmentalPower.create(:name=>"Some Gov Power")
  13 + @gov_sphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere")
  14 + @juridical_nature = GovUserPlugin::JuridicalNature.create(:name => "Autarquia")
15 15 @institution = create_public_institution(
16 16 "Ministerio Publico da Uniao",
17 17 "MPU",
... ...
src/noosfero-spb/gov_user/test/unit/governmental_power_test.rb 0 → 100644
... ... @@ -0,0 +1,33 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/institution_test_helper'
  3 +
  4 +class GovUserPlugin::GovernmentalPowerTest < ActiveSupport::TestCase
  5 +
  6 + def setup
  7 + @gov_sphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere")
  8 + @juridical_nature = GovUserPlugin::JuridicalNature.create(:name => "Autarquia")
  9 + end
  10 +
  11 + def teardown
  12 + GovUserPlugin::Institution.destroy_all
  13 + end
  14 +
  15 + should "get public institutions" do
  16 + inst_name = "Ministerio Publico da Uniao"
  17 + inst_cnpj = "12.345.678/9012-45"
  18 + gov_power = GovUserPlugin::GovernmentalPower.create(:name=>"Some gov power")
  19 + InstitutionTestHelper.create_public_institution(
  20 + inst_name,
  21 + "MPU",
  22 + "BR",
  23 + "DF",
  24 + "Gama",
  25 + @juridical_nature,
  26 + gov_power,
  27 + @gov_sphere,
  28 + inst_cnpj
  29 + )
  30 +
  31 + assert_equal gov_power.institutions.public_institutions.count, GovUserPlugin::PublicInstitution.count
  32 + end
  33 +end
... ...
src/noosfero-spb/gov_user/test/unit/institution_test.rb 0 → 100644
... ... @@ -0,0 +1,76 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
  3 +
  4 +class GovUserPlugin::InstitutionTest < ActiveSupport::TestCase
  5 + include PluginTestHelper
  6 + def setup
  7 + @gov_power = GovUserPlugin::GovernmentalPower.create(:name=>"Some Gov Power")
  8 + @gov_sphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere")
  9 + @juridical_nature = GovUserPlugin::JuridicalNature.create(:name => "Autarquia")
  10 +
  11 + @institution = create_public_institution(
  12 + "Ministerio Publico da Uniao",
  13 + "MPU",
  14 + "BR",
  15 + "Distrito Federal",
  16 + "Gama",
  17 + @juridical_nature,
  18 + @gov_power,
  19 + @gov_sphere,
  20 + "11.222.333/4444-55"
  21 + )
  22 + end
  23 +
  24 + def teardown
  25 + GovUserPlugin::GovernmentalPower.destroy_all
  26 + GovUserPlugin::GovernmentalSphere.destroy_all
  27 + GovUserPlugin::JuridicalNature.destroy_all
  28 + @institution = nil
  29 + end
  30 +
  31 + should "not save institutions without name" do
  32 + @institution.name = nil
  33 + assert_equal false, @institution.save
  34 + assert_equal true, @institution.errors.messages.keys.include?(:name)
  35 + end
  36 +
  37 + should "not save if institution has invalid type" do
  38 + invalid_msg = "Type invalid, only public and private institutions are allowed."
  39 + @institution.type = "Other type"
  40 + assert_equal false, @institution.save
  41 + assert_equal true, @institution.errors.messages.keys.include?(:type)
  42 + end
  43 +
  44 + should "not save without country" do
  45 + @institution.community.country = nil
  46 + assert_equal false, @institution.save
  47 + assert_equal true, @institution.errors.messages.keys.include?(:country)
  48 + end
  49 +
  50 + should "not save without state" do
  51 + @institution.community.state = nil
  52 +
  53 + assert_equal false, @institution.save
  54 + assert_equal true, @institution.errors.messages.keys.include?(:state)
  55 + end
  56 +
  57 + should "not save without city" do
  58 + @institution.community.city = nil
  59 + @institution.community.state = "DF"
  60 +
  61 + assert_equal false, @institution.save
  62 + assert_equal true, @institution.errors.messages.keys.include?(:city)
  63 + end
  64 +
  65 + should "only return institutions of a specific environment" do
  66 + env1 = Environment.create(:name => "Environment One")
  67 + env2 = Environment.create(:name => "Environment Two")
  68 +
  69 + env1.communities << @institution.community
  70 + search_result_env1 = GovUserPlugin::Institution.search_institution("Ministerio", env1).collect{ |i| i.id }
  71 + search_result_env2 = GovUserPlugin::Institution.search_institution("Ministerio", env2).collect{ |i| i.id }
  72 +
  73 + assert_includes search_result_env1, @institution.id
  74 + assert_not_includes search_result_env2, @institution.id
  75 + end
  76 +end
... ...
src/noosfero-spb/gov_user/test/unit/institutions_block_test.rb 0 → 100644
... ... @@ -0,0 +1,77 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
  3 +
  4 +class GovUserPlugin::InstitutionsBlockTest < ActiveSupport::TestCase
  5 + def setup
  6 + environment = Environment.default
  7 + environment.enable_plugin(GovUserPlugin)
  8 + end
  9 +
  10 + include PluginTestHelper
  11 + should 'inherit from Block' do
  12 + assert_kind_of Block, GovUserPlugin::InstitutionsBlock.new
  13 + end
  14 +
  15 + should 'declare its default title' do
  16 + GovUserPlugin::InstitutionsBlock.any_instance.stubs(:profile_count).returns(0)
  17 + assert_not_equal Block.new.default_title, GovUserPlugin::InstitutionsBlock.new.default_title
  18 + end
  19 +
  20 + should 'describe itself' do
  21 + assert_not_equal Block.description, GovUserPlugin::InstitutionsBlock.description
  22 + end
  23 +
  24 + should 'give empty footer on unsupported owner type' do
  25 + block = GovUserPlugin::InstitutionsBlock.new
  26 + block.expects(:owner).returns(1)
  27 + assert_equal '', block.footer
  28 + end
  29 +
  30 + should 'list institutions' do
  31 + Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([GovUserPlugin.new])
  32 + user = create_person("Jose_Augusto",
  33 + "jose_augusto@email.com",
  34 + "aaaaaaa",
  35 + "aaaaaaa",
  36 + "DF",
  37 + "Gama"
  38 + )
  39 +
  40 + institution = create_private_institution(
  41 + "inst name",
  42 + "IN",
  43 + "country",
  44 + "state",
  45 + "city",
  46 + "00.111.222/3333-44"
  47 + )
  48 + institution.community.add_member(user)
  49 +
  50 + block = GovUserPlugin::InstitutionsBlock.new
  51 + block.expects(:owner).at_least_once.returns(user)
  52 +
  53 + assert_equivalent [institution.community], block.profiles
  54 + end
  55 +
  56 +
  57 + should 'not list communities' do
  58 + user = create_person("Jose_Augusto",
  59 + "jose_augusto@email.com",
  60 + "aaaaaaa",
  61 + "aaaaaaa",
  62 + "DF",
  63 + "Gama"
  64 + )
  65 + institution = InstitutionTestHelper.create_private_institution("inst name", "IN", "country", "state",
  66 + "city", "00.111.222/3333-44")
  67 + community = fast_create(Community)
  68 + institution.community.add_member(user)
  69 + community.add_member(user)
  70 +
  71 + block = GovUserPlugin::InstitutionsBlock.new
  72 + block.expects(:owner).at_least_once.returns(user)
  73 +
  74 + assert_equivalent block.profiles, [institution.community]
  75 + end
  76 +
  77 +end
... ...
src/noosfero-spb/gov_user/test/unit/institutions_organization_ratings_test.rb 0 → 100644
... ... @@ -0,0 +1,50 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
  3 +
  4 +class GovUserPlugin::InstitutionsOrganizationRatingsTest < ActiveSupport::TestCase
  5 + include PluginTestHelper
  6 +
  7 + def setup
  8 + @environment = Environment.default
  9 + @environment.enabled_plugins = ['SoftwareCommunitiesPlugin', 'GovUserPlugin']
  10 + @environment.save!
  11 + end
  12 +
  13 + should 'validate presence of institution' do
  14 + relation = GovUserPlugin::InstitutionsOrganizationRatings.new
  15 + relation.valid?
  16 + assert relation.errors[:institution].present?
  17 + end
  18 +
  19 + should 'validate presence of organization_rating' do
  20 + relation = GovUserPlugin::InstitutionsOrganizationRatings.new
  21 + relation.valid?
  22 + assert relation.errors[:organization_rating].present?
  23 + end
  24 +
  25 + should "validate institution if there is an institution_id" do
  26 + private_institution = build_private_institution "huehue", "hue", "11.222.333/4444-55"
  27 + relation = GovUserPlugin::InstitutionsOrganizationRatings.new(:institution => private_institution)
  28 + assert !relation.valid?
  29 + assert relation.errors[:institution].include?("not found")
  30 +
  31 + private_institution.save
  32 + relation.institution = private_institution
  33 + relation.valid?
  34 + assert !relation.errors[:institution].include?("not found")
  35 + end
  36 +
  37 + private
  38 +
  39 + def build_private_institution name, corporate_name, cnpj, country="AR"
  40 + community = Community.new :name => name
  41 + community.country = country
  42 +
  43 + institution = GovUserPlugin::PrivateInstitution.new :name=> name
  44 + institution.corporate_name = corporate_name
  45 + institution.cnpj = cnpj
  46 + institution.community = community
  47 +
  48 + institution
  49 + end
  50 +end
... ...
src/noosfero-spb/gov_user/test/unit/juridical_nature_test.rb 0 → 100644
... ... @@ -0,0 +1,23 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
  3 +
  4 +class GovUserPlugin::JuridicalNatureTest < ActiveSupport::TestCase
  5 +
  6 + include PluginTestHelper
  7 +
  8 + def setup
  9 + @govPower = GovUserPlugin::GovernmentalPower.create(:name=>"Some Gov Power")
  10 + @govSphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere")
  11 + end
  12 +
  13 + def teardown
  14 + GovUserPlugin::Institution.destroy_all
  15 + end
  16 +
  17 + should "get public institutions" do
  18 + juridical_nature = GovUserPlugin::JuridicalNature.create(:name => "Autarquia")
  19 + create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", juridical_nature, @govPower, @govSphere, "22.333.444/5555-66")
  20 + create_public_institution("Tribunal Regional da Uniao", "TRU", "BR", "DF", "Brasilia", juridical_nature, @govPower, @govSphere, "22.333.444/5555-77")
  21 + assert juridical_nature.institutions.public_institutions.count == GovUserPlugin::PublicInstitution.count
  22 + end
  23 +end
... ...
src/noosfero-spb/gov_user/test/unit/person_test.rb 0 → 100644
... ... @@ -0,0 +1,36 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
  3 +
  4 +class SoftwareCommunitiesPluginPersonTest < ActiveSupport::TestCase
  5 + include PluginTestHelper
  6 + def setup
  7 + @plugin = GovUserPlugin.new
  8 +
  9 + @user = fast_create(User)
  10 + @person = create_person(
  11 + "My Name",
  12 + "user@email.com",
  13 + "123456",
  14 + "123456",
  15 + "Any State",
  16 + "Some City"
  17 + )
  18 + end
  19 +
  20 + should 'calculate the percentege of person incomplete fields' do
  21 + @person.cell_phone = "76888919"
  22 + @person.contact_phone = "987654321"
  23 +
  24 + assert_equal(64, @plugin.calc_percentage_registration(@person))
  25 +
  26 + @person.comercial_phone = "11223344"
  27 + @person.country = "I dont know"
  28 + @person.state = "I dont know"
  29 + @person.city = "I dont know"
  30 + @person.organization_website = "www.whatever.com"
  31 + @person.image = Image::new :uploaded_data=>fixture_file_upload('/files/rails.png', 'image/png')
  32 + @person.save
  33 +
  34 + assert_equal(100, @plugin.calc_percentage_registration(@person))
  35 + end
  36 +end
... ...
src/noosfero-spb/gov_user/test/unit/private_institution_test.rb 0 → 100644
... ... @@ -0,0 +1,43 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
  3 +
  4 +class GovUserPlugin::PrivateInstitutionTest < ActiveSupport::TestCase
  5 + include PluginTestHelper
  6 + def setup
  7 + @institution = create_private_institution(
  8 + "Simple Private Institution",
  9 + "SPI",
  10 + "BR",
  11 + "Distrito Federal",
  12 + "Gama",
  13 + "00.000.000/0001-00"
  14 + )
  15 + end
  16 +
  17 + def teardown
  18 + @institution = nil
  19 + GovUserPlugin::Institution.destroy_all
  20 + end
  21 +
  22 + should "not save without a cnpj" do
  23 + @institution.cnpj = nil
  24 +
  25 + assert_equal false, @institution.save
  26 +
  27 + @institution.cnpj = "11.111.111/1111-11"
  28 + assert_equal true, @institution.save
  29 + end
  30 +
  31 + should "save without fantasy name" do
  32 + @institution.acronym = nil
  33 + @institution.community.save
  34 +
  35 + assert @institution.save
  36 + end
  37 +
  38 + should "not verify cnpj if it isnt a brazilian institution" do
  39 + @institution.cnpj = nil
  40 + @institution.community.country = "AR"
  41 + assert_equal true, @institution.save
  42 + end
  43 +end
... ...
src/noosfero-spb/gov_user/test/unit/public_institution_test.rb 0 → 100644
... ... @@ -0,0 +1,79 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
  3 +
  4 +class GovUserPlugin::PublicInstitutionTest < ActiveSupport::TestCase
  5 + include PluginTestHelper
  6 + def setup
  7 + @gov_power = GovUserPlugin::GovernmentalPower.create(:name=>"Some Gov Power")
  8 + @gov_sphere = GovUserPlugin::GovernmentalSphere.create(:name=>"Some Gov Sphere")
  9 + @juridical_nature = GovUserPlugin::JuridicalNature.create(:name => "Autarquia")
  10 +
  11 + @institution = create_public_institution(
  12 + "Ministerio Publico da Uniao",
  13 + "MPU",
  14 + "BR",
  15 + "Distrito Federal",
  16 + "Gama",
  17 + @juridical_nature,
  18 + @gov_power,
  19 + @gov_sphere,
  20 + "11.222.333/4444-55"
  21 + )
  22 + end
  23 +
  24 + def teardown
  25 + GovUserPlugin::GovernmentalPower.destroy_all
  26 + GovUserPlugin::GovernmentalSphere.destroy_all
  27 + GovUserPlugin::JuridicalNature.destroy_all
  28 + GovUserPlugin::Institution.destroy_all
  29 + @gov_power = nil
  30 + @gov_sphere = nil
  31 + @juridical_nature = nil
  32 + @institution = nil
  33 + end
  34 +
  35 + should "save without a cnpj" do
  36 + @institution.cnpj = nil
  37 + assert @institution.save
  38 + end
  39 +
  40 + should "save institution without an acronym" do
  41 + @institution.acronym = nil
  42 + assert @institution.save
  43 + end
  44 +
  45 + should "Not save institution without a governmental_power" do
  46 + invalid_msg = "Governmental power can't be blank"
  47 + @institution.governmental_power = nil
  48 +
  49 + assert !@institution.save
  50 + assert @institution.errors.full_messages.include? invalid_msg
  51 + end
  52 +
  53 + should "Not save institution without a governmental_sphere" do
  54 + invalid_msg = "Governmental sphere can't be blank"
  55 + @institution.governmental_sphere = nil
  56 +
  57 + assert !@institution.save
  58 + assert @institution.errors.full_messages.include? invalid_msg
  59 + end
  60 +
  61 + should "not save institution without juridical nature" do
  62 + invalid_msg = "Juridical nature can't be blank"
  63 + @institution.juridical_nature = nil
  64 +
  65 + assert !@institution.save
  66 + assert @institution.errors.full_messages.include? invalid_msg
  67 + end
  68 +
  69 +
  70 + should "verify cnpj format if it is filled" do
  71 + @institution.cnpj = "123456789"
  72 +
  73 + assert_equal false, @institution.save
  74 +
  75 + @institution.cnpj = "11.222.333/4444-55"
  76 +
  77 + assert_equal true, @institution.save
  78 + end
  79 +end
... ...
src/noosfero-spb/gov_user/test/unit/user_test.rb 0 → 100644
... ... @@ -0,0 +1,25 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper'
  3 +
  4 +class UserTest < ActiveSupport::TestCase
  5 + include PluginTestHelper
  6 +
  7 + should 'not save user whose email has already been used' do
  8 + user1 = create_default_user
  9 + user2 = fast_create(User)
  10 +
  11 + user2.email = "primary@email.com"
  12 + assert !user2.save
  13 + end
  14 +
  15 + private
  16 +
  17 + def create_default_user
  18 + user = fast_create(User)
  19 + user.login = "a-login"
  20 + user.email = "primary@email.com"
  21 + user.save
  22 +
  23 + return user
  24 + end
  25 +end
... ...