Sha256: 37aff77d2fa19f531e8431b8deaed8d39a4b307797256e0b686148e072554289
Contents?: true
Size: 1.27 KB
Versions: 29
Compression:
Stored size: 1.27 KB
Contents
ActiveSupport::TestCase.class_eval do def self.should_require_login(*args) args = Hash[*args] login_url = args.delete :login_url args.each do |action, verb| should "Require login for '#{action}' action" do send(verb, action) assert_redirected_to(login_url) end end end def self.should_require_role(role, redirect_url, *actions) actions.each do |action| should "require role for '#{action}' action" do get(action) ensure_flash(/permission/i) assert_response :redirect end end end #from: http://blog.internautdesign.com/2008/9/11/more-on-custom-shoulda-macros-scoping-of-instance-variables def self.should_not_allow action, object, url= "/login", msg=nil msg ||= "a #{object.class.to_s.downcase}" should "not be able to #{action} #{msg}" do object = eval(object, self.send(:binding), __FILE__, __LINE__) get action, :id => object.id assert_redirected_to url end end def self.should_allow action, object, msg=nil msg ||= "a #{object.class.to_s.downcase}" should "be able to #{action} #{msg}" do object = eval(object, self.send(:binding), __FILE__, __LINE__) get action, :id => object.id assert_response :success end end end
Version data entries
29 entries across 29 versions & 3 rubygems