Commit 1c9a41e0 authored by GitLab's avatar GitLab

adding tests for the ssh keys feature

parent b9d58c4c
......@@ -40,7 +40,7 @@ class Profiles::KeysController < ApplicationController
if params[:username].present?
begin
user = User.find_by_username(params[:username])
user.present? ? (render :text => user.all_ssh_keys) :
user.present? ? (render :text => user.all_ssh_keys.join('\n')) :
(render_404 and return)
rescue => e
render text: e.message
......
......@@ -393,6 +393,6 @@ class User < ActiveRecord::Base
end
def all_ssh_keys
keys.collect{|x| x.key}.join("\n")
keys.collect{|x| x.key}
end
end
......@@ -276,4 +276,16 @@ describe User do
User.by_username_or_id('bar').should be_nil
end
end
describe 'all_ssh_keys' do
it { should have_many(:keys).dependent(:destroy) }
it "should have all ssh keys" do
user = create :user
key = create :key, key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD33bWLBxu48Sev9Fert1yzEO4WGcWglWF7K/AwblIUFselOt/QdOL9DSjpQGxLagO1s9wl53STIO8qGS4Ms0EJZyIXOEFMjFJ5xmjSy+S37By4sG7SsltQEHMxtbtFOaW5LV2wCrX+rUsRNqLMamZjgjcPO0/EgGCXIGMAYW4O7cwGZdXWYIhQ1Vwy+CsVMDdPkPgBXqK7nR/ey8KMs8ho5fMNgB5hBw/AL9fNGhRw3QTD6Q12Nkhl4VZES2EsZqlpNnJttnPdp847DUsT6yuLRlfiQfz5Cn9ysHFdXObMN5VYIiPFwHeYCZp1X2S4fDZooRE8uOLTfxWHPXwrhqSH", user_id: user.id
user.all_ssh_keys.should include(key.key)
end
end
end
......@@ -183,6 +183,11 @@ describe Profiles::KeysController, "routing" do
it "to #destroy" do
delete("/profile/keys/1").should route_to('profiles/keys#destroy', id: '1')
end
# get all the ssh-keys of a user
it "to #get_keys" do
get("/foo.keys").should route_to('profiles/keys#get_keys', username: 'foo')
end
end
# dashboard GET /dashboard(.:format) dashboard#show
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment