polisher 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/README.rdoc +84 -14
  2. data/Rakefile +21 -19
  3. data/TODO +5 -4
  4. data/bin/server +1 -0
  5. data/config/polisher.yml +0 -15
  6. data/db/connection.rb +13 -10
  7. data/db/migrations/{002_create_managed_gems.rb → 001_create_projects.rb} +4 -5
  8. data/db/migrations/{001_create_sources.rb → 002_create_sources.rb} +1 -3
  9. data/db/migrations/003_create_project_source_versions.rb +28 -0
  10. data/db/migrations/{003_create_events.rb → 004_create_events.rb} +2 -2
  11. data/db/migrations/005_create_project_dependencies.rb +28 -0
  12. data/db/models/event.rb +47 -21
  13. data/db/models/project.rb +110 -0
  14. data/db/models/project_dependency.rb +27 -0
  15. data/db/models/project_source_version.rb +31 -0
  16. data/db/models/source.rb +82 -16
  17. data/lib/common.rb +37 -5
  18. data/lib/dsl.rb +292 -0
  19. data/lib/event_handlers.rb +139 -73
  20. data/lib/gem_adapter.rb +94 -0
  21. data/polisher.rb +302 -50
  22. data/public/stylesheets/style.css +15 -31
  23. data/spec/common_spec.rb +28 -0
  24. data/spec/dsl_spec.rb +357 -0
  25. data/spec/event_handlers_spec.rb +166 -30
  26. data/spec/gem_adapter_spec.rb +89 -0
  27. data/spec/models_spec.rb +635 -107
  28. data/spec/polisher_spec.rb +496 -56
  29. data/views/layout.haml +3 -5
  30. data/views/projects/index.haml +42 -0
  31. data/views/projects/index.html.haml +38 -0
  32. data/views/result.haml +9 -0
  33. data/views/sources/index.haml +24 -41
  34. data/views/sources/index.html.haml +26 -0
  35. metadata +131 -12
  36. data/db/models/managed_gem.rb +0 -111
  37. data/public/javascripts/jquery-1.2.6.min.js +0 -32
  38. data/public/javascripts/polisher.js +0 -15
  39. data/views/gems/index.haml +0 -106
@@ -7,116 +7,534 @@
7
7
  # it under the terms of the GNU Affero General Public License
8
8
  # as published by the Free Software Foundation, either version 3
9
9
  # of the License, or (at your option) any later version.
10
- #
10
+ #
11
11
  # You should have received a copy of the the GNU Affero
12
- # General Public License, along with Polisher. If not, see
12
+ # General Public License, along with Polisher. If not, see
13
13
  # <http://www.gnu.org/licenses/>
14
14
 
15
15
  require File.dirname(__FILE__) + '/spec_helper'
16
16
 
17
+ require 'libxml'
18
+
17
19
  describe "Polisher" do
18
20
 
19
- it "should redirect / to /gems" do
21
+ it "should redirect / to /projects.html" do
20
22
  get '/'
21
23
  last_response.should_not be_ok
22
24
  follow_redirect!
23
- last_request.url.should == "http://example.org/gems"
25
+ last_request.url.should == "http://example.org/projects.html"
26
+ last_response.should be_ok
27
+ end
28
+
29
+ it "should return projects in html format" do
30
+ get '/projects.html'
24
31
  last_response.should be_ok
25
32
  end
26
33
 
27
- it "should respond to /gems" do
28
- get '/gems'
34
+ it "should return projects in xml format" do
35
+ post '/projects/create', :name => 'project-xml-test1'
36
+ post '/projects/create', :name => 'project-xml-test2'
37
+ get '/projects'
29
38
  last_response.should be_ok
