got it... I forgot to write an Include Exceptions in my
DocumentsController
where the SecurityTransgression is defined....
On 16 juil, 18:12, Erwin <yves_duf...-ee4meeAH724@public.gmane.org>
wrote:> in one of my functional test, I check the followoing :
>
> def test_user_should_not_show_documents
> login_as (:quentin)
> assert_raise (Exceptions::SecurityTransgression) { get :show, :id
> => 2, :franchise_id => 3 }
> end
>
> In my controller , I wrote :
>
> before_filter :login_required
> before_filter :find_parent
> def show
> raise SecurityTransgression unless @parent.can_be_edited_by?
> (current_user)
> @document = Document.find(params[:id].to_i)
> .....
> end
>
> I wrote the exception class and rescue action in my application.rb
> class SecurityTransgression < StandardError; end
>
> class ApplicationController < ActionController::Base
> include AuthenticatedSystem
> ...
> def rescue_action_locally(exception)
> begin
> case exception
> when ::Exceptions::SecurityTransgression
> render :file => "#{RAILS_ROOT}/public/403.html",
:status =>
> 403
> ......
> end
>
> in testing, the exception is raised, (as @parent cannot be edited by
> the current_user... I checked it...) the log gives a failure I cannot
> explain :
>
> 1) Failure:
> test_user_should_not_show_documents(DocumentsControllerTest)
> [./test/functional/documents_controller_test.rb:66:in
> `test_user_should_not_show_documents''
> /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/
> active_support/testing/setup_and_teardown.rb:67:in `__send__''
> /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/
> active_support/testing/setup_and_teardown.rb:67:in `run'']:
> <Exceptions::SecurityTransgression> exception expected but was
> Class: <SecurityTransgression>
> Message: <"SecurityTransgression">
> ---Backtrace---
> /Users/yves/Developpement/Projects/aelmat/intranet/app/controllers/
> documents_controller.rb:19:in `show''
> ........
>
> the exception is expected, but ...
>
> what could be the problem ?
>
> Note : I am using the same assert_raise
> (Exceptions::SecurityTransgression) in testing another controller
> without any problem ...
>
> thanks for your suggestions
>
> erwin
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---