Commit 1c9a41e0d5cac3ee937555ae4189ecd1ad597004
1 parent
b9d58c4c
Exists in
spb-stable
and in
3 other branches
adding tests for the ssh keys feature
Showing
4 changed files
with
19 additions
and
2 deletions
Show diff stats
app/controllers/profiles/keys_controller.rb
| ... | ... | @@ -40,7 +40,7 @@ class Profiles::KeysController < ApplicationController |
| 40 | 40 | if params[:username].present? |
| 41 | 41 | begin |
| 42 | 42 | user = User.find_by_username(params[:username]) |
| 43 | - user.present? ? (render :text => user.all_ssh_keys) : | |
| 43 | + user.present? ? (render :text => user.all_ssh_keys.join('\n')) : | |
| 44 | 44 | (render_404 and return) |
| 45 | 45 | rescue => e |
| 46 | 46 | render text: e.message | ... | ... |
app/models/user.rb
spec/models/user_spec.rb
| ... | ... | @@ -276,4 +276,16 @@ describe User do |
| 276 | 276 | User.by_username_or_id('bar').should be_nil |
| 277 | 277 | end |
| 278 | 278 | end |
| 279 | + | |
| 280 | + describe 'all_ssh_keys' do | |
| 281 | + it { should have_many(:keys).dependent(:destroy) } | |
| 282 | + | |
| 283 | + it "should have all ssh keys" do | |
| 284 | + user = create :user | |
| 285 | + key = create :key, key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD33bWLBxu48Sev9Fert1yzEO4WGcWglWF7K/AwblIUFselOt/QdOL9DSjpQGxLagO1s9wl53STIO8qGS4Ms0EJZyIXOEFMjFJ5xmjSy+S37By4sG7SsltQEHMxtbtFOaW5LV2wCrX+rUsRNqLMamZjgjcPO0/EgGCXIGMAYW4O7cwGZdXWYIhQ1Vwy+CsVMDdPkPgBXqK7nR/ey8KMs8ho5fMNgB5hBw/AL9fNGhRw3QTD6Q12Nkhl4VZES2EsZqlpNnJttnPdp847DUsT6yuLRlfiQfz5Cn9ysHFdXObMN5VYIiPFwHeYCZp1X2S4fDZooRE8uOLTfxWHPXwrhqSH", user_id: user.id | |
| 286 | + | |
| 287 | + user.all_ssh_keys.should include(key.key) | |
| 288 | + end | |
| 289 | + | |
| 290 | + end | |
| 279 | 291 | end | ... | ... |
spec/routing/routing_spec.rb
| ... | ... | @@ -183,6 +183,11 @@ describe Profiles::KeysController, "routing" do |
| 183 | 183 | it "to #destroy" do |
| 184 | 184 | delete("/profile/keys/1").should route_to('profiles/keys#destroy', id: '1') |
| 185 | 185 | end |
| 186 | + | |
| 187 | + # get all the ssh-keys of a user | |
| 188 | + it "to #get_keys" do | |
| 189 | + get("/foo.keys").should route_to('profiles/keys#get_keys', username: 'foo') | |
| 190 | + end | |
| 186 | 191 | end |
| 187 | 192 | |
| 188 | 193 | # dashboard GET /dashboard(.:format) dashboard#show | ... | ... |