39
+
40
+ expect = "<projects>"
41
+ Project.find(:all).each { |p|
42
+ expect += "<project><id>#{p.id}</id><name>#{p.name}</name><versions>"
43
+ p.versions.each { |v|
44
+ expect += "<version><id>#{v}</id><sources>"
45
+ p.project_source_versions_for_version(v).each { |ps|
46
+ expect += "<source><uri>#{ps.source.uri}</uri><version>#{ps.source_version}</version></source>"
47
+ }
48
+ expect += "</sources><events>"
49
+ p.events_for_version(v).each { |e|
50
+ expect += ("<event><process>#{e.process}</process>" +
51
+ "<process_options>#{e.process_options}</process_options>" +
52
+ "<version_qualifier>#{e.version_qualifier}</version_qualifier>" +
53
+ "<version>#{e.version}</version></event>")
54
+ }
55
+ expect += "</events><dependencies>"
56
+ p.dependencies_for_version(v).each { |d|
57
+ expect += ("<dependency><project_id>#{d.depends_on_project.id}</project_id>" +
58
+ "<project_name>#{d.depends_on_project.name}</project_name>" +
59
+ "<project_version>#{d.depends_on_project_version}</project_version>" +
60
+ "</dependency>")
61
+
62
+ }
63
+ expect += "</dependencies></version>"
64
+ }
65
+ expect += "</versions></project>"
66
+ }
67
+ expect += "</projects>"
68
+ last_response.body.gsub(/\s*/, '').should == expect.gsub(/\s*/, '') # ignore whitespace differences
30
69
  end
31
70
 
32
- it "should allow gem creations" do
71
+ it "should allow project creations" do
33
72
  lambda do
34
- post '/gems/create', :name => 'create-gem-test', :source_id => 1
35
- end.should change(ManagedGem, :count).by(1)
36
- follow_redirect!
73
+ post '/projects/create', :name => 'create-project-test'
74
+ end.should change(Project, :count).by(1)
75
+ project = Project.find(:first, :conditions => [ 'name = ?', 'create-project-test'])
76
+ project.should_not be_nil
77
+
37
78
  last_response.should be_ok
38
- last_request.url.should == "http://example.org/gems"
79
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "true"
39
80
  end
40
81
 
41
- it "should allow gem deletions" do
42
- post '/gems/create', :name => 'delete-gem-test', :source_id => 1
82
+ it "should return an error if project name is not specified on creation" do
43
83
  lambda do
44
- delete '/gems/destroy/2'
45
- end.should change(ManagedGem, :count).by(-1)
46
- follow_redirect!
84
+ post '/projects/create'
85
+ end.should_not change(Project, :count)
47
86
  last_response.should be_ok
48
- last_request.url.should == "http://example.org/gems"
87
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
49
88
  end
50
89
 
51
- # run simulate gemcutter api firing process
52
- it "should successfully post-process an updated gem" do
53
- gem = ManagedGem.create :name => 'foobar', :source_id => 1
90
+ it "should return an error if a duplicate project is created" do
91
+ lambda do
92
+ post '/projects/create', :name => 'create-project-test2'
93
+ end.should change(Project, :count).by(1)
94
+
95
+ lambda do
96
+ post '/projects/create', :name => 'create-project-test2'
97
+ end.should_not change(Project, :count)
98
+ last_response.should be_ok
99
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
100
+ end
101
+
102
+ it "should allow project deletions" do
103
+ post '/projects/create', :name => 'delete-project-test'
104
+ project_id = Project.find(:first, :conditions => ['name = ?', 'delete-project-test']).id
105
+ lambda do
106
+ delete "/projects/destroy/#{project_id}"
107
+ end.should change(Project, :count).by(-1)
108
+ last_response.should be_ok
109
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "true"
110
+ end
111
+
112
+ it "should return an error if project id to delete is invalid" do
113
+ lambda do
114
+ delete "/projects/destroy/abc"
115
+ end.should_not change(Project, :count)
116
+ last_response.should be_ok
117
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
118
+ end
54
119
 
55
- event = Event.create :managed_gem => gem,
56
- :process => "integration_test_handler1",
57
- :version_qualifier => '>',
58
- :gem_version => 1.2
120
+ # test triggering release event
121
+ it "should successfully post-process a released project" do
122
+ project = Project.create :name => 'myproj'
59
123
 
