Guest User

Untitled

a guest
Apr 25th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. describe "logged in as admin area user", :shared=>true do
  2. it 'should redirect to login if not logged in' do
  3. #overwrite the stub again to make it not logged in
  4. controller.stub!(:current_user).and_return(:false)
  5. do_action
  6. response.should redirect_to(new_admin_session_path)
  7. end
  8. def do_action
  9. %w(get post put delete).each do |action|
  10. self.send "do_#{action}" if self.respond_to?("do_#{action}")
  11. end
  12. end
  13. end
  14.  
  15. describe 'admin user with administrative privileges', :shared=>true do
  16. it_should_behave_like "logged in as admin area user"
  17. it 'should respond with forbidden message if not admin' do
  18. controller.stub!(:current_user).and_return(mock_model(User, :login_required? =>true, :authorized? =>true, :is_enabled? => true, :is_admin? => false))
  19. do_action
  20. response.response_code.should == 403 #forbidden http status code
  21. end
  22. def do_action
  23. %w(get post put delete).each do |action|
  24. self.send "do_#{action}" if self.respond_to?("do_#{action}")
  25. end
  26. end
  27. end
Add Comment
Please, Sign In to add comment