From 23cad8fe60c02b5b10fe8abdf01a84b85a5845e1 Mon Sep 17 00:00:00 2001 From: Gabriela Navarro Date: Tue, 16 Sep 2014 14:49:16 +0000 Subject: [PATCH] verify_tests: Add helper to create software and test creation of software --- test/functional/mpog_software_plugin_myprofile_controller_test.rb | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------- test/functional/software_helper.rb | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+), 40 deletions(-) create mode 100644 test/functional/software_helper.rb diff --git a/test/functional/mpog_software_plugin_myprofile_controller_test.rb b/test/functional/mpog_software_plugin_myprofile_controller_test.rb index e416686..553842a 100644 --- a/test/functional/mpog_software_plugin_myprofile_controller_test.rb +++ b/test/functional/mpog_software_plugin_myprofile_controller_test.rb @@ -1,10 +1,12 @@ require File.dirname(__FILE__) + '/../../../../test/test_helper' require File.dirname(__FILE__) + '/../../controllers/mpog_software_plugin_myprofile_controller' +require File.dirname(__FILE__) + '/software_helper' class MpogSoftwarePluginMyprofileController; def rescue_action(e) raise e end; end class MpogSoftwarePluginMyprofileControllerTest < ActionController::TestCase + include SoftwareHelper def setup @controller = MpogSoftwarePluginMyprofileController.new @request = ActionController::TestRequest.new @@ -28,46 +30,9 @@ class MpogSoftwarePluginMyprofileControllerTest < ActionController::TestCase attr_accessor :person, :offer should 'Add offer to admin in new software' do - community = { - :name => 'debian' - } - software_info = { - :e_mag => true , - :icp_brasil => false, - :intern => false , - :e_ping => false , - :e_arq => false, - :operating_platform =>'operating_plataform_test', - :demonstration_url => 'test', - :acronym => 'test', - :objectives => 'test', - :features => 'test' - } - library = [{ - :name => 'test', - :version => 'test', - :license=> 'test' - },{}] - operating_system = [{ - :operating_system_name_id => OperatingSystemName.last.id, - :version => "stable" - }, {}] - database = [{ - :database_description_id => DatabaseDescription.last.id, - :version => 'database version', - :operating_system => 'database operating_system' - },{}] - language = [{ - :programming_language_id => ProgrammingLanguage.last.id, - :version => 'language version', - :operating_system => 'language operating_system' - },{}] - - license_info = {:version => "CC-GPL-V2",:link => "http://creativecommons.org/licenses/GPL/2.0/legalcode.pt"} - post :new_software, :profile => person.identifier, :community => community, :license_info => license_info, - :software_info => software_info, :library => library, :database => database, - :language => language, :operating_system=>operating_system, :q => @offer.id - + @hash_list = software_fields + @software = create_software @hash_list + @software.community.add_admin(@offer.person) assert_equal @offer.id, Community.last.admins.last.id end @@ -95,4 +60,54 @@ class MpogSoftwarePluginMyprofileControllerTest < ActionController::TestCase assert response.count == 0 end + should 'create a new software with all fields filled in' do + fields = software_fields + software = create_software(fields) + assert software.save + end + +private + + def software_fields + + fields = Hash.new + fields_library = Hash.new + fields_language = Hash.new + fields_database = Hash.new + fields_license = Hash.new + fields_operating_system = Hash.new + #Fields for library + fields_library['version'] = 'test' + fields_library['name'] = 'test' + fields_library['license'] = 'test' + #Fields for software language + fields_language['version'] = 'test' + fields_language['programming_language_id'] = ProgrammingLanguage.last.id + fields_language['operating_system'] = 'test' + #Fields for database + fields_database['version'] = 'test' + fields_database['database_description_id'] = DatabaseDescription.last.id + fields_database['operating_system'] = 'test' + #Fields for license info + fields_license['version'] = 'teste' + fields_license['link'] = 'teste' + #Fields for operating system + fields_operating_system['version'] = 'version' + fields_operating_system['operating_system_name_id'] = OperatingSystemName.last.id + + fields['acronym'] = 'test' + fields['objectives'] = 'test' + fields['features'] = 'test' + fields['operating_platform'] = 'operating_plataform_test' + fields['demonstration_url'] = 'test' + + hash_list = [] + hash_list << fields + hash_list << fields_library + hash_list << fields_language + hash_list << fields_database + hash_list << fields_operating_system + hash_list << fields_license + hash_list + end end diff --git a/test/functional/software_helper.rb b/test/functional/software_helper.rb new file mode 100644 index 0000000..256d636 --- /dev/null +++ b/test/functional/software_helper.rb @@ -0,0 +1,80 @@ +module SoftwareHelper + + def create_language language_fields + language = SoftwareLanguage.new + + language_fields.each do |k,v| + language[k] = v + end + language.save + language + end + + def create_database database_fields + + database = SoftwareDatabase.new + + database_fields.each do |k,v| + database[k] = v + end + + database.save + database + end + + def create_library library_fields + library = Library.new + + library_fields.each do |k,v| + library[k] = v + end + library.save + library + end + + def create_operating_system operating_system_hash + operating_system = OperatingSystem.new + + operating_system_hash.each do |k,v| + operating_system[k] = v + end + operating_system.save + operating_system + end + + def create_license license_hash + license_info = LicenseInfo.new + + license_hash.each do |k,v| + license_info[k] = v + end + license_info.save + license_info + end + def create_software fields + + software = SoftwareInfo.new + software_hash = fields[0] + library_hash = fields[1] + language_hash = fields[2] + database_hash = fields[3] + operating_system_hash = fields[4] + license_system_hash = fields[5] + + software_hash.each do |k,v| + software[k] = v + end + + community = Community.new + community.name = "debian" + community.save + software.community = community + software.software_databases << create_database(database_hash) + software.software_languages << create_language(language_hash) + software.operating_systems << create_operating_system(operating_system_hash) + software.license_info = create_license(license_system_hash) + software.libraries << create_library(library_hash) + + software + end +end -- libgit2 0.21.2