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

Version Path
muck-activities-0.1.23 test/rails_root/test/shoulda_macros/controller.rb
muck-activities-0.1.22 test/rails_root/test/shoulda_macros/controller.rb
muck-activities-0.1.21 test/rails_root/test/shoulda_macros/controller.rb
muck-activities-0.1.20 test/rails_root/test/shoulda_macros/controller.rb
muck-activities-0.1.17 test/rails_root/test/shoulda_macros/controller.rb
muck-activities-0.1.18 test/rails_root/test/shoulda_macros/controller.rb
muck-activities-0.1.19 test/rails_root/test/shoulda_macros/controller.rb
muck-users-0.1.4 test/rails_root/test/shoulda_macros/controller.rb
muck-users-0.1.5 test/rails_root/test/shoulda_macros/controller.rb
muck-activities-0.1.8 test/rails_root/test/shoulda_macros/controller.rb
muck-activities-0.1.9 test/rails_root/test/shoulda_macros/controller.rb
muck-activities-0.1.10 test/rails_root/test/shoulda_macros/controller.rb
muck-activities-0.1.11 test/rails_root/test/shoulda_macros/controller.rb
muck-activities-0.1.12 test/rails_root/test/shoulda_macros/controller.rb
muck-activities-0.1.13 test/rails_root/test/shoulda_macros/controller.rb
muck-activities-0.1.14 test/rails_root/test/shoulda_macros/controller.rb
muck-activities-0.1.15 test/rails_root/test/shoulda_macros/controller.rb
muck-activities-0.1.16 test/rails_root/test/shoulda_macros/controller.rb
muck-activity-0.1.1 test/shoulda_macros/controller.rb
muck-activities-0.1.7 test/shoulda_macros/controller.rb