Sha256: 8b06db593b14964a25bf218f9d79bf54a31ab9dcdee7424dfa94f37b78e6ee48

Contents?: true

Size: 1.09 KB

Versions: 9

Compression:

Stored size: 1.09 KB

Contents

require 'rack/test'

module RackTestMethods
  include ::Rack::Test::Methods
  include Spontaneous::Rack::Constants

  def auth_post(path, params={}, env={})
    post(path, params, csrf_header(env))
  end

  def auth_get(path, params={}, env={})
    get(path, params, csrf_header(env))
  end

  def auth_put(path, params={}, env={})
    put(path, params, csrf_header(env))
  end

  def auth_delete(path, params={}, env={})
    delete(path, params, csrf_header(env))
  end

  alias_method :auth_del, :auth_delete

  def auth_patch(path, params={}, env={})
    patch(path, params, csrf_header(env))
  end

  def csrf_header(env)
    token = api_key.generate_csrf_token
    env.merge(Spontaneous::Rack::CSRF_ENV => token)
  end

  def api_key
    # Override in test suites
  end

  def login_user(user, params={})
    post "/@spontaneous/login", {"user[login]" => user.login, "user[password]" => user.password}.merge(params)
    key_id  = rack_mock_session.cookie_jar[Spontaneous::Rack::AUTH_COOKIE]
    @user   = user
    @key    = Spontaneous::Permissions::AccessKey.authenticate(key_id)
    [@user, @key]
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta10 test/support/rack.rb
spontaneous-0.2.0.beta9 test/support/rack.rb
spontaneous-0.2.0.beta8 test/support/rack.rb
spontaneous-0.2.0.beta7 test/support/rack.rb
spontaneous-0.2.0.beta6 test/support/rack.rb
spontaneous-0.2.0.beta5 test/support/rack.rb
spontaneous-0.2.0.beta4 test/support/rack.rb
spontaneous-0.2.0.beta3 test/support/rack.rb
spontaneous-0.2.0.beta2 test/support/rack.rb