Commit b3d90985386043f6f20925068f120cc0995ee6d0
Committed by
Luciano Prestes
1 parent
eee6f248
Exists in
master
and in
5 other branches
fixes_software: Add server-side database dynamic table validations and tests
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing
3 changed files
with
91 additions
and
39 deletions
Show diff stats
features/software_registration.feature
| ... | ... | @@ -6,25 +6,19 @@ Feature: software registration |
| 6 | 6 | Background: |
| 7 | 7 | Given "MpogSoftwarePlugin" plugin is enabled |
| 8 | 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 | 10 | And I go to /admin/plugins |
| 11 | 11 | And I check "MpogSoftwarePlugin" |
| 12 | 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 | 14 | @selenium |
| 24 | 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 | 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 | 22 | And I follow "New language" |
| 29 | 23 | And I should see "3" of this selector ".software-language-table" |
| 30 | 24 | And I follow "Delete" |
| ... | ... | @@ -33,9 +27,12 @@ Feature: software registration |
| 33 | 27 | |
| 34 | 28 | @selenium |
| 35 | 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 | 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 | 36 | And I follow "New Database" |
| 40 | 37 | And I should see "3" of this selector ".database-table" |
| 41 | 38 | And I follow "Delete" |
| ... | ... | @@ -43,12 +40,39 @@ Feature: software registration |
| 43 | 40 | #3 because one is always hidden |
| 44 | 41 | |
| 45 | 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 | 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 | 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 | 13 | def self.list_database new_databases |
| 4 | 14 | return [] if new_databases.nil? or new_databases.length == 0 |
| 5 | 15 | list_databases = [] |
| 6 | 16 | |
| 7 | 17 | new_databases.each do |new_database| |
| 8 | - unless SoftwareHelper.all_table_is_empty? new_database | |
| 18 | + if isValidDatabase? new_database | |
| 9 | 19 | database = SoftwareDatabase.new |
| 10 | 20 | database.database_description_id = new_database[:database_description_id] |
| 11 | 21 | database.version = new_database[:version] | ... | ... |
test/unit/database_helper_test.rb
| ... | ... | @@ -5,29 +5,34 @@ class DatabaseHelperTest < ActiveSupport::TestCase |
| 5 | 5 | include DatabaseHelper |
| 6 | 6 | |
| 7 | 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 | 15 | @database_objects |
| 12 | 16 | end |
| 13 | 17 | |
| 14 | 18 | def teardown |
| 15 | 19 | @database_objects = nil |
| 20 | + DatabaseDescription.destroy_all | |
| 16 | 21 | end |
| 17 | 22 | |
| 18 | 23 | should "return an empty list" do |
| 19 | 24 | empty_list = [] |
| 20 | - assert_equal [],DatabaseHelper.list_database(empty_list) | |
| 25 | + assert_equal [], DatabaseHelper.list_database(empty_list) | |
| 21 | 26 | end |
| 22 | 27 | |
| 23 | 28 | should "return a list with current database objects" do |
| 24 | 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 | 31 | end |
| 27 | 32 | |
| 28 | 33 | should "have same information from the list passed as parameter" do |
| 29 | 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 | 36 | end |
| 32 | 37 | |
| 33 | 38 | should "return a list with the same size of the parameter" do |
| ... | ... | @@ -40,19 +45,32 @@ class DatabaseHelperTest < ActiveSupport::TestCase |
| 40 | 45 | assert_equal false,DatabaseHelper.valid_list_database?(list_compare) |
| 41 | 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 | 75 | end |
| 76 | +end | ... | ... |