Sha256: 29e1d9239d8c96a23c6962faf14063d14f8bb8dc86752efe15cdd974f17a23aa

Contents?: true

Size: 1.43 KB

Versions: 38

Compression:

Stored size: 1.43 KB

Contents

module MuckEngine # :nodoc:
  module Controllers # :nodoc:
    module Matchers
   
      # Ensure a login is required for the given action
      # Parameters:
      #     action      - Name of the action in the control that should require a login ie "index"
      #     verb        - Method to use to call the action ie :post, :get
      #     login_url   - Optional url the user should be redirected to if they aren't logged in.  Defaults to '/login'
      #
      # Example:
      #           it { should require_login 'index', :get, '/signup' }
      def require_login(action, verb, login_url = '/login')
        RequireLoginMatcher.new(action, verb, login_url, self)
      end
      
      class RequireLoginMatcher
        
        def initialize(action, verb, login_url, context)
          @action = action
          @verb = verb
          @login_url = login_url
          @context = context
        end
        
        def matches?(controller)
          @controller = controller
          requires_login?
        end
        
        def failure_message
          "Expected a #{@action} to #{@action} to require login"
        end

        def description
          "require login #{@action}"
        end
        
        private
        
          def requires_login?
            response = @context.send(@verb, @action, :id => 1)
            @context.send(:assert_redirected_to, @login_url)
            true
          end
      end
      
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
muck-engine-3.5.0 lib/muck-engine/test/controllers/matchers/login_matcher.rb
muck-engine-3.4.0 lib/muck-engine/test/controllers/matchers/login_matcher.rb
muck-engine-3.3.18 lib/muck-engine/test/controllers/matchers/login_matcher.rb
muck-engine-3.3.17 lib/muck-engine/test/controllers/matchers/login_matcher.rb
muck-engine-3.3.16 lib/muck-engine/test/controllers/matchers/login_matcher.rb
muck-engine-3.3.15 lib/muck-engine/test/controllers/matchers/login_matcher.rb
muck-engine-3.3.14 lib/muck-engine/test/controllers/matchers/login_matcher.rb
muck-engine-3.3.13 lib/muck-engine/test/controllers/matchers/login_matcher.rb
muck-engine-3.3.12 lib/muck-engine/test/controllers/matchers/login_matcher.rb
muck-engine-3.3.11 lib/muck-engine/test/controllers/matchers/login_matcher.rb
muck-engine-3.3.10 lib/muck-engine/test/controllers/matchers/login_matcher.rb
muck-engine-3.3.9 lib/muck-engine/test/controllers/matchers/login_matcher.rb
muck-engine-3.3.8 lib/muck-engine/test/controllers/matchers/login_matcher.rb
muck-engine-3.3.7 lib/muck-engine/test/controllers/matchers/login_matcher.rb
muck-engine-3.3.6 lib/muck-engine/test/controllers/matchers/login_matcher.rb
muck-engine-3.3.5 lib/muck-engine/test/controllers/matchers/login_matcher.rb
muck-engine-3.3.4 lib/muck-engine/test/controllers/matchers/login_matcher.rb
muck-engine-3.3.3 lib/muck-engine/test/controllers/matchers/login_matcher.rb
muck-engine-3.3.2 lib/muck-engine/test/controllers/matchers/login_matcher.rb
muck-engine-3.3.1 lib/muck-engine/test/controllers/matchers/login_matcher.rb