# HG changeset patch # User Jakob Skjerning # Date 1249307428 -7200 # Node ID 55f2042ef79597c7684bd65efcdadd278a58ede1 # Parent 5b0e96544a07193d5527314efa52c39b9702b177 There is no need to fetch_changesets for all repositories - just need to fetch them for the repository in question, and only if it's a Git repository diff -r 5b0e96544a07193d5527314efa52c39b9702b177 -r 55f2042ef79597c7684bd65efcdadd278a58ede1 app/controllers/github_hook_controller.rb --- a/app/controllers/github_hook_controller.rb Mon Aug 03 16:56:52 2009 +0200 +++ b/app/controllers/github_hook_controller.rb Mon Aug 03 15:50:28 2009 +0200 @@ -20,7 +20,7 @@ exec(command) # Fetch the new changesets into Redmine - Repository.fetch_changesets + repository.fetch_changesets render(:text => 'OK') end diff -r 5b0e96544a07193d5527314efa52c39b9702b177 -r 55f2042ef79597c7684bd65efcdadd278a58ede1 test/functional/github_hook_controller_test.rb --- a/test/functional/github_hook_controller_test.rb Mon Aug 03 16:56:52 2009 +0200 +++ b/test/functional/github_hook_controller_test.rb Mon Aug 03 15:50:28 2009 +0200 @@ -48,9 +48,11 @@ }' @project = Project.first @repository = Repository::Git.new - @project.stubs(:repository).returns(@repository) + @repository.stubs(:fetch_changesets).returns(true) + @project.expects(:repository).at_least(1).returns(@repository) @controller.stubs(:exec) Project.stubs(:find_by_identifier).with('github').returns(@project) + Repository.expects(:fetch_changesets).never end def do_post(payload = nil) @@ -76,6 +78,13 @@ assert_equal 'OK', @response.body end + def test_should_fetch_changesets_into_the_repository + @repository.expects(:fetch_changesets).returns(true) + do_post + assert_response :success + assert_equal 'OK', @response.body + end + def test_should_return_404_if_project_not_found assert_raises ActiveRecord::RecordNotFound do Project.expects(:find_by_identifier).with('foobar').returns(nil) @@ -83,8 +92,8 @@ end end - def test_should_return_404_if_project_has_no_repository - assert_raises ActiveRecord::RecordNotFound do + def test_should_return_500_if_project_has_no_repository + assert_raises TypeError do project = mock('project') project.expects(:repository).returns(nil) Project.expects(:find_by_identifier).with('github').returns(project)