Permalink
Browse files

Fix Project.find for unknown ids.

  • Loading branch information...
1 parent 9c7050d commit b68e7fa7eb4d8dfd770de171d9fa75764c708547 @KL-7 KL-7 committed Apr 19, 2012
Showing with 21 additions and 1 deletion.
  1. +1 −1 app/models/project.rb
  2. +16 −0 test/integration/app_test.rb
  3. +4 −0 test/unit/project_test.rb
@@ -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

0 comments on commit b68e7fa

Please sign in to comment.