summaryrefslogtreecommitdiff
path: root/test/functional/keys_controller_test.rb
blob: f5e26918a5c463b7a59fccc1d1b6c8cd6c3993a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require 'test_helper'

class KeysControllerTest < ActionController::TestCase

  test "get key for username with dot" do
    assert_recognizes({controller: 'keys', action: 'show', login: 'username.with.dot'}, 'key/username.with.dot')
  end

  test "get existing public key" do
    public_key = 'my public key'
    @user = stub_record :user, :public_key => public_key
    User.stubs(:find_by_login).with(@user.login).returns(@user)
    get :show, :login => @user.login
    assert_response :success
    assert_equal "text/text", response.content_type
    assert_equal public_key, response.body
  end

  test "get non-existing public key for user" do
    # this isn't a scenerio that should generally occur.
    @user = stub_record :user
    User.stubs(:find_by_login).with(@user.login).returns(@user)
    get :show, :login => @user.login
    assert_response :success
    assert_equal "text/text", response.content_type
    assert_equal '', response.body.strip
  end

  test "get public key for non-existing user" do
    # raise 404 error if user doesn't exist (doesn't need to be this routing error, but seems fine to assume for now):
    assert_raise(ActionController::RoutingError) {
      get :show, :login => 'asdkljslksjfdlskfj'
    }
  end

end