60
- event = Event.create :managed_gem => gem,
61
- :process => "integration_test_handler2",
62
- :version_qualifier => '<',
63
- :gem_version => 1.1
124
+ event = Event.create :project => project,
125
+ :process => "integration_test_handler3",
126
+ :version_qualifier => '=',
127
+ :version => "5.6"
64
128
 
65
- post '/gems/updated', :name => 'foobar',
66
- :version => '1.3',
67
- :gem_uri => 'http://gemcutter.org/gems/foobar-1.3.gem'
129
+ event = Event.create :project => project,
130
+ :process => "integration_test_handler4",
131
+ :version_qualifier => '>',
132
+ :version => "7.9"
68
133
 
69
- $integration_test_handler_flags.include?(1).should == true
70
- $integration_test_handler_flags.include?(2).should == false
134
+ post '/projects/released', :name => 'myproj',
135
+ :version => "5.6"
136
+
137
+ last_response.should be_ok
138
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "true"
139
+
140
+ $integration_test_handler_flags.include?(3).should be_true
141
+ $integration_test_handler_flags.include?(4).should be_false
142
+ end
143
+
144
+ it "should return an error if there is a problem in the project release process" do
145
+ project = Project.create :name => 'foobar42'
146
+
147
+ event = Event.create :project => project,
148
+ :process => "failed_event_handler",
149
+ :version_qualifier => '=',
150
+ :version => 1.0
151
+
152
+
153
+ # need to specify name and version
154
+ post '/projects/released', :name => 'foobar42'
155
+ last_response.should be_ok
156
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
157
+
158
+ post '/projects/released', :version => '1.0'
159
+ last_response.should be_ok
160
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
161
+
162
+ # event handler should throw exception, which the app should return
163
+ post '/projects/released', :name => 'foobar42',
164
+ :version => '1.0'
165
+ last_response.should be_ok
166
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
167
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "errors" }.content.strip.should =~ /.*MYERROR.*/
168
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "message" }.content.strip.should =~ /.*MYERROR.*/
169
+ end
170
+
171
+ # test triggering release event
172
+ it "should successfully post-process a released project w/ request params" do
173
+ project = Project.create :name => 'post-process-project2'
174
+
175
+ event = Event.create :project => project,
176
+ :process => "integration_test_handler5",
177
+ :version_qualifier => '=',
178
+ :version => "5.0"
179
+
180
+ post '/projects/released', :name => 'post-process-project2',
181
+ :version => "5.0",
182
+ :xver => "5.0.2-122"
183
+
184
+ $integration_test_handler_flags.include?("xver5.0.2-122").should be_true
71
185
  end
72
186
 
73
- it "should respond to /sources" do
187
+ it "should return sources in html format" do
188
+ get '/sources.html'
189
+ last_response.should be_ok
190
+ end
191
+
192
+ it "should return sources in xml format" do
193
+ post '/sources/create', :name => 'sources-xml-test1', :uri => 'http://foo.uri', :source_type => 'file'
194
+ post '/sources/create', :name => 'sources-xml-test2', :uri => 'http://bar.uri', :source_type => 'file'
74
195
  get '/sources'
75
196
  last_response.should be_ok
197
+
198
+ expect = "<sources>"
199
+ Source.find(:all).each { |s|
200
+ expect += "<source><id>#{s.id}</id><name>#{s.name}</name><source_type>#{s.source_type}</source_type><uri>#{s.uri}</uri><versions>"
201
+ s.versions.each { |v|
202
+ expect += "<version><id>#{v}</id><projects>"
203
+ s.project_source_versions_for_version(v).each { |ps|
204
+ expect += "<project><name>#{ps.project.name}</name><version>#{ps.project_version}</version></project>"
205
+ }
206
+ expect += "</projects></version>"
207
+ }
208
+ expect += "</versions></source>"
209
+ }
210
+ expect += "</sources>"
211
+ last_response.body.gsub(/\s*/, '').should == expect.gsub(/\s*/, '') # ignore whitespace differences
76
212
  end
