Commit bda47639d057b51c75a6b0f10eb8ad5b0890c528

Authored by Marcos Pereira
1 parent 5b115b7a

fixes type for admin panel organizations list

Signed-off-by: Alexandre Barbosa <alexandreab@live.com>
Signed-off-by: ArthurJahn <stutrzbecher@gmail.com>
Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com>
app/controllers/admin/organizations_controller.rb
... ... @@ -7,7 +7,11 @@ class OrganizationsController &lt; AdminController
7 7 @title = _('Organization profiles')
8 8 @type = params[:type] || "any"
9 9 @types_filter = [[_('All'), 'any'], [_('Community'), 'Community'], [_('Enterprise'), 'Enterprise']]
10   - @types_filter = @types_filter | @plugins.dispatch(:organization_types_filter_options)
  10 + @plugins.dispatch_without_flatten(:organization_types_filter_options).each do |plugin_response|
  11 + @types_filter = @types_filter | plugin_response
  12 + end
  13 + @types_hash = {}
  14 + @types_filter.each{|list| @types_hash[list.last] = list.first}
11 15  
12 16 scope = @plugins.dispatch_first(:filter_manage_organization_scope, @type)
13 17 if scope.blank?
... ...
app/views/organizations/_results.html.erb
... ... @@ -30,7 +30,7 @@
30 30 </div>
31 31 </td>
32 32  
33   - <td> <%= _(p.type) %> </td>
  33 + <td> <%= @types_hash[p.type] %> </td>
34 34 </tr>
35 35 <% end %>
36 36 </table>
... ...
test/functional/organizations_controller_test.rb
... ... @@ -79,6 +79,36 @@ class OrganizationsControllerTest &lt; ActionController::TestCase
79 79 assert_match(/Community Test/, @response.body)
80 80 end
81 81  
  82 + should 'show custom organization type filter through hotspot' do
  83 + fast_create(Community, :environment_id => Environment.default, :name=>"Community Test")
  84 +
  85 + class GreatPlugin < Noosfero::Plugin
  86 + def organization_types_filter_options
  87 + [['TotallyDifferentName','GreatPlugin::GreatOrganization']]
  88 + end
  89 + end
  90 +
  91 + class GreatPlugin::GreatOrganization < Organization
  92 + end
  93 +
  94 + Noosfero::Plugin.stubs(:all).returns(['OrganizationsControllerTest::GreatPlugin'])
  95 + environment.enable_plugin(GreatPlugin)
  96 +
  97 + GreatPlugin::GreatOrganization.create!(:name => 'Great', :identifier=>'great')
  98 +
  99 + get :index, :type => 'any'
  100 +
  101 + assert_tag :option, :attributes => {:value=> 'GreatPlugin::GreatOrganization'}, :content => 'TotallyDifferentName'
  102 +
  103 + assert_match(/Great/, @response.body)
  104 + assert_match(/Community Test/, @response.body)
  105 +
  106 + get :index, :type => 'GreatPlugin::GreatOrganization'
  107 +
  108 + assert_match(/Great/, @response.body)
  109 + assert_no_match(/Community Test/, @response.body)
  110 + end
  111 +
82 112 should 'activate organization profile' do
83 113 organization = fast_create(Organization, :visible => false, :environment_id => environment.id)
84 114 refute organization.visible?
... ...