travis-ci/travis-ci — Issue #389: BuildsController#show should return a 404
Author: tenderlove
Created: 2012-01-17 22:45:25+00:00
State: open

Hi,

Right now, BuildsController will return a build even if build it looks up is not part of the repository. It should return a 404. I think that [this line](https://github.com/travis-ci/travis-ci/blob/master/app/controllers/builds_controller.rb#L34) should read something like `repository.builds.find(params[:id])`. I tried to fix it, but it was too hard for me.

I think this is a valid test case:

```patch

diff --git a/spec/controllers/builds_controller_spec.rb b/spec/controllers/builds_controller_spec.rb
index 155738d..03daf10 100644
--- a/spec/controllers/builds_controller_spec.rb
+++ b/spec/controllers/builds_controller_spec.rb
@@ -16,8 +16,17 @@ describe BuildsController do

describe 'GET :show' do
it 'returns build details in json' do
- get :show, :repository_id => repository.id, :id => builds.first.id, :format => :json
+ build = repository.builds.first
+ get :show, :repository_id => repository.id, :id => build.id, :format => :json
json_response.should == json_for_http(builds.first)
end
+
+ it 'returns 404 with wrong repoid' do
+ repoid = repository.id + 1
+ lambda {
+ get :show, :repository_id => repoid, :id => builds.first.id, :format => :json
+ }.should_raise ActiveRecord::RecordNotFound
+ response.status.should == 404
+ end
end
end
```