77
213
 
78
- it "shold allow source creations" do
214
+ it "should allow source creations" do
79
215
  lambda do
80
- post '/sources/create', :name => 'create-source-test', :uri => 'http://example1.org'
216
+ post '/sources/create', :name => 'create-source-test', :uri => 'http://create-source-test.uri', :source_type => 'gem'
81
217
  end.should change(Source, :count).by(1)
82
- follow_redirect!
218
+ project = Source.find(:first, :conditions => [ 'name = ? AND uri = ? AND source_type = ?', 'create-source-test', 'http://create-source-test.uri', 'gem'])
219
+ project.should_not be_nil
220
+
83
221
  last_response.should be_ok
84
- last_request.url.should == "http://example.org/sources"
222
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "true"
223
+ end
224
+
225
+ it "should return an error if source name, uri, or source_type is not specified on creation" do
226
+ lambda do
227
+ post '/sources/create'
228
+ end.should_not change(Source, :count)
229
+ last_response.should be_ok
230
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
231
+
232
+ lambda do
233
+ post '/sources/create', :name => 'invalid-source-test1'
234
+ end.should_not change(Source, :count)
235
+ last_response.should be_ok
236
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
237
+
238
+ lambda do
239
+ post '/sources/create', :name => 'invalid-source-test2', :uri => 'http://invalid-source2.uri'
240
+ end.should_not change(Source, :count)
241
+ last_response.should be_ok
242
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
243
+
244
+ lambda do
245
+ post '/sources/create', :source_type => 'gem'
246
+ end.should_not change(Source, :count)
247
+ last_response.should be_ok
248
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
249
+ end
250
+
251
+ it "should return an error if a duplicate project or other error occurs on creation" do
252
+ lambda do
253
+ post '/sources/create', :name => 'create-source-test42', :uri => "http://create.42", :source_type => "file"
254
+ end.should change(Source, :count).by(1)
255
+
256
+ lambda do
257
+ post '/sources/create', :name => 'create-source-test42', :uri => "http://create.42", :source_type => "file"
258
+ end.should_not change(Source, :count)
259
+ last_response.should be_ok
260
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
261
+
262
+ # invalid source_type
263
+ lambda do
264
+ post '/sources/create', :name => 'create-source-test420', :uri => "http://create.420", :source_type => "xyz"
265
+ end.should_not change(Source, :count)
266
+ last_response.should be_ok
267
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
85
268
  end
86
269
 
87
270
  it "should allow source deletions" do
88
- post '/sources/create', :name => 'delete-source-test', :uri => 'http://example2.org'
271
+ post '/sources/create', :name => 'delete-source-test', :uri => 'http://delete.source.test', :source_type => 'gem'
272
+ source_id = Source.find(:first, :conditions => ['name = ?', 'delete-source-test']).id
89
273
  lambda do
90
- delete '/sources/destroy/2'
274
+ delete "/sources/destroy/#{source_id}"
91
275
  end.should change(Source, :count).by(-1)
92
- follow_redirect!
93
276
  last_response.should be_ok
94
- last_request.url.should == "http://example.org/sources"
277
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "true"
278
+ end
279
+
280
+ it "should return an error if source id to delete is invalid" do
281
+ lambda do
282
+ delete "/sources/destroy/abc"
283
+ end.should_not change(Project, :count)
284
+ last_response.should be_ok
285
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
286
+ end
287
+
288
+ # test triggering release event
289
+ it "should successfully post-process a released source" do
290
+ project = Project.create! :name => 'myproj42'
291
+ project.sources << Source.create!(:name => 'mysource', :source_type => 'file',
292
+ :uri => 'http://my.source.uri')
293
+ project.save!
294
+
295
+ event = Event.create :project => project,
296
+ :process => "integration_test_handler6",
297
+ :version_qualifier => '=',
298
+ :version => "5.6"
299
+
300
+ # since we don't specify source_id / project_id in project_source_versions above, the project
301
+ # version used to trigger the events will be the same as the source version
302
+ post '/sources/released', :name => 'mysource',
303
+ :version => "5.6"
304
+
305
+ last_response.should be_ok
306
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "true"
307
+
308
+ $integration_test_handler_flags.include?("5.6").should == true
95
309
  end
