Skip to content

Commit

Permalink
Merge pull request #11 from KL-7/fix-non-existent-projects
Browse files Browse the repository at this point in the history
Fix Project.find for unknown ids.
  • Loading branch information
holman committed Apr 19, 2012
2 parents df867f2 + b68e7fa commit 280392c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/project.rb
Expand Up @@ -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.
Expand Down
16 changes: 16 additions & 0 deletions test/integration/app_test.rb
Expand Up @@ -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
4 changes: 4 additions & 0 deletions test/unit/project_test.rb
Expand Up @@ -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 280392c

Please sign in to comment.