Commit e80430110ac3d8d72118e856b3578f59c7a6e9f5
1 parent
23cad8fe
Exists in
master
and in
5 other branches
Add tests and helper for create new software.
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com> Signed-off-by: Gustavo Jaruga <darksshades@gmail.com> Signed-off-by: Parley Martins <parley@outlook.com>
Showing
3 changed files
with
13 additions
and
132 deletions
Show diff stats
test/functional/mpog_software_plugin_myprofile_controller_test.rb
1 | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
2 | 2 | require File.dirname(__FILE__) + '/../../controllers/mpog_software_plugin_myprofile_controller' |
3 | -require File.dirname(__FILE__) + '/software_helper' | |
3 | +require File.dirname(__FILE__) + '/software_test_helper' | |
4 | 4 | |
5 | 5 | class MpogSoftwarePluginMyprofileController; def rescue_action(e) raise e end; |
6 | 6 | end |
7 | 7 | |
8 | 8 | class MpogSoftwarePluginMyprofileControllerTest < ActionController::TestCase |
9 | - include SoftwareHelper | |
9 | + include SoftwareTestHelper | |
10 | 10 | def setup |
11 | 11 | @controller = MpogSoftwarePluginMyprofileController.new |
12 | 12 | @request = ActionController::TestRequest.new |
... | ... | @@ -22,9 +22,9 @@ class MpogSoftwarePluginMyprofileControllerTest < ActionController::TestCase |
22 | 22 | OperatingSystemName.create(:name=>"Debian") |
23 | 23 | |
24 | 24 | login_as(@person.user.login) |
25 | - e = Environment.default | |
26 | - e.enable_plugin('MpogSoftwarePlugin') | |
27 | - e.save! | |
25 | + @e = Environment.default | |
26 | + @e.enable_plugin('MpogSoftwarePlugin') | |
27 | + @e.save! | |
28 | 28 | end |
29 | 29 | |
30 | 30 | attr_accessor :person, :offer |
... | ... | @@ -32,8 +32,9 @@ class MpogSoftwarePluginMyprofileControllerTest < ActionController::TestCase |
32 | 32 | should 'Add offer to admin in new software' do |
33 | 33 | @hash_list = software_fields |
34 | 34 | @software = create_software @hash_list |
35 | - @software.community.add_admin(@offer.person) | |
36 | - assert_equal @offer.id, Community.last.admins.last.id | |
35 | + @software.community.add_admin(@offer.person) | |
36 | + @software.save | |
37 | + assert_equal @offer.id, @software.community.admins.last.id | |
37 | 38 | end |
38 | 39 | |
39 | 40 | should 'search new offers while creating a new software' do |
... | ... | @@ -62,52 +63,12 @@ class MpogSoftwarePluginMyprofileControllerTest < ActionController::TestCase |
62 | 63 | |
63 | 64 | should 'create a new software with all fields filled in' do |
64 | 65 | fields = software_fields |
65 | - software = create_software(fields) | |
66 | - assert software.save | |
67 | - end | |
68 | - | |
69 | -private | |
70 | - | |
71 | - def software_fields | |
72 | 66 | |
73 | - fields = Hash.new | |
74 | - fields_library = Hash.new | |
75 | - fields_language = Hash.new | |
76 | - fields_database = Hash.new | |
77 | - fields_license = Hash.new | |
78 | - fields_operating_system = Hash.new | |
79 | - #Fields for library | |
80 | - fields_library['version'] = 'test' | |
81 | - fields_library['name'] = 'test' | |
82 | - fields_library['license'] = 'test' | |
83 | - #Fields for software language | |
84 | - fields_language['version'] = 'test' | |
85 | - fields_language['programming_language_id'] = ProgrammingLanguage.last.id | |
86 | - fields_language['operating_system'] = 'test' | |
87 | - #Fields for database | |
88 | - fields_database['version'] = 'test' | |
89 | - fields_database['database_description_id'] = DatabaseDescription.last.id | |
90 | - fields_database['operating_system'] = 'test' | |
91 | - #Fields for license info | |
92 | - fields_license['version'] = 'teste' | |
93 | - fields_license['link'] = 'teste' | |
94 | - #Fields for operating system | |
95 | - fields_operating_system['version'] = 'version' | |
96 | - fields_operating_system['operating_system_name_id'] = OperatingSystemName.last.id | |
67 | + post :new_software, :profile => person.identifier, :community => fields[6], :license_info => fields[5], | |
68 | + :software_info => fields[0], :library => fields[1], :database => fields[3], | |
69 | + :language => fields[2], :operating_system=> fields[4] | |
70 | + assert @response.success? | |
71 | + end | |
97 | 72 | |
98 | - fields['acronym'] = 'test' | |
99 | - fields['objectives'] = 'test' | |
100 | - fields['features'] = 'test' | |
101 | - fields['operating_platform'] = 'operating_plataform_test' | |
102 | - fields['demonstration_url'] = 'test' | |
103 | 73 | |
104 | - hash_list = [] | |
105 | - hash_list << fields | |
106 | - hash_list << fields_library | |
107 | - hash_list << fields_language | |
108 | - hash_list << fields_database | |
109 | - hash_list << fields_operating_system | |
110 | - hash_list << fields_license | |
111 | - hash_list | |
112 | - end | |
113 | 74 | end | ... | ... |
test/functional/software_helper.rb
... | ... | @@ -1,80 +0,0 @@ |
1 | -module SoftwareHelper | |
2 | - | |
3 | - def create_language language_fields | |
4 | - language = SoftwareLanguage.new | |
5 | - | |
6 | - language_fields.each do |k,v| | |
7 | - language[k] = v | |
8 | - end | |
9 | - language.save | |
10 | - language | |
11 | - end | |
12 | - | |
13 | - def create_database database_fields | |
14 | - | |
15 | - database = SoftwareDatabase.new | |
16 | - | |
17 | - database_fields.each do |k,v| | |
18 | - database[k] = v | |
19 | - end | |
20 | - | |
21 | - database.save | |
22 | - database | |
23 | - end | |
24 | - | |
25 | - def create_library library_fields | |
26 | - library = Library.new | |
27 | - | |
28 | - library_fields.each do |k,v| | |
29 | - library[k] = v | |
30 | - end | |
31 | - library.save | |
32 | - library | |
33 | - end | |
34 | - | |
35 | - def create_operating_system operating_system_hash | |
36 | - operating_system = OperatingSystem.new | |
37 | - | |
38 | - operating_system_hash.each do |k,v| | |
39 | - operating_system[k] = v | |
40 | - end | |
41 | - operating_system.save | |
42 | - operating_system | |
43 | - end | |
44 | - | |
45 | - def create_license license_hash | |
46 | - license_info = LicenseInfo.new | |
47 | - | |
48 | - license_hash.each do |k,v| | |
49 | - license_info[k] = v | |
50 | - end | |
51 | - license_info.save | |
52 | - license_info | |
53 | - end | |
54 | - def create_software fields | |
55 | - | |
56 | - software = SoftwareInfo.new | |
57 | - software_hash = fields[0] | |
58 | - library_hash = fields[1] | |
59 | - language_hash = fields[2] | |
60 | - database_hash = fields[3] | |
61 | - operating_system_hash = fields[4] | |
62 | - license_system_hash = fields[5] | |
63 | - | |
64 | - software_hash.each do |k,v| | |
65 | - software[k] = v | |
66 | - end | |
67 | - | |
68 | - community = Community.new | |
69 | - community.name = "debian" | |
70 | - community.save | |
71 | - software.community = community | |
72 | - software.software_databases << create_database(database_hash) | |
73 | - software.software_languages << create_language(language_hash) | |
74 | - software.operating_systems << create_operating_system(operating_system_hash) | |
75 | - software.license_info = create_license(license_system_hash) | |
76 | - software.libraries << create_library(library_hash) | |
77 | - | |
78 | - software | |
79 | - end | |
80 | -end |