96
310
 
97
- it "shold allow event creations" do
98
- gem = ManagedGem.create :name => "create-event-test-gem", :source_id => 1
311
+ it "should return an error if there is a problem in the project release process" do
312
+ project = Project.create :name => 'foobar142'
313
+ project.sources << Source.create!(:name => 'mysource42', :source_type => 'file',
314
+ :uri => 'http://my.source42.uri')
315
+ project.save!
316
+
317
+ event = Event.create :project => project,
318
+ :process => "failed_event_handler",
319
+ :version_qualifier => '=',
320
+ :version => 1.0
321
+
322
+
323
+ # need to specify name and version
324
+ post '/sources/released', :name => 'mysource42'
325
+ last_response.should be_ok
326
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
327
+
328
+ post '/sources/released', :version => '1.0'
329
+ last_response.should be_ok
330
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
331
+
332
+ # event handler should throw exception, which the app should return
333
+ post '/sources/released', :name => 'mysource42',
334
+ :version => '1.0'
335
+ last_response.should be_ok
336
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
337
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "errors" }.content.strip.should =~ /.*MYERROR.*/
338
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "message" }.content.strip.should =~ /.*MYERROR.*/
339
+ end
340
+
341
+ it "should allow project source version creations" do
342
+ project = Project.create! :name => "create-project-source-testproject1"
343
+ source = Source.create! :name => "create-project_source-testsource1", :source_type => 'file', :uri => 'http://cpsts1'
344
+
99
345
  lambda do
