Commit b3d90985386043f6f20925068f120cc0995ee6d0

Authored by Fabio Teixeira
Committed by Luciano Prestes
1 parent eee6f248
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

fixes_software: Add server-side database dynamic table validations and tests

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
features/software_registration.feature
@@ -6,25 +6,19 @@ Feature: software registration @@ -6,25 +6,19 @@ Feature: software registration
6 Background: 6 Background:
7 Given "MpogSoftwarePlugin" plugin is enabled 7 Given "MpogSoftwarePlugin" plugin is enabled
8 And SoftwareInfo has initial default values on database 8 And SoftwareInfo has initial default values on database
9 - And I am logged in as admin 9 + And I am logged in as mpog_admin
10 And I go to /admin/plugins 10 And I go to /admin/plugins
11 And I check "MpogSoftwarePlugin" 11 And I check "MpogSoftwarePlugin"
12 And I press "Save changes" 12 And I press "Save changes"
13 13
14 - Scenario: Show library fields when click in New Library  
15 - Given I go to admin_user's control panel  
16 - And I follow "Manage my groups"  
17 - And I follow "Create a new software"  
18 - And I follow "New Library"  
19 - Then I should see "Name"  
20 - Then I should see "Version"  
21 - Then I should see "License"  
22 -  
23 @selenium 14 @selenium
24 Scenario: Show SoftwareLangue fields when click in New Language 15 Scenario: Show SoftwareLangue fields when click in New Language
25 - Given I go to admin_user's control panel  
26 - And I follow "Manage my groups" 16 + Given I go to /myprofile/mpog-admin
27 And I follow "Create a new software" 17 And I follow "Create a new software"
  18 + And I fill in "community_name" with "basic software"
  19 + And I fill in "software_info_finality" with "basic software finality"
  20 + And I press "Create"
  21 + And I follow "Public Software"
28 And I follow "New language" 22 And I follow "New language"
29 And I should see "3" of this selector ".software-language-table" 23 And I should see "3" of this selector ".software-language-table"
30 And I follow "Delete" 24 And I follow "Delete"
@@ -33,9 +27,12 @@ Feature: software registration @@ -33,9 +27,12 @@ Feature: software registration
33 27
34 @selenium 28 @selenium
35 Scenario: Show databasefields when click in New database 29 Scenario: Show databasefields when click in New database
36 - Given I go to admin_user's control panel  
37 - And I follow "Manage my groups" 30 + Given I go to /myprofile/mpog-admin
38 And I follow "Create a new software" 31 And I follow "Create a new software"
  32 + And I fill in "community_name" with "basic software"
  33 + And I fill in "software_info_finality" with "basic software finality"
  34 + And I press "Create"
  35 + And I follow "Public Software"
39 And I follow "New Database" 36 And I follow "New Database"
40 And I should see "3" of this selector ".database-table" 37 And I should see "3" of this selector ".database-table"
41 And I follow "Delete" 38 And I follow "Delete"
@@ -43,12 +40,39 @@ Feature: software registration @@ -43,12 +40,39 @@ Feature: software registration
43 #3 because one is always hidden 40 #3 because one is always hidden
44 41
45 @selenium 42 @selenium
46 - Scenario: Delete software libraries  
47 - Given I go to admin_user's control panel  
48 - And I follow "Manage my groups" 43 + Scenario: Software database name should be an autocomplete
  44 + Given I go to /myprofile/mpog-admin
49 And I follow "Create a new software" 45 And I follow "Create a new software"
50 - And I follow "New Library"  
51 - And I should see "2" of this selector ".library-table"  
52 - And I follow "Delete"  
53 - Then I should see "1" of this selector ".library-table" 46 + And I fill in "community_name" with "basic software"
  47 + And I fill in "software_info_finality" with "basic software finality"
  48 + And I press "Create"
  49 + And I follow "Public Software"
  50 + And I follow "New Database"
  51 + And I type in "my" into autocomplete list "database_autocomplete" and I choose "MySQL"
  52 + And I fill in "database_autocomplete" with "Replace me with MySQL"
  53 + And I fill in "database__version" with ""
  54 + Then selector ".database_autocomplete" should have any "MySQL"
54 55
  56 + @selenium
  57 + Scenario: Create software with all dynamic table fields filled
  58 + Given I go to /myprofile/mpog-admin
  59 + And I follow "Create a new software"
  60 + And I fill in "community_name" with "basic software"
  61 + And I fill in "software_info_finality" with "basic software finality"
  62 + And I press "Create"
  63 + And I follow "Public Software"
  64 + And I follow "New language"
  65 + And I fill in "language__version" with "1.2.3"
  66 + And I fill in "language__operating_system" with "Unix"
  67 + And I follow "New Database"
  68 + And I type in "my" into autocomplete list "database_autocomplete" and I choose "MySQL"
  69 + And I fill in "database__version" with "4.5.6"
  70 + And I fill in "database__operating_system" with "Unix"
  71 + And I press "Save"
  72 + And I follow "Software Info"
  73 + And I follow "Public Software"
  74 + And selector "#language__version" should have any "1.2.3"
  75 + And selector "#language__operating_system" should have any "Unix"
  76 + And selector ".database_autocomplete" should have any "MySQL"
  77 + And selector "#database__version" should have any "4.5.6"
  78 + Then selector "#database__operating_system" should have any "Unix"
