From b3d90985386043f6f20925068f120cc0995ee6d0 Mon Sep 17 00:00:00 2001 From: Fabio Teixeira Date: Mon, 27 Oct 2014 18:08:20 -0200 Subject: [PATCH] fixes_software: Add server-side database dynamic table validations and tests --- features/software_registration.feature | 66 +++++++++++++++++++++++++++++++++++++++++++++--------------------- lib/database_helper.rb | 12 +++++++++++- test/unit/database_helper_test.rb | 52 +++++++++++++++++++++++++++++++++++----------------- 3 files changed, 91 insertions(+), 39 deletions(-) diff --git a/features/software_registration.feature b/features/software_registration.feature index 9d6764f..89beede 100644 --- a/features/software_registration.feature +++ b/features/software_registration.feature @@ -6,25 +6,19 @@ Feature: software registration Background: Given "MpogSoftwarePlugin" plugin is enabled And SoftwareInfo has initial default values on database - And I am logged in as admin + And I am logged in as mpog_admin And I go to /admin/plugins And I check "MpogSoftwarePlugin" And I press "Save changes" - Scenario: Show library fields when click in New Library - Given I go to admin_user's control panel - And I follow "Manage my groups" - And I follow "Create a new software" - And I follow "New Library" - Then I should see "Name" - Then I should see "Version" - Then I should see "License" - @selenium Scenario: Show SoftwareLangue fields when click in New Language - Given I go to admin_user's control panel - And I follow "Manage my groups" + Given I go to /myprofile/mpog-admin And I follow "Create a new software" + And I fill in "community_name" with "basic software" + And I fill in "software_info_finality" with "basic software finality" + And I press "Create" + And I follow "Public Software" And I follow "New language" And I should see "3" of this selector ".software-language-table" And I follow "Delete" @@ -33,9 +27,12 @@ Feature: software registration @selenium Scenario: Show databasefields when click in New database - Given I go to admin_user's control panel - And I follow "Manage my groups" + Given I go to /myprofile/mpog-admin And I follow "Create a new software" + And I fill in "community_name" with "basic software" + And I fill in "software_info_finality" with "basic software finality" + And I press "Create" + And I follow "Public Software" And I follow "New Database" And I should see "3" of this selector ".database-table" And I follow "Delete" @@ -43,12 +40,39 @@ Feature: software registration #3 because one is always hidden @selenium - Scenario: Delete software libraries - Given I go to admin_user's control panel - And I follow "Manage my groups" + Scenario: Software database name should be an autocomplete + Given I go to /myprofile/mpog-admin And I follow "Create a new software" - And I follow "New Library" - And I should see "2" of this selector ".library-table" - And I follow "Delete" - Then I should see "1" of this selector ".library-table" + And I fill in "community_name" with "basic software" + And I fill in "software_info_finality" with "basic software finality" + And I press "Create" + And I follow "Public Software" + And I follow "New Database" + And I type in "my" into autocomplete list "database_autocomplete" and I choose "MySQL" + And I fill in "database_autocomplete" with "Replace me with MySQL" + And I fill in "database__version" with "" + Then selector ".database_autocomplete" should have any "MySQL" + @selenium + Scenario: Create software with all dynamic table fields filled + Given I go to /myprofile/mpog-admin + And I follow "Create a new software" + And I fill in "community_name" with "basic software" + And I fill in "software_info_finality" with "basic software finality" + And I press "Create" + And I follow "Public Software" + And I follow "New language" + And I fill in "language__version" with "1.2.3" + And I fill in "language__operating_system" with "Unix" + And I follow "New Database" + And I type in "my" into autocomplete list "database_autocomplete" and I choose "MySQL" + And I fill in "database__version" with "4.5.6" + And I fill in "database__operating_system" with "Unix" + And I press "Save" + And I follow "Software Info" + And I follow "Public Software" + And selector "#language__version" should have any "1.2.3" + And selector "#language__operating_system" should have any "Unix" + And selector ".database_autocomplete" should have any "MySQL" + And selector "#database__version" should have any "4.5.6" + Then selector "#database__operating_system" should have any "Unix" diff --git a/lib/database_helper.rb b/lib/database_helper.rb index 17a3b28..b637ad6 100644 --- a/lib/database_helper.rb +++ b/lib/database_helper.rb @@ -1,11 +1,21 @@ module DatabaseHelper + def self.isValidDatabase? database + return false if SoftwareHelper.all_table_is_empty?(database) + + database_description_id_list = DatabaseDescription.select(:id).collect {|dd| dd.id } + + return false unless database_description_id_list.include?(database[:database_description_id].to_i) + + true + end + def self.list_database new_databases return [] if new_databases.nil? or new_databases.length == 0 list_databases = [] new_databases.each do |new_database| - unless SoftwareHelper.all_table_is_empty? new_database + if isValidDatabase? new_database database = SoftwareDatabase.new database.database_description_id = new_database[:database_description_id] database.version = new_database[:version] diff --git a/test/unit/database_helper_test.rb b/test/unit/database_helper_test.rb index 8afe4cf..3645bcf 100644 --- a/test/unit/database_helper_test.rb +++ b/test/unit/database_helper_test.rb @@ -5,29 +5,34 @@ class DatabaseHelperTest < ActiveSupport::TestCase include DatabaseHelper def setup - @database_objects = [{"database_description_id" => "1" ,"version" => "2.0", "operating_system" => "debian"}, - {"database_description_id" => "2" ,"version" => "2.1", "operating_system" => "debian"}, - {"database_description_id" => "3" ,"version" => "2.2", "operating_system" => "debian"}] + dd1 = DatabaseDescription.create(:name => "Oracle") + dd2 = DatabaseDescription.create(:name => "MySQL") + + @database_objects = [ + {:database_description_id => dd1.id.to_s ,:version => "2.0", :operating_system => "debian"}, + {:database_description_id => dd2.id.to_s ,:version => "2.1", :operating_system => "debian"}, + {:database_description_id => dd1.id.to_s ,:version => "2.2", :operating_system => "debian"}] @database_objects end def teardown @database_objects = nil + DatabaseDescription.destroy_all end should "return an empty list" do empty_list = [] - assert_equal [],DatabaseHelper.list_database(empty_list) + assert_equal [], DatabaseHelper.list_database(empty_list) end should "return a list with current database objects" do list_compare = [] - assert_equal list_compare.class, DatabaseHelper.list_database(@database_objects).class + assert_equal list_compare.class, DatabaseHelper.list_database(@database_objects).class end should "have same information from the list passed as parameter" do list_compare = DatabaseHelper.list_database(@database_objects) - assert_equal @database_objects.first[:database_description_id], list_compare.first.database_description_id + assert_equal @database_objects.first[:database_description_id].to_i, list_compare.first.database_description_id end should "return a list with the same size of the parameter" do @@ -40,19 +45,32 @@ class DatabaseHelperTest < ActiveSupport::TestCase assert_equal false,DatabaseHelper.valid_list_database?(list_compare) end - should "return a html text with operating system equals to linux" do - databases = [] + should "return a html text with operating system equals to linux" do + databases = [] + + database_description = DatabaseDescription.new + database_description.name = "teste" + + software_database = SoftwareDatabase.new + software_database.version = 2 + software_database.operating_system = "linux" + software_database.database_description = database_description - database_description = DatabaseDescription.new - database_description.name = "teste" + databases << software_database - software_database = SoftwareDatabase.new - software_database.version = 2 - software_database.operating_system = "linux" - software_database.database_description = database_description + assert_not_nil DatabaseHelper.database_as_tables(databases).first.call.index("linux") + end + + should "remove invalid tables from the list" do + @database_objects.push({ + :database_description_id => "I'm not a valid id", + :version => "2.0", + :operating_system => "debian" + }) - databases << software_database + database_objects_length = @database_objects.count + list_compare = DatabaseHelper.list_database(@database_objects) - assert_not_nil DatabaseHelper.database_as_tables(databases).first.call.index("linux") - end + assert_equal database_objects_length-1, list_compare.count end +end -- libgit2 0.21.2