BigW Consortium Gitlab

keys_controller_spec.rb 1.92 KB
Newer Older
1 2 3
require 'spec_helper'

describe Profiles::KeysController do
4 5
  let(:user) { create(:user) }

6 7
  describe "#get_keys" do
    describe "non existant user" do
8
      it "does not generally work" do
9 10 11 12 13 14 15
        get :get_keys, username: 'not-existent'

        expect(response).not_to be_success
      end
    end

    describe "user with no keys" do
16
      it "does generally work" do
17 18 19 20 21
        get :get_keys, username: user.username

        expect(response).to be_success
      end

22
      it "renders all keys separated with a new line" do
23 24 25 26
        get :get_keys, username: user.username

        expect(response.body).to eq("")
      end
27

28
      it "responds with text/plain content type" do
29 30 31
        get :get_keys, username: user.username
        expect(response.content_type).to eq("text/plain")
      end
32 33 34
    end

    describe "user with keys" do
35 36 37
      let!(:key) { create(:key, user: user) }
      let!(:another_key) { create(:another_key, user: user) }
      let!(:deploy_key) { create(:deploy_key, user: user) }
38

39
      it "does generally work" do
40 41 42 43 44
        get :get_keys, username: user.username

        expect(response).to be_success
      end

45
      it "renders all non deploy keys separated with a new line" do
46 47
        get :get_keys, username: user.username

48
        expect(response.body).not_to eq('')
49
        expect(response.body).to eq(user.all_ssh_keys.join("\n"))
50

51
        expect(response.body).to include(key.key.sub(' dummy@gitlab.com', ''))
52
        expect(response.body).to include(another_key.key.sub(' dummy@gitlab.com', ''))
53 54

        expect(response.body).not_to include(deploy_key.key)
55 56
      end

57
      it "does not render the comment of the key" do
58 59 60
        get :get_keys, username: user.username

        expect(response.body).not_to match(/dummy@gitlab.com/)
61
      end
62

63
      it "responds with text/plain content type" do
64 65 66
        get :get_keys, username: user.username
        expect(response.content_type).to eq("text/plain")
      end
67 68 69
    end
  end
end