From 982fcc8548a764d812ce19aceebd0aed0e64efc2 Mon Sep 17 00:00:00 2001 From: Gabriela Navarro Date: Wed, 22 Apr 2015 13:42:14 +0000 Subject: [PATCH] Add tests for software communities plugin controller --- test/functional/software_communities_plugin_controller_test.rb | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 96 insertions(+), 27 deletions(-) diff --git a/test/functional/software_communities_plugin_controller_test.rb b/test/functional/software_communities_plugin_controller_test.rb index 0f6f7ee..78ae2e0 100644 --- a/test/functional/software_communities_plugin_controller_test.rb +++ b/test/functional/software_communities_plugin_controller_test.rb @@ -4,7 +4,6 @@ require File.dirname(__FILE__) + '/../../controllers/software_communities_plugin class SoftwareCommunitiesPluginController; def rescue_action(e) raise e end; end class SoftwareCommunitiesPluginControllerTest < ActionController::TestCase - def setup @admin = create_user("adminuser").person @admin.stubs(:has_permission?).returns("true") @@ -15,33 +14,103 @@ class SoftwareCommunitiesPluginControllerTest < ActionController::TestCase @environment.add_admin(@admin) @environment.save - @gov_power = GovernmentalPower.create(:name=>"Some Gov Power") - @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") - @juridical_nature = JuridicalNature.create(:name => "Autarquia") + LicenseInfo.create(:version=>"CC-GPL-V2", :link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt") + LicenseInfo.create(:version=>"Academic Free License 3.0 (AFL-3.0)", :link=>"http://www.openfoundry.org/en/licenses/753-academic-free-license-version-30-afl") + LicenseInfo.create(:version=>"Apache License 2.0 (Apache-2.0)", :link=>"http://www.apache.org/licenses/LICENSE-2.0") + LicenseInfo.create(:version=>'BSD 2-Clause "Simplified" or "FreeBSD" License (BSD-2-Clause)', :link=>"http://opensource.org/licenses/BSD-2-Clause") + + ProgrammingLanguage.create(:name =>"Java") + ProgrammingLanguage.create(:name =>"Ruby") + ProgrammingLanguage.create(:name =>"C") + ProgrammingLanguage.create(:name =>"C++") + DatabaseDescription.create(:name => "PostgreSQL") + DatabaseDescription.create(:name => "MySQL") + DatabaseDescription.create(:name => "MongoDB") + DatabaseDescription.create(:name => "Oracle") + OperatingSystemName.create(:name=>"Debian") + @response = ActionController::TestResponse.new + end + + should 'return the licenses datas' do + xhr :get, :get_license_data, :query => "" + + licenses = JSON.parse(@response.body) + + assert_equal 4, licenses.count + end + + should 'return licenses that has Free on their version name' do + xhr :get, :get_license_data, :query => "Free" + + licenses = JSON.parse(@response.body) + + assert_equal 2, licenses.count + end + + should 'return no licenses that has Common on their version name' do + xhr :get, :get_license_data, :query => "Common" + + licenses = JSON.parse(@response.body) + + assert_equal 0, licenses.count + end + + should 'render block template' do + xhr :get, :get_block_template + + assert_tag :tag => 'input', :attributes => { :class => "block_download_name" } + assert_tag :tag => 'input', :attributes => { :class => "block_download_link" } + assert_tag :tag => 'input', :attributes => { :class => "block_download_software_description" } + assert_tag :tag => 'input', :attributes => { :class => "block_download_minimum_requirements" } + assert_tag :tag => 'input', :attributes => { :class => "block_download_size" } + end + + should 'return the programming languages' do + xhr :get, :get_field_data, :query => "", :field => "software_language" + + languages = JSON.parse(@response.body) + + assert_equal 4, languages.count + end + + should 'return the programming languages that has C on their name' do + xhr :get, :get_field_data, :query => "C", :field => "software_language" + + languages = JSON.parse(@response.body) + + assert_equal 2, languages.count + end + + should 'dont return the programming languages that has HTML on their name' do + xhr :get, :get_field_data, :query => "HTML", :field => "software_language" + + languages = JSON.parse(@response.body) + + assert_equal 1, languages.count + end + + should 'return the databases' do + xhr :get, :get_field_data, :query => "", :field => "software_database" + + databases = JSON.parse(@response.body) + + assert_equal 4, databases.count + end + + should 'return the databases that has SQL on their name' do + xhr :get, :get_field_data, :query => "SQL", :field => "software_database" + + databases = JSON.parse(@response.body) + + assert_equal 3, databases.count + end + + should 'dont return the database that has on their name' do + xhr :get, :get_field_data, :query => "Cache", :field => "software_database" + + databases = JSON.parse(@response.body) - @institution_list = [] - @institution_list << InstitutionTestHelper.create_public_institution( - "Ministerio Publico da Uniao", - "MPU", - "BR", - "DF", - "Gama", - @juridical_nature, - @gov_power, - @gov_sphere, - "12.345.678/9012-45" - ) - @institution_list << InstitutionTestHelper.create_public_institution( - "Tribunal Regional da Uniao", - "TRU", - "BR", - "DF", - "Brasilia", - @juridical_nature, - @gov_power, - @gov_sphere, - "12.345.678/9012-90" - ) + assert_equal 1, databases.count end end -- libgit2 0.21.2