Commit 44606433ec3e97ff3a750dcf0e8156bd07c56f8d
1 parent
cf647cbe
Exists in
master
and in
5 other branches
Update search_controller_test and move plugin_test_helper to folder helpers
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com> Signed-off-by: Parley Martins <parley@outlook.com>
Showing
14 changed files
with
95 additions
and
183 deletions
Show diff stats
test/functional/search_controller_test.rb
1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
2 | require File.dirname(__FILE__) + '/../../../../app/controllers/public/search_controller' | 2 | require File.dirname(__FILE__) + '/../../../../app/controllers/public/search_controller' |
3 | -require File.dirname(__FILE__) + '/software_test_helper' | 3 | +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' |
4 | 4 | ||
5 | class SearchController; def rescue_action(e) raise e end; end | 5 | class SearchController; def rescue_action(e) raise e end; end |
6 | 6 | ||
7 | class SearchControllerTest < ActionController::TestCase | 7 | class SearchControllerTest < ActionController::TestCase |
8 | - include SoftwareTestHelper | 8 | + include PluginTestHelper |
9 | + | ||
9 | def setup | 10 | def setup |
10 | environment = Environment.default | 11 | environment = Environment.default |
11 | environment.enabled_plugins = ['MpogSoftwarePlugin'] | 12 | environment.enabled_plugins = ['MpogSoftwarePlugin'] |
@@ -15,107 +16,18 @@ class SearchControllerTest < ActionController::TestCase | @@ -15,107 +16,18 @@ class SearchControllerTest < ActionController::TestCase | ||
15 | @request = ActionController::TestRequest.new | 16 | @request = ActionController::TestRequest.new |
16 | @request.stubs(:ssl?).returns(:false) | 17 | @request.stubs(:ssl?).returns(:false) |
17 | @response = ActionController::TestResponse.new | 18 | @response = ActionController::TestResponse.new |
18 | - | ||
19 | - LicenseInfo.create(:version=>"GPL-2", :link =>"www.gpl2.com") | ||
20 | - ProgrammingLanguage.create(:name=>"C++") | ||
21 | - DatabaseDescription.create(:name => "Oracle") | ||
22 | - OperatingSystemName.create(:name=>"Debian") | ||
23 | - | ||
24 | - operating_system = OperatingSystem.new(version: '1.0') | ||
25 | - operating_system.operating_system_name = OperatingSystemName.last | ||
26 | - operating_system.save! | ||
27 | - | ||
28 | - software_language = SoftwareLanguage.new(version: "1.0", operating_system: "windows") | ||
29 | - software_language.programming_language = ProgrammingLanguage.last | ||
30 | - software_language.save! | ||
31 | - | ||
32 | - software_database = SoftwareDatabase.new(version: "1.0", operating_system: "windows") | ||
33 | - software_database.database_description = DatabaseDescription.last | ||
34 | - software_database.save! | ||
35 | - | ||
36 | - end | ||
37 | - | ||
38 | - should "search for people by identifier" do | ||
39 | - p1 = create_user("user 1", "DF", "Gama", "user_1@user.com").person | ||
40 | - | ||
41 | - get :people, :query => "user-1" | ||
42 | - | ||
43 | - assert_includes assigns(:searches)[:people][:results], p1 | ||
44 | end | 19 | end |
45 | 20 | ||
46 | - should "search for people by name" do | ||
47 | - p1 = create_user("user_1", "DF", "Gama", "user_1@user.com").person | ||
48 | - | ||
49 | - get :people, :query => "user_1" | ||
50 | - | ||
51 | - assert_includes assigns(:searches)[:people][:results], p1 | ||
52 | - end | ||
53 | - | ||
54 | - should "search for people by state" do | ||
55 | - p1 = create_user("user_1", "DF", "Gama", "user_1@user.com").person | ||
56 | - | ||
57 | - get :people, :state => "DF" | ||
58 | - | ||
59 | - assert_includes assigns(:searches)[:people][:results], p1 | ||
60 | - end | ||
61 | - | ||
62 | - should "search for people by city" do | ||
63 | - p1 = create_user("user_1", "DF", "Gama", "user_1@user.com").person | ||
64 | - | ||
65 | - get :people, :city => "Gama" | ||
66 | - | ||
67 | - assert_includes assigns(:searches)[:people][:results], p1 | ||
68 | - end | ||
69 | - | ||
70 | - should "search for people by email" do | ||
71 | - p1 = create_user("user_1", "DF", "Gama", "user_1@user.com").person | ||
72 | - | ||
73 | - get :people, :email => "user_1@user.com" | ||
74 | - | ||
75 | - assert_includes assigns(:searches)[:people][:results], p1 | ||
76 | - end | ||
77 | - | ||
78 | - should "search for people by email and state" do | ||
79 | - p1 = create_user("user_1", "DF", "Gama", "user_1@user.com").person | ||
80 | - | ||
81 | - get :people, :email => "user_1@user.com", :state => "DF" | ||
82 | - | ||
83 | - assert_includes assigns(:searches)[:people][:results], p1 | ||
84 | - end | ||
85 | - | ||
86 | - should "search for software by identifier" do | ||
87 | - fields = software_fields | ||
88 | - software = create_software fields | ||
89 | - software.save | ||
90 | - | ||
91 | - params = {"type"=>"Software", "query"=>"", "name"=>"debian", "database_description"=>{"id"=>""}, "programming_language"=>{"id"=>""}, "operating_system"=>{"id"=>""}, "software_categories"=>"", "license_info"=>{"id"=>""}, "e_ping"=>"", "e_mag"=>"", "icp_brasil"=>"", "e_arq"=>"", "internacionalizable"=>"", "commit"=>"Search"} | ||
92 | - get :communities, params | ||
93 | - | ||
94 | - assert_includes assigns(:searches)[:communities][:results], software.community | ||
95 | - end | ||
96 | - | ||
97 | - should "search for software by name" do | ||
98 | - fields = software_fields | ||
99 | - software = create_software fields | ||
100 | - software.save | ||
101 | - | ||
102 | - params = {"type"=>"Software", "query"=>"", "name"=>"debian", "database_description"=>{"id"=>""}, "programming_language"=>{"id"=>""}, "operating_system"=>{"id"=>""}, "software_categories"=>"", "license_info"=>{"id"=>""}, "e_ping"=>"", "e_mag"=>"", "icp_brasil"=>"", "e_arq"=>"", "internacionalizable"=>"", "commit"=>"Search"} | ||
103 | - get :communities, params | ||
104 | - | ||
105 | - assert_includes assigns(:searches)[:communities][:results], software.community | ||
106 | - end | 21 | + should "communities searches don't have software or institution" do |
22 | + community = create_community("New Community") | ||
23 | + software = create_software_info("New Software") | ||
24 | + institution = create_private_institution("New Private Institution", "NPI" , "Brazil", "DF", "Gama", "66.544.314/0001-63") | ||
107 | 25 | ||
108 | - protected | 26 | + get :communities, :query => "New" |
109 | 27 | ||
110 | - def create_user name, state, city, email | ||
111 | - user = fast_create(User) | ||
112 | - user.person = fast_create(Person) | ||
113 | - user.person.state = state | ||
114 | - user.person.city = city | ||
115 | - user.person.email = email | ||
116 | - user.save! | ||
117 | - user.person.save! | ||
118 | - user | 28 | + assert_includes assigns(:searches)[:communities][:results], community |
29 | + assert_not_includes assigns(:searches)[:communities][:results], software | ||
30 | + assert_not_includes assigns(:searches)[:communities][:results], institution | ||
119 | end | 31 | end |
120 | 32 | ||
121 | end | 33 | end |
@@ -0,0 +1,68 @@ | @@ -0,0 +1,68 @@ | ||
1 | +require File.dirname(__FILE__) + '/../helpers/institution_test_helper' | ||
2 | + | ||
3 | +module PluginTestHelper | ||
4 | + | ||
5 | + def create_public_institution *params | ||
6 | + InstitutionTestHelper.create_public_institution *params | ||
7 | + end | ||
8 | + | ||
9 | + def create_community name | ||
10 | + community = fast_create(Community) | ||
11 | + community.name = name | ||
12 | + community.save | ||
13 | + community | ||
14 | + end | ||
15 | + | ||
16 | + def create_software_info name | ||
17 | + community = create_community(name) | ||
18 | + software_info = SoftwareInfo.new | ||
19 | + software_info.community = community | ||
20 | + software_info.save | ||
21 | + software_info | ||
22 | + end | ||
23 | + | ||
24 | + def create_private_institution name, acronym, country, state, city, cnpj | ||
25 | + InstitutionTestHelper.create_private_institution(name, acronym, country, state, city, cnpj) | ||
26 | + end | ||
27 | + | ||
28 | + def create_community_institution name, country, state, city | ||
29 | + community = fast_create(Community) | ||
30 | + community.name = name | ||
31 | + community.country = country | ||
32 | + community.state = state | ||
33 | + community.city = city | ||
34 | + community.save | ||
35 | + community | ||
36 | + end | ||
37 | + | ||
38 | + def create_person name, email, password, password_confirmation, secondary_email, state, city | ||
39 | + user = create_user(name.to_slug, email, password, password_confirmation, secondary_email) | ||
40 | + person = Person::new | ||
41 | + | ||
42 | + user.person = person | ||
43 | + person.user = user | ||
44 | + | ||
45 | + person.name = name | ||
46 | + person.identifier = name.to_slug | ||
47 | + person.state = state | ||
48 | + person.city = city | ||
49 | + | ||
50 | + user.save | ||
51 | + person.save | ||
52 | + | ||
53 | + person | ||
54 | + end | ||
55 | + | ||
56 | + def create_user login, email, password, password_confirmation, secondary_email | ||
57 | + user = User.new | ||
58 | + | ||
59 | + user.login = login | ||
60 | + user.email = email | ||
61 | + user.password = password | ||
62 | + user.password_confirmation = password_confirmation | ||
63 | + user.secondary_email = secondary_email | ||
64 | + | ||
65 | + user | ||
66 | + end | ||
67 | + | ||
68 | +end |
test/unit/communities_block_test.rb
1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
2 | require File.dirname(__FILE__) + '/../helpers/institution_test_helper' | 2 | require File.dirname(__FILE__) + '/../helpers/institution_test_helper' |
3 | -require File.dirname(__FILE__) + '/plugin_test_helper' | 3 | +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' |
4 | 4 | ||
5 | class CommunitiesBlockTest < ActiveSupport::TestCase | 5 | class CommunitiesBlockTest < ActiveSupport::TestCase |
6 | include PluginTestHelper | 6 | include PluginTestHelper |
test/unit/institution_test.rb
1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
2 | -require File.dirname(__FILE__) + '/plugin_test_helper' | 2 | +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' |
3 | 3 | ||
4 | class InstitutionTest < ActiveSupport::TestCase | 4 | class InstitutionTest < ActiveSupport::TestCase |
5 | include PluginTestHelper | 5 | include PluginTestHelper |
@@ -28,14 +28,14 @@ class InstitutionTest < ActiveSupport::TestCase | @@ -28,14 +28,14 @@ class InstitutionTest < ActiveSupport::TestCase | ||
28 | assert !@institution.save, 'Invalid type' | 28 | assert !@institution.save, 'Invalid type' |
29 | assert @institution.errors.full_messages.include? "Type invalid, only public and private institutions are allowed." | 29 | assert @institution.errors.full_messages.include? "Type invalid, only public and private institutions are allowed." |
30 | end | 30 | end |
31 | - | ||
32 | - should "not save without country" do | 31 | + |
32 | + should "not save without country" do | ||
33 | @institution.community.country = nil | 33 | @institution.community.country = nil |
34 | assert !@institution.save, "Country can't be blank" | 34 | assert !@institution.save, "Country can't be blank" |
35 | assert @institution.errors.full_messages.include? "Country can't be blank" | 35 | assert @institution.errors.full_messages.include? "Country can't be blank" |
36 | end | 36 | end |
37 | 37 | ||
38 | - should "not save without state" do | 38 | + should "not save without state" do |
39 | @institution.community.state = nil | 39 | @institution.community.state = nil |
40 | 40 | ||
41 | assert !@institution.save, "State can't be blank" | 41 | assert !@institution.save, "State can't be blank" |
test/unit/institutions_block_test.rb
1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
2 | -require File.dirname(__FILE__) + '/plugin_test_helper' | 2 | +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' |
3 | 3 | ||
4 | class InstitutionsBlockTest < ActiveSupport::TestCase | 4 | class InstitutionsBlockTest < ActiveSupport::TestCase |
5 | include PluginTestHelper | 5 | include PluginTestHelper |
test/unit/juridical_nature_test.rb
1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
2 | -require File.dirname(__FILE__) + '/plugin_test_helper' | 2 | +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' |
3 | 3 | ||
4 | class JuridicalNatureTest < ActiveSupport::TestCase | 4 | class JuridicalNatureTest < ActiveSupport::TestCase |
5 | 5 |
test/unit/mpog_software_plugin_test.rb
1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
2 | -require File.dirname(__FILE__) + '/plugin_test_helper' | 2 | +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' |
3 | 3 | ||
4 | class MpogSoftwarePluginTest < ActiveSupport::TestCase | 4 | class MpogSoftwarePluginTest < ActiveSupport::TestCase |
5 | include PluginTestHelper | 5 | include PluginTestHelper |
test/unit/mpog_software_plugin_user_test.rb
1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
2 | -require File.dirname(__FILE__) + '/plugin_test_helper' | 2 | +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' |
3 | 3 | ||
4 | class MpogSoftwarePluginUserTest < ActiveSupport::TestCase | 4 | class MpogSoftwarePluginUserTest < ActiveSupport::TestCase |
5 | include PluginTestHelper | 5 | include PluginTestHelper |
@@ -82,7 +82,7 @@ class MpogSoftwarePluginUserTest < ActiveSupport::TestCase | @@ -82,7 +82,7 @@ class MpogSoftwarePluginUserTest < ActiveSupport::TestCase | ||
82 | user2 = fast_create(User) | 82 | user2 = fast_create(User) |
83 | user2.email = "test2@email.com" | 83 | user2.email = "test2@email.com" |
84 | user2.secondary_email = "" | 84 | user2.secondary_email = "" |
85 | - assert user2.save | 85 | + assert user2.save |
86 | end | 86 | end |
87 | should 'return an error if secondary email is governmental and primary is not' do | 87 | should 'return an error if secondary email is governmental and primary is not' do |
88 | user = fast_create(User) | 88 | user = fast_create(User) |
test/unit/mpog_validation_test.rb
1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
2 | -require File.dirname(__FILE__) + '/plugin_test_helper' | 2 | +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' |
3 | 3 | ||
4 | class MpogSoftwarePluginValidationTest < ActiveSupport::TestCase | 4 | class MpogSoftwarePluginValidationTest < ActiveSupport::TestCase |
5 | include PluginTestHelper | 5 | include PluginTestHelper |
test/unit/plugin_test_helper.rb
@@ -1,68 +0,0 @@ | @@ -1,68 +0,0 @@ | ||
1 | -require File.dirname(__FILE__) + '/../helpers/institution_test_helper' | ||
2 | - | ||
3 | -module PluginTestHelper | ||
4 | - | ||
5 | - def create_public_institution *params | ||
6 | - InstitutionTestHelper.create_public_institution *params | ||
7 | - end | ||
8 | - | ||
9 | - def create_community name | ||
10 | - community = fast_create(Community) | ||
11 | - community.name = name | ||
12 | - community.save | ||
13 | - community | ||
14 | - end | ||
15 | - | ||
16 | - def create_software_info name | ||
17 | - community = create_community(name) | ||
18 | - software_info = SoftwareInfo.new | ||
19 | - software_info.community = community | ||
20 | - software_info.save | ||
21 | - software_info | ||
22 | - end | ||
23 | - | ||
24 | - def create_private_institution *params | ||
25 | - InstitutionTestHelper.create_private_institution *params | ||
26 | - end | ||
27 | - | ||
28 | - def create_community_institution name, country, state, city | ||
29 | - community = fast_create(Community) | ||
30 | - community.name = name | ||
31 | - community.country = country | ||
32 | - community.state = state | ||
33 | - community.city = city | ||
34 | - community.save | ||
35 | - community | ||
36 | - end | ||
37 | - | ||
38 | - def create_person name, email, password, password_confirmation, secondary_email, state, city | ||
39 | - user = create_user(name.to_slug, email, password, password_confirmation, secondary_email) | ||
40 | - person = Person::new | ||
41 | - | ||
42 | - user.person = person | ||
43 | - person.user = user | ||
44 | - | ||
45 | - person.name = name | ||
46 | - person.identifier = name.to_slug | ||
47 | - person.state = state | ||
48 | - person.city = city | ||
49 | - | ||
50 | - user.save | ||
51 | - person.save | ||
52 | - | ||
53 | - person | ||
54 | - end | ||
55 | - | ||
56 | - def create_user login, email, password, password_confirmation, secondary_email | ||
57 | - user = User.new | ||
58 | - | ||
59 | - user.login = login | ||
60 | - user.email = email | ||
61 | - user.password = password | ||
62 | - user.password_confirmation = password_confirmation | ||
63 | - user.secondary_email = secondary_email | ||
64 | - | ||
65 | - user | ||
66 | - end | ||
67 | - | ||
68 | -end |
test/unit/private_institution_test.rb
1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
2 | -require File.dirname(__FILE__) + '/plugin_test_helper' | 2 | +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' |
3 | 3 | ||
4 | class PrivateInstitutionTest < ActiveSupport::TestCase | 4 | class PrivateInstitutionTest < ActiveSupport::TestCase |
5 | include PluginTestHelper | 5 | include PluginTestHelper |
test/unit/public_institution_test.rb
1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
2 | -require File.dirname(__FILE__) + '/plugin_test_helper' | 2 | +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' |
3 | 3 | ||
4 | class PublicInstitutionTest < ActiveSupport::TestCase | 4 | class PublicInstitutionTest < ActiveSupport::TestCase |
5 | include PluginTestHelper | 5 | include PluginTestHelper |
@@ -24,7 +24,7 @@ class PublicInstitutionTest < ActiveSupport::TestCase | @@ -24,7 +24,7 @@ class PublicInstitutionTest < ActiveSupport::TestCase | ||
24 | 24 | ||
25 | should "not save without a cnpj" do | 25 | should "not save without a cnpj" do |
26 | @institution.cnpj = nil | 26 | @institution.cnpj = nil |
27 | - assert !@institution.save | 27 | + assert !@institution.save |
28 | end | 28 | end |
29 | 29 | ||
30 | should "save institution without an acronym" do | 30 | should "save institution without an acronym" do |
test/unit/search_person_test.rb
1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
2 | -require File.dirname(__FILE__) + '/plugin_test_helper' | 2 | +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' |
3 | 3 | ||
4 | 4 | ||
5 | class SearchPersonTest < ActiveSupport::TestCase | 5 | class SearchPersonTest < ActiveSupport::TestCase |
test/unit/softwares_block_test.rb
1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
2 | -require File.dirname(__FILE__) + '/plugin_test_helper' | 2 | +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' |
3 | 3 | ||
4 | class SoftwaresBlockTest < ActiveSupport::TestCase | 4 | class SoftwaresBlockTest < ActiveSupport::TestCase |
5 | include PluginTestHelper | 5 | include PluginTestHelper |