BigW Consortium Gitlab

profile_keys_controller_spec.rb 1.48 KB
Newer Older
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
require 'spec_helper'

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

  describe "#get_keys" do
    describe "non existant user" do
      it "should generally not work" do
        get :get_keys, username: 'not-existent'

        expect(response).not_to be_success
      end
    end

    describe "user with no keys" do
      it "should generally work" do
        get :get_keys, username: user.username

        expect(response).to be_success
      end

      it "should render all keys separated with a new line" do
        get :get_keys, username: user.username

        expect(response.body).to eq("")
      end
27 28 29 30 31

      it "should respond with text/plain content type" do
        get :get_keys, username: user.username
        expect(response.content_type).to eq("text/plain")
      end
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
    end

    describe "user with keys" do
      before do
        user.keys << create(:key)
        user.keys << create(:another_key)
      end

      it "should generally work" do
        get :get_keys, username: user.username

        expect(response).to be_success
      end

      it "should render all keys separated with a new line" do
        get :get_keys, username: user.username

        expect(response.body).not_to eq("")
        expect(response.body).to eq(user.all_ssh_keys.join("\n"))
      end
52 53 54 55 56

      it "should respond with text/plain content type" do
        get :get_keys, username: user.username
        expect(response.content_type).to eq("text/plain")
      end
57 58 59
    end
  end
end