100
- post '/events/create', :managed_gem_id => gem.id,
101
- :process => 'fooproc',
102
- :gem_version => '1.0',
346
+ post '/project_source_versions/create', :project_id => project.id, :source_id => source.id
347
+ end.should change(ProjectSourceVersion, :count).by(1)
348
+ ps = ProjectSourceVersion.find(:first, :conditions => [ 'project_id = ? AND source_id = ?', project.id, source.id])
349
+ ps.should_not be_nil
350
+
351
+ last_response.should be_ok
352
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "true"
353
+ end
354
+
355
+ it "should return an error if project source version project_id or source_id is not specified on creation" do
356
+ project = Project.create! :name => "create-project_source-test2"
357
+ source = Source.create! :name => "create-project_source-testsource2", :source_type => 'file', :uri => 'http://cpsts10'
358
+
359
+ lambda do
360
+ post '/project_source_versions/create', :project_id => project.id
361
+ end.should_not change(ProjectSourceVersion, :count)
362
+ last_response.should be_ok
363
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
364
+
365
+ lambda do
366
+ post '/project_source_versions/create', :source_id => source.id
367
+ end.should_not change(ProjectSourceVersion, :count)
368
+ last_response.should be_ok
369
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
370
+ end
371
+
372
+ it "should return an error if project source version project_id or source_id is invalid" do
373
+ project = Project.create! :name => "create-project_source-test42"
374
+ source = Source.create! :name => "create-project_source-testsource42", :source_type => 'file', :uri => 'http://cpsts10110'
375
+
376
+ lambda do
377
+ post '/project_source_versions/create', :project_id => 'abc', :source_id => source.id
378
+ end.should_not change(ProjectSourceVersion, :count)
379
+ last_response.should be_ok
380
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
381
+
382
+ lambda do
383
+ post '/project_source_versions/create', :source_id => 'def', :project_id => project.id
384
+ end.should_not change(ProjectSourceVersion, :count)
385
+ last_response.should be_ok
386
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
387
+ end
388
+
389
+ it "should allow project source version deletions" do
390
+ project = Project.create! :name => "create-project_source-test20"
391
+ source = Source.create! :name => "create-project_source-testsource420024", :source_type => 'file', :uri => 'http://cpsts20'
392
+ post '/project_source_versions/create', :project_id => project.id, :source_id => source.id
393
+
394
+ ps = ProjectSourceVersion.find(:first, :conditions => [ 'source_id = ? AND project_id = ?', source.id, project.id])
395
+ lambda do
396
+ delete "/project_source_versions/destroy/#{ps.id}"
397
+ end.should change(ProjectSourceVersion, :count).by(-1)
398
+ last_response.should be_ok
399
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "true"
400
+ end
401
+
402
+ it "should return an error if project source version id to delete is invalid" do
403
+ lambda do
404
+ delete "/project_source_versions/destroy/abc"
405
+ end.should_not change(ProjectSourceVersion, :count)
406
+ last_response.should be_ok
407
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
408
+ end
409
+
410
+ it "should allow project dependency creations" do
411
+ project1 = Project.create! :name => "create-project-dep-testprojectA"
412
+ project2 = Project.create! :name => "create-project-dep-testprojectB"
413
+
414
+ lambda do
415
+ post '/project_dependencies/create', :project_id => project1.id, :depends_on_project_id => project2.id
416
+ end.should change(ProjectDependency, :count).by(1)
417
+ pd = ProjectDependency.find(:first, :conditions => [ 'project_id = ? AND depends_on_project_id = ?', project1.id, project2.id])
418
+ pd.should_not be_nil
419
+
420
+ last_response.should be_ok
421
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "true"
422
+ end
423
+
424
+ it "should return an error if project_id or depends_on_project_id is not specified on dependency creation" do
425
+ project = Project.create! :name => "create-project-dep-testprojectC"
426
+
427
+ lambda do
428
+ post '/project_dependencies/create', :project_id => project.id
429
+ end.should_not change(ProjectDependency, :count)
430
+ last_response.should be_ok
431
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
432
+
433
+ lambda do
434
+ post '/project_dependencies/create', :depends_on_project_id => project.id
435
+ end.should_not change(ProjectDependency, :count)
436
+ last_response.should be_ok
437
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
438
+ end
439
+
440
+ it "should return an error if project_id or depends_on_project_id is invalid" do
441
+ project = Project.create! :name => "create-project-dep-testprojectD"
442
+
443
+ lambda do
444
+ post '/project_dependencies/create', :project_id => 'abc', :depends_on_project_id => project.id
445
+ end.should_not change(ProjectDependency, :count)
446
+ last_response.should be_ok
447
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
448
+
449
+ lambda do
450
+ post '/project_source_versions/create', :depends_on_project_id => 'def', :project_id => project.id
451
+ end.should_not change(ProjectDependency, :count)
452
+ last_response.should be_ok
453
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
454
+ end
455
+
456
+ it "should allow project dependency deletions" do
457
+ project1 = Project.create! :name => "delete-project-dep-testprojectA"
458
+ project2 = Project.create! :name => "delete-project-dep-testprojectB"
459
+ post '/project_dependencies/create', :project_id => project1.id, :depends_on_project_id => project2.id
460
+
461
+ ps = ProjectDependency.find(:first, :conditions => [ 'project_id = ? AND depends_on_project_id = ?', project1.id, project2.id])
462
+ lambda do
463
+ delete "/project_dependencies/destroy/#{ps.id}"
464
+ end.should change(ProjectDependency, :count).by(-1)
465
+ last_response.should be_ok
466
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "true"
467
+ end
468
+
469
+ it "should return an error if project dependency id to delete is invalid" do
470
+ lambda do
471
+ delete "/project_dependencies/destroy/abc"
472
+ end.should_not change(ProjectDependency, :count)
473
+ last_response.should be_ok
474
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
475
+ end
476
+
477
+ it "should allow project event creations" do
478
+ project = Project.create! :name => "create-event-test-project"
479
+ lambda do
480
+ post '/events/create', :project_id => project.id,
481
+ :process => 'fooproc',
482
+ :version => '1.0',
103
483
  :version_qualifier => ">",
