Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/thoughtworks/cruisecontrol.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
mrduncan committed Sep 18, 2009
2 parents 0d09fc2 + 5f695bd commit 46bce7f
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 157 deletions.
46 changes: 44 additions & 2 deletions app/models/project.rb
Expand Up @@ -9,9 +9,25 @@ class << self
attr_accessor :current_project

def all(dir=CRUISE_DATA_ROOT + "/projects")
Projects.new(dir).load_all
load_all(dir).map do |project_dir|
load_project project_dir
end
end


def create(project_name, scm, dir=CRUISE_DATA_ROOT + "/projects")
returning(Project.new(project_name, scm)) do |project|
raise "Project named #{project.name.inspect} already exists in #{dir}" if Project.all(dir).include?(project)
begin
save_project(project, dir)
checkout_local_copy(project)
write_config_example(project)
rescue
FileUtils.rm_rf "#{dir}/#{project.name}"
raise
end
end
end

def plugin(plugin_name)
self.plugin_names << plugin_name unless RAILS_ENV == 'test' or self.plugin_names.include? plugin_name
end
Expand Down Expand Up @@ -42,6 +58,32 @@ def load_project(dir)
project.path = dir
end
end

private

def load_all(dir)
Dir["#{dir}/*"].find_all {|child| File.directory?(child)}.sort
end

def save_project(project, dir)
project.path = File.join(dir, project.name)
FileUtils.mkdir_p project.path
end

def checkout_local_copy(project)
work_dir = File.join(project.path, 'work')
FileUtils.mkdir_p work_dir
project.source_control.checkout
end

def write_config_example(project)
config_example = File.join(RAILS_ROOT, 'config', 'cruise_config.rb.example')
config_in_subversion = File.join(project.path, 'work', 'cruise_config.rb')
cruise_config = File.join(project.path, 'cruise_config.rb')
if File.exists?(config_example) and not File.exists?(config_in_subversion)
FileUtils.cp(config_example, cruise_config)
end
end
end

def initialize(name, scm = nil)
Expand Down
57 changes: 0 additions & 57 deletions app/models/projects.rb

This file was deleted.

2 changes: 1 addition & 1 deletion script/add_project
Expand Up @@ -70,7 +70,7 @@ begin

source_control = SourceControl.create(scm_options)

Project.all << Project.new(project_name, source_control)
Project.create(project_name, source_control)

if source_control.repository =~ /^svn\+ssh\:\/\//
puts "IMPORTANT!!! - It looks like you are connecting to your repository with an svn+ssh connection. " +
Expand Down
2 changes: 1 addition & 1 deletion test/functional/projects_controller_test.rb
Expand Up @@ -185,7 +185,7 @@ def test_build_should_request_build
project = create_project_stub('two')
Project.expects(:find).with('two').returns(project)
project.expects(:request_build)
Project.stubs(:load_all).returns [ project ]
Project.stubs(:all).returns [ project ]
post :build, :id => "two"
assert_response :success
assert_equal 'two', assigns(:project).name
Expand Down
1 change: 1 addition & 0 deletions test/test_helper.rb
Expand Up @@ -2,6 +2,7 @@
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
require 'mocha'
require 'ostruct'

$LOAD_PATH << File.dirname(__FILE__)
require 'file_sandbox'
Expand Down
2 changes: 0 additions & 2 deletions test/unit/application_helper_test.rb
@@ -1,6 +1,4 @@
require File.dirname(__FILE__) + '/../test_helper'
require 'builds_controller'
require "build"

class ApplicationHelperTest < Test::Unit::TestCase

Expand Down
1 change: 0 additions & 1 deletion test/unit/build_status_test.rb
@@ -1,5 +1,4 @@
require File.dirname(__FILE__) + '/../test_helper'
require 'build_status'

class BuildStatusTest < Test::Unit::TestCase
include FileSandbox
Expand Down
2 changes: 0 additions & 2 deletions test/unit/builder_starter_test.rb
@@ -1,6 +1,4 @@
require File.dirname(__FILE__) + '/../test_helper'
require 'builder_starter'
require 'project'

class BuilderStarterTest < Test::Unit::TestCase
include FileSandbox
Expand Down
1 change: 0 additions & 1 deletion test/unit/command_line_test.rb
@@ -1,5 +1,4 @@
require File.dirname(__FILE__) + '/../test_helper'
require 'fileutils'

class CommandLineTest < Test::Unit::TestCase
include FileSandbox
Expand Down
2 changes: 1 addition & 1 deletion test/unit/plugins/build_reaper_test.rb
@@ -1,5 +1,5 @@
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
require 'build_reaper'

