teamcity 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.travis.yml +3 -0
  4. data/.yardopts +1 -0
  5. data/CHANGELOG.md +83 -0
  6. data/Gemfile +4 -0
  7. data/Guardfile +9 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +194 -0
  10. data/Rakefile +1 -0
  11. data/lib/faraday/null_response_body.rb +17 -0
  12. data/lib/teamcity.rb +26 -0
  13. data/lib/teamcity/api.rb +19 -0
  14. data/lib/teamcity/client.rb +16 -0
  15. data/lib/teamcity/client/build_types.rb +305 -0
  16. data/lib/teamcity/client/builds.rb +92 -0
  17. data/lib/teamcity/client/common.rb +23 -0
  18. data/lib/teamcity/client/projects.rb +159 -0
  19. data/lib/teamcity/client/tests.rb +24 -0
  20. data/lib/teamcity/client/vcs_roots.rb +70 -0
  21. data/lib/teamcity/configuration.rb +51 -0
  22. data/lib/teamcity/connection.rb +28 -0
  23. data/lib/teamcity/element_builder.rb +27 -0
  24. data/lib/teamcity/headers.rb +47 -0
  25. data/lib/teamcity/request.rb +35 -0
  26. data/lib/teamcity/version.rb +3 -0
  27. data/spec/cassettes/BuildTypes/DELETE/_delete_agent_requirement/should_delete_the_agent_requirement.yml +83 -0
  28. data/spec/cassettes/BuildTypes/DELETE/_delete_buildtype/should_delete_a_buildtype.yml +40 -0
  29. data/spec/cassettes/BuildTypes/DELETE/_delete_buildtype_parameter/should_delete_a_buildtype_parameter.yml +81 -0
  30. data/spec/cassettes/BuildTypes/GET/_buildtype/should_fetch_the_details_of_a_buildtype_by_id.yml +89 -0
  31. data/spec/cassettes/BuildTypes/GET/_buildtype/should_raise_an_error_if_the_buildtype_does_not_exist.yml +52 -0
  32. data/spec/cassettes/BuildTypes/GET/_buildtype_agent_requirements/should_fetch_the_build_configuration_agent_requirements_for_a_buildtype.yml +46 -0
  33. data/spec/cassettes/BuildTypes/GET/_buildtype_agent_requirements/should_return_an_array.yml +46 -0
  34. data/spec/cassettes/BuildTypes/GET/_buildtype_agent_requirements/should_return_nil_if_there_are_no_agent_requirements_defined.yml +46 -0
  35. data/spec/cassettes/BuildTypes/GET/_buildtype_artifact_dependencies/should_fetch_the_build_configuration_artifact_dependencies_for_a_buildtype.yml +46 -0
  36. data/spec/cassettes/BuildTypes/GET/_buildtype_artifact_dependencies/should_return_an_array.yml +46 -0
  37. data/spec/cassettes/BuildTypes/GET/_buildtype_artifact_dependencies/should_return_nil_if_there_are_no_artifact_dependencies_defined.yml +46 -0
  38. data/spec/cassettes/BuildTypes/GET/_buildtype_branches/should_fetch_vcs_branches_the_vcs_root_is_configured_to_use.yml +46 -0
  39. data/spec/cassettes/BuildTypes/GET/_buildtype_features/should_fetch_the_build_configuration_features_for_a_buildtype.yml +46 -0
  40. data/spec/cassettes/BuildTypes/GET/_buildtype_features/should_return_an_array.yml +46 -0
  41. data/spec/cassettes/BuildTypes/GET/_buildtype_features/should_return_nil_if_there_are_no_features_defined.yml +46 -0
  42. data/spec/cassettes/BuildTypes/GET/_buildtype_investigations/should_get_investigation_details.yml +48 -0
  43. data/spec/cassettes/BuildTypes/GET/_buildtype_investigations/should_return_nil_if_no_one_is_investigating.yml +46 -0
  44. data/spec/cassettes/BuildTypes/GET/_buildtype_parameters/should_fetch_the_build_configuration_parameters_for_a_buildtype.yml +46 -0
  45. data/spec/cassettes/BuildTypes/GET/_buildtype_parameters/should_return_an_array.yml +46 -0
  46. data/spec/cassettes/BuildTypes/GET/_buildtype_parameters/should_return_nil_if_there_are_no_parameters_defined.yml +46 -0
  47. data/spec/cassettes/BuildTypes/GET/_buildtype_settings/should_fetch_the_settings_for_a_given_buildtype.yml +89 -0
  48. data/spec/cassettes/BuildTypes/GET/_buildtype_settings/should_return_an_array.yml +89 -0
  49. data/spec/cassettes/BuildTypes/GET/_buildtype_snapshot_dependencies/should_fetch_the_build_configuration_snapshot_dependencies_for_a_buildtype.yml +46 -0
  50. data/spec/cassettes/BuildTypes/GET/_buildtype_snapshot_dependencies/should_return_an_array.yml +46 -0
  51. data/spec/cassettes/BuildTypes/GET/_buildtype_snapshot_dependencies/should_return_nil_if_there_are_no_snapshot_dependencies_defined.yml +46 -0
  52. data/spec/cassettes/BuildTypes/GET/_buildtype_state/should_fetch_the_state_of_the_buildtype.yml +89 -0
  53. data/spec/cassettes/BuildTypes/GET/_buildtype_steps/should_fetch_the_build_configuration_steps_for_a_buildtype.yml +47 -0
  54. data/spec/cassettes/BuildTypes/GET/_buildtype_steps/should_return_an_array.yml +46 -0
  55. data/spec/cassettes/BuildTypes/GET/_buildtype_steps/should_return_nil_if_there_are_no_steps_defined.yml +46 -0
  56. data/spec/cassettes/BuildTypes/GET/_buildtype_template/should_return_nil_if_the_buildtype_is_not_associated_with_a_template.yml +52 -0
  57. data/spec/cassettes/BuildTypes/GET/_buildtype_template/should_return_the_attributes_of_the_associated_template.yml +46 -0
  58. data/spec/cassettes/BuildTypes/GET/_buildtype_triggers/should_fetch_the_build_configuration_triggers_for_a_buildtype.yml +46 -0
  59. data/spec/cassettes/BuildTypes/GET/_buildtype_triggers/should_return_an_array.yml +46 -0
  60. data/spec/cassettes/BuildTypes/GET/_buildtype_triggers/should_return_nil_if_there_are_no_triggers_defined.yml +46 -0
  61. data/spec/cassettes/BuildTypes/GET/_buildtype_vcs_root_entries/should_fetch_the_build_configuration_vcs_root_entries_for_a_buildtype.yml +47 -0
  62. data/spec/cassettes/BuildTypes/GET/_buildtype_vcs_root_entries/should_return_an_array.yml +47 -0
  63. data/spec/cassettes/BuildTypes/GET/_buildtype_vcs_root_entries/should_return_nil_if_there_are_no_vcs_root_entries_defined.yml +46 -0
  64. data/spec/cassettes/BuildTypes/GET/_buildtypes/should_fetch_all_the_buildtypes.yml +46 -0
  65. data/spec/cassettes/BuildTypes/POST/_attach_vcs_root/should_attach_a_vcs_root_to_a_buildtype.yml +47 -0
  66. data/spec/cassettes/BuildTypes/POST/_create_agent_requirement/should_create_an_agent_requirement_for_a_buildtype.yml +46 -0
  67. data/spec/cassettes/BuildTypes/POST/_create_build_step/should_create_a_build_step_for_a_given_build_type.yml +46 -0
  68. data/spec/cassettes/BuildTypes/POST/_create_build_trigger/should_create_a_build_trigger_for_a_given_build_type.yml +46 -0
  69. data/spec/cassettes/BuildTypes/POST/_create_buildtype/should_create_a_build_type.yml +86 -0
  70. data/spec/cassettes/BuildTypes/PUT/_set_build_step_field/should_disable_a_build_step.yml +44 -0
  71. data/spec/cassettes/BuildTypes/PUT/_set_build_step_field/should_enable_a_build_step.yml +48 -0
  72. data/spec/cassettes/BuildTypes/PUT/_set_buildtype_field/should_pause_a_project.yml +44 -0
  73. data/spec/cassettes/BuildTypes/PUT/_set_buildtype_field/should_set_a_projects_description.yml +44 -0
  74. data/spec/cassettes/BuildTypes/PUT/_set_buildtype_field/should_set_the_buildtype_name.yml +44 -0
  75. data/spec/cassettes/BuildTypes/PUT/_set_buildtype_parameter/should_set_a_buildtype_parameter.yml +44 -0
  76. data/spec/cassettes/BuildTypes/PUT/_set_buildtype_setting/should_set_if_it_should_perform_clean_builds.yml +46 -0
  77. data/spec/cassettes/BuildTypes/PUT/_set_buildtype_setting/should_set_what_is_the_timeout_in_minutes_when_executing_builds.yml +46 -0
  78. data/spec/cassettes/BuildTypes/PUT/_set_buildtype_setting/should_set_where_the_checkout_happens_when_building.yml +46 -0
  79. data/spec/cassettes/Builds/DELETE/_unpin_build/should_unpin_a_build.yml +83 -0
  80. data/spec/cassettes/Builds/GET/_build/should_fetch_the_build_details.yml +91 -0
  81. data/spec/cassettes/Builds/GET/_build/should_raise_an_error_if_the_build_does_not_exist.yml +53 -0
  82. data/spec/cassettes/Builds/GET/_build_artifacts/should_fetch_all_the_artifacts.yml +89 -0
  83. data/spec/cassettes/Builds/GET/_build_pinned_/should_return_false_when_a_build_is_not_pinned.yml +126 -0
  84. data/spec/cassettes/Builds/GET/_build_pinned_/should_return_true_when_a_build_is_pinned.yml +126 -0
  85. data/spec/cassettes/Builds/GET/_build_statistics/should_return_statistics_for_a_build.yml +89 -0
  86. data/spec/cassettes/Builds/GET/_build_tags/should_fetch_the_build_tags.yml +89 -0
  87. data/spec/cassettes/Builds/GET/_build_tags/should_return_an_empty_array_if_there_are_no_build_tags_defined_for_a_build.yml +89 -0
  88. data/spec/cassettes/Builds/GET/_builds/should_allow_you_to_filter_by_multiple_build_locators.yml +46 -0
  89. data/spec/cassettes/Builds/GET/_builds/should_allow_you_to_filter_results_by_build_locators.yml +46 -0
  90. data/spec/cassettes/Builds/GET/_builds/should_fetch_all_the_builds.yml +46 -0
  91. data/spec/cassettes/Builds/GET/_builds/should_return_an_empty_array_if_no_results_are_found.yml +46 -0
  92. data/spec/cassettes/Builds/PUT/_pin_build/should_pin_a_build.yml +83 -0
  93. data/spec/cassettes/Projects/DELETE/_delete_project/should_delete_a_project.yml +82 -0
  94. data/spec/cassettes/Projects/DELETE/_delete_project_parameter/should_delete_a_project_parameter.yml +123 -0
  95. data/spec/cassettes/Projects/GET/_parent_project/should_fetch_the_parent_project_for_a_given_project.yml +46 -0
  96. data/spec/cassettes/Projects/GET/_parent_project/should_return_nil_if_there_is_no_parent_project_for_a_given_project.yml +46 -0
  97. data/spec/cassettes/Projects/GET/_project/should_fetch_a_single_project_by_id.yml +47 -0
  98. data/spec/cassettes/Projects/GET/_project/should_raise_an_error_if_the_project_does_not_exist.yml +52 -0
  99. data/spec/cassettes/Projects/GET/_project_buildtypes/should_fetch_all_the_buildTypes_for_a_project.yml +46 -0
  100. data/spec/cassettes/Projects/GET/_project_buildtypes/should_return_nil_if_the_project_does_not_have_any_build_types.yml +46 -0
  101. data/spec/cassettes/Projects/GET/_project_parameters/should_fetch_all_the_paramters_for_a_given_project.yml +46 -0
  102. data/spec/cassettes/Projects/GET/_project_parameters/should_return_nil_if_there_are_no_parameters_defined_for_a_project.yml +46 -0
  103. data/spec/cassettes/Projects/GET/_projects/should_fetch_projects.yml +46 -0
  104. data/spec/cassettes/Projects/POST/_copy_project/should_copy_a_project.yml +135 -0
  105. data/spec/cassettes/Projects/POST/_create_project/should_create_a_project.yml +45 -0
  106. data/spec/cassettes/Projects/PUT/_set_parent_project/should_set_a_parent_project_for_a_given_project.yml +134 -0
  107. data/spec/cassettes/Projects/PUT/_set_project_field/should_archive_a_project.yml +86 -0
  108. data/spec/cassettes/Projects/PUT/_set_project_field/should_set_a_projects_description.yml +86 -0
  109. data/spec/cassettes/Projects/PUT/_set_project_field/should_set_a_projects_name.yml +86 -0
  110. data/spec/cassettes/Projects/PUT/_set_project_parameter/should_set_a_project_parameter.yml +86 -0
  111. data/spec/cassettes/Tests/GET/_tests/should_allow_you_to_filter_by_test_id.yml +49 -0
  112. data/spec/cassettes/Tests/GET/_tests/should_allow_you_to_filter_results_by_test_count_locator.yml +55 -0
  113. data/spec/cassettes/Tests/GET/_tests/should_fetch_all_the_tests.yml +60 -0
  114. data/spec/cassettes/Tests/GET/_tests/should_return_an_empty_array_if_no_build_is_found.yml +51 -0
  115. data/spec/cassettes/Tests/GET/_tests/should_return_an_empty_array_if_no_test_is_found.yml +51 -0
  116. data/spec/cassettes/Tests/GET/_tests/should_return_an_empty_array_if_not_build_is_given.yml +51 -0
  117. data/spec/cassettes/VCSRoots/GET/_vcs_root_details/should_fetch_the_vcs_root_details.yml +91 -0
  118. data/spec/cassettes/VCSRoots/GET/_vcs_roots/should_fetch_vcs_roots.yml +47 -0
  119. data/spec/cassettes/VCSRoots/POST/_create_vcs_root/should_create_a_git_vcs_root_that_is_shared_with_the_project_and_sub-projects.yml +89 -0
  120. data/spec/cassettes/VCSRoots/POST/_create_vcs_root/should_create_a_subversion_vcs_root_that_is_shared_with_the_project_and_sub-projects.yml +89 -0
  121. data/spec/cassettes/VCSRoots/PUT/_set_vcs_root_field/should_set_a_vcs_modification_check_interval.yml +179 -0
  122. data/spec/faraday/null_response_body_spec.rb +18 -0
  123. data/spec/spec_helper.rb +22 -0
  124. data/spec/support/vcr_setup.rb +9 -0
  125. data/spec/teamcity/api_spec.rb +64 -0
  126. data/spec/teamcity/client/builds_spec.rb +113 -0
  127. data/spec/teamcity/client/buildtypes_spec.rb +308 -0
  128. data/spec/teamcity/client/projects_spec.rb +207 -0
  129. data/spec/teamcity/client/tests_spec.rb +47 -0
  130. data/spec/teamcity/client/vcs_roots_spec.rb +86 -0
  131. data/spec/teamcity/client_spec.rb +14 -0
  132. data/spec/teamcity/element_builder_spec.rb +30 -0
  133. data/spec/teamcity/headers_spec.rb +43 -0
  134. data/spec/teamcity/version_spec.rb +7 -0
  135. data/spec/teamcity_spec.rb +89 -0
  136. data/teamcity.gemspec +26 -0
  137. metadata +344 -0
