Sha256: 91a851574f42b85276f951d0f202618f0a7bb99bb857fce16476b2bafe892d60

Contents?: true

Size: 1.45 KB

Versions: 118

Compression:

Stored size: 1.45 KB

Contents

module MuckControllerMacros

  def 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
        if [:put, :delete].include?(verb) # put and delete require an id even if it is a bogus one
          send(verb, action, :id => 1)
        else
          send(verb, action)
        end
        assert_redirected_to(login_url)
      end
    end
  end

  def 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 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 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

ActionController::TestCase.extend(MuckControllerMacros)

Version data entries

118 entries across 118 versions & 10 rubygems

Version Path
overlord-3.0.2 test/rails_test/test/shoulda_macros/controller.rb
overlord-3.0.1 test/rails_test/test/shoulda_macros/controller.rb
overlord-3.0.0 test/rails_test/test/shoulda_macros/controller.rb
overlord-0.1.22 test/rails_root/test/shoulda_macros/controller.rb
overlord-0.1.21 test/rails_root/test/shoulda_macros/controller.rb
overlord-0.1.20 test/rails_root/test/shoulda_macros/controller.rb
overlord-0.1.19 test/rails_root/test/shoulda_macros/controller.rb
overlord-0.1.18 test/rails_root/test/shoulda_macros/controller.rb
overlord-0.1.17 test/rails_root/test/shoulda_macros/controller.rb
overlord-0.1.16 test/rails_root/test/shoulda_macros/controller.rb
overlord-0.1.15 test/rails_root/test/shoulda_macros/controller.rb
overlord-0.1.14 test/rails_root/test/shoulda_macros/controller.rb
overlord-0.1.13 test/rails_root/test/shoulda_macros/controller.rb
overlord-0.1.12 test/rails_root/test/shoulda_macros/controller.rb
overlord-0.1.11 test/rails_root/test/shoulda_macros/controller.rb
overlord-0.1.10 test/rails_root/test/shoulda_macros/controller.rb
overlord-0.1.9 test/rails_root/test/shoulda_macros/controller.rb
overlord-0.1.8 test/rails_root/test/shoulda_macros/controller.rb
overlord-0.1.7 test/rails_root/test/shoulda_macros/controller.rb
overlord-0.1.6 test/rails_root/test/shoulda_macros/controller.rb