diff --git a/lib/ext/person.rb b/lib/ext/person.rb index 5a7f078..fd88c0c 100644 --- a/lib/ext/person.rb +++ b/lib/ext/person.rb @@ -12,9 +12,9 @@ class Person def institutions institutions = [] - unless self.user.institutions.nil? - self.user.institutions.each do |institution| - institutions << institution.name + self.communities.each do |community| + if community.institution? + institutions << community end end institutions diff --git a/lib/ext/profile_controller.rb b/lib/ext/profile_controller.rb index cd72996..bd21b16 100644 --- a/lib/ext/profile_controller.rb +++ b/lib/ext/profile_controller.rb @@ -4,9 +4,11 @@ class ProfileController def communities type = [] - if params[:type] == "Software" + params[:type].downcase! unless params[:type].nil? + + if params[:type] == "software" type = profile.softwares - elsif params[:type] == "Institution" + elsif params[:type] == "institution" type = profile.institutions else profile.communities.select do |community| diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb new file mode 100644 index 0000000..f02b3ca --- /dev/null +++ b/test/functional/profile_controller_test.rb @@ -0,0 +1,72 @@ +require File.dirname(__FILE__) + '/../../../../test/test_helper' +require File.dirname(__FILE__) + '/../helpers/institution_test_helper' +require File.dirname(__FILE__) + '/../helpers/software_test_helper' +require( + File.dirname(__FILE__) + + '/../../../../app/controllers/public/profile_controller' +) + +class ProfileController; def rescue_action(e) raise e end; end + +class ProfileControllerTest < ActionController::TestCase + include InstitutionTestHelper + include SoftwareTestHelper + + + def setup + @environment = Environment.default + @environment.enabled_plugins = ['SoftwareCommunitiesPlugin'] + @environment.save! + + @controller = ProfileController.new + @request = ActionController::TestRequest.new + @request.stubs(:ssl?).returns(:false) + @response = ActionController::TestResponse.new + + @user = create_user('testuser').person + + LicenseInfo.create( + :version=>"CC-GPL-V2", + :link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt" + ) + + @community = fast_create(Community, :name=> "Test community") + + @institution = InstitutionTestHelper.create_private_institution "Test institution", "ti", "BR", "DF", "Brasilia", "11.111.111/1111-11" + + basic_fields = software_fields + @software = create_software basic_fields + + @community.add_member(@user) + @institution.community.add_member(@user) + @software.community.add_member(@user) + login_as(@user.identifier) + end + + + should "Show only communities on community block view all" do + get :communities, :profile => @user.identifier + + assert_match Regexp.new("#{@community.name}"), @response.body + assert_not_match Regexp.new("#{@institution.community.name}"), @response.body + assert_not_match Regexp.new("#{@software.community.name}"), @response.body + end + + + should "Show only institutions on community block view all with type=software" do + get :communities,:type => "Software", :profile => @user.identifier + + assert_not_match Regexp.new("#{@community.name}"), @response.body + assert_not_match Regexp.new("#{@institution.community.name}"), @response.body + assert_match Regexp.new("#{@software.community.name}"), @response.body + end + + + should "Show only communities on community block view all with type=institution" do + get :communities,:type => "Institution", :profile => @user.identifier + + assert_not_match Regexp.new("#{@community.name}"), @response.body + assert_match Regexp.new("#{@institution.community.name}"), @response.body + assert_not_match Regexp.new("#{@software.community.name}"), @response.body + end +end \ No newline at end of file -- libgit2 0.21.2