104
484
  :process_options => 'opts'
105
485
  end.should change(Event, :count).by(1)
106
- follow_redirect!
486
+ Event.find(:first,
487
+ :conditions => ['project_id = ? AND process = ? AND version = ? ' +
488
+ 'AND version_qualifier = ? AND process_options = ?',
489
+ project.id, 'fooproc', '1.0', '>', 'opts']).should_not be_nil
490
+ last_response.should be_ok
491
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "true"
492
+ end
493
+
494
+ it "should return an error if event process id or process is missing or invalid on creation" do
495
+ project = Project.create! :name => "create-event-test-project2"
496
+
497
+ lambda do
498
+ post '/events/create'
499
+ end.should_not change(Event, :count)
500
+ last_response.should be_ok
501
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
502
+
503
+ lambda do
504
+ post '/events/create', :process => "fooproc"
505
+ end.should_not change(Event, :count)
506
+ last_response.should be_ok
507
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
508
+
509
+ lambda do
510
+ post '/events/create', :project_id => project.id
511
+ end.should_not change(Event, :count)
107
512
  last_response.should be_ok
108
- last_request.url.should == "http://example.org/gems"
513
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
514
+
515
+ lambda do
516
+ post '/events/create', :project_id => 'abc'
517
+ end.should_not change(Event, :count)
518
+ last_response.should be_ok
519
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
109
520
  end
110
521
 
111
522
  it "should allow event deletions" do
112
- gem = ManagedGem.create :name => "delete-event-test-gem", :source_id => 1
113
- post '/events/create', :managed_gem_id => gem.id, :process => 'fooproc'
523
+ proj = Project.create :name => "delete-event-test-project"
524
+ event = Event.create :project => proj, :process => 'fooproc'
114
525
  lambda do
115
- delete '/events/destroy/1'
526
+ delete "/events/destroy/#{event.id}"
116
527
  end.should change(Event, :count).by(-1)
117
- follow_redirect!
118
528
  last_response.should be_ok
119
- last_request.url.should == "http://example.org/gems"
529
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "true"
530
+ end
531
+
532
+ it "should return an error if event id to delete is invalid" do
533
+ lambda do
534
+ delete "/events/destroy/abc"
535
+ end.should_not change(Event, :count)
536
+ last_response.should be_ok
537
+ LibXML::XML::Document.string(last_response.body).root.children.find { |c| c.name == "success" }.content.strip.should == "false"
120
538
  end
121
539
 
122
540
  end
@@ -124,10 +542,32 @@ end
124
542
  # prolly a better way todo this, but fine for now
125
543
  $integration_test_handler_flags = []
126
544
 
127
- def integration_test_handler1(gem)
545
+ def failed_event_handler(event, version, args = {})
546
+ raise ArgumentError, "MYERROR"
547
+ end
548
+
549
+ def integration_test_handler1(event, version, args = {})
128
550
  $integration_test_handler_flags << 1
129
551
  end
130
552
 
131
- def integration_test_handler2(gem)
553
+ def integration_test_handler2(event, version, args = {})
132
554
  $integration_test_handler_flags << 2
133
555
  end
556
+
557
+ def integration_test_handler3(event, version, args = {})
558
+ $integration_test_handler_flags << 3
559
+ end
560
+
561
+ def integration_test_handler4(event, version, args = {})
562
+ $integration_test_handler_flags << 4
563
+ end
564
+
565
+ def integration_test_handler5(event, version, args = {})
566
+ args.each { |k,v|
567
+ $integration_test_handler_flags << "#{k}#{v}"
568
+ }
569
+ end
570
+
571
+ def integration_test_handler6(event, version, args = {})
572
+ $integration_test_handler_flags << version
573
+ end