From 09cf54dcfdd1abde73be56b96fb3e1dcf06141e9 Mon Sep 17 00:00:00 2001 From: Gabriel Silva Date: Wed, 27 Jan 2016 18:45:08 +0000 Subject: [PATCH] Fixes software_communities unit and functional tests --- src/noosfero-spb/software_communities/lib/ext/search_controller.rb | 2 +- src/noosfero-spb/software_communities/lib/license_helper.rb | 2 +- src/noosfero-spb/software_communities/lib/software_info.rb | 2 +- src/noosfero-spb/software_communities/test/functional/profile_editor_controller_test.rb | 5 ----- src/noosfero-spb/software_communities/test/functional/search_controller_test.rb | 4 ---- src/noosfero-spb/software_communities/test/helpers/plugin_test_helper.rb | 17 +++++------------ src/noosfero-spb/software_communities/test/unit/communities_block_test.rb | 7 ------- src/noosfero-spb/software_communities/test/unit/database_helper_test.rb | 6 ------ src/noosfero-spb/software_communities/test/unit/database_validation_test.rb | 6 ------ src/noosfero-spb/software_communities/test/unit/library_helper_test.rb | 4 ---- src/noosfero-spb/software_communities/test/unit/library_validation_test.rb | 4 ---- src/noosfero-spb/software_communities/test/unit/operating_system_helper_test.rb | 10 +++------- src/noosfero-spb/software_communities/test/unit/operating_system_validation_test.rb | 4 ---- src/noosfero-spb/software_communities/test/unit/software_communities_person_test.rb | 23 ++++++++--------------- src/noosfero-spb/software_communities/test/unit/software_database_test.rb | 5 ----- src/noosfero-spb/software_communities/test/unit/software_info_validation_test.rb | 10 ---------- src/noosfero-spb/software_communities/test/unit/software_language_helper_test.rb | 5 ----- src/noosfero-spb/software_communities/test/unit/software_language_validation.rb | 5 ----- src/noosfero-spb/software_communities/test/unit/software_registration_test.rb | 6 ------ src/noosfero-spb/software_communities/views/search/_full_community.html.erb | 2 +- 20 files changed, 20 insertions(+), 109 deletions(-) diff --git a/src/noosfero-spb/software_communities/lib/ext/search_controller.rb b/src/noosfero-spb/software_communities/lib/ext/search_controller.rb index 43a266c..f54ee76 100644 --- a/src/noosfero-spb/software_communities/lib/ext/search_controller.rb +++ b/src/noosfero-spb/software_communities/lib/ext/search_controller.rb @@ -100,7 +100,7 @@ class SearchController @public_software_selected = false end - filtered_software_list.select!{ |software| visible_communities.include?(software.community) } + filtered_software_list = filtered_software_list.select{ |software| visible_communities.include?(software.community) } category_ids = get_filter_category_ids unless category_ids.empty? diff --git a/src/noosfero-spb/software_communities/lib/license_helper.rb b/src/noosfero-spb/software_communities/lib/license_helper.rb index 8a21a2b..c471629 100644 --- a/src/noosfero-spb/software_communities/lib/license_helper.rb +++ b/src/noosfero-spb/software_communities/lib/license_helper.rb @@ -1,7 +1,7 @@ module LicenseHelper def self.find_licenses query licenses = LicenseInfo.where("version ILIKE ?", "%#{query}%").select("id, version") - licenses.reject!{|license| license.version == "Another"} + licenses = licenses.reject{|license| license.version == "Another"} license_another = LicenseInfo.find_by_version("Another") licenses << license_another if license_another licenses diff --git a/src/noosfero-spb/software_communities/lib/software_info.rb b/src/noosfero-spb/software_communities/lib/software_info.rb index c0c874e..1120aaf 100644 --- a/src/noosfero-spb/software_communities/lib/software_info.rb +++ b/src/noosfero-spb/software_communities/lib/software_info.rb @@ -21,7 +21,7 @@ class SoftwareInfo < ActiveRecord::Base SoftwareInfo.joins(:community).where("profiles.visible = ? AND environment_id = ? ", true, env.id) else searchable_software_objects = SoftwareInfo.transform_list_in_methods_list(SEARCHABLE_SOFTWARE_CLASSES) - includes(searchable_software_objects).where("to_tsvector('simple', #{search_fields}) @@ to_tsquery('#{filtered_query}')").where("profiles.visible = ? AND environment_id = ?", true, env.id) + includes(searchable_software_objects).joins(:community).where("to_tsvector('simple', #{search_fields}) @@ to_tsquery('#{filtered_query}')").where("profiles.visible = ? AND environment_id = ?", true, env.id) end } diff --git a/src/noosfero-spb/software_communities/test/functional/profile_editor_controller_test.rb b/src/noosfero-spb/software_communities/test/functional/profile_editor_controller_test.rb index f1b1607..78ec3a7 100644 --- a/src/noosfero-spb/software_communities/test/functional/profile_editor_controller_test.rb +++ b/src/noosfero-spb/software_communities/test/functional/profile_editor_controller_test.rb @@ -35,11 +35,6 @@ class ProfileEditorControllerTest < ActionController::TestCase @environment.save end - def teardown - Community.destroy_all - SoftwareInfo.destroy_all - end - should "redirect to edit_software_community on edit community of software" do software = create_software(software_fields) post :edit, :profile => software.community.identifier diff --git a/src/noosfero-spb/software_communities/test/functional/search_controller_test.rb b/src/noosfero-spb/software_communities/test/functional/search_controller_test.rb index aaca7ce..f51e6f4 100644 --- a/src/noosfero-spb/software_communities/test/functional/search_controller_test.rb +++ b/src/noosfero-spb/software_communities/test/functional/search_controller_test.rb @@ -42,10 +42,6 @@ class SearchControllerTest < ActionController::TestCase @softwares[1].save! end - def teardown - SoftwareInfo.destroy_all - end - should "communities searches don't have software" do community = create_community("Community One") diff --git a/src/noosfero-spb/software_communities/test/helpers/plugin_test_helper.rb b/src/noosfero-spb/software_communities/test/helpers/plugin_test_helper.rb index 0f89976..9a1b5ce 100644 --- a/src/noosfero-spb/software_communities/test/helpers/plugin_test_helper.rb +++ b/src/noosfero-spb/software_communities/test/helpers/plugin_test_helper.rb @@ -28,22 +28,14 @@ module PluginTestHelper name.to_slug, email, password, - password_confirmation, + password_confirmation ) - person = Person::new - user.person = person - person.user = user - - person.name = name - person.identifier = name.to_slug - person.state = state - person.city = city + user.person.state = state + user.person.city = city user.save - person.save - - person + user.person end def create_user login, email, password, password_confirmation @@ -54,6 +46,7 @@ module PluginTestHelper user.password = password user.password_confirmation = password_confirmation + user.save user end diff --git a/src/noosfero-spb/software_communities/test/unit/communities_block_test.rb b/src/noosfero-spb/software_communities/test/unit/communities_block_test.rb index 0a92eb3..bb10b0c 100644 --- a/src/noosfero-spb/software_communities/test/unit/communities_block_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/communities_block_test.rb @@ -12,17 +12,10 @@ class CommunitiesBlockTest < ActiveSupport::TestCase @community = create_community("Nova Comunidade") @community.add_member(@person) - @comminities_block = CommunitiesBlock.new @comminities_block.expects(:owner).at_least_once.returns(@person) end - def teardown - CommunitiesBlock.destroy_all - @person = nil - @community = nil - @software_info = nil - end should "not have community of software or institution in block" do assert_includes @comminities_block.profile_list, @community assert_not_includes @comminities_block.profile_list, @software_info.community diff --git a/src/noosfero-spb/software_communities/test/unit/database_helper_test.rb b/src/noosfero-spb/software_communities/test/unit/database_helper_test.rb index 9e5e0a4..c0c410f 100644 --- a/src/noosfero-spb/software_communities/test/unit/database_helper_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/database_helper_test.rb @@ -12,12 +12,6 @@ class DatabaseHelperTest < ActiveSupport::TestCase ] end - def teardown - @database_objects = nil - SoftwareDatabase.destroy_all - DatabaseDescription.destroy_all - end - should "return an empty list" do empty_list = [] assert_equal [], DatabaseHelper.list_database(empty_list) diff --git a/src/noosfero-spb/software_communities/test/unit/database_validation_test.rb b/src/noosfero-spb/software_communities/test/unit/database_validation_test.rb index 73502ce..3586711 100644 --- a/src/noosfero-spb/software_communities/test/unit/database_validation_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/database_validation_test.rb @@ -10,12 +10,6 @@ class DatabaseValidationTest < ActiveSupport::TestCase @database end - def teardown - @database = nil - DatabaseDescription.destroy_all - SoftwareDatabase.destroy_all - end - should "Save database if all fields are filled" do assert_equal true, @database.save end diff --git a/src/noosfero-spb/software_communities/test/unit/library_helper_test.rb b/src/noosfero-spb/software_communities/test/unit/library_helper_test.rb index 888e4e4..3876f46 100644 --- a/src/noosfero-spb/software_communities/test/unit/library_helper_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/library_helper_test.rb @@ -9,10 +9,6 @@ class LibraryHelperTest < ActiveSupport::TestCase {"name" => "license3" ,"version" => "2.2", "license" => "debian", "software_id" => "1"}] end - def teardown - @license_objects = nil - end - should "return an empty list" do empty_list = [] assert_equal [],LibraryHelper.list_library(empty_list) diff --git a/src/noosfero-spb/software_communities/test/unit/library_validation_test.rb b/src/noosfero-spb/software_communities/test/unit/library_validation_test.rb index 1ce6ea9..2f6f6d9 100644 --- a/src/noosfero-spb/software_communities/test/unit/library_validation_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/library_validation_test.rb @@ -9,10 +9,6 @@ class LibraryValidationTest < ActiveSupport::TestCase @library.license = "license" end - def teardown - @Libray = nil - end - should "Save Libray if all fields are filled" do assert @library.save end diff --git a/src/noosfero-spb/software_communities/test/unit/operating_system_helper_test.rb b/src/noosfero-spb/software_communities/test/unit/operating_system_helper_test.rb index ec6056b..0e369eb 100644 --- a/src/noosfero-spb/software_communities/test/unit/operating_system_helper_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/operating_system_helper_test.rb @@ -8,17 +8,13 @@ class OperatingSystemHelperTest < ActiveSupport::TestCase def setup @operating_system_objects = [ - {:operating_system_name_id => "1" ,:version => "2.0"}, - {:operating_system_name_id => "2" ,"version" => "2.1"}, - {:operating_system_name_id => "3" ,"version" => "2.2"} + {:operating_system_name_id => OperatingSystemName.find_by_name("Debina").id.to_s, :version => "2.0"}, + {:operating_system_name_id => OperatingSystemName.find_by_name("Fedora").id.to_s, "version" => "2.1"}, + {:operating_system_name_id => OperatingSystemName.find_by_name("CentOS").id.to_s, "version" => "2.2"} ] @operating_system_objects end - def teardown - @operating_system_objects = nil - end - should "return an empty list" do empty_list = [] assert_equal [],OperatingSystemHelper.list_operating_system(empty_list) diff --git a/src/noosfero-spb/software_communities/test/unit/operating_system_validation_test.rb b/src/noosfero-spb/software_communities/test/unit/operating_system_validation_test.rb index df81bc1..236530a 100644 --- a/src/noosfero-spb/software_communities/test/unit/operating_system_validation_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/operating_system_validation_test.rb @@ -9,10 +9,6 @@ class OperatingSystemValidationTest < ActiveSupport::TestCase @operating_system end - def teardown - @operating_system.destroy - end - should "save OperatingSystem if all fields are filled" do assert_equal true, @operating_system.save end diff --git a/src/noosfero-spb/software_communities/test/unit/software_communities_person_test.rb b/src/noosfero-spb/software_communities/test/unit/software_communities_person_test.rb index c12962d..0babeb2 100644 --- a/src/noosfero-spb/software_communities/test/unit/software_communities_person_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/software_communities_person_test.rb @@ -9,31 +9,24 @@ class GovUserPluginPersonTest < ActiveSupport::TestCase def setup @plugin = SoftwareCommunitiesPlugin.new - @user = fast_create(User) - @person = create_person( - "My Name", - "user@email.com", - "123456", - "123456", - "Any State", - "Some City" + @user = create_user( + "user", + "user@email.com", + "123456", + "123456" ) end - def teardown - @plugin = nil - end - should 'get a list of softwares of a person' do software1 = create_software_info "noosfero" software2 = create_software_info "colab" community = create_community "simple_community" - software1.community.add_member @person + software1.community.add_member @user.person software1.save! - community.add_member @person + community.add_member @user.person community.save! - assert_equal 1, @person.softwares.count + assert_equal 1, @user.person.softwares.count end end diff --git a/src/noosfero-spb/software_communities/test/unit/software_database_test.rb b/src/noosfero-spb/software_communities/test/unit/software_database_test.rb index e6e01a4..212fc80 100644 --- a/src/noosfero-spb/software_communities/test/unit/software_database_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/software_database_test.rb @@ -9,11 +9,6 @@ class SoftwareDatabaseTest < ActiveSupport::TestCase @software_database.database_description_id = 1 end - def teardown - DatabaseDescription.destroy_all - SoftwareDatabase.destroy_all - end - should "save if all informations of @software_database are filled" do assert @software_database.save, "Database should have been saved" end diff --git a/src/noosfero-spb/software_communities/test/unit/software_info_validation_test.rb b/src/noosfero-spb/software_communities/test/unit/software_info_validation_test.rb index 0688784..c8a832d 100644 --- a/src/noosfero-spb/software_communities/test/unit/software_info_validation_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/software_info_validation_test.rb @@ -55,16 +55,6 @@ class SoftwareInfoValidationTest < ActiveSupport::TestCase @software_info.community = @community end - def teardown - ProgrammingLanguage.destroy_all - SoftwareLanguage.destroy_all - DatabaseDescription.destroy_all - SoftwareDatabase.destroy_all - OperatingSystem.destroy_all - OperatingSystemName.destroy_all - SoftwareInfo.destroy_all - end - should 'Save SoftwareInfo if all fields are filled' do assert_equal true, @software_info.save end diff --git a/src/noosfero-spb/software_communities/test/unit/software_language_helper_test.rb b/src/noosfero-spb/software_communities/test/unit/software_language_helper_test.rb index 991743e..3ab7dda 100644 --- a/src/noosfero-spb/software_communities/test/unit/software_language_helper_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/software_language_helper_test.rb @@ -13,11 +13,6 @@ class SoftwareLanguageHelperTest < ActiveSupport::TestCase @software_language_objects end - def teardown - @software_language_objects = nil - ProgrammingLanguage.destroy_all - end - should "return an empty list" do empty_list = [] assert_equal [], SoftwareLanguageHelper.list_language(empty_list) diff --git a/src/noosfero-spb/software_communities/test/unit/software_language_validation.rb b/src/noosfero-spb/software_communities/test/unit/software_language_validation.rb index 8a2e4a3..d20f1cc 100644 --- a/src/noosfero-spb/software_communities/test/unit/software_language_validation.rb +++ b/src/noosfero-spb/software_communities/test/unit/software_language_validation.rb @@ -7,11 +7,6 @@ class SoftwareLanguageValidationTest < ActiveSupport::TestCase @software_info.save end - def teardown - @software_info = nil - SoftwareInfo.destroy_all - end - should "Save SoftwareLanguage if version and prog_language are filled" do @software_language = create_software_language assert_equal true, @software_language.save diff --git a/src/noosfero-spb/software_communities/test/unit/software_registration_test.rb b/src/noosfero-spb/software_communities/test/unit/software_registration_test.rb index 5e66480..b33a78b 100644 --- a/src/noosfero-spb/software_communities/test/unit/software_registration_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/software_registration_test.rb @@ -9,12 +9,6 @@ class SoftwareRegistrationTest < ActiveSupport::TestCase @license_info = LicenseInfo.create(:version => "New License", :link => "#") end - def teardown - Community.destroy_all - SoftwareInfo.destroy_all - Task.destroy_all - end - should 'include software registration task if is admin' do person = create_user('molly').person @environment.add_admin(person) diff --git a/src/noosfero-spb/software_communities/views/search/_full_community.html.erb b/src/noosfero-spb/software_communities/views/search/_full_community.html.erb index ae8100e..eedc05b 100644 --- a/src/noosfero-spb/software_communities/views/search/_full_community.html.erb +++ b/src/noosfero-spb/software_communities/views/search/_full_community.html.erb @@ -23,7 +23,7 @@
<% body_stripped = strip_tags(software.finality) %> - <%= link_to(excerpt(body_stripped, body_stripped.first(3), 200), community.url) if body_stripped %> + <%= link_to(excerpt(body_stripped, body_stripped.first(3), radius: 200), community.url) if body_stripped %>
-- libgit2 0.21.2