profile_controller_test.rb 2.51 KB
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