@@ -0,0 +1,113 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe 'Builds' do
4
+
5
+ before(:each) do
6
+ @tc = TeamCity
7
+ configure_client_with_authentication
8
+ end
9
+
10
+ # Get requests
11
+ describe 'GET', :vcr do
12
+
13
+ before(:each) do
14
+ @buildtype_id = 'BuildTests_GetBuildTests'
15
+ end
16
+
17
+ describe '.builds' do
18
+ it 'should fetch all the builds' do
19
+ builds = @tc.builds
20
+ builds.should have_at_least(1).items
21
+ end
22
+
23
+ it 'should allow you to filter results by build locators' do
24
+ @tc.builds(count:1).should have(1).items
25
+ end
26
+
27
+ it 'should allow you to filter by multiple build locators' do
28
+ @tc.builds(count: 2, status: 'SUCCESS').should have(2).items
29
+ end
30
+
31
+ it 'should return an empty array if no results are found' do
32
+ @tc.builds(tags: 'return-empty-result').should be_empty
33
+ end
34
+ end
35
+
36
+ describe '.build' do
37
+ it 'should fetch the build details' do
38
+ build_id = @tc.builds.first.id
39
+ @tc.build(id: build_id).id.should eq(build_id)
40
+ end
41
+
42
+ it 'should raise an error if the build does not exist' do
43
+ expect { @tc.build(id: 'doesnotexist') }.to raise_error
44
+ end
45
+
46
+ it 'should raise an error if an id is not provided' do
47
+ expect { @tc.build }.to raise_exception(ArgumentError)
48
+ end
49
+ end
50
+
51
+ describe '.build_tags' do
52
+ it 'should fetch the build tags' do
53
+ build = @tc.builds(tags: 'tag-test').first
54
+ tags = @tc.build_tags(id: build.id)
55
+ tags.should include('tag-test')
56
+ end
57
+
58
+ it 'should return an empty array if there are no build tags defined for a build' do
59
+ build = @tc.builds.first
60
+ @tc.build_tags(id: build.id).should be_empty
61
+ end
62
+ end
63
+
64
+ describe '.build_pinned?', :vcr do
65
+ it 'should return true when a build is pinned' do
66
+ build_to_pin = @tc.builds.first
67
+ @tc.pin_build(build_to_pin.id)
68
+ @tc.build_pinned?(build_to_pin.id).should be_true
69
+ end
70
+
71
+ it 'should return false when a build is not pinned' do
72
+ build_to_unpin = @tc.builds.first
73
+ @tc.unpin_build(build_to_unpin.id)
74
+ @tc.build_pinned?(build_to_unpin.id).should be_false
75
+ end
76
+ end
77
+
78
+ describe '.build_statistics' do
79
+ it 'should return statistics for a build' do
80
+ build = @tc.builds.first
81
+ results = @tc.build_statistics(build.id)
82
+ results.should have_at_least(1).items
83
+ end
84
+ end
85
+
86
+ describe '.build_artifacts' do
87
+ it 'should fetch all the artifacts' do
88
+ build = @tc.builds.first
89
+ artifacts = @tc.build_artifacts(build.id)
90
+ artifacts.should have_at_least(2).items
91
+ end
92
+ end
93
+ end
94
+
95
+ describe 'PUT', :vcr do
96
+ describe '.pin_build' do
97
+ it 'should pin a build' do
98
+ build_to_pin = @tc.builds.first
99
+ comment = 'this will add a comment'
100
+ @tc.pin_build(build_to_pin.id, comment).should be_nil
101
+ end
102
+ end
103
+ end
104
+
105
+ describe 'DELETE', :vcr do
106
+ describe '.unpin_build' do
107
+ it 'should unpin a build' do
108
+ build_to_unpin = @tc.builds.first
109
+ @tc.unpin_build(build_to_unpin.id).should be_nil
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,308 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe 'BuildTypes' do
4
+
5
+ before(:each) do
6
+ @tc = TeamCity
7
+ end
8
+
9
+ after(:all) do
10
+ TeamCity.reset
11
+ end
12
+
13
+ # Get requests
14
+ describe 'GET', :vcr do
15
+
16
+ before(:each) do
17
+ TeamCity.reset
18
+ TeamCity.configure do |config|
19
+ config.endpoint = 'http://localhost:8111/guestAuth/app/rest'
20
+ end
21
+ @tc = TeamCity
22
+ end
23
+
24
+ describe '.buildtypes' do
25
+ it 'should fetch all the buildtypes' do
26
+ build_types = @tc.buildtypes
27
+ build_types.should_not be_empty
28
+ end
29
+ end
30
+
31
+ describe '.buildtype' do
32
+ it 'should fetch the details of a buildtype by id' do
33
+ build_type = @tc.buildtypes[0]
34
+ @tc.buildtype(id: build_type.id).id.should_not be_empty
35
+ end
36
+
37
+ it 'should raise an error if the buildtype does not exist' do
38
+ expect { @tc.buildtype(id: 'missing') }.to raise_error
39
+ end
40
+
41
+ it 'should raise an error if an id is not provided' do
42
+ expect { @tc.buildtype }.to raise_error
43
+ end
44
+ end
45
+
46
+ describe '.buildtype_branches' do
47
+ it 'should fetch vcs branches the vcs root is configured to use' do
48
+ buildtype_id = 'BuildTypeTests_GetBuildTypeConfigTests'
49
+ @tc.buildtype_branches(buildtype_id).first.name.should eq('refs/heads/master')
50
+ end
51
+ end
52
+
53
+ describe '.buildtype_state' do
54
+ it 'should fetch the state of the buildtype' do
55
+ build_type = @tc.buildtypes[0]
56
+ @tc.buildtype_state(id: build_type.id).should eq('false')
57
+ end
58
+ end
59
+
60
+ describe '.buildtype_settings' do
61
+
62
+ before(:each) do
63
+ @build_type = @tc.buildtypes[0]
64
+ end
65
+
66
+ it 'should fetch the settings for a given buildtype' do
67
+ @tc.buildtype_settings(id: @build_type.id).should_not be_empty
68
+ end
69
+
70
+ it 'should return an array' do
71
+ @tc.buildtype_settings(id: @build_type.id).should be_kind_of(Array)
72
+ end
73
+ end
74
+
75
+ describe '.buildtype_template' do
76
+ it 'should return the attributes of the associated template' do
77
+ @tc.buildtype_template(id: 'BuildTypeTests_BuildTypeWithTemplate').id.should_not be_nil
78
+ end
79
+
80
+ it 'should return nil if the buildtype is not associated with a template' do
81
+ @tc.buildtype_template(id: 'BuildTypeTests_BuildTypeWithNoTemplate').should be_nil
82
+ end
83
+ end
84
+
85
+ [
86
+ :parameters,
87
+ :steps,
88
+ :features,
89
+ :triggers,
90
+ :agent_requirements,
91
+ :snapshot_dependencies,
92
+ :artifact_dependencies,
93
+ :vcs_root_entries
94
+ ].each do |type|
95
+ describe ".buildtype_#{type}" do
96
+
97
+ before(:each) do
98
+ @method_name = "buildtype_#{type}"
99
+ @buildtype_id_with_settings = 'BuildTypeTests_GetBuildTypeConfigTests'
100
+ @buildtype_id_with_no_settings = 'BuildTypeTests_GetBuildTypeEmptyConfigTests'
101
+ end
102
+
103
+ it "should fetch the build configuration #{type} for a buildtype" do
104
+ @tc.send(@method_name, id: @buildtype_id_with_settings).should have_at_least(1).items
105
+ end
106
+
107
+ it 'should return an array' do
108
+ @tc.send(@method_name, id: @buildtype_id_with_settings).should be_kind_of(Array)
109
+ end
110
+
111
+ it "should return nil if there are no #{type} defined" do
112
+ @tc.send(@method_name, id: @buildtype_id_with_no_settings).should be_empty
113
+ end
114
+ end
115
+ end
116
+
117
+ describe '.buildtype_investigations' do
118
+ before(:each) do
119
+ configure_client_with_authentication
120
+ end
121
+
122
+ it 'should get investigation details' do
123
+ @tc.buildtype_investigations('BuildTypeTests_GetBuildTypeWithInvestigations').should_not be_empty
124
+ end
125
+
126
+ it 'should return nil if no one is investigating' do
127
+ @tc.buildtype_investigations('BuildTypeTests_GetBuildTypeWithNoInvestigations').should be_empty
128
+ end
129
+ end
130
+ end
131
+
132
+ describe 'PUT', :vcr do
133
+
134
+ before(:all) do
135
+ configure_client_with_authentication
136
+ end
137
+
138
+ describe '.set_buildtype_parameter' do
139
+ it 'should set a buildtype parameter' do
140
+ buildtype_id = 'BuildTypeTests_PutSetBuildTypeParameters'
141
+ param_name = 'test-setting-buildtype-parameters'
142
+ param_value = 'param-value'
143
+ @tc.set_buildtype_parameter(buildtype_id, param_name, param_value).should eq(param_value)
144
+ end
145
+ end
146
+
147
+ describe '.set_buildtype_field' do
148
+ before(:each) do
149
+ @buildtype_id = 'BuildTypeTests_PutSetBuildTypeField'
150
+ end
151
+
152
+ it 'should set the buildtype name' do
153
+ field_name = 'name'
154
+ field_value = 'PutSetBuildTypeField_Name_Changed_By_Test'
155
+ @tc.set_buildtype_field(@buildtype_id, field_name, field_value).should eq(field_value)
156
+ end
157
+
158
+ it 'should set a projects description' do
159
+ field_name = 'description'
160
+ field_value = 'description-set_buildtype_field'
161
+ @tc.set_buildtype_field(@buildtype_id, field_name, field_value).should eq(field_value)
162
+ end
163
+
164
+ it 'should pause a project' do
165
+ field_name = 'paused'
166
+ field_value = 'true'
167
+ @tc.set_buildtype_field(@buildtype_id, field_name, field_value).should eq(field_value)
168
+ end
169
+ end
170
+
171
+ describe '.set_buildtype_setting' do
172
+ before(:each) do
173
+ @buildtype_id = 'BuildTypeTests_PutSetBuildTypeSettings'
174
+ end
175
+
176
+ it 'should set if it should perform clean builds' do
177
+ settings_name = 'cleanBuild'
178
+ settings_value = 'true'
179
+ @tc.set_buildtype_setting(@buildtype_id, settings_name, settings_value).should eq(settings_value)
180
+ end
181
+
182
+ it 'should set where the checkout happens when building' do
183
+ settings_name = 'checkoutMode'
184
+ settings_value = 'ON_AGENT'
185
+ @tc.set_buildtype_setting(@buildtype_id, settings_name, settings_value).should eq(settings_value)
186
+ end
187
+
188
+ it 'should set what is the timeout in minutes when executing builds' do
189
+ settings_name = 'executionTimeoutMin'
190
+ settings_value = '10'
191
+ @tc.set_buildtype_setting(@buildtype_id, settings_name, settings_value).should eq(settings_value)
192
+ end
193
+ end
194
+
195
+ describe '.set_build_step_field' do
196
+ before(:each) do
197
+ @buildtype_id = 'BuildTypeTests_PutSetBuildStepField'
198
+ @build_step_id = 'RUNNER_7'
199
+ end
200
+
201
+ it 'should disable a build step' do
202
+ field_name = 'disabled'
203
+ field_value = 'true'
204
+ @tc.set_build_step_field(@buildtype_id, @build_step_id, field_name, field_value)
205
+ end
206
+
207
+ it 'should enable a build step' do
208
+ field_name = 'disabled'
209
+ field_value = 'false'
210
+ @tc.set_build_step_field(@build_type_id, @build_step_id, field_name, field_value)
211
+ end
212
+ end
213
+ end
214
+
215
+ describe 'POST', :vcr do
216
+ before(:all) do
217
+ configure_client_with_authentication
218
+ end
219
+
220
+ before(:each) do
221
+ @buildtype_id = 'BuildTypeTests_PostBuildTypeTests'
222
+ end
223
+
224
+ describe '.create_buildtype' do
225
+ it 'should create a build type' do
226
+ project_id = 'ProjectToTestBuildTypes'
227
+ buildtype_name = 'PostCreateBuildType'
228
+ buildtype_id = "#{project_id}_#{buildtype_name}"
229
+ @tc.create_project(project_id)
230
+ response = @tc.create_buildtype(project_id, buildtype_name)
231
+ response.id.should eq(buildtype_id)
232
+ end
233
+ end
234
+
235
+ describe '.attach_vcs_root' do
236
+ it 'should attach a vcs root to a buildtype' do
237
+ vcs_root_id = 'teamcity_ruby_client'
238
+ @tc.attach_vcs_root(@buildtype_id, vcs_root_id).id.should eq(vcs_root_id)
239
+ end
240
+ end
241
+
242
+ describe '.create_agent_requirement' do
243
+ it 'should create an agent requirement for a buildtype' do
244
+ parameter_name = 'post-agent-requirement-name'
245
+ parameter_value = 'post-agent-requirement-value'
246
+ condition = 'equals'
247
+ args = [@buildtype_id, parameter_name, parameter_value, condition]
248
+ response = @tc.create_agent_requirement(*args)
249
+ response.id.should eq(parameter_name)
250
+ end
251
+ end
252
+
253
+ describe '.create_build_step' do
254
+ it 'should create a build step for a given build type' do
255
+ response = @tc.create_build_step(@buildtype_id, name: 'Unit Tests', type: 'Maven') do |properties|
256
+ properties['goals'] = 'verify'
257
+ properties['mavenSelection'] = 'mavenSelection:default'
258
+ properties['pomLocation'] = 'pom.xml'
259
+ end
260
+ response.name.should eq('Unit Tests')
261
+ end
262
+ end
263
+
264
+ describe '.create_build_trigger' do
265
+ it 'should create a build trigger for a given build type' do
266
+ response = @tc.create_build_trigger(@buildtype_id, type: 'vcsTrigger') do |properties|
267
+ properties['groupCheckkinsByCommitter'] = 'true'
268
+ properties['perCheckinTriggering'] = 'true'
269
+ properties['quietPeriodMode'] = 'DO_NOT_USE'
270
+ end
271
+ response.type.should eq('vcsTrigger')
272
+ end
273
+ end
274
+ end
275
+
276
+ describe 'DELETE', :vcr do
277
+ before(:all) do
278
+ configure_client_with_authentication
279
+ end
280
+
281
+ before(:each) do
282
+ @buildtype_id = 'BuildTypeTests_DeleteBuildTypeSettings'
283
+ end
284
+
285
+ describe '.delete_buildtype_parameter' do
286
+ it 'should delete a buildtype parameter' do
287
+ param_to_delete = 'delete-buildtype-param'
288
+ @tc.set_buildtype_parameter(@buildtype_id, param_to_delete, '')
289
+ @tc.delete_buildtype_parameter(@buildtype_id, 'delete-me').should be_nil
290
+ end
291
+ end
292
+
293
+ describe '.delete_agent_requirement' do
294
+ it 'should delete the agent requirement' do
295
+ agent_requirement_to_delete = 'delete-agent-requirement'
296
+ @tc.create_agent_requirement(@buildtype_id, agent_requirement_to_delete, '', 'equals')
297
+ @tc.delete_agent_requirement(@buildtype_id, agent_requirement_to_delete).should be_nil
298
+ end
299
+ end
300
+
301
+ describe '.delete_buildtype' do
302
+ it 'should delete a buildtype' do
303
+ project_id_to_delete = 'BuildTypeTests_DeleteBuildTypeRequest'
304
+ @tc.delete_buildtype(project_id_to_delete).should be_nil
305
+ end
306
+ end
307
+ end
308
+ end
@@ -0,0 +1,207 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe 'Projects' do
4
+
5
+ before(:each) do
6
+ @tc = TeamCity
7
+ end
8
+
9
+ after(:all) do
10
+ TeamCity.reset
11
+ end
12
+
13
+ # GET requests
14
+ describe 'GET', :vcr do
15
+
16
+ before(:all) do
17
+ TeamCity.configure do |config|
18
+ config.endpoint = 'http://localhost:8111/guestAuth/app/rest'
19
+ end
20
+ end
21
+
22
+ before(:each) do
23
+ @tc = TeamCity
24
+ end
25
+
26
+ describe '.projects' do
27
+ it 'should fetch projects' do
28
+ @tc.projects.should_not be_nil
29
+ end
30
+ end
31
+
32
+ describe '.project' do
33
+
34
+ it 'should fetch a single project by id' do
35
+ @tc.project(id: 'GetProjectRequest').should_not be_nil
36
+ end
37
+
38
+ it 'should raise an error if the project does not exist' do
39
+ expect { @tc.project(id: 'missing') }.to raise_error
40
+ end
41
+
42
+ it 'should raise an error if an id is not provided' do
43
+ expect { @tc.project }.to raise_error
44
+ end
45
+ end
46
+
47
+
48
+ describe '.project_buildtypes' do
49
+
50
+ it 'should fetch all the buildTypes for a project' do
51
+ bts = @tc.project_buildtypes(id: 'GetProjectBuildTypes')
52
+ bts.each do |bt|
53
+ bt.projectId.should eq('GetProjectBuildTypes')
54
+ end
55
+ end
56
+
57
+ it 'should return nil if the project does not have any build types' do
58
+ bts = @tc.project_buildtypes(id: 'GetProjectWithNoBuildTypes')
59
+ bts.should be_empty
60
+ end
61
+ end
62
+
63
+ describe '.project_parameters' do
64
+ it 'should fetch all the paramters for a given project' do
65
+ parameters = @tc.project_parameters(id: 'GetProjectWithParameters')
66
+ parameters.size.should_not eq(0)
67
+ end
68
+
69
+ it 'should return nil if there are no parameters defined for a project' do
70
+ parameters = @tc.project_parameters(id: 'GetProjectWithNoParameters')
71
+ parameters.should be_empty
72
+ end
73
+
74
+ it 'should raise an error if the project does not exist' do
75
+ expect { @tc.project_parameters(id: 'missing')}
76
+ end
77
+ end
78
+
79
+ describe '.parent_project' do
80
+ it 'should fetch the parent project for a given project' do
81
+ parent = @tc.parent_project(id: 'GetProjectWithParent').should_not be_nil
82
+ end
83
+
84
+ it 'should return nil if there is no parent project for a given project' do
85
+ parent = @tc.parent_project(id: 'GetProjectWithNoParent').should be_nil
86
+ end
87
+
88
+ it 'should raise an error if the project does not exist' do
89
+ expect { @tc.parent_project(id: 'missing') }
90
+ end
91
+ end
92
+ end
93
+
94
+ # POST Requests
95
+ describe 'POST', :vcr do
96
+
97
+ before(:all) do
98
+ configure_client_with_authentication
99
+ end
100
+
101
+ describe '.create_project' do
102
+ it 'should create a project' do
103
+ response = @tc.create_project('PostCreateProject')
104
+ response.id.should eq('PostCreateProject')
105
+ end
106
+ end
107
+
108
+ describe '.copy_project' do
109
+ it 'should copy a project' do
110
+ @tc.create_project('PostProjectToBeCopied')
111
+ source_project = @tc.project(id: 'PostProjectToBeCopied')
112
+ copied_project_name = 'PostCopyProject'
113
+ response = @tc.copy_project(
114
+ source_project.id,
115
+ copied_project_name,
116
+ :copyAllAssociatedSettings => true
117
+ )
118
+ response.name.should eq(copied_project_name)
119
+ end
120
+ end
121
+ end
122
+
123
+ describe 'DELETE', :vcr do
124
+
125
+ before(:all) do
126
+ configure_client_with_authentication
127
+ end
128
+
129
+ describe '.delete_project' do
130
+ it 'should delete a project' do
131
+ response = @tc.create_project('ProjectToDelete')
132
+ @tc.delete_project(response.id).should be_nil
133
+ end
134
+ end
135
+
136
+ describe '.delete_project_parameter' do
137
+ it 'should delete a project parameter' do
138
+ project_id = 'DeleteProjectParameters'
139
+ param_to_delete = 'delete-this-param'
140
+ @tc.create_project(project_id)
141
+ @tc.set_project_parameter(project_id, param_to_delete, 'delete-me')
142
+ response = @tc.delete_project_parameter(project_id, param_to_delete)
143
+ response.should be_nil
144
+ end
145
+ end
146
+ end
147
+
148
+ describe 'PUT', :vcr do
149
+
150
+ before(:all) do
151
+ configure_client_with_authentication
152
+ end
153
+
154
+ describe '.set_project_parameter' do
155
+ it 'should set a project parameter' do
156
+ project_id = 'PutCreateProjectParam'
157
+ param_name = 'set-with-param'
158
+ param_value = 'some-value'
159
+ @tc.create_project(project_id)
160
+ @tc.set_project_parameter(project_id, param_name, param_value).should eq(param_value)
161
+ end
162
+ end
163
+
164
+ describe '.set_project_field' do
165
+ it 'should set a projects name' do
166
+ project_id = 'PutSetProjectNameField'
167
+ @tc.create_project(project_id)
168
+ field_value = 'PutNewProjectName'
169
+ @tc.set_project_field(project_id, 'name', field_value).should eq(field_value)
170
+ end
171
+
172
+ it 'should set a projects description' do
173
+ project_id = 'PutSetProjectDescriptionField'
174
+ @tc.create_project(project_id)
175
+ field_value = 'description-changed-by-test'
176
+ @tc.set_project_field(project_id, 'description', field_value).should eq(field_value)
177
+ end
178
+
179
+ it 'should archive a project' do
180
+ project_id = 'PutSetProjectArchiveField'
181
+ @tc.create_project(project_id)
182
+ field_value = 'true'
183
+ @tc.set_project_field(project_id, 'archived', field_value).should eq(field_value)
184
+ end
185
+ end
186
+
187
+ describe '.set_parent_project' do
188
+ it 'should set a parent project for a given project' do
189
+ project_id = 'PutSetParentProject'
190
+ @tc.create_project(project_id)
191
+
192
+ parent_project_id = 'PutParentProject'
193
+ @tc.create_project(parent_project_id)
194
+
195
+ @tc.set_parent_project(project_id, parent_project_id)['id'].should eq(project_id)
196
+ end
197
+
198
+ it 'should raise an error if the parent project does not exist' do
199
+ expect { @tc.parent_project('GetProjectWithoutParent', 'missing') }.to raise_error
200
+ end
201
+
202
+ it 'should raise an error if the child project does not exist' do
203
+ expect { @tc.parent_project('missing', 'GetParentProject') }.to raise_error
204
+ end
205
+ end
206
+ end
207
+ end