Commit baea397210f818ca5fd70aacaae6982b78ead24a

Authored by AntonioTerceiro
1 parent af2a416a

ActionItem16: checkpoint; adding initial implementation of enterprise_validation_controller



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@860 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/application.rb
... ... @@ -40,8 +40,8 @@ class ApplicationController < ActionController::Base
40 40 end
41 41 end
42 42  
43   - def render_not_found(path)
44   - @path = path
  43 + def render_not_found(path = nil)
  44 + @path ||= request.path
45 45 render(:file => File.join(RAILS_ROOT, 'app', 'views', 'shared', 'not_found.rhtml'), :layout => 'not_found', :status => 404) && false
46 46 end
47 47  
... ...
app/controllers/profile_admin/enterprise_validation_controller.rb
1 1 class EnterpriseValidationController < ProfileAdminController
2 2  
3 3 def index
4   - #@pending = profile.pending_validations
5   - render :text => profile.inspect
  4 + @pending_validations = profile.pending_validations
  5 + end
  6 +
  7 + def details
  8 + @pending = profile.pending_validations(:code => params[:id]).first
  9 + unless @pending
  10 + render_not_found
  11 + end
6 12 end
7 13  
8 14 end
... ...
app/controllers/public/enterprise_registration_controller.rb
1 1 class EnterpriseRegistrationController < ApplicationController
2 2  
  3 + before_filter :login_required
  4 +
3 5 # Just go to the first step.
4 6 #
5 7 # FIXME: shouldn't this action present some sort of welcome message and point
... ...
app/views/enterprise_validation/index.rhtml 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +<h2><%= _("Pending enterprise validations") %></h2>
  2 +
  3 +<% for pending in @pending_validations %>
  4 + <h3><%= pending.name %></h3>
  5 + <ul>
  6 + <li>
  7 + <strong><%= _('Address') %>:</strong>
  8 + <%= pending.address %>
  9 + </li>
  10 + <li>
  11 + <strong><%= _('Contact Phone') %>:</strong>
  12 + <%= pending.contact_phone %>
  13 + </li>
  14 + <li>
  15 + <strong><%= _('Contact Person') %>:</strong>
  16 + <%= pending.contact_person %>
  17 + </li>
  18 + </ul>
  19 +
  20 + <%= link_to _("See details/approve/reject"), :action => 'details', :id => pending.code %>
  21 +<% end %>
... ...
test/functional/enterprise_validation_test.rb
... ... @@ -13,18 +13,39 @@ all_fixtures
13 13 @request = ActionController::TestRequest.new
14 14 @response = ActionController::TestResponse.new
15 15 login_as 'ze'
  16 +
  17 + @org = Organization.create!(:identifier => 'myorg', :name => "My Org")
  18 + Profile.expects(:find_by_identifier).with('myorg').returns(@org).at_least_once
16 19 end
17 20  
18 21 should 'list pending validations on index' do
19   - flunk 'not yet'
  22 + empty = []
  23 + @org.expects(:pending_validations).returns(empty)
  24 + get :index, :profile => 'myorg'
  25 + assert_same empty, assigns(:pending_validations)
  26 + assert_template 'index'
20 27 end
21 28  
22   - should 'prompt for needed data when approving or rejecting enterprise' do
23   - flunk 'not yet'
  29 + should 'display details and prompt for needed data when approving or rejecting enterprise' do
  30 + validating = CreateEnterprise.new
  31 + @org.expects(:pending_validations).with(:code => 'kakakaka').returns([validating])
  32 +
  33 + get :details, :profile => 'myorg', :id => 'kakakaka'
  34 + assert_same validating, assigns(:pending)
  35 + end
  36 +
  37 + should 'refuse to validate unexisting request' do
  38 + @org.expects(:pending_validations).with(:code => 'kakakaka').returns([])
  39 + get :details , :profile => 'myorg', :id => 'kakakaka'
  40 + assert_response 404
24 41 end
25 42  
26 43 should 'be able to actually validate enterprise on request' do
27 44 flunk 'not yet'
28 45 end
29 46  
  47 + should 'be able to reject an enterprise' do
  48 + flunk 'not yet'
  49 + end
  50 +
30 51 end
... ...