Skip to content

Commit

Permalink
Merge branch 'pull-requests' of github.com:travis-ci/travis-ci into p…
Browse files Browse the repository at this point in the history
…ull-requests
  • Loading branch information
Sven Fuchs committed Apr 16, 2012
2 parents d49d7fd + 600c041 commit 463b295
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 40 deletions.
8 changes: 1 addition & 7 deletions app/controllers/builds_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@ def repository
end

def builds_type
base = repository.builds.includes('request')

if params['event_type'] == 'pull_requests'
base.pull_requests
else
base.pushes
end
repository.builds.for_event_type(params['event_type'])
end

def builds
Expand Down
15 changes: 7 additions & 8 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@

[Repository, Commit, Request, Build].each{ |klass| klass.reset_column_information }

10.times do
repository = FactoryGirl.create(:seed_repository)
10.times do
repository = FactoryGirl.create(:seed_repository)

50.times do
build = FactoryGirl.create(:seed_build, :repository => repository)
end

repository.last_build_id = repository.last_build.id
repository.save
50.times do
build = FactoryGirl.create(:seed_build, :repository => repository)
end

repository.last_build_id = repository.last_build.id
repository.save
end
end
4 changes: 3 additions & 1 deletion spec/javascripts/helpers/factories.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Test.Factory = {
last_build_number: '1',
last_build_result: '0',
last_build_started_at: '2011-01-01T01:00:10Z',
last_build_finished_at: '2011-01-01T01:00:20Z'
last_build_finished_at: '2011-01-01T01:00:20Z',
event_type: 'push'
}, 1);
return Travis.store.find(Travis.Repository, 1);
},
Expand Down Expand Up @@ -70,6 +71,7 @@ Test.Factory = {
author_name: 'Alex P',
author_email: 'alexp@coffeenco.de',
compare_url: 'https://github.com/travis-ci/travis-ci/compare/fe64573...3d1e844',
event_type: 'push',
matrix: [
{
id: 2,
Expand Down
11 changes: 9 additions & 2 deletions spec/javascripts/models/build_spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
describe('Build', function() {
describe('class methods', function() {
describe('byRepositoryId', function() {
describe('pushesByRepositoryId', function() {
it('requests GET /repositories.json', function() {
Travis.Build.byRepositoryId(1);
Travis.Build.pushesByRepositoryId(1);
expect(mostRecentAjaxRequest().url).toEqual('/repositories/1/builds.json?bare=true');
});
});

describe('pullRequestsByRepositoryId', function() {
it('requests GET /repositories.json', function() {
Travis.Build.pullRequestsByRepositoryId(1);
expect(mostRecentAjaxRequest().url).toEqual('/repositories/1/builds.json?bare=true&event_type=pull_requests');
});
});

describe('createOrUpdate', function() {
it('calls createOrUpdate for each of the matrix builds, too', function() {
var build = Travis.Build.createOrUpdate({ id: 99, number: '1', matrix: [{ id: 2, number: '1.1' }]});
Expand Down
1 change: 1 addition & 0 deletions spec/support/factories/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
end

factory :commit do
repository { Repository.first || Factory(:repository) }
commit '62aae5f70ceee39123ef'
branch 'master'
message 'the commit message'
Expand Down
44 changes: 22 additions & 22 deletions spec/support/factories/forged_factories.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
FactoryGirl.define do
factory :seed_repository, :class => Repository do
name { Forgery(:repository).name }
url { Forgery(:repository).url }
owner_name { Forgery(:repository).owner_name }
owner_email { Forgery(:repository).owner_email }
last_duration { Forgery(:repository).duration }
created_at { Forgery(:repository).time }
updated_at { Forgery(:repository).time }
name { Forgery(:repository).name }
url { Forgery(:repository).url }
owner_name { Forgery(:repository).owner_name }
owner_email { Forgery(:repository).owner_email }
last_duration { Forgery(:repository).duration }
created_at { Forgery(:repository).time }
updated_at { Forgery(:repository).time }
end

factory :seed_commit, :class => Commit do
commit { Forgery(:commit).commit }
branch { Forgery(:commit).branch }
message { Forgery(:commit).message }
committed_at { Forgery(:repository).time }
committer_name { Forgery(:commit).commiter_name }
committer_email { Forgery(:commit).commiter_email }
author_name { Forgery(:commit).commiter_name }
author_email { Forgery(:commit).commiter_email }
compare_url { Forgery(:commit).compare_url }
commit { Forgery(:commit).commit }
branch { Forgery(:commit).branch }
message { Forgery(:commit).message }
committed_at { Forgery(:repository).time }
committer_name { Forgery(:commit).commiter_name }
committer_email { Forgery(:commit).commiter_email }
author_name { Forgery(:commit).commiter_name }
author_email { Forgery(:commit).commiter_email }
compare_url { Forgery(:commit).compare_url }
end


Expand All @@ -27,12 +27,12 @@
end

factory :seed_build, :class=> Build do
config { Forgery(:build).config }
commit { Factory(:seed_commit) }
started_at { Forgery(:repository).time }
finished_at { Forgery(:repository).time }
state "finished"
status { rand(2) }
config { Forgery(:build).config }
commit { |b| Factory(:seed_commit, repository: b.repository) }
started_at { Forgery(:repository).time }
finished_at { Forgery(:repository).time }
state "finished"
status { rand(2) }

after_build do |build|
build.request = Factory(:seed_request, :repository => build.repository, :commit => build.commit)
Expand Down

0 comments on commit 463b295

Please sign in to comment.