class BuildReaperTest < Test::Unit::TestCase
include FileSandbox
include BuildFactory
Expand Down
2 changes: 1 addition & 1 deletion test/unit/plugins/email_notifier_test.rb
Expand Up @@ -23,7 +23,7 @@ def setup
@notifier.emails = ["jeremystellsmith@gmail.com", "jeremy@thoughtworks.com"]
@notifier.from = 'cruisecontrol@thoughtworks.com'

@project.add_plugin(@notifier)
@project.add_plugin(@notifier, :test_email_notifier)
end

def teardown
Expand Down
1 change: 0 additions & 1 deletion test/unit/polling_scheduler_test.rb
@@ -1,4 +1,3 @@
require 'date'
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')

class PollingSchedulerTest < Test::Unit::TestCase
Expand Down
1 change: 0 additions & 1 deletion test/unit/project_config_tracker_test.rb
@@ -1,4 +1,3 @@
require 'date'
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')

class ProjectConfigTrackerTest < Test::Unit::TestCase
Expand Down
59 changes: 46 additions & 13 deletions test/unit/project_test.rb
@@ -1,8 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
require 'date'
require 'ostruct'
require 'email_notifier'
require 'fileutils'

class ProjectTest < ActiveSupport::TestCase
include FileSandbox
Expand Down Expand Up @@ -434,21 +430,19 @@ def test_build_requested
assert @project.build_requested?
end

def test_build_should_generate_new_label_if_same_name_label_exists
def test_build_should_generate_new_label_if_same_name_label_exists
existing_build1 = stub_build('20')
existing_build2 = stub_build('20.1')
new_build = stub_build('20.2')
new_build_with_interesting_number = stub_build('2')

builder_status = Object.new
builder_status.stubs(:build_initiated).returns(true)
BuilderStatus.expects(:new).returns(builder_status)

BuilderStatus.expects(:new).returns stub(:build_initiated => true)

project = Project.new('project1', @svn)
@svn.stubs(:update)
project.stubs(:log_changeset)
project.stubs(:log_changeset)
project.stubs(:builds).returns([existing_build1, existing_build2])
project.stubs(:last_build).returns(nil)
project.stubs(:last_build).returns(nil)
project.stubs(:new_revisions).returns(nil)

Build.expects(:new).with(project, '20.2').returns(new_build)
Expand Down Expand Up @@ -733,7 +727,7 @@ def test_project_all_should_always_reload_project_objects
end
end

test "Projects.load_project should load the project in the given directory" do
test "Project.load_project should load the project in the given directory" do
in_sandbox do |sandbox|
sandbox.new :file => 'one/cruise_config.rb', :with_content => ''

Expand All @@ -744,7 +738,7 @@ def test_project_all_should_always_reload_project_objects
end
end

test "Projects.load_project should load a project without any configuration" do
test "Project.load_project should load a project without any configuration" do
in_sandbox do |sandbox|
sandbox.new :directory => "myproject/work/.svn"
sandbox.new :directory => "myproject/builds-1"
Expand All @@ -757,6 +751,45 @@ def test_project_all_should_always_reload_project_objects
end
end

test "Project.create should add a new project" do
in_sandbox do |sandbox|
Project.create "one", @svn, sandbox.root
Project.create "two", @svn, sandbox.root
assert_equal %w(one two), Project.all(sandbox.root).map(&:name)
end
end

test "Project.create should check out an existing project" do
in_sandbox do |sandbox|
Project.create "one", @svn, sandbox.root
assert SandboxFile.new('one/work').exists?
assert SandboxFile.new('one/work/README').exists?
end
end

test "Project.create should clean up after itself if the source control throws an exception" do
in_sandbox do |sandbox|
@svn.expects(:checkout).raises("svn error")

assert_raise RuntimeError, 'svn error' do
Project.create "one", @svn, sandbox.root
end

assert_false SandboxFile.new('one/work').exists?
assert_false SandboxFile.new('one').exists?
end
end

test "Project.create should not allow you to add the same project twice" do
in_sandbox do |sandbox|
project = Project.create "one", @svn, sandbox.root
assert_raise RuntimeError, "Project named \"one\" already exists in #{sandbox.root}" do
Project.create "one", @svn, sandbox.root
end
assert File.directory?(project.path), "Project directory does not exist."
end
end

private

def stub_build(label)
Expand Down
73 changes: 0 additions & 73 deletions test/unit/projects_test.rb

This file was deleted.

0 comments on commit 46bce7f

Please sign in to comment.