ref: master
test/functional/organizations_controller_test.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
require_relative '../test_helper' class OrganizationsControllerTest < ActionController::TestCase def setup @controller = OrganizationsController.new @environment = Environment.default admin_user = create_user_with_permission('adminuser', 'manage_environment_organizations', environment) login_as('adminuser') end attr_accessor :environment should 'not access without right permission' do create_user('guest') login_as 'guest' get :index assert_response 403 # forbidden end should 'grant access with right permission' do get :index assert_response :success end should 'show list to deactivate organizations' do enabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"enabled community") disabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"disabled community") disabled_community.disable get :index, :filter => 'enabled' assert_match(/enabled community/, @response.body) assert_no_match(/disabled community/, @response.body) end should 'show list to activate organizations' do enabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"enabled community") disabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"disabled community") disabled_community.disable get :index, :filter => 'disabled' assert_no_match(/enabled community/, @response.body) assert_match(/disabled community/, @response.body) end should 'show list only of enterprises' do community = fast_create(Community, :environment_id => Environment.default, :name=>"Community Test") enterprise = fast_create(Enterprise, :environment_id => Environment.default, :name=>"Enterprise Test") get :index, :type => 'Enterprise' assert_match(/Enterprise Test/, @response.body) assert_no_match(/Community Test/, @response.body) end should 'show list only of communities' do community = fast_create(Community, :environment_id => Environment.default, :name=>"Community Test") enterprise = fast_create(Enterprise, :environment_id => Environment.default, :name=>"Enterprise Test") get :index, :type => 'Community' assert_no_match(/Enterprise Test/, @response.body) assert_match(/Community Test/, @response.body) end should 'show list all organizations' do community = fast_create(Community, :environment_id => Environment.default, :name=>"Community Test") enterprise = fast_create(Enterprise, :environment_id => Environment.default, :name=>"Enterprise Test") get :index, :type => 'any' assert_match(/Enterprise Test/, @response.body) assert_match(/Community Test/, @response.body) end should 'show custom organization type filter through hotspot' do fast_create(Community, :environment_id => Environment.default, :name=>"Community Test") class GreatPlugin < Noosfero::Plugin def organization_types_filter_options [['TotallyDifferentName','GreatPlugin::GreatOrganization']] end end class GreatPlugin::GreatOrganization < Organization end Noosfero::Plugin.stubs(:all).returns(['OrganizationsControllerTest::GreatPlugin']) environment.enable_plugin(GreatPlugin) GreatPlugin::GreatOrganization.create!(:name => 'Great', :identifier=>'great') get :index, :type => 'any' assert_tag :option, :attributes => {:value=> 'GreatPlugin::GreatOrganization'}, :content => 'TotallyDifferentName' assert_match(/Great/, @response.body) assert_match(/Community Test/, @response.body) get :index, :type => 'GreatPlugin::GreatOrganization' assert_match(/Great/, @response.body) assert_no_match(/Community Test/, @response.body) end should 'activate organization profile' do organization = fast_create(Organization, :visible => false, :environment_id => environment.id) refute organization.visible? get :activate, {:id => organization.id} organization.reload assert organization.visible end should 'deactivate organization profile' do organization = fast_create(Organization, :visible => true, :environment_id => environment.id) assert organization.visible get :deactivate, {:id => organization.id} organization.reload refute organization.visible end should 'destroy organization profile' do organization = fast_create(Organization, :environment_id => environment.id) post :destroy, {:id => organization.id} assert_raise ActiveRecord::RecordNotFound do organization.reload end end end |