Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #11 from KL-7/fix-non-existent-projects

Fix Project.find for unknown ids.
  • Loading branch information...
commit 280392c02895b6b76b7f84e11ccd80e91ceea514 2 parents df867f2 + b68e7fa
@holman authored
View
2  app/models/project.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.
View
16 test/integration/app_test.rb
@@ -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
View
4 test/unit/project_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.