| |   |
| 3 | 3 | |
| 4 | 4 | def index |
| 5 | 5 | @ssh_keys = current_user.ssh_keys |
| 6 | respond_to do |format| |
| 7 | format.html |
| 8 | format.xml { render :xml => @ssh_keys } |
| 9 | end |
| 6 | 10 | end |
| 7 | 11 | |
| 8 | 12 | def new |
| 9 | 13 | @ssh_key = current_user.ssh_keys.new |
| 10 | 14 | end |
| 11 | | |
| 15 | # respond_to do |format| |
| 16 | # if @event.save |
| 17 | # flash[:notice] = 'Event was successfully created.' |
| 18 | # format.html { redirect_to(@event) } |
| 19 | # format.xml { render :xml => @event, :status => :created, :location => @event } |
| 20 | # else |
| 21 | # format.html { render :action => "new" } |
| 22 | # format.xml { render :xml => @event.errors, :status => :unprocessable_entity } |
| 23 | # end |
| 12 | 24 | def create |
| 13 | 25 | @ssh_key = current_user.ssh_keys.new |
| 14 | 26 | @ssh_key.key = params[:ssh_key][:key] |
| 15 | | if @ssh_key.save |
| 16 | | flash[:notice] = "Key added" |
| 17 | | redirect_to account_path |
| 18 | | else |
| 19 | | render :action => "new" |
| 27 | |
| 28 | respond_to do |format| |
| 29 | if @ssh_key.save |
| 30 | flash[:notice] = "Key added" |
| 31 | format.html { redirect_to account_path } |
| 32 | format.xml { render :xml => @ssh_key, :status => :created, :location => account_key_path(@ssh_key) } |
| 33 | else |
| 34 | format.html { render :action => "new" } |
| 35 | format.xml { render :xml => @ssh_key.errors, :status => :unprocessable_entity } |
| 36 | end |
| 20 | 37 | end |
| 21 | 38 | end |
| 22 | 39 | |
| 23 | 40 | def show |
| 24 | 41 | @ssh_key = current_user.ssh_keys.find(params[:id]) |
| 42 | |
| 43 | respond_to do |format| |
| 44 | format.html |
| 45 | format.xml { render :xml => @ssh_key } |
| 46 | end |
| 25 | 47 | end |
| 26 | 48 | |
| 27 | 49 | # can't update keys since yet we'd have to to search/replace through |
| toggle raw diff |
--- a/app/controllers/keys_controller.rb
+++ b/app/controllers/keys_controller.rb
@@ -3,25 +3,47 @@ class KeysController < ApplicationController
def index
@ssh_keys = current_user.ssh_keys
+ respond_to do |format|
+ format.html
+ format.xml { render :xml => @ssh_keys }
+ end
end
def new
@ssh_key = current_user.ssh_keys.new
end
-
+ # respond_to do |format|
+ # if @event.save
+ # flash[:notice] = 'Event was successfully created.'
+ # format.html { redirect_to(@event) }
+ # format.xml { render :xml => @event, :status => :created, :location => @event }
+ # else
+ # format.html { render :action => "new" }
+ # format.xml { render :xml => @event.errors, :status => :unprocessable_entity }
+ # end
def create
@ssh_key = current_user.ssh_keys.new
@ssh_key.key = params[:ssh_key][:key]
- if @ssh_key.save
- flash[:notice] = "Key added"
- redirect_to account_path
- else
- render :action => "new"
+
+ respond_to do |format|
+ if @ssh_key.save
+ flash[:notice] = "Key added"
+ format.html { redirect_to account_path }
+ format.xml { render :xml => @ssh_key, :status => :created, :location => account_key_path(@ssh_key) }
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @ssh_key.errors, :status => :unprocessable_entity }
+ end
end
end
def show
@ssh_key = current_user.ssh_keys.find(params[:id])
+
+ respond_to do |format|
+ format.html
+ format.xml { render :xml => @ssh_key }
+ end
end
# can't update keys since yet we'd have to to search/replace through |
| |   |
| 28 | 28 | end |
| 29 | 29 | end |
| 30 | 30 | |
| 31 | describe KeysController, "index.xml" do |
| 32 | |
| 33 | before(:each) do |
| 34 | authorize_as :johan |
| 35 | end |
| 36 | |
| 37 | def do_get |
| 38 | @request.env["HTTP_ACCEPT"] = "application/xml" |
| 39 | get :index |
| 40 | end |
| 41 | |
| 42 | it "requires login" do |
| 43 | authorize_as(nil) |
| 44 | do_get |
| 45 | response.code.to_i.should == 401 |
| 46 | end |
| 47 | |
| 48 | it "GET account/keys is successful" do |
| 49 | do_get |
| 50 | response.should be_success |
| 51 | end |
| 52 | |
| 53 | it "scopes to the current_users keys" do |
| 54 | do_get |
| 55 | response.body.should == users(:johan).ssh_keys.to_xml |
| 56 | end |
| 57 | end |
| 58 | |
| 31 | 59 | describe KeysController, "new" do |
| 32 | 60 | |
| 33 | 61 | before(:each) do |
| … | … | |
| 83 | 83 | end |
| 84 | 84 | end |
| 85 | 85 | |
| 86 | | describe KeysController, "create" do |
| 87 | | |
| 88 | | before(:each) do |
| 89 | | login_as :johan |
| 90 | | end |
| 91 | | |
| 92 | | def valid_key |
| 86 | module KeyStubs |
| 87 | def valid_key |
| 93 | 88 | <<-EOS |
| 94 | 89 | ssh-rsa bXljYWtkZHlpemltd21vY2NqdGJnaHN2bXFjdG9zbXplaGlpZnZ0a3VyZWFz |
| 95 | 90 | c2dkanB4aXNxamxieGVib3l6Z3hmb2ZxZW15Y2FrZGR5aXppbXdtb2NjanRi |
| 96 | 91 | Z2hzdm1xY3Rvc216ZWhpaWZ2dGt1cmVhc3NnZGpweGlzcWpsYnhlYm95emd4 |
| 97 | 92 | Zm9mcWU= foo@example.com |
| 98 | 93 | EOS |
| 99 | | end |
| 94 | end |
| 95 | |
| 96 | def invalid_key |
| 97 | "ooger booger wooger@burger" |
| 98 | end |
| 99 | end |
| 100 | |
| 101 | describe KeysController, "create" do |
| 102 | include KeyStubs |
| 100 | 103 | |
| 101 | | def invalid_key |
| 102 | | "ooger booger wooger@burger" |
| 104 | before(:each) do |
| 105 | login_as :johan |
| 103 | 106 | end |
| 104 | 107 | |
| 105 | 108 | def do_post(opts={}) |
| … | … | |
| 125 | 125 | response.should be_redirect |
| 126 | 126 | end |
| 127 | 127 | end |
| 128 | |
| 129 | describe KeysController, "create.xml" do |
| 130 | include KeyStubs |
| 131 | |
| 132 | before(:each) do |
| 133 | authorize_as :johan |
| 134 | end |
| 135 | |
| 136 | def do_post(opts={}) |
| 137 | @request.env["HTTP_ACCEPT"] = "application/xml" |
| 138 | post :create, :ssh_key => {:key => valid_key}.merge(opts) |
| 139 | end |
| 140 | |
| 141 | it "should require login" do |
| 142 | authorize_as(nil) |
| 143 | do_post |
| 144 | response.code.to_i.should == 401 |
| 145 | end |
| 146 | |
| 147 | it "scopes to the current_user" do |
| 148 | do_post |
| 149 | assigns[:ssh_key].user_id.should == users(:johan).id |
| 150 | end |
| 151 | |
| 152 | it "POST account/keys/create is successful" do |
| 153 | do_post |
| 154 | response.code.to_i.should == 201 |
| 155 | end |
| 156 | end |
| toggle raw diff |
--- a/spec/controllers/keys_controller_spec.rb
+++ b/spec/controllers/keys_controller_spec.rb
@@ -28,6 +28,34 @@ describe KeysController, "index" do
end
end
+describe KeysController, "index.xml" do
+
+ before(:each) do
+ authorize_as :johan
+ end
+
+ def do_get
+ @request.env["HTTP_ACCEPT"] = "application/xml"
+ get :index
+ end
+
+ it "requires login" do
+ authorize_as(nil)
+ do_get
+ response.code.to_i.should == 401
+ end
+
+ it "GET account/keys is successful" do
+ do_get
+ response.should be_success
+ end
+
+ it "scopes to the current_users keys" do
+ do_get
+ response.body.should == users(:johan).ssh_keys.to_xml
+ end
+end
+
describe KeysController, "new" do
before(:each) do
@@ -55,23 +83,26 @@ describe KeysController, "new" do
end
end
-describe KeysController, "create" do
-
- before(:each) do
- login_as :johan
- end
-
- def valid_key
+module KeyStubs
+ def valid_key
<<-EOS
ssh-rsa bXljYWtkZHlpemltd21vY2NqdGJnaHN2bXFjdG9zbXplaGlpZnZ0a3VyZWFz
c2dkanB4aXNxamxieGVib3l6Z3hmb2ZxZW15Y2FrZGR5aXppbXdtb2NjanRi
Z2hzdm1xY3Rvc216ZWhpaWZ2dGt1cmVhc3NnZGpweGlzcWpsYnhlYm95emd4
Zm9mcWU= foo@example.com
EOS
- end
+ end
+
+ def invalid_key
+ "ooger booger wooger@burger"
+ end
+end
+
+describe KeysController, "create" do
+ include KeyStubs
- def invalid_key
- "ooger booger wooger@burger"
+ before(:each) do
+ login_as :johan
end
def do_post(opts={})
@@ -94,3 +125,32 @@ EOS
response.should be_redirect
end
end
+
+describe KeysController, "create.xml" do
+ include KeyStubs
+
+ before(:each) do
+ authorize_as :johan
+ end
+
+ def do_post(opts={})
+ @request.env["HTTP_ACCEPT"] = "application/xml"
+ post :create, :ssh_key => {:key => valid_key}.merge(opts)
+ end
+
+ it "should require login" do
+ authorize_as(nil)
+ do_post
+ response.code.to_i.should == 401
+ end
+
+ it "scopes to the current_user" do
+ do_post
+ assigns[:ssh_key].user_id.should == users(:johan).id
+ end
+
+ it "POST account/keys/create is successful" do
+ do_post
+ response.code.to_i.should == 201
+ end
+end |