Fix Project.find for unknown ids. #11

Merged
merged 1 commit into from Apr 19, 2012
View
@@ -67,7 +67,7 @@ def self.create(url)
# Returns the Project.
def self.find(id)
hash = $redis.hgetall("#{Project.key}:#{id}")
- new(hash['url'])
+ new(hash['url']) if hash.has_key?('url')
end
# Finds a Project by name.
@@ -30,4 +30,20 @@
get "/projects/#{project.id}"
assert_match 'holman/play', last_response.body.strip
end
+
+ test '/projects/jump' do
+ project = Project.new('github.com/holman/play')
+ project.save
+ get "/projects/jump", :url => 'https://github.com/holman/play'
+
+ assert last_response.redirect?
+ assert_match "/projects/#{project.id}", last_response.location
+ end
+
+ test '/projects/jump (with non-existent project url)' do
+ get "/projects/jump", :url => 'https://github.com/non/existent'
+
+ assert last_response.redirect?
+ assert_match "/projects", last_response.location
+ end
end
@@ -165,4 +165,8 @@
@project.save
assert_equal @project.url, Project.find(@project.id).url
end
+
+ test 'find (with non-existent id)' do
+ assert_nil Project.find('123')
+ end
end