| | 86 | def test_prepare_cloning |
| | 87 | original = create_new_project(:name => 'Some Project', :template => 'mod_rails', :description => "Dr. Foo") |
| | 88 | my = create_new_project(:template => 'mongrel_rails') |
| | 89 | |
| | 90 | my.prepare_cloning(original) |
| | 91 | assert_equal "Clone of Some Project", my.name |
| | 92 | assert_equal "Clone of Some Project: Dr. Foo", my.description |
| | 93 | assert_equal original.template, my.template |
| | 94 | end |
| | 95 | |
| | 96 | def test_clone |
| | 97 | # setup |
| | 98 | original = create_new_project(:name => 'Some Project', :template => 'mod_rails') |
| | 99 | 3.times do |i| |
| | 100 | create_new_project_configuration(:project => original, :name => "#{i}-project-conf", :value => "value-#{i}") |
| | 101 | end |
| | 102 | stage_1 = create_new_stage(:project => original, :name => 'test') |
| | 103 | create_new_stage_configuration(:stage => stage_1, :name => "stage1-conf", :value => "stage1-value") |
| | 104 | stage_2 = create_new_stage(:project => original, :name => 'prod') |
| | 105 | create_new_stage_configuration(:stage => stage_2, :name => "stage2-conf", :value => "stage2-value") |
| | 106 | recipe = create_new_recipe |
| | 107 | stage_1.recipes << recipe |
| | 108 | |
| | 109 | new_project = create_new_project |
| | 110 | new_project.clone(original) |
| | 111 | |
| | 112 | # check project configuration |
| | 113 | assert_equal original.configuration_parameters.count, new_project.configuration_parameters.count |
| | 114 | new_project.configuration_parameters.each_with_index do |conf, i| |
| | 115 | orig = original.configuration_parameters.find_by_name(conf.name) |
| | 116 | |
| | 117 | if conf.name == 'application' |
| | 118 | assert_match 'some_project',conf.value |
| | 119 | else |
| | 120 | assert_equal orig.name, conf.name |
| | 121 | assert_equal orig.value, conf.value |
| | 122 | assert_equal orig.prompt_on_deploy, conf.prompt_on_deploy |
| | 123 | end |
| | 124 | end |
| | 125 | |
| | 126 | # check stages |
| | 127 | assert_equal 2, new_project.stages.count |
| | 128 | cloned_stage_1 = new_project.stages.find_by_name("test") |
| | 129 | cloned_stage_2 = new_project.stages.find_by_name("prod") |
| | 130 | assert_equal stage_1.configuration_parameters.first.name, cloned_stage_1.configuration_parameters.first.name |
| | 131 | assert_equal stage_1.configuration_parameters.first.value, cloned_stage_1.configuration_parameters.first.value |
| | 132 | assert_equal stage_2.configuration_parameters.first.name, cloned_stage_2.configuration_parameters.first.name |
| | 133 | assert_equal stage_2.configuration_parameters.first.value, cloned_stage_2.configuration_parameters.first.value |
| | 134 | assert_equal [recipe], cloned_stage_1.recipes |
| | 135 | end |
| | 136 | |