Commit 5bcdb7aaaf88c371cc92255f5cc67bd55dffa283

Authored by Fabio Teixeira
Committed by Gabriela Navarro
1 parent a63a2900

Fix person institution get method and add functional tests

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
lib/ext/person.rb
... ... @@ -12,9 +12,9 @@ class Person
12 12  
13 13 def institutions
14 14 institutions = []
15   - unless self.user.institutions.nil?
16   - self.user.institutions.each do |institution|
17   - institutions << institution.name
  15 + self.communities.each do |community|
  16 + if community.institution?
  17 + institutions << community
18 18 end
19 19 end
20 20 institutions
... ...
lib/ext/profile_controller.rb
... ... @@ -4,9 +4,11 @@ class ProfileController
4 4  
5 5 def communities
6 6 type = []
7   - if params[:type] == "Software"
  7 + params[:type].downcase! unless params[:type].nil?
  8 +
  9 + if params[:type] == "software"
8 10 type = profile.softwares
9   - elsif params[:type] == "Institution"
  11 + elsif params[:type] == "institution"
10 12 type = profile.institutions
11 13 else
12 14 profile.communities.select do |community|
... ...
test/functional/profile_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,72 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../helpers/institution_test_helper'
  3 +require File.dirname(__FILE__) + '/../helpers/software_test_helper'
  4 +require(
  5 + File.dirname(__FILE__) +
  6 + '/../../../../app/controllers/public/profile_controller'
  7 +)
  8 +
  9 +class ProfileController; def rescue_action(e) raise e end; end
  10 +
  11 +class ProfileControllerTest < ActionController::TestCase
  12 + include InstitutionTestHelper
  13 + include SoftwareTestHelper
  14 +
  15 +
  16 + def setup
  17 + @environment = Environment.default
  18 + @environment.enabled_plugins = ['SoftwareCommunitiesPlugin']
  19 + @environment.save!
  20 +
  21 + @controller = ProfileController.new
  22 + @request = ActionController::TestRequest.new
  23 + @request.stubs(:ssl?).returns(:false)
  24 + @response = ActionController::TestResponse.new
  25 +
  26 + @user = create_user('testuser').person
  27 +
  28 + LicenseInfo.create(
  29 + :version=>"CC-GPL-V2",
  30 + :link=>"http://creativecommons.org/licenses/GPL/2.0/legalcode.pt"
  31 + )
  32 +
  33 + @community = fast_create(Community, :name=> "Test community")
  34 +
  35 + @institution = InstitutionTestHelper.create_private_institution "Test institution", "ti", "BR", "DF", "Brasilia", "11.111.111/1111-11"
  36 +
  37 + basic_fields = software_fields
  38 + @software = create_software basic_fields
  39 +
  40 + @community.add_member(@user)
  41 + @institution.community.add_member(@user)
  42 + @software.community.add_member(@user)
  43 + login_as(@user.identifier)
  44 + end
  45 +
  46 +
  47 + should "Show only communities on community block view all" do
  48 + get :communities, :profile => @user.identifier
  49 +
  50 + assert_match Regexp.new("#{@community.name}"), @response.body
  51 + assert_not_match Regexp.new("#{@institution.community.name}"), @response.body
  52 + assert_not_match Regexp.new("#{@software.community.name}"), @response.body
  53 + end
  54 +
  55 +
  56 + should "Show only institutions on community block view all with type=software" do
  57 + get :communities,:type => "Software", :profile => @user.identifier
  58 +
  59 + assert_not_match Regexp.new("#{@community.name}"), @response.body
  60 + assert_not_match Regexp.new("#{@institution.community.name}"), @response.body
  61 + assert_match Regexp.new("#{@software.community.name}"), @response.body
  62 + end
  63 +
  64 +
  65 + should "Show only communities on community block view all with type=institution" do
  66 + get :communities,:type => "Institution", :profile => @user.identifier
  67 +
  68 + assert_not_match Regexp.new("#{@community.name}"), @response.body
  69 + assert_match Regexp.new("#{@institution.community.name}"), @response.body
  70 + assert_not_match Regexp.new("#{@software.community.name}"), @response.body
  71 + end
  72 +end
0 73 \ No newline at end of file
... ...