Permalink
Browse files

Fixed problems listing servers with no IP.

  • Loading branch information...
1 parent a27fbde commit 6dc577702991dde32e6d26656a2a58421e7006da @fcoury fcoury committed Oct 10, 2010
View
3 lib/stackfu/commands/list_command.rb
@@ -26,8 +26,9 @@ class << self
validated = ""
end
+ ip = item.respond_to?(:ip) ? item.ip : ""
- [item.slug, item._id, item.ip, validated, last_seen]
+ [item.slug, item._id, ip, validated, last_seen]
end,
"You have no servers yet. You can add new servers to your account in http://stackfu.com."
],
View
13 spec/fixtures/fcoury.json
@@ -0,0 +1,13 @@
+HTTP/1.1 200 OK
+Content-Type: application/json; charset=utf-8
+Transfer-Encoding: chunked
+Connection: keep-alive
+Status: 200
+X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 2.2.15
+ETag: "b3cf4272f7ca0a6ae42a7857a0d2f320"
+X-UA-Compatible: IE=Edge,chrome=1
+X-Runtime: 0.009943
+Cache-Control: max-age=0, private, must-revalidate
+Server: nginx/0.7.67 + Phusion Passenger 2.2.15 (mod_rails/mod_rack)
+
+{"slug":"fcoury","name":"Felipe Coury","encrypted_password":"$2a$10$oLUOcTB7KLW9.QtgvDSxJuLi7GsWlLoNu6mN1S8XZ.R1prGYjMfye","company":"Webbynode","location":"Campinas, SP, Brazil","created_at":"2010-09-06T20:19:34-04:00","updated_at":"2010-09-16T16:03:24-04:00","last_sign_in_ip":"69.172.231.32","last_sign_in_at":"2010-09-16T16:03:14-04:00","_id":"4c8585167d7c425923000003","sign_in_count":30540,"password_salt":"$2a$10$oLUOcTB7KLW9.QtgvDSxJu","website":"http://felipecoury.com","remember_token":"RaKFlotbuKfseiMRKWoa","following_user_ids":["4c8abb277d7c4212aa00033b"],"current_sign_in_ip":"208.88.124.171","authentication_token":"znwcz2xEJVDnUu2xJRFb","remember_created_at":"2010-09-16T10:47:33-04:00","current_sign_in_at":"2010-09-16T16:03:24-04:00","watched_stack_ids":[],"login":"fcoury","confirmation_password":"r4nd0mp4ssf0rth3w1n","watched_script_ids":["4c8585167d7c425923000008","4c85b7e77d7c425a8a00000a","4c8666a97d7c4261a3000006","4c8672bd7d7c4261a3000198","4c88ea567d7c420655000004","4c88eda37d7c420662000135","4c8585167d7c425923000014","4c8a84ad7d7c4212aa000011","4c8a85b07d7c4212aa00001c","4c8a85c17d7c4212aa000025","4c8a86937d7c4212aa0000a5","4c8a87817d7c4212aa000112","4c8b87d77d7c4217a6000006","4c8b88b77d7c4217a600004d","4c8b92e77d7c4217b30000b8","4c8bab3d7d7c421ca8000066","4c8bb2bb7d7c421cc7000090","4c8bb3737d7c421ec400001a","4c8bb4767d7c421cc70000a5","4c8bc9087d7c422038000007","4c8bd1df7d7c422045000018","4c8bd45e7d7c422045000046","4c8bd5427d7c42204500005e","4c8bd8557d7c422290000034","4c8bded67d7c422559000003","4c8bdfc77d7c42256700001e","4c8be3107d7c4226c3000008","4c8c0f037d7c4226c300002c","4c8be47a7d7c4226c3000022","4c885b3f7d7c420354000009","4c9031a97d7c424684000003","4c9040cb7d7c42496800001c","4c9134767d7c424eed000015","4c921b587d7c4252cb000003","4c921c697d7c4252cb000007","4c922df97d7c425401000003","4c9255d97d7c42542b000008"],"member_since":"2010-09-06","form_type":"settings","followed_user_ids":["4c8585167d7c425923000004","4c8abb277d7c4212aa00033b"],"email":"felipe.coury@gmail.com"}
View
12 spec/fixtures/servers/no_ip.json
@@ -0,0 +1,12 @@
+HTTP/1.1 200 OK
+Etag: "b68cbf1eec558ebda6d5489e18e4c5c7"
+Connection: Keep-Alive
+Content-Type: application/json; charset=utf-8
+Date: Mon, 06 Sep 2010 18:44:12 GMT
+Server: WEBrick/1.3.1 (Ruby/1.8.7/2009-12-24)
+X-Runtime: 0.587104
+Content-Length: 1034
+Cache-Control: max-age=0, private, must-revalidate
+Set-Cookie: _stackfu_session=BAh7ByIPc2Vzc2lvbl9pZCIlZDE4NTAwMmE4ZGQ3OWZiNDE4Nzg4NDU3ZmUzMGUwYWMiGXdhcmRlbi51c2VyLnVzZXIua2V5WwciCVVzZXJvOhNCU09OOjpPYmplY3RJRAY6CkBkYXRhWxFpUWkBg2kB%2FmkkaQHUaQGJaQHoaQGTaQGPaQBpAGkI--770ce6221b6798c4f1bd8903b1e8b1f2b767ba48; path=/; HttpOnly
+
+[{"slug":"webbynode","name":"Webbynode","created_at":"2010-09-05T17:31:27-03:00","updated_at":"2010-09-06T15:43:43-03:00","_id":"4c83fe1fd489e8938f000017","provider_name":"Linnode","user_id":"4c83fe1fd489e8938f000003","last_checked_in":"2010-09-06T15:43:43-03:00","description":"Nunc hendrerit blandit ultrices. Cras pellentesque turpis et dolo\n molestie vitae lacinia nisi iaculis. Pellentesque vitae quam enim. Vivamus dui quam,\n aliquet in condimentum vel, placerat sit amet quam. Aliquam ac sollicitudin dui."},{"slug":"mydog","name":"MyDog","created_at":"2010-09-05T17:31:27-03:00","updated_at":"2010-09-06T15:43:43-03:00","_id":"4c83fe1fd489e8938f000018","provider_name":"Rackspace","user_id":"4c83fe1fd489e8938f000003","ip":"123.45.678.91","last_checked_in":"2010-09-06T15:43:43-03:00","description":"Nulla gravida lacus nec sapien ornare ullamcorper varius ipsum venenatis.\n Duis sit amet turpis risus, id venenatis neque. Vestibulum ultrices condimentum mi ac elementum.\n Sed vitae velit dui. Integer ac urna erat."}]
View
13 spec/fixtures/users/fcoury.json
@@ -0,0 +1,13 @@
+HTTP/1.1 200 OK
+Content-Type: application/json; charset=utf-8
+Transfer-Encoding: chunked
+Connection: keep-alive
+Status: 200
+X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 2.2.15
+ETag: "ba683de741937a8ad5f1ddf681d7ba3a"
+X-UA-Compatible: IE=Edge,chrome=1
+X-Runtime: 0.010493
+Cache-Control: max-age=0, private, must-revalidate
+Server: nginx/0.7.67 + Phusion Passenger 2.2.15 (mod_rails/mod_rack)
+
+{"slug":"fcoury","name":"Felipe Coury","encrypted_password":"$2a$10$oLUOcTB7KLW9.QtgvDSxJuLi7GsWlLoNu6mN1S8XZ.R1prGYjMfye","company":"Webbynode","location":"Campinas, SP, Brazil","created_at":"2010-09-06T20:19:34-04:00","updated_at":"2010-09-16T16:04:24-04:00","last_sign_in_ip":"69.172.231.32","last_sign_in_at":"2010-09-16T16:04:15-04:00","_id":"4c8585167d7c425923000003","sign_in_count":30544,"password_salt":"$2a$10$oLUOcTB7KLW9.QtgvDSxJu","website":"http://felipecoury.com","remember_token":"RaKFlotbuKfseiMRKWoa","following_user_ids":["4c8abb277d7c4212aa00033b"],"current_sign_in_ip":"208.88.124.171","authentication_token":"znwcz2xEJVDnUu2xJRFb","remember_created_at":"2010-09-16T10:47:33-04:00","current_sign_in_at":"2010-09-16T16:04:24-04:00","watched_stack_ids":[],"login":"fcoury","confirmation_password":"r4nd0mp4ssf0rth3w1n","watched_script_ids":["4c8585167d7c425923000008","4c85b7e77d7c425a8a00000a","4c8666a97d7c4261a3000006","4c8672bd7d7c4261a3000198","4c88ea567d7c420655000004","4c88eda37d7c420662000135","4c8585167d7c425923000014","4c8a84ad7d7c4212aa000011","4c8a85b07d7c4212aa00001c","4c8a85c17d7c4212aa000025","4c8a86937d7c4212aa0000a5","4c8a87817d7c4212aa000112","4c8b87d77d7c4217a6000006","4c8b88b77d7c4217a600004d","4c8b92e77d7c4217b30000b8","4c8bab3d7d7c421ca8000066","4c8bb2bb7d7c421cc7000090","4c8bb3737d7c421ec400001a","4c8bb4767d7c421cc70000a5","4c8bc9087d7c422038000007","4c8bd1df7d7c422045000018","4c8bd45e7d7c422045000046","4c8bd5427d7c42204500005e","4c8bd8557d7c422290000034","4c8bded67d7c422559000003","4c8bdfc77d7c42256700001e","4c8be3107d7c4226c3000008","4c8c0f037d7c4226c300002c","4c8be47a7d7c4226c3000022","4c885b3f7d7c420354000009","4c9031a97d7c424684000003","4c9040cb7d7c42496800001c","4c9134767d7c424eed000015","4c921b587d7c4252cb000003","4c921c697d7c4252cb000007","4c922df97d7c425401000003","4c9255d97d7c42542b000008"],"member_since":"2010-09-06","form_type":"settings","followed_user_ids":["4c8585167d7c425923000004","4c8abb277d7c4212aa00033b"],"email":"felipe.coury@gmail.com"}
View
12 spec/fixtures/users/fcoury/mongodb.json
@@ -0,0 +1,12 @@
+HTTP/1.1 200 OK
+X-Ua-Compatible: IE=Edge,chrome=1
+Etag: "d2b971e4380435ff92bffc46c8f13642"
+Connection: Keep-Alive
+Content-Type: application/json; charset=utf-8
+Date: Thu, 16 Sep 2010 20:11:36 GMT
+Server: WEBrick/1.3.1 (Ruby/1.8.7/2009-12-24)
+X-Runtime: 0.561455
+Content-Length: 1570
+Cache-Control: max-age=0, private, must-revalidate
+
+{"name":"mongodb","controls":[{"label":"Ports","name":"ports","_id":"4c9250ccd489e8625d00000a","_type":"Textbox","type":"Textbox","hint":"separate by comma's"}],"slug":"mongodb","created_at":"2010-09-16T17:15:56Z","updated_at":"2010-09-16T17:15:56Z","_id":"4c9250ccd489e8625d00000d","validations":[{"body":"test -x ufw","_id":"4c9250cbd489e8625d000002","_type":"ExecutableExists","params":{"data":"ufw"},"description":"File ufw exists and is executable"}],"user_id":"4c9250cbd489e8625d000003","requirements":[{"body":"test -x apt-get","_id":"4c9250cbd489e8625d000001","_type":"ExecutableExists","params":{"data":"apt-get"},"description":"File apt-get exists and is executable"}],"executions":[{"body":" # \n # configure_ufw.sh\n # Tue Dec 01 15:06:48 -0200 2009\n #\n\n apt-get update\n apt-get install -y ufw\n","_id":"4c9250ccd489e8625d00000b","_type":"Executable","description":"Install Ufw"},{"body":" # \n # install_ufw.sh\n # Tue Dec 01 15:06:48 -0200 2009\n #\n\n ufw default deny\n <% ports.split(\",\").each do |port| %>\n ufw allow <%= port %> \n <% end %>\n","_id":"4c9250ccd489e8625d00000c","_type":"Executable","description":"Configure Ufw"}],"description":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n In et erat sem, at pellentesque augue. Aliquam tincidunt viverra mauris,\n non auctor nibh pretium ac. Phasellus dapibus interdum rutrum. Nunc eget\n felis sed nulla porta elementum. Proin nec tortor sit amet turpis scelerisque ullamcorper.","watching_user_ids":[]}
View
24 spec/spec_helper.rb
@@ -23,34 +23,30 @@ def read_fixture(file)
File.read(File.join(File.dirname(__FILE__), "fixtures", file))
end
+ def url(uri)
+ if StackFu::API =~ /(https*):\/\/(.*)/
+ return "#{$1}://abc123:X@#{$2}#{uri}"
+ end
+ end
+
def prepare_raise(method, uri, error)
- request = stub_request(method,
- "#{StackFu::API.gsub("http://", "http://abc123:X@")}#{uri}")
+ request = stub_request(method, "#{url(uri)}")
request.to_raise(error)
end
def prepare_multi(method, uri, *fixtures)
- d "#{StackFu::API.gsub("http://", "http://abc123:X@")}#{uri}"
- d fixtures.map { |f| read_fixture(f) }
-
- request = stub_request(method,
- "#{StackFu::API.gsub("http://", "http://abc123:X@")}#{uri}")
-
+ request = stub_request(method, "#{url(uri)}")
request.to_return(fixtures.map { |f| read_fixture(f) })
end
def prepare(method, uri, fixture=uri, options=nil)
- request = stub_request(method,
- "#{StackFu::API.gsub("http://", "http://abc123:X@")}#{uri}")
-
+ request = stub_request(method, "#{url(uri)}")
request = request.with(options) if options
-
request.to_return(read_fixture(fixture))
end
def prepare_status(method, uri, status)
- request = stub_request(method,
- "#{StackFu::API.gsub("http://", "http://abc123:X@")}#{uri}")
+ request = stub_request(method, "#{url(uri)}")
request.to_return(:status => status)
end
View
12 spec/stackfu/commands/list_command_spec.rb
@@ -50,4 +50,16 @@
stdout.should =~ /123.45.678.90/
stdout.should =~ /123.45.678.91/
end
+
+ it "shows blank when ip isn't present" do
+ prepare(:get, '/servers.json', 'servers/no_ip.json')
+ prepare(:get, '/scripts.json', 'scripts/none.json')
+
+ command "list"
+
+ stdout.should =~ /Listing 2 servers/
+ stdout.should =~ /webbynode/
+ stdout.should =~ /mydog/
+ stdout.should =~ /123.45.678.91/
+ end
end

0 comments on commit 6dc5777

Please sign in to comment.