adding tests for the ssh keys feature

This commit is contained in:
GitLab 2014-02-06 14:42:59 +05:30
parent b9d58c4cec
commit 1c9a41e0d5
4 changed files with 19 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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