lib/database_helper.rb
1 module DatabaseHelper 1 module DatabaseHelper
2 2
  3 + def self.isValidDatabase? database
  4 + return false if SoftwareHelper.all_table_is_empty?(database)
  5 +
  6 + database_description_id_list = DatabaseDescription.select(:id).collect {|dd| dd.id }
  7 +
  8 + return false unless database_description_id_list.include?(database[:database_description_id].to_i)
  9 +
  10 + true
  11 + end
  12 +
3 def self.list_database new_databases 13 def self.list_database new_databases
4 return [] if new_databases.nil? or new_databases.length == 0 14 return [] if new_databases.nil? or new_databases.length == 0
5 list_databases = [] 15 list_databases = []
6 16
7 new_databases.each do |new_database| 17 new_databases.each do |new_database|
8 - unless SoftwareHelper.all_table_is_empty? new_database 18 + if isValidDatabase? new_database
9 database = SoftwareDatabase.new 19 database = SoftwareDatabase.new
10 database.database_description_id = new_database[:database_description_id] 20 database.database_description_id = new_database[:database_description_id]
11 database.version = new_database[:version] 21 database.version = new_database[:version]
test/unit/database_helper_test.rb
@@ -5,29 +5,34 @@ class DatabaseHelperTest &lt; ActiveSupport::TestCase @@ -5,29 +5,34 @@ class DatabaseHelperTest &lt; ActiveSupport::TestCase
5 include DatabaseHelper 5 include DatabaseHelper
6 6
7 def setup 7 def setup
8 - @database_objects = [{"database_description_id" => "1" ,"version" => "2.0", "operating_system" => "debian"},  
9 - {"database_description_id" => "2" ,"version" => "2.1", "operating_system" => "debian"},  
10 - {"database_description_id" => "3" ,"version" => "2.2", "operating_system" => "debian"}] 8 + dd1 = DatabaseDescription.create(:name => "Oracle")
  9 + dd2 = DatabaseDescription.create(:name => "MySQL")
  10 +
  11 + @database_objects = [
  12 + {:database_description_id => dd1.id.to_s ,:version => "2.0", :operating_system => "debian"},
  13 + {:database_description_id => dd2.id.to_s ,:version => "2.1", :operating_system => "debian"},
  14 + {:database_description_id => dd1.id.to_s ,:version => "2.2", :operating_system => "debian"}]
11 @database_objects 15 @database_objects
12 end 16 end
13 17
14 def teardown 18 def teardown
15 @database_objects = nil 19 @database_objects = nil
  20 + DatabaseDescription.destroy_all
16 end 21 end
17 22
18 should "return an empty list" do 23 should "return an empty list" do
19 empty_list = [] 24 empty_list = []
20 - assert_equal [],DatabaseHelper.list_database(empty_list) 25 + assert_equal [], DatabaseHelper.list_database(empty_list)
21 end 26 end
22 27
23 should "return a list with current database objects" do 28 should "return a list with current database objects" do
24 list_compare = [] 29 list_compare = []
25 - assert_equal list_compare.class, DatabaseHelper.list_database(@database_objects).class 30 + assert_equal list_compare.class, DatabaseHelper.list_database(@database_objects).class
26 end 31 end
27 32
28 should "have same information from the list passed as parameter" do 33 should "have same information from the list passed as parameter" do
29 list_compare = DatabaseHelper.list_database(@database_objects) 34 list_compare = DatabaseHelper.list_database(@database_objects)
30 - assert_equal @database_objects.first[:database_description_id], list_compare.first.database_description_id 35 + assert_equal @database_objects.first[:database_description_id].to_i, list_compare.first.database_description_id
31 end 36 end
32 37
33 should "return a list with the same size of the parameter" do 38 should "return a list with the same size of the parameter" do
@@ -40,19 +45,32 @@ class DatabaseHelperTest &lt; ActiveSupport::TestCase @@ -40,19 +45,32 @@ class DatabaseHelperTest &lt; ActiveSupport::TestCase
40 assert_equal false,DatabaseHelper.valid_list_database?(list_compare) 45 assert_equal false,DatabaseHelper.valid_list_database?(list_compare)
41 end 46 end
42 47
43 - should "return a html text with operating system equals to linux" do  
44 - databases = [] 48 + should "return a html text with operating system equals to linux" do
  49 + databases = []
  50 +
  51 + database_description = DatabaseDescription.new
  52 + database_description.name = "teste"
  53 +
  54 + software_database = SoftwareDatabase.new
  55 + software_database.version = 2
  56 + software_database.operating_system = "linux"
  57 + software_database.database_description = database_description
45 58
46 - database_description = DatabaseDescription.new  
47 - database_description.name = "teste" 59 + databases << software_database
48 60
49 - software_database = SoftwareDatabase.new  
50 - software_database.version = 2  
51 - software_database.operating_system = "linux"  
52 - software_database.database_description = database_description 61 + assert_not_nil DatabaseHelper.database_as_tables(databases).first.call.index("linux")
  62 + end
  63 +
  64 + should "remove invalid tables from the list" do
  65 + @database_objects.push({
  66 + :database_description_id => "I'm not a valid id",
  67 + :version => "2.0",
  68 + :operating_system => "debian"
  69 + })
53 70
54 - databases << software_database 71 + database_objects_length = @database_objects.count
  72 + list_compare = DatabaseHelper.list_database(@database_objects)
55 73
56 - assert_not_nil DatabaseHelper.database_as_tables(databases).first.call.index("linux")  
57 - end 74 + assert_equal database_objects_length-1, list_compare.count
58 end 75 end
  76 +end