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
@@ -4,16 +4,6 @@ a{
4
4
  color: gray;
5
5
  }
6
6
 
7
- form{
8
- padding-top: 5px;
9
- padding-left: 15px;
10
- }
11
-
12
- /* set fixed width of first column in form tables */
13
- form tr > td:first-child{
14
- width: 150px;;
15
- }
16
-
17
7
  #header {
18
8
  width: 850px;
19
9
  margin-left: auto;
@@ -46,24 +36,26 @@ form tr > td:first-child{
46
36
  padding-left: 10px;
47
37
  }
48
38
 
39
+ #main h1,
40
+ #main h3,
49
41
  #main h5,
50
- #main h6{
51
- display: inline;
52
- }
53
-
54
- #main h4{
55
- margin-top: 25px;
56
- margin-bottom: 0;
42
+ #main h6,
43
+ #main ul,
44
+ #main li{
45
+ padding: 0 0 3px;
46
+ margin: 0 15px;
47
+ white-space:nowrap;
48
+ overflow: hidden;
57
49
  }
58
50
 
59
- #main h6{
60
- padding-left: 15px;
51
+ #main h1{
52
+ font-size: 1.5em;
61
53
  }
62
54
 
63
- #main ul{
64
- margin-top: 3px;
65
- margin-bottom: 3px;
66
- padding-left: 20px;
55
+ #main h2,
56
+ #main h4{
57
+ font-size: 0.8em;
58
+ display: inline;
67
59
  }
68
60
 
69
61
  #main ul li{
@@ -73,11 +65,3 @@ form tr > td:first-child{
73
65
  #main ul li:before {
74
66
  content: "\00BB \0020";
75
67
  }
76
-
77
- #main ul li ul li{
78
- padding-top: 5px;
79
- }
80
-
81
- #main input#gem_version {
82
- width: 125px;
83
- }
@@ -0,0 +1,28 @@
1
+ # polisher common spec
2
+ #
3
+ # Copyright (C) 2010 Red Hat, Inc.
4
+ # Written by Mohammed Morsi <mmorsi@redhat.com>
5
+ #
6
+ # This program is free software, you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License
8
+ # as published by the Free Software Foundation, either version 3
9
+ # of the License, or (at your option) any later version.
10
+ #
11
+ # You should have received a copy of the the GNU Affero
12
+ # General Public License, along with Polisher. If not, see
13
+ # <http://www.gnu.org/licenses/>
14
+
15
+ require File.dirname(__FILE__) + '/spec_helper'
16
+
17
+ describe "Polisher::Common" do
18
+ it "should convert has to/from string" do
19
+ hash = {:a => 123, :b => "foo"}
20
+ str = String.from_h(hash)
21
+ stra = str.split(";")
22
+ stra.include?("a=123").should be_true
23
+ stra.include?("b=foo").should be_true
24
+ hash = str.to_h
25
+ hash["a"].should == "123"
26
+ hash["b"].should == "foo"
27
+ end
28
+ end
@@ -0,0 +1,357 @@
1
+ # ruby gem polisher dsl spec
2
+ #
3
+ # Copyright (C) 2010 Red Hat, Inc.
4
+ # Written by Mohammed Morsi <mmorsi@redhat.com>
5
+ #
6
+ # This program is free software, you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License
8
+ # as published by the Free Software Foundation, either version 3
9
+ # of the License, or (at your option) any later version.
10
+ #
11
+ # You should have received a copy of the the GNU Affero
12
+ # General Public License, along with Polisher. If not, see
13
+ # <http://www.gnu.org/licenses/>
14
+
15
+ ##########################
16
+ ## target typical dsl use case:
17
+ #
18
+ # polisher "http://localhost:3000"
19
+ #
20
+ # project :name => "ruby" do |proj|
21
+ # proj.add_archive :name => 'ruby_source', :uri => "ftp://ftp.ruby-lang.org/pub/ruby/%{rubyxver}/ruby-%{arcver}.tar.bz2" do |archive|
22
+ # archive.version "1.8.6", :rubyxver => "1.8", :arcver => "1.8.7-p311", :corresponds_to => proj.version("1.8.6")
23
+ # proj.version "1.9.1", :corresponds_to => archive.version("1.9.1", :rubyxver => "1.9", :arcver => "1.8.7-p300")
24
+ # end
25
+ # proj.add_patch "http://cvs.fedoraproject.org/viewvc/rpms/ruby/F-13/ruby-deadcode.patch?view=markup"
26
+ # # etc...
27
+ #
28
+ # proj.on_version "*", "create package"
29
+ # proj.on_version "=", "1.8.6", "update repo", "stable"
30
+ # proj.on_version ">=", "1.9.1", "update repo", "devel"
31
+ # end
32
+ #
33
+ # project :name => "ruby-postgres" do |p|
34
+ # end
35
+ #
36
+ # project :name => "rubygem-rails" do |p|
37
+ # p.add_gem "http://rubygems.org/gems/rails-%{version}.gem" do |g|
38
+ # g.is_the_primary_source # instruct polisher to process this project w/ gem2rpm
39
+ # g.version ..., :corresponds_to p.version ...
40
+ # end
41
+ #
42
+ # p.on_version "*", "create package"
43
+ # p.on_version "<", "2.0", "update repo", "legacy"
44
+ # p.on_version "=", "2.0", "update repo", "stable"
45
+ # p.on_version ">=", "2.1", "update repo", "rawhide"
46
+ #
47
+ # # etc....
48
+ # end
49
+ #
50
+ # project :name => 'my_project' do |p|
51
+ # # ...
52
+ # end
53
+ #
54
+ ######
55
+ ## Test firing events
56
+ #project(:name => "ruby").released "1.8.6", :any => "other", :optional => "params"
57
+
58
+ # TODO test primary_source in Polisher::Source, project_source_versions/create rest call, and source method
59
+
60
+ require File.dirname(__FILE__) + '/spec_helper'
61
+
62
+ require 'thin'
63
+ require 'lib/dsl'
64
+
65
+ # start up the polisher server to handle rest requests
66
+ server = Thin::Server.new('127.0.0.1', 3000, app)
67
+ server_thread = Thread.new { server.start }
68
+
69
+ polisher "http://localhost:3000"
70
+
71
+ describe "Polisher::DSL::Project" do
72
+ it "should accept members as constructor parameters" do
73
+ proj = Polisher::Project.new :id => 20, :name => 'foobar'
74
+ proj.id.should == 20
75
+ proj.name.should == "foobar"
76
+ end
77
+
78
+ # TODO test add_archive, add_file, add_patch, add_gem
79
+
80
+ it "should be instantiatable from xml" do
81
+ # TODO versions, sources, events
82
+ xml = "<project><id>10</id><name>foo</name></project>"
83
+ project = Polisher::Project.from_xml xml
84
+ project.id.should == 10
85
+ project.name.should == "foo"
86
+ end
87
+
88
+ it "should return all projects" do
89
+ proj1 = Project.create! :name => 'dsl-projects-test1'
90
+ proj2 = Project.create! :name => 'dsl-projects-test2'
91
+ test_projects = Project.all
92
+ Project.find(:all).each { |proj|
93
+ test_projects.find { |p| p.name == proj.name }.should_not be_nil
94
+ }
95
+ end
96
+
97
+ it "should permit creating projects" do
98
+ proj = Polisher::Project.new :name => 'project-creation-test'
99
+ lambda {
100
+ proj.create
101
+ }.should change(Project, :count).by(1)
102
+ end
103
+
104
+ it "should raise and exception if project cannot be created" do
105
+ proj = Project.create! :name => 'project-invalid-creation-test'
106
+ proj = Polisher::Project.new :name => 'project-invalid-creation-test'
107
+ lambda {
108
+ proj.create
109
+ }.should raise_error(RuntimeError)
110
+ end
111
+
112
+ it "should allow project deletions" do
113
+ db_project = Project.create! :name => "project-event-deletion-test"
114
+ project = Polisher::Project.new :id => db_project.id, :name => db_project.name
115
+ lambda {
116
+ project.delete
117
+ }.should change(Project, :count).by(-1)
118
+ lambda {
119
+ Project.find(db_project.id)
120
+ }.should raise_error(ActiveRecord::RecordNotFound)
121
+ end
122
+
123
+ it "should raise and exception if project cannot be deleted" do
124
+ project = Polisher::Project.new :id => "abc"
125
+ lambda {
126
+ project.delete
127
+ }.should raise_error(RuntimeError)
128
+ end
129
+
130
+ it "should allow event creations" do
131
+ db_project = Project.create! :name => "project-event-creation-test"
132
+ project = Polisher::Project.new :id => db_project.id, :name => db_project.name
133
+ lambda {
134
+ project.on_version "<", "3.9", "do something", "options"
135
+ }.should change(Event, :count).by(1)
136
+ Event.find(:first, :conditions => [ 'project_id = ? AND version_qualifier = ? AND version = ? AND process = ? AND process_options = ?',
137
+ project.id, "<", "3.9", "do_something", "options" ]).
138
+ should_not be_nil
139
+ end
140
+
141
+ it "should accept additional process options in event creation" do
142
+ db_project = Project.create! :name => "project-event-creation-test2"
143
+ project = Polisher::Project.new :id => db_project.id, :name => db_project.name
144
+ lambda {
145
+ project.on_version "<", "3.9", "do something", "options", :more => 'thing', :to => 'set'
146
+ }.should change(Event, :count).by(1)
147
+ event = Event.find(:first, :conditions => [ 'project_id = ? AND version_qualifier = ? AND version = ? AND process = ?',
148
+ project.id, "<", "3.9", "do_something"])
149
+ event.should_not be_nil
150
+ po = event.process_options.split(";")
151
+ po.include?("options").should be_true
152
+ po.include?("more=thing").should be_true
153
+ po.include?("to=set").should be_true
154
+ end
155
+
156
+ it "should correctly setup project/source versions" do
157
+ proj = Project.create! :name => 'project-source-version-test-proj1'
158
+ src = Source.create! :name => 'project-source-version-test-src1', :source_type => 'file', :uri => 'http://host.bar'
159
+
160
+ proj1 = Polisher::Project.new :id => proj.id, :name => 'project-source-version-test-proj1'
161
+ proj2 = proj1.version "1.9"
162
+ proj2.should be(proj1)
163
+ proj1.project_version.should == "1.9"
164
+
165
+ src1 = Polisher::Source.new :id => src.id
166
+ src1 = src1.version("2.0.12", :some => 'attr')
167
+
168
+ lambda {
169
+ proj1.version "1.6.5", :corresponds_to => src1
170
+ }.should change(ProjectSourceVersion, :count).by(1)
171
+
172
+ ProjectSourceVersion.find(:first, :conditions => ['project_version = ? AND source_version = ? AND project_id = ? AND source_id = ? AND source_uri_params = ?',
173
+ "1.6.5", "2.0.12", proj.id, src.id, 'some=attr']).should_not be_nil
174
+ end
175
+
176
+ it "should correctly setup project dependencies" do
177
+ proj1 = Project.create! :name => 'project-deps-test-proj490'
178
+ proj2 = Project.create! :name => 'project-deps-test-proj491'
179
+
180
+ dproj1 = Polisher::Project.new :id => proj1.id, :name => proj1.name
181
+ dproja = dproj1.version("2.5")
182
+ dproja.should be(dproj1)
183
+ dproja.project_version.should == "2.5"
184
+
185
+ dproj2 = Polisher::Project.new :id => proj2.id, :name => proj2.name
186
+ dprojb = dproj2.version("5.6", :some => 'foo', :bar => 'camp')
187
+ dprojb.should be(dproj2)
188
+ dprojb.project_version.should == "5.6"
189
+ dprojb.dependency_params[:some].should == 'foo'
190
+ dprojb.dependency_params[:bar].should == 'camp'
191
+
192
+ lambda {
193
+ dproj1.version "1.6.5", :some => "attr", :depends_on => dproj2
194
+ }.should change(ProjectDependency, :count).by(1)
195
+
196
+ pd = ProjectDependency.find(:first, :conditions => ['project_id = ? AND project_version = ? AND depends_on_project_id = ? AND depends_on_project_version = ?',
197
+ proj1.id, "1.6.5", proj2.id, "5.6"])
198
+ pd.should_not be_nil
199
+ params = pd.depends_on_project_params.split(";")
200
+ params.include?("some=attr").should be_true
201
+ params.include?("bar=camp").should be_true
202
+ end
203
+
204
+ it "should trigger release" do
205
+ db_project = Project.create :name => 'dsl-trigger-test'
206
+ event = Event.create :project => db_project,
207
+ :process => "integration_test_handler2",
208
+ :version_qualifier => '<',
209
+ :version => 1.0
210
+
211
+ project = Polisher::Project.new :id => db_project.id, :name => db_project.name
212
+ project.released 0.9
213
+ $integration_test_handler_flags.include?(2).should == true
214
+ end
215
+ end
216
+
217
+ describe "Polisher::DSL::Source" do
218
+ it "should accept members as constructor parameters" do
219
+ src = Polisher::Source.new(:id => 20, :name => 'foobar', :uri => 'http://foo.uri')
220
+ src.id.should == 20
221
+ src.name.should == "foobar"
222
+ src.uri.should == "http://foo.uri"
223
+ end
224
+
225
+ it "should be instantiatable from xml" do
226
+ # TODO versions, projects, events
227
+ xml = "<source><id>10</id><name>foo</name><source_type>archive</source_type><uri>http://bar.uri</uri></source>"
228
+ src = Polisher::Source.from_xml xml
229
+ src.id.should == 10
230
+ src.name.should == "foo"
231
+ src.source_type.should == "archive"
232
+ src.uri.should == "http://bar.uri"
233
+ end
234
+
235
+ it "should return all sources" do
236
+ src1 = Source.create! :name => 'dsl-sources-test1', :source_type => 'patch', :uri => 'ftp://abc.def'
237
+ src2 = Source.create! :name => 'dsl-sources-test2', :source_type => 'patch', :uri => 'http://111.222'
238
+ test_sources = Source.all
239
+ Source.find(:all).each { |src|
240
+ test_sources.find { |s| s.name == src.name && s.type == src.type && s.uri == src.uri }.should_not be_nil
241
+ }
242
+ end
243
+
244
+ it "should permit creating sources" do
245
+ src = Polisher::Source.new(:name => 'project-creation-test', :source_type => 'archive', :uri => 'http://abc53')
246
+ lambda {
247
+ src.create
248
+ }.should change(Source, :count).by(1)
249
+ end
250
+
251
+ it "should raise an exception if source cannot be created" do
252
+ args = {:name => 'source-invalid-creation-test', :source_type => 'patch', :uri => 'ftp://invalid.source'}
253
+ Source.create! args
254
+ src = Polisher::Source.new args
255
+ lambda {
256
+ src.create
257
+ }.should raise_error(RuntimeError)
258
+ end
259
+
260
+ it "should correctly setup project/source versions" do
261
+ proj = Project.create! :name => 'project-source-version-test-proj41'
262
+ src = Source.create! :name => 'project-source-version-test-src41', :source_type => 'file', :uri => 'http://bar.host.uri'
263
+
264
+ src1 = Polisher::Source.new :id => src.id, :name => 'project-source-version-test-src41'
265
+ src2 = src1.version "1.9", :some => "attr", :other => 'thing'
266
+ src2.should be(src1)
267
+ src1.source_version.should == "1.9"
268
+
269
+ uri_args = src1.uri_args.split(";")
270
+ uri_args.include?("some=attr").should be_true
271
+ uri_args.include?("other=thing").should be_true
272
+
273
+ proj1 = Polisher::Project.new :id => proj.id
274
+ proj1 = proj1.version("2.0.12")
275
+
276
+ lambda {
277
+ src1.version "1.6.5", :some => "attr", :other => 'thing', :corresponds_to => proj1
278
+ }.should change(ProjectSourceVersion, :count).by(1)
279
+
280
+ ps = ProjectSourceVersion.find(:first, :conditions => ['source_version = ? AND project_version = ? AND project_id = ? AND source_id = ?',
281
+ "1.6.5", "2.0.12", proj.id, src1.id])
282
+ ps.should_not be_nil
283
+ uri_args = ps.source_uri_params.split(";")
284
+ uri_args.include?("some=attr").should be_true
285
+ uri_args.include?("other=thing").should be_true
286
+ end
287
+ end
288
+
289
+
290
+ describe "Polisher::DSL" do
291
+ it "should return all projects" do
292
+ proj1 = Project.create! :name => 'dsl-projects-test100'
293
+ proj2 = Project.create! :name => 'dsl-projects-test200'
294
+ test_projects = projects
295
+ Project.find(:all).each { |proj|
296
+ test_projects.find { |p| p.name == proj.name }.should_not be_nil
297
+ }
298
+ end
299
+
300
+ it "should find or create project" do
301
+ test_project = nil
302
+ lambda {
303
+ test_project = project :name => "dsl-project-testc"
304
+ }.should change(Project, :count).by(1)
305
+ db_project = Project.find(:first, :conditions => ['name = ?', 'dsl-project-testc'])
306
+ test_project.id.should == db_project.id
307
+
308
+ lambda {
309
+ test_project = project :name => "dsl-project-testc"
310
+ }.should_not change(Project, :count)
311
+ test_project.id.should == db_project.id
312
+ end
313
+
314
+ it "should return all sources" do
315
+ source1 = Source.create! :name => 'dsl-sources-test51', :uri => "http://test1.host", :source_type => 'archive'
316
+ source2 = Source.create! :name => 'dsl-sources-test52', :uri => "http://test2.host", :source_type => 'patch'
317
+ test_sources = sources
318
+ Source.find(:all).each { |source|
319
+ test_sources.find { |s| s.name == source.name && s.uri == source.uri }.should_not be_nil
320
+ }
321
+ test_sources.find { |s| s.name == "dsl-sources-test51" && s.uri == "http://test1.host" && s.source_type == "archive" }.should_not be_nil
322
+ test_sources.find { |s| s.name == "dsl-sources-test52" && s.uri == "http://test2.host" && s.source_type == "patch" }.should_not be_nil
323
+ end
324
+
325
+ it "should find or create source" do
326
+ test_source = nil
327
+ lambda {
328
+ test_source = source :name => "dsl-source-test", :uri => "http://source.testc", :source_type => 'archive'
329
+ }.should change(Source, :count).by(1)
330
+ db_source = Source.find(:first, :conditions => ['name = ? AND uri = ? AND source_type = ?', 'dsl-source-test', 'http://source.testc', 'archive'])
331
+ test_source.id.should == db_source.id
332
+
333
+ lambda {
334
+ test_source = source :name => "dsl-source-test", :uri => "http://source.testc"
335
+ }.should_not change(Source, :count)
336
+ test_source.id.should == db_source.id
337
+
338
+ test_source = source :name => "dsl-source-test"
339
+ test_source.id.should == db_source.id
340
+ end
341
+
342
+ end
343
+
344
+ # prolly a better way todo this, but fine for now
345
+ $integration_test_handler_flags = []
346
+
347
+ def integration_test_handler1(entity, process_options = [], optional_params = {})
348
+ $integration_test_handler_flags << 1
349
+ end
350
+
351
+ def integration_test_handler2(entity, process_options = [], optional_params = {})
352
+ $integration_test_handler_flags << 2
353
+ end
354
+
355
+ # stop the sinatra server
356
+ #server.stop!
357
+ #server_thread.kill!