PageRenderTime 22ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/test/shoulda_macros/controllers.rb

https://github.com/newrooky/lftwb
Ruby | 31 lines | 26 code | 4 blank | 1 comment | 1 complexity | f31558079cfb3234e35a8a3c497d1549 MD5 | raw file
Possible License(s): MIT
  1. Test::Unit::TestCase.class_eval do
  2. def self.should_require_login(*actions)
  3. actions.each do |action|
  4. should "Require login for '#{action}' action" do
  5. get(action)
  6. assert_redirected_to(login_url)
  7. end
  8. end
  9. end
  10. #from: http://blog.internautdesign.com/2008/9/11/more-on-custom-shoulda-macros-scoping-of-instance-variables
  11. def self.should_not_allow action, object, url= "/login", msg=nil
  12. msg ||= "a #{object.class.to_s.downcase}"
  13. should "not be able to #{action} #{msg}" do
  14. object = eval(object, self.send(:binding), __FILE__, __LINE__)
  15. get action, :id => object.id
  16. assert_redirected_to url
  17. end
  18. end
  19. def self.should_allow action, object, msg=nil
  20. msg ||= "a #{object.class.to_s.downcase}"
  21. should "be able to #{action} #{msg}" do
  22. object = eval(object, self.send(:binding), __FILE__, __LINE__)
  23. get action, :id => object.id
  24. assert_response :success
  25. end
  26. end
  27. end