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
@@ -16,59 +16,107 @@ require 'fileutils'
16
16
 
17
17
  require File.dirname(__FILE__) + '/spec_helper'
18
18
 
19
- BUILD_VERSION='fc11'
19
+ include EventHandlers
20
20
 
21
- describe "Polisher::EventHandlers" do
21
+ describe "EventHandlers" do
22
+
23
+ before(:all) do
24
+ @gem = Project.create! :name => 'rubygem-polisher'
25
+ @gem.primary_source = Source.new :name => 'polisher', :source_type => 'gem', :uri => 'http://rubygems.org/gems/polisher-%{version}.gem'
26
+ @gem_event0 = Event.create! :project => @gem, :process => 'download_sources'
27
+ @gem_event1 = Event.create! :project => @gem, :process => 'create_rpm_package', :process_options => "mock=fedora-12-x86_64"
28
+
29
+ @gem_event2 = Event.create! :project => @gem, :process => 'create_rpm_package',
30
+ :process_options => "spec=#{ARTIFACTS_DIR}/templates/polisher.spec.tpl;mock=fedora-12-x86_64"
31
+
32
+ @gem_event3 = Event.create! :project => @gem, :process => 'update_repo', :process_options => "#{ARTIFACTS_DIR}/repos/fedora-ruby"
33
+
34
+ @project = Project.create :name => 'ruby-activerecord'
35
+ @project.sources << Source.new(:name => 'activerecord', :source_type => 'file',
36
+ :uri => 'http://rubyforge.org/frs/download.php/%{level}/activerecord-%{version}.tgz')
37
+
38
+ @project_event0 = Event.create! :project => @project, :process => 'download_sources', :process_options => "level=28874"
39
+ @project_event1 = Event.create! :project => @project, :process => 'create_rpm_package',
40
+ :process_options => "spec=#{ARTIFACTS_DIR}/templates/polisher-projects.spec.tpl;mock=fedora-12-x86_64"
41
+
42
+ @project_event2 = Event.create! :project => @project, :process => 'update_repo', :process_options => "#{ARTIFACTS_DIR}/repos/fedora-ruby"
43
+ end
22
44
 
23
45
  before(:each) do
24
- FileUtils.rm_rf(ARTIFACTS_DIR)
25
- FileUtils.mkdir_p(ARTIFACTS_DIR + '/gems')
26
- FileUtils.mkdir_p(ARTIFACTS_DIR + '/repos')
27
- FileUtils.mkdir_p(ARTIFACTS_DIR + '/SOURCES')
28
- FileUtils.mkdir_p(ARTIFACTS_DIR + '/SPECS')
29
- FileUtils.mkdir_p(ARTIFACTS_DIR + '/templates')
30
-
31
- unless defined? @gem
32
- @gem = ManagedGem.create :name => 'polisher', :source_id => 1
33
- end
46
+ FileUtils.rm_rf(ARTIFACTS_DIR) if File.directory? ARTIFACTS_DIR
47
+ FileUtils.mkdir_p(ARTIFACTS_DIR + '/repos')
48
+ FileUtils.mkdir_p(ARTIFACTS_DIR + '/SOURCES')
49
+ FileUtils.mkdir_p(ARTIFACTS_DIR + '/SPECS')
50
+ FileUtils.mkdir_p(ARTIFACTS_DIR + '/templates')
51
+
52
+ File.write(ARTIFACTS_DIR + '/templates/polisher.spec.tpl', POLISHER_GEM2RPM_TEST_TEMPLATE)
53
+ File.write(ARTIFACTS_DIR + '/templates/polisher-projects.spec.tpl', POLISHER_ERB_TEST_TEMPLATE)
54
+ end
55
+
56
+ after(:each) do
57
+ FileUtils.rm_rf(ARTIFACTS_DIR) if File.directory? ARTIFACTS_DIR
34
58
  end
35
59
 
36
- it "should correctly create package" do
37
- create_package(@gem)
38
- File.exists?(ARTIFACTS_DIR + '/gems/polisher-0.1.gem').should == true
39
- File.exists?(ARTIFACTS_DIR + '/SOURCES/polisher-0.1.gem').should == true
60
+ it "should download sources" do
61
+ download_sources(@gem_event0, "0.3")
62
+ File.exists?(ARTIFACTS_DIR + '/SOURCES/polisher-0.3.gem').should == true
63
+
64
+ download_sources(@project_event0, "2.0.1")
65
+ File.exists?(ARTIFACTS_DIR + '/SOURCES/activerecord-2.0.1.tgz').should == true
66
+ end
67
+
68
+ it "should correctly create a gem based package" do
69
+ download_sources(@gem_event0, "0.3")
70
+ create_rpm_package(@gem_event1, "0.3")
40
71
  File.exists?(ARTIFACTS_DIR + '/SPECS/rubygem-polisher.spec').should == true
41
- File.exists?(ARTIFACTS_DIR + "/SRPMS/rubygem-polisher-0.1-1.#{BUILD_VERSION}.src.rpm").should == true
42
- File.exists?(ARTIFACTS_DIR + "/RPMS/noarch/rubygem-polisher-0.1-1.#{BUILD_VERSION}.noarch.rpm").should == true
72
+ File.exists?(ARTIFACTS_DIR + "/SRPMS/rubygem-polisher-0.3-1.fc11.src.rpm").should == true
73
+ File.exists?(ARTIFACTS_DIR + "/RPMS/noarch/rubygem-polisher-0.3-1.fc12.noarch.rpm").should == true
43
74
  end
44
75
 
45
- it "should correctly create package using template" do
46
- File.write(ARTIFACTS_DIR + '/templates/polisher.spec.tpl', POLISHER_TEST_TEMPLATE)
47
- create_package(@gem, '/polisher.spec.tpl')
76
+ it "should correctly create a gem based package using template" do
77
+ download_sources(@gem_event0, "0.3")
78
+ create_rpm_package(@gem_event2, '0.3')
48
79
  File.exists?(ARTIFACTS_DIR + '/SPECS/rubygem-polisher.spec').should == true
49
80
  File.read_all(ARTIFACTS_DIR + '/SPECS/rubygem-polisher.spec').should =~ /.*by polisher.*/
50
81
  end
51
82
 
83
+ it "should correctly create an upstream based project package" do
84
+ download_sources(@project_event0, "2.0.1")
85
+ create_rpm_package(@project_event1, "2.0.1", :release => 3)
86
+
87
+ File.exists?(ARTIFACTS_DIR + '/SPECS/ruby-activerecord.spec').should == true
88
+ File.exists?(ARTIFACTS_DIR + "/SRPMS/ruby-activerecord-2.0.1-3.fc11.src.rpm").should == true
89
+ File.exists?(ARTIFACTS_DIR + "/RPMS/noarch/ruby-activerecord-2.0.1-3.fc12.noarch.rpm").should == true
90
+ File.exists?(ARTIFACTS_DIR + "/RPMS/noarch/ruby-activerecord-subpkg-2.0.1-3.fc12.noarch.rpm").should == true
91
+ File.exists?(ARTIFACTS_DIR + "/RPMS/noarch/another-subpkg-2.0.1-3.fc12.noarch.rpm").should == true
92
+ end
93
+
52
94
  it "should correctly update repository" do
53
- create_package(@gem)
54
- update_repo(@gem, 'fedora-ruby')
95
+ download_sources(@gem_event0, "0.3")
96
+ create_rpm_package(@gem_event1, '0.3')
97
+ update_yum_repo(@gem_event3, '0.3')
98
+
99
+ template = ARTIFACTS_DIR + '/templates/polisher-projects.spec.tpl'
100
+ File.write(template, POLISHER_ERB_TEST_TEMPLATE)
101
+ download_sources(@project_event0, "2.0.1")
102
+ create_rpm_package(@project_event1, "2.0.1", :release => 3)
103
+ update_yum_repo(@project_event2, '2.0')
104
+
55
105
  File.directory?(ARTIFACTS_DIR + '/repos/fedora-ruby/noarch').should == true
56
106
  File.directory?(ARTIFACTS_DIR + '/repos/fedora-ruby/repodata').should == true
57
- File.exists?(ARTIFACTS_DIR + '/repos/fedora-ruby/noarch/rubygem-polisher.rpm').should == true
107
+ File.exists?(ARTIFACTS_DIR + "/repos/fedora-ruby/noarch/rubygem-polisher-0.3-1.fc12.noarch.rpm").should == true
108
+ File.exists?(ARTIFACTS_DIR + "/repos/fedora-ruby/noarch/ruby-activerecord-2.0.1-3.fc12.noarch.rpm").should == true
109
+ File.exists?(ARTIFACTS_DIR + "/repos/fedora-ruby/noarch/ruby-activerecord-subpkg-2.0.1-3.fc12.noarch.rpm").should == true
110
+ File.exists?(ARTIFACTS_DIR + "/repos/fedora-ruby/noarch/another-subpkg-2.0.1-3.fc12.noarch.rpm").should == true
58
111
  File.exists?(ARTIFACTS_DIR + '/repos/fedora-ruby/repodata/repomd.xml').should == true
59
112
  File.exists?(ARTIFACTS_DIR + '/repos/fedora-ruby/repodata/primary.xml.gz').should == true
60
113
  File.exists?(ARTIFACTS_DIR + '/repos/fedora-ruby/repodata/other.xml.gz').should == true
61
114
  File.exists?(ARTIFACTS_DIR + '/repos/fedora-ruby/repodata/filelists.xml.gz').should == true
62
115
  end
63
116
 
64
- it "should correctly notify email recipients" do
65
- # TODO test notify subscribers
66
- #notify_subscribers(@gem, [...])
67
- end
68
-
69
117
  end
70
118
 
71
- POLISHER_TEST_TEMPLATE =
119
+ POLISHER_GEM2RPM_TEST_TEMPLATE =
72
120
  %q{# Generated from <%= File::basename(format.gem_path) %> by polisher -*- rpm-spec -*-
73
121
  %define ruby_sitelib %(ruby -rrbconfig -e "puts Config::CONFIG['sitelibdir']")
74
122
  %define gemdir %(ruby -rubygems -e 'puts Gem::dir' 2>/dev/null)
@@ -162,3 +210,91 @@ rm -rf %{buildroot}
162
210
  * <%= Time.now.strftime("%a %b %d %Y") %> <%= packager %> - <%= spec.version %>-1
163
211
  - Initial package
164
212
  }
213
+
214
+ # copied w/ changes from http://cvs.fedoraproject.org/viewvc/rpms/ruby-activerecord/F-13/ruby-activerecord.spec?revision=1.6&view=co
215
+ POLISHER_ERB_TEST_TEMPLATE =
216
+ %q{
217
+ %{!?ruby_sitelib: %define ruby_sitelib %(ruby -rrbconfig -e "puts Config::CONFIG['sitelibdir']")}
218
+ %define rname activerecord
219
+ # Only run the tests on distros that have sqlite3
220
+ %define with_check 0
221
+
222
+ Name: ruby-%{rname}
223
+ Version: <%= version %>
224
+ Release: <%= release %>%{?dist}
225
+ Summary: Implements the ActiveRecord pattern for ORM
226
+
227
+ Group: Development/Languages
228
+
229
+ License: MIT
230
+ URL: http://rubyforge.org/projects/activerecord/
231
+ Source0: http://rubyforge.org/frs/download.php/28874/activerecord-%{version}.tgz
232
+ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
233
+
234
+ BuildArch: noarch
235
+ BuildRequires: ruby >= 1.8
236
+ %if %with_check
237
+ BuildRequires: ruby(active_support) = 2.0.1
238
+ BuildRequires: ruby(sqlite3)
239
+ %endif
240
+ Requires: ruby(abi) = 1.8
241
+ Requires: ruby(active_support) = 2.0.1
242
+ Provides: ruby(active_record) = %{version}
243
+
244
+ %description
245
+ Implements the ActiveRecord pattern (Fowler, PoEAA) for ORM. It ties
246
+ database tables and classes together for business objects, like Customer or
247
+ Subscription, that can find, save, and destroy themselves without resorting
248
+ to manual SQL.
249
+
250
+ %package subpkg
251
+ Summary: Test sub package
252
+ Group: Development/Languages
253
+
254
+ %package -n another-subpkg
255
+ Summary: Another test sub package
256
+ Group: Development/Languages
257
+
258
+ %description subpkg
259
+ Test subpackage
260
+
261
+ %description -n another-subpkg
262
+ Another est subpackage
263
+
264
+ %prep
265
+ %setup -q -n %{rname}-%{version}
266
+ chmod 0644 README
267
+
268
+ %build
269
+
270
+ %install
271
+ rm -rf $RPM_BUILD_ROOT
272
+ install -d $RPM_BUILD_ROOT/%{ruby_sitelib}/
273
+ cp -pr lib/* $RPM_BUILD_ROOT/%{ruby_sitelib}/
274
+ find $RPM_BUILD_ROOT/%{ruby_sitelib} -type f | xargs chmod a-x
275
+
276
+ %check
277
+ %if %with_check
278
+ cd test
279
+ ruby -I "connections/native_sqlite3" base_test.rb
280
+ %endif
281
+
282
+ %clean
283
+ rm -rf $RPM_BUILD_ROOT
284
+
285
+ %files
286
+ %defattr(-,root,root,-)
287
+ %{ruby_sitelib}/activerecord.rb
288
+ %{ruby_sitelib}/active_record.rb
289
+ %{ruby_sitelib}/active_record
290
+ %doc README CHANGELOG examples/
291
+
292
+ %files subpkg
293
+ %defattr(-,root,root,-)
294
+ %doc README
295
+
296
+ %files -n another-subpkg
297
+ %defattr(-,root,root,-)
298
+ %doc CHANGELOG
299
+
300
+ }
@@ -0,0 +1,89 @@
1
+ # ruby gem polisher gem adapter 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 'uri'
16
+ require 'json'
17
+ require 'net/http'
18
+
19
+ require File.dirname(__FILE__) + '/spec_helper'
20
+
21
+ describe "Polisher::GemAdapter" do
22
+ it "should successfully subscribe/unsubscribe to updates" do
23
+ gem = Source.new :name => "polisher", :source_type => "gem",
24
+ :uri => "http://rubygems.org/downloads/polisher-0.3.gem"
25
+
26
+ Polisher::GemAdapter.subscribe(gem,
27
+ "http://projects.morsi.org/polisher/demo/gems/released/1",
28
+ POLISHER_CONFIG["gem_api_key"])
29
+ Polisher::GemAdapter.subscribed?(gem, POLISHER_CONFIG["gem_api_key"]).should == true
30
+ Polisher::GemAdapter.unsubscribe(gem,
31
+ "http://projects.morsi.org/polisher/demo/gems/released/1",
32
+ POLISHER_CONFIG["gem_api_key"])
33
+ Polisher::GemAdapter.subscribed?(gem, POLISHER_CONFIG["gem_api_key"]).should == false
34
+ end
35
+
36
+ it "should raise error if subscribe source, callback_url, or api_key is invalid" do
37
+ lambda {
38
+ Polisher::GemAdapter.subscribe(nil,
39
+ "http://projects.morsi.org/polisher/demo/gems/released/1",
40
+ POLISHER_CONFIG['gem_api_key'])
41
+ }.should raise_error(ArgumentError)
42
+
43
+ gem = Source.new :name => "polisher", :source_type => "gem",
44
+ :uri => "http://rubygems.org/downloads/polisher-0.3.gem"
45
+ lambda {
46
+ Polisher::GemAdapter.subscribe(gem, 42, POLISHER_CONFIG['gem_api_key'])
47
+ }.should raise_error(ArgumentError)
48
+
49
+ lambda {
50
+ Polisher::GemAdapter.subscribe(gem,
51
+ "http://projects.morsi.org/polisher/demo/gems/released/1",
52
+ nil)
53
+ }.should raise_error(ArgumentError)
54
+ end
55
+
56
+ it "should raise error if subscription target is invalid" do
57
+ gem = Source.new :name => "polisher", :source_type => "gem",
58
+ :uri => "http://non.existant/downloads/polisher-0.3.gem"
59
+ lambda {
60
+ Polisher::GemAdapter.subscribe(gem,
61
+ "http://projects.morsi.org/polisher/demo/gems/released/1",
62
+ POLISHER_CONFIG["gem_api_key"])
63
+ }.should raise_error(RuntimeError)
64
+
65
+ gem = Source.new :name => "polisher", :source_type => "gem",
66
+ :uri => "http://morsi.org/downloads/polisher-0.3.gem"
67
+ lambda {
68
+ Polisher::GemAdapter.subscribe(gem,
69
+ "http://projects.morsi.org/polisher/demo/gems/released/1",
70
+ POLISHER_CONFIG["gem_api_key"])
71
+ }.should raise_error(RuntimeError)
72
+ end
73
+
74
+ it "should successfully get remote gem info" do
75
+ gem = Source.new :name => "polisher", :source_type => "gem",
76
+ :uri => "http://rubygems.org/downloads/polisher-0.3.gem"
77
+ info = Polisher::GemAdapter.get_info(gem)
78
+ info["name"].should == "polisher"
79
+ end
80
+
81
+ it "should raise error if get info target is invalid" do
82
+ gem = Source.new :name => "polisher", :source_type => "gem",
83
+ :uri => "http://invalid.uri/downloads/polisher-0.3.gem"
84
+ lambda {
85
+ Polisher::GemAdapter.get_info(gem)
86
+ }.should raise_error(RuntimeError)
87
+ end
88
+
89
+ end
@@ -7,177 +7,664 @@
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
+ describe "Polisher::Project" do
18
+ before(:each) do
19
+ FileUtils.rm_rf(ARTIFACTS_DIR) if File.directory? ARTIFACTS_DIR
20
+ FileUtils.mkdir_p(ARTIFACTS_DIR)
21
+ end
17
22
 
18
- describe "Polisher::Source" do
19
- it "should not be valid if name or uri is missing" do
20
- src = Source.new :name => 'foo', :uri => 'bar'
21
- src.valid?.should be(true)
23
+ after(:each) do
24
+ FileUtils.rm_rf(ARTIFACTS_DIR) if File.directory? ARTIFACTS_DIR
25
+ end
22
26
 
23
- src.name = nil
24
- src.valid?.should be(false)
25
- src.name = 'foo'
27
+ it "should not be valid if name is missing" do
28
+ project = Project.new :name => 'foo'
29
+ project.should be_valid
26
30
 
27
- src.uri = nil
28
- src.valid?.should be(false)
29
- end
31
+ project.name = nil
32
+ project.should_not be_valid
33
+ end
30
34
 
31
- it "should clean uri properly" do
32
- src = Source.new :uri => 'http://example.com/'
33
- src.clean_uri!
34
- src.uri.should == 'http://example.com'
35
- end
35
+ it "should not be valid if duplicate name exists" do
36
+ Project.create! :name => 'dup-project-name-test'
37
+ project = Project.new :name => 'dup-project-name-test'
38
+ project.should_not be_valid
39
+ end
40
+
41
+ it "should provide access to all dependencies and dependent projects" do
42
+ project1 = Project.create! :name => "project-dependency-tree1"
43
+ project2 = Project.create! :name => "project-dependency-tree2"
44
+ project3 = Project.create! :name => "project-dependency-tree3"
45
+ project4 = Project.create! :name => "project-dependency-tree4"
46
+ project5 = Project.create! :name => "project-dependency-tree5"
47
+
48
+ pd1 = ProjectDependency.create! :project => project2, :depends_on_project => project1
49
+ pd2 = ProjectDependency.create! :project => project3, :depends_on_project => project2
50
+ pd3 = ProjectDependency.create! :project => project4, :depends_on_project => project2
51
+ pd4 = ProjectDependency.create! :project => project4, :depends_on_project => project5
52
+
53
+ deps = project1.dependencies
54
+ deps.size.should == 0
55
+ depts = project1.dependents
56
+ depts.size.should == 1
57
+ depts[0].project.id.should == project2.id
58
+
59
+ deps = project2.dependencies
60
+ deps.size.should == 1
61
+ deps[0].depends_on_project.id.should == project1.id
62
+ depts = project2.dependents
63
+ depts.size.should == 2
64
+ depts[0].project.id.should == project3.id
65
+ depts[1].project.id.should == project4.id
66
+
67
+ deps = project3.dependencies
68
+ deps.size.should == 1
69
+ deps[0].depends_on_project.id.should == project2.id
70
+ depts = project3.dependents
71
+ depts.size.should == 0
72
+
73
+ deps = project4.dependencies
74
+ deps.size.should == 2
75
+ deps[0].depends_on_project.id.should == project2.id
76
+ deps[1].depends_on_project.id.should == project5.id
77
+ depts = project4.dependents
78
+ depts.size.should == 0
79
+
80
+ deps = project5.dependencies
81
+ deps.size.should == 0
82
+ depts = project5.dependents
83
+ depts.size.should == 1
84
+ depts[0].project.id.should == project4.id
85
+ end
86
+
87
+ it "should download all sources" do
88
+ project = Project.create! :name => 'project-dl-test100'
89
+
90
+ # see FIXME in Project::download_to
91
+ source1 = Source.create! :name => 'jffi-spec', :uri => 'http://mo.morsi.org/files/jruby/jffi.spec', :source_type => 'spec'
92
+ source2 = Source.create! :name => 'joni-spec', :uri => 'http://mo.morsi.org/files/jruby/joni.spec', :source_type => 'spec'
93
+
94
+ ps1 = ProjectSourceVersion.create! :project => project, :source => source1
95
+ ps2 = ProjectSourceVersion.create! :project => project, :source => source2, :project_version => "1.5"
96
+
97
+ project.download_to :dir => ARTIFACTS_DIR
98
+
99
+ File.size?(ARTIFACTS_DIR + '/joni.spec').should_not be_nil
100
+ File.size?(ARTIFACTS_DIR + '/jffi.spec').should_not be_nil
101
+ end
102
+
103
+ it "should download all sources for specified version" do
104
+ project = Project.new :name => 'project-dl-test100'
105
+ source1 = Source.new :name => 'jffi-spec', :uri => 'http://mo.morsi.org/%{dir}/%{cluster}/jffi.spec', :source_type => 'spec'
106
+ source2 = Source.new :name => 'joni-spec', :uri => 'http://mo.morsi.org/%{dir}/%{cluster}/joni.spec', :source_type => 'spec'
107
+
108
+ ps1 = ProjectSourceVersion.new :project => project, :source => source1, :project_version => "1.6", :source_uri_params => "cluster=jruby;filetype=spec"
109
+ ps2 = ProjectSourceVersion.new :project => project, :source => source2, :project_version => "1.5", :source_uri_params => "cluster=jruby;dir=files"
110
+ project.project_source_versions << ps1 << ps2
111
+
112
+ project.download_to :version => "1.5", :dir => ARTIFACTS_DIR
113
+
114
+ File.size?(ARTIFACTS_DIR + '/joni.spec').should_not be_nil
115
+ File.size?(ARTIFACTS_DIR + '/jffi.spec').should be_nil
116
+ end
117
+
118
+ it "should return all events for the specified version" do
119
+ project = Project.new :name => 'project-dl-test100'
120
+ event1 = Event.new :version_qualifier => "=", :version => "1.5"
121
+ event2 = Event.new :version_qualifier => ">", :version => "1.6"
122
+ project.events << event1 << event2
123
+
124
+ events = project.events_for_version("1.5")
125
+ events.size.should == 1
126
+ events.include?(event1).should be_true
127
+ events.include?(event2).should be_false
128
+ end
129
+
130
+ it "should return all project_source_versions for the specified version" do
131
+ project = Project.new :name => 'project-dl-test100'
132
+ source1 = Source.new :name => 'jffi-spec', :uri => 'http://mo.morsi.org/%{dir}/%{cluster}/jffi.spec', :source_type => 'spec'
133
+ source2 = Source.new :name => 'joni-spec', :uri => 'http://mo.morsi.org/%{dir}/%{cluster}/joni.spec', :source_type => 'spec'
134
+ source3 = Source.new :name => 'jruby-spec', :uri => 'http://mo.morsi.org/%{dir}/%{cluster}/jruby.spec', :source_type => 'spec'
135
+
136
+ ps1 = ProjectSourceVersion.new :project => project, :source => source1, :project_version => '1.6', :source_uri_params => "cluster=jruby;filetype=spec"
137
+ ps2 = ProjectSourceVersion.new :project => project, :source => source2, :project_version => "1.5", :source_uri_params => "cluster=jruby;dir=files"
138
+ ps3 = ProjectSourceVersion.new :project => project, :source => source3, :source_uri_params => "cluster=jruby;filetype=spec"
139
+ project.project_source_versions << ps1 << ps2 << ps3
140
+
141
+ project_sources = project.project_source_versions_for_version("1.5")
142
+ project_sources.size.should == 2
143
+ project_sources.include?(ps1).should be_false
144
+ project_sources.include?(ps2).should be_true
145
+ project_sources.include?(ps3).should be_true
146
+ end
147
+
148
+ it "should return all sources for the specified version with formatted uris" do
149
+ project = Project.new :name => 'project-dl-test100'
150
+ source1 = Source.new :name => 'jffi-spec', :uri => 'http://mo.morsi.org/%{dir}/%{cluster}/jffi.spec', :source_type => 'spec'
151
+ source2 = Source.new :name => 'joni-spec', :uri => 'http://mo.morsi.org/%{dir}/%{cluster}/joni.spec', :source_type => 'spec'
152
+ source3 = Source.new :name => 'jruby-spec', :uri => 'http://mo.morsi.org/%{dir}/%{cluster}/jruby.spec', :source_type => 'spec'
153
+
154
+ ps1 = ProjectSourceVersion.new :project => project, :source => source1, :project_version => "1.6", :source_uri_params => "cluster=jruby;filetype=spec"
155
+ ps2 = ProjectSourceVersion.new :project => project, :source => source2, :project_version => "1.5", :source_uri_params => "cluster=jruby;dir=files"
156
+ ps3 = ProjectSourceVersion.new :project => project, :source => source3, :source_uri_params => "cluster=jruby;dir=files"
157
+ project.project_source_versions << ps1 << ps2 << ps3
158
+
159
+ sources = project.sources_for_version("1.5")
160
+ sources.size.should == 2
161
+ sources.include?(source1).should be_false
162
+ sources.include?(source2).should be_true
163
+ sources.include?(source3).should be_true
164
+
165
+ sources[0].uri.should == "http://mo.morsi.org/files/jruby/joni.spec"
166
+ sources[1].uri.should == "http://mo.morsi.org/files/jruby/jruby.spec"
167
+ end
168
+
169
+ it "should provide access to primary source" do
170
+ project = Project.create! :name => 'primary-source-project-test'
171
+ source1 = Source.create!(:name => 'primary-source-test1', :source_type => 'file', :uri => 'http://foo1.foo')
172
+ source2 = Source.create!(:name => 'primary-source-test2', :source_type => 'file', :uri => 'http://foo2.foo')
173
+ project.sources << source1
174
+ project.primary_source= source2
175
+
176
+ primary_src = project.primary_source
177
+ primary_src.should_not be_nil
178
+ primary_src.name.should == source2.name
179
+ end
180
+
181
+ it "should provide access to all dependencies for the specified version" do
182
+ project1 = Project.create! :name => "project-dependency-tree10"
183
+ project2 = Project.create! :name => "project-dependency-tree20"
184
+ project3 = Project.create! :name => "project-dependency-tree30"
185
+ project4 = Project.create! :name => "project-dependency-tree40"
186
+
187
+ pd1 = ProjectDependency.create! :project => project1, :depends_on_project => project2, :project_version => "1.0.0"
188
+ pd2 = ProjectDependency.create! :project => project1, :depends_on_project => project3, :project_version => "2.0.0"
189
+ pd2 = ProjectDependency.create! :project => project1, :depends_on_project => project4
190
+
191
+ deps = project1.dependencies_for_version("1.0.0")
192
+ deps.size.should == 2
193
+ deps[0].depends_on_project.id.should == project2.id
194
+ deps[1].depends_on_project.id.should == project4.id
195
+ end
196
+
197
+ it "should return all versions which the project is configured for" do
198
+ project = Project.new :name => 'project-dl-test100'
199
+ event1 = Event.new :version_qualifier => "=", :version => "1.5"
200
+ event2 = Event.new :version_qualifier => ">", :version => "1.6"
201
+ project.events << event1 << event2
202
+
203
+ source1 = Source.new :name => 'jffi-spec', :uri => 'http://mo.morsi.org/%{dir}/%{cluster}/jffi.spec', :source_type => 'spec'
204
+ source2 = Source.new :name => 'joni-spec', :uri => 'http://mo.morsi.org/%{dir}/%{cluster}/joni.spec', :source_type => 'spec'
205
+ source3 = Source.new :name => 'jruby-spec', :uri => 'http://mo.morsi.org/%{dir}/%{cluster}/jruby.spec', :source_type => 'spec'
206
+ ps1 = ProjectSourceVersion.new :project => project, :source => source1, :source_uri_params => "cluster=jruby;filetype=spec"
207
+ ps2 = ProjectSourceVersion.new :project => project, :source => source2, :project_version => "1.5", :source_uri_params => "cluster=jruby;dir=files"
208
+ ps3 = ProjectSourceVersion.new :project => project, :source => source3, :project_version => "1.7", :source_uri_params => "cluster=jruby;dir=files"
209
+ project.project_source_versions << ps1 << ps2 << ps3
210
+
211
+ projectd = Project.new :name => 'project-version-test99'
212
+ project.project_dependencies << ProjectDependency.new(:project => project, :depends_on_project => projectd, :project_version => "9.9")
213
+
214
+ versions = project.versions
215
+ versions.size.should == 4
216
+ versions.include?("1.5").should be_true
217
+ versions.include?("1.6").should be_true
218
+ versions.include?("1.7").should be_true
219
+ versions.include?("9.9").should be_true
220
+ end
36
221
 
222
+ it "should trigger dependencies and events upon release" do
223
+ project = Project.create :name => 'project-release-test-199'
224
+
225
+ Event.create :project => project,
226
+ :process => "project_released_test_handlerAAA",
227
+ :version_qualifier => '=',
228
+ :version => "5.6"
229
+
230
+ Event.create :project => project,
231
+ :process => "project_released_test_handlerBBB",
232
+ :version_qualifier => '>',
233
+ :version => "7.9"
234
+
235
+ projectd1 = Project.create :name => 'project-release-test-299'
236
+ Event.create :project => projectd1,
237
+ :process => "project_released_test_handlerDDD"
238
+ Event.create :project => projectd1,
239
+ :process => "project_released_test_handlerEEE",
240
+ :version_qualifier => "=",
241
+ :version => "1.9"
242
+
243
+ projectd2 = Project.create :name => 'project-release-test-399'
244
+ Event.create :project => projectd2,
245
+ :process => "project_released_test_handlerFFF",
246
+ :version_qualifier => "=",
247
+ :version => "1.9"
248
+ Event.create :project => projectd2,
249
+ :process => "project_released_test_handlerGGG",
250
+ :version_qualifier => "=",
251
+ :version => "6.5"
252
+
253
+ projectd3 = Project.create :name => 'project-release-test-499'
254
+ Event.create :project => projectd3,
255
+ :process => "project_released_test_handlerCCC"
256
+
257
+ pd1 = ProjectDependency.new :project => project, :depends_on_project => projectd1, :depends_on_project_params => "jim=bo;john=mark"
258
+ pd2 = ProjectDependency.new :project => project, :depends_on_project => projectd2, :project_version => "5.6", :depends_on_project_version => "6.5"
259
+ pd3 = ProjectDependency.new :project => project, :depends_on_project => projectd3, :project_version => "7.9"
260
+ project.project_dependencies << pd1 << pd2 << pd3
261
+
262
+ project.released_version("5.6", :joe => 'bob', :sam => 'sue')
263
+
264
+ $project_released_test_handler_flags.include?('AAA').should be_true
265
+ $project_released_test_handler_flags.include?('BBB').should be_false
266
+ $project_released_test_handler_flags.include?('CCC').should be_false
267
+ $project_released_test_handler_flags.include?('DDD').should be_true
268
+ $project_released_test_handler_flags.include?('EEE').should be_true
269
+ $project_released_test_handler_flags.include?('FFF').should be_false
270
+ $project_released_test_handler_flags.include?('GGG').should be_true
271
+ $project_released_test_handler_flags.include?('joe=bob').should be_true
272
+ $project_released_test_handler_flags.include?('sam=sue').should be_true
273
+ $project_released_test_handler_flags.include?('jim=bo').should be_true
274
+ $project_released_test_handler_flags.include?('john=mark').should be_true
275
+ end
37
276
  end
38
277
 
278
+ describe "Polisher::Source" do
279
+ before(:each) do
280
+ FileUtils.rm_rf(ARTIFACTS_DIR) if File.directory? ARTIFACTS_DIR
281
+ FileUtils.mkdir_p(ARTIFACTS_DIR)
282
+ end
283
+
284
+ after(:each) do
285
+ FileUtils.rm_rf(ARTIFACTS_DIR) if File.directory? ARTIFACTS_DIR
286
+ end
39
287
 
40
- describe "Polisher::ManagedGem" do
41
- it "should not be valid if name or source is missing" do
42
- gem = ManagedGem.new :name => 'foo', :source_id => 1
43
- gem.valid?.should be(true)
288
+ it "should not be valid if name, source_type, or uri is missing or invalid" do
289
+ source = Source.new :uri => 'uri', :name => "foo", :source_type => "gem"
290
+ source.should be_valid
44
291
 
45
- gem.name = nil
46
- gem.valid?.should be(false)
47
- gem.name = 'foo'
292
+ source.uri = nil
293
+ source.should_not be_valid
294
+ source.uri = 'uri'
48
295
 
49
- gem.source_id = nil
50
- gem.valid?.should be(false)
296
+ source.source_type = nil
297
+ source.should_not be_valid
298
+ source.source_type = 'bar'
299
+ source.should_not be_valid
300
+ source.source_type = 'file'
301
+
302
+ source.name = nil
303
+ source.should_not be_valid
51
304
  end
52
305
 
53
- it "should not be valid if name is not unique within source scope" do
54
- gem1 = ManagedGem.create :name => 'foo', :source_id => 1
55
- gem2 = ManagedGem.new :name => 'foo', :source_id => 1
56
- gem2.valid?.should be(false)
306
+ it "should not be valid if name or uri is not unique in scope" do
307
+ source1 = Source.create! :uri => 'uri', :name => "foo", :source_type => "gem"
308
+ source2 = Source.new :uri => 'uri', :name => "bar", :source_type => "archive"
309
+ source2.should_not be_valid
310
+
311
+ source3 = Source.new :uri => 'zaz', :name => "foo", :source_type => "archive"
312
+ source3.should_not be_valid
57
313
  end
58
314
 
59
- it "should generate correct source uri from gem uri" do
60
- ManagedGem.uri_to_source_uri('http://rubygems.org/downloads/polisher-0.1.gem').
61
- should == 'http://rubygems.org'
315
+ it "should return filename generated from uri" do
316
+ source = Source.new(
317
+ :uri => 'http://mo.morsi.org/files/jruby/joni-123.spec?addition=foo&params=bar',
318
+ :name => "joni-spec", :source_type => "spec")
319
+ source.filename.should == "joni-123.spec"
62
320
  end
63
321
 
64
- it "should successfully subscribe/unsubscribe to updates" do
65
- gem = ManagedGem.new :name => "polisher", :source_id => 1
66
- gem.subscribe :callback_url => "http://projects.morsi.org/polisher/demo/gems/updated/1"
67
- gem.subscribed?.should == true
68
- gem.unsubscribe :callback_url => "http://projects.morsi.org/polisher/demo/gems/updated/1"
69
- gem.subscribed?.should == false
322
+ it "should return all project_source_versions for the specified version" do
323
+ project1 = Project.new :name => 'project-src-p100'
324
+ project2 = Project.new :name => 'project-src-p101'
325
+ project3 = Project.new :name => 'project-src-p102'
326
+ source = Source.new :name => 'jffi-spec', :uri => 'http://mo.morsi.org/%{dir}/%{cluster}/jffi.spec', :source_type => 'spec'
327
+
328
+ ps1 = ProjectSourceVersion.new :project => project1, :source => source, :source_uri_params => "cluster=jruby;filetype=spec"
329
+ ps2 = ProjectSourceVersion.new :project => project2, :source => source, :project_version => "1.5", :source_uri_params => "cluster=jruby;dir=files"
330
+ ps3 = ProjectSourceVersion.new :project => project3, :source => source, :project_version => "1.6", :source_uri_params => "cluster=jruby;dir=files"
331
+ source.project_source_versions << ps1 << ps2
332
+
333
+ project_sources = source.project_source_versions_for_version("1.5")
334
+ project_sources.size.should == 2
335
+ project_sources.include?(ps1).should be_true
336
+ project_sources.include?(ps2).should be_true
337
+ project_sources.include?(ps3).should be_false
70
338
  end
71
339
 
72
- it "should successfully get remote gem info" do
73
- gem = ManagedGem.new :name => "polisher", :source_id => 1
74
- info = gem.get_info
75
- info["name"].should == "polisher"
340
+ it "should return all projects for the specified version" do
341
+ project1 = Project.new :name => 'project-src-p100'
342
+ project2 = Project.new :name => 'project-src-p101'
343
+ project3 = Project.new :name => 'project-src-p102'
344
+ source = Source.new :name => 'jffi-spec', :uri => 'http://mo.morsi.org/%{dir}/%{cluster}/jffi.spec', :source_type => 'spec'
345
+
346
+ ps1 = ProjectSourceVersion.new :project => project1, :source => source, :source_uri_params => "cluster=jruby;filetype=spec"
347
+ ps2 = ProjectSourceVersion.new :project => project2, :source => source, :source_version => "1.5", :source_uri_params => "cluster=jruby;dir=files"
348
+ ps3 = ProjectSourceVersion.new :project => project3, :source => source, :source_version => "1.6", :source_uri_params => "cluster=jruby;dir=files"
349
+ source.project_source_versions << ps1 << ps2 << ps3
350
+
351
+ projects = source.project_source_versions_for_version("1.5")
352
+ projects.size.should == 2
353
+ projects.collect { |p| p.source_version }.include?(nil).should be_true
354
+ projects.collect { |p| p.source_version }.include?("1.5").should be_true
355
+ projects.collect { |p| p.source_version }.include?("1.6").should be_false
356
+
357
+ projects.collect { |p| p.project.name }.include?("project-src-p100").should be_true
358
+ projects.collect { |p| p.project.name }.include?("project-src-p101").should be_true
359
+ projects.collect { |p| p.project.name }.include?("project-src-p102").should be_false
76
360
  end
77
361
 
78
- it "should successfully download gem" do
79
- FileUtils.rm_rf(ARTIFACTS_DIR) if File.directory? ARTIFACTS_DIR
80
- FileUtils.mkdir_p(ARTIFACTS_DIR)
362
+ it "should return all versions which the source is configured for" do
363
+ project1 = Project.new :name => 'project-src-p100'
364
+ project2 = Project.new :name => 'project-src-p101'
365
+ project3 = Project.new :name => 'project-src-p102'
366
+ source = Source.new :name => 'jffi-spec', :uri => 'http://mo.morsi.org/%{dir}/%{cluster}/jffi.spec', :source_type => 'spec'
367
+
368
+ ps1 = ProjectSourceVersion.new :project => project1, :source => source, :source_uri_params => "cluster=jruby;filetype=spec"
369
+ ps2 = ProjectSourceVersion.new :project => project2, :source => source, :source_version => "1.5", :source_uri_params => "cluster=jruby;dir=files"
370
+ ps3 = ProjectSourceVersion.new :project => project3, :source => source, :source_version => "1.6", :source_uri_params => "cluster=jruby;dir=files"
371
+ source.project_source_versions << ps1 << ps2 << ps3
372
+
373
+ versions = source.versions
374
+ versions.size.should == 2
375
+ versions.include?("1.5").should be_true
376
+ versions.include?("1.6").should be_true
377
+ end
81
378
 
82
- gem = ManagedGem.new :name => "polisher", :source_id => 1
83
- path = gem.download_to(:dir => ARTIFACTS_DIR, :version => 0.1)
84
- File.size?(ARTIFACTS_DIR + '/polisher-0.1.gem').should_not be_nil
85
- FileUtils.rm(ARTIFACTS_DIR + '/polisher-0.1.gem')
86
- path.should == ARTIFACTS_DIR + '/polisher-0.1.gem'
379
+ it "should format the uri w/ the specified variables" do
380
+ source = Source.new :uri => "http://%{var1}.%{var2}/%{another}?%{yet_another}=%{even_more}&%{last}"
381
+ source.format_uri! :var1 => 'val1', :var2 => 'val2',
382
+ :another => 'foo', :yet_another => 'bar',
383
+ :even_more => 'something', :last => '123'
87
384
 
385
+ source.uri.should == "http://val1.val2/foo?bar=something&123"
386
+ end
88
387
 
89
- gem.download_to(:path => ARTIFACTS_DIR + '/my.gem', :version => 0.1)
90
- File.size?(ARTIFACTS_DIR + '/my.gem').should_not be_nil
388
+ it "should be downloadable" do
389
+ source = Source.new(
390
+ :uri => 'http://mo.morsi.org/files/jruby/joni.spec',
391
+ :name => "joni-spec", :source_type => "spec")
392
+ path = source.download_to(:dir => ARTIFACTS_DIR)
393
+ File.size?(ARTIFACTS_DIR + '/joni.spec').should_not be_nil
394
+ FileUtils.rm(ARTIFACTS_DIR + '/joni.spec')
395
+ path.should == ARTIFACTS_DIR + '/joni.spec'
396
+
397
+ source.download_to(:path => ARTIFACTS_DIR + '/joni.spec')
398
+ File.size?(ARTIFACTS_DIR + '/joni.spec').should_not be_nil
399
+ end
91
400
 
92
- gem.download_to(:dir => ARTIFACTS_DIR)
93
- File.size?(ARTIFACTS_DIR + '/polisher-0.1.gem').should_not be_nil
401
+ it "should permit a parameterized download" do
402
+ source = Source.new(
403
+ :uri => 'http://mo.morsi.org/files/%{group}/%{name}.spec',
404
+ :name => "joni-spec", :source_type => 'spec')
405
+ path = source.download_to(:dir => ARTIFACTS_DIR, :group => "jruby", :name => "joni")
406
+ File.size?(ARTIFACTS_DIR + '/joni.spec').should_not be_nil
407
+ FileUtils.rm(ARTIFACTS_DIR + '/joni.spec')
408
+ path.should == ARTIFACTS_DIR + '/joni.spec'
409
+
410
+ source.download_to(:path => ARTIFACTS_DIR + '/joni.spec')
411
+ File.size?(ARTIFACTS_DIR + '/joni.spec').should_not be_nil
94
412
  end
95
413
 
414
+ it "should raise an exception if download source uri or destination path is invalid" do
415
+ source = Source.new(
416
+ :uri => 'http://invalid.uri',
417
+ :name => 'invalid-source1', :source_type => 'file')
418
+ lambda {
419
+ path = source.download_to(:dir => ARTIFACTS_DIR)
420
+ }.should raise_error(RuntimeError)
421
+
422
+ source = Source.new(
423
+ :uri => 'http://mo.morsi.org/files/jruby/joni.spec',
424
+ :name => 'invalid-source2', :source_type => 'spec')
425
+ lambda {
426
+ path = source.download_to(:dir => '/')
427
+ }.should raise_error(RuntimeError)
428
+
429
+ lambda {
430
+ path = source.download_to(:dir => '/nonexistantfoobar')
431
+ }.should raise_error(RuntimeError)
432
+ end
96
433
  end
97
434
 
98
- describe "Polisher::Event" do
435
+ describe "Polisher::ProjectSourceVersion" do
436
+
437
+ it "should default primary_source to false" do
438
+ project = Project.create! :name => 'project-source-valid-testproj0'
439
+ source = Source.create! :name => 'project-source-valid-testsource0',
440
+ :uri => 'http://presvts234', :source_type => 'file'
441
+ ps = ProjectSourceVersion.create! :project => project, :source => source
442
+ ps.primary_source.should be_false
443
+ end
444
+
445
+ it "should default versions to nil" do
446
+ project = Project.create! :name => 'project-source-valid-testproj10'
447
+ source = Source.create! :name => 'project-source-valid-testsource10',
448
+ :uri => 'http://presvts098', :source_type => 'file'
449
+ ps = ProjectSourceVersion.create! :project => project, :source => source, :project_version => "", :source_version => ""
450
+ ps.project_version.should be_nil
451
+ ps.source_version.should be_nil
452
+ end
453
+
454
+ it "should not be valid if a project id/version is associated w/ a source multiple times" do
455
+ project = Project.create! :name => 'project-source-valid-testproj1'
456
+ source = Source.create! :name => 'project-source-valid-testsource1',
457
+ :uri => 'http://presvts581', :source_type => 'file'
458
+
459
+ ps1 = ProjectSourceVersion.create! :project => project, :source => source, :project_version => '1.6'
460
+ ps2 = ProjectSourceVersion.new :project => project, :source => source, :project_version => '1.6'
461
+
462
+ ps2.valid?.should be_false
463
+ end
464
+
465
+ it "should not be valid if a project id/version is associated w/ multiple primary sources" do
466
+ project = Project.create! :name => 'project-source-valid-testproj2'
467
+ source1 = Source.create! :name => 'project-source-valid-testsource100',
468
+ :uri => 'http://presvts690', :source_type => 'file'
469
+ source2 = Source.create! :name => 'project-source-valid-testsource200',
470
+ :uri => 'http://presvts456', :source_type => 'file'
471
+
472
+ ps1 = ProjectSourceVersion.create! :project => project, :source => source1, :project_version => '1.6',
473
+ :primary_source => true
474
+
475
+ ps2 = ProjectSourceVersion.new :project => project, :source => source2, :project_version => '1.6',
476
+ :primary_source => true
99
477
 
100
- it "should not be valid if managed_gem or process is missing" do
101
- gem = ManagedGem.create :name => 'valid-event-test-gem1', :source_id => 1
478
+ ps2.valid?.should be_false
479
+ end
480
+
481
+ end
482
+
483
+ describe "Polisher::ProjectDependency" do
484
+
485
+ it "should default versions to nil" do
486
+ project1 = Project.create! :name => 'project-dep-valid-testproj10'
487
+ project2 = Project.create! :name => 'project-dep-valid-testproj20'
488
+
489
+ pd = ProjectDependency.create! :project => project1, :depends_on_project => project2
490
+ pd.project_version.should be_nil
491
+ pd.depends_on_project_version.should be_nil
492
+ end
493
+
494
+ it "should not be valid if missing project or depends_on_project" do
495
+ project1 = Project.create! :name => 'project-dep-valid-testproj30'
496
+ project2 = Project.create! :name => 'project-dep-valid-testproj40'
497
+
498
+ pd = ProjectDependency.new
499
+ pd.should_not be_valid
500
+
501
+
502
+ pd = ProjectDependency.new :project => project1
503
+ pd.should_not be_valid
504
+
505
+ pd = ProjectDependency.new :depends_on_project => project2
506
+ pd.should_not be_valid
507
+
508
+ pd = ProjectDependency.new :project => project1, :depends_on_project => project2
509
+ pd.should be_valid
510
+ end
511
+
512
+ it "should not be valid if project/depends_on_project/project_version/depends_on_project_version are not unique" do
513
+ project1 = Project.create! :name => 'project-dep-valid-testproj50'
514
+ project2 = Project.create! :name => 'project-dep-valid-testproj60'
515
+
516
+ pd = ProjectDependency.create! :project => project1, :depends_on_project => project2, :project_version => "1.0.0", :depends_on_project_version => "2.0.1"
102
517
 
103
- event = Event.new :managed_gem_id => gem.id, :process => 'create_repo'
104
- event.valid?.should be(true)
518
+ pd2 = ProjectDependency.new :project => project1, :depends_on_project => project2, :project_version => "1.0.0", :depends_on_project_version => "2.0.1"
519
+ pd2.should_not be_valid
105
520
 
106
- event.managed_gem = nil
107
- event.valid?.should be(false)
108
- event.managed_gem = gem
521
+ pd2.depends_on_project_version = "2.0.2"
522
+ pd2.should be_valid
523
+ end
524
+
525
+ end
526
+
527
+ describe "Polisher::Event" do
528
+
529
+ it "should return list of supported event handlers" do
530
+ processes = Event::processes
531
+ processes.size.should == 3
532
+ processes.include?("download_sources").should be_true
533
+ processes.include?("create_rpm_package").should be_true
534
+ processes.include?("update_yum_repo").should be_true
535
+ end
536
+
537
+ it "should not be valid if process is missing" do
538
+ project = Project.create! :name => 'valid-event-test-project0'
539
+ event = Event.new :project_id => project.id, :process => 'create_repo'
540
+ event.should be_valid
109
541
 
110
542
  event.process = nil
111
- event.valid?.should be(false)
543
+ event.should_not be_valid
544
+ end
545
+
546
+ it "should not be valid if project is missing" do
547
+ project = Project.create! :name => 'valid-event-test-project1'
548
+ event = Event.new :process => 'create_repo'
549
+ event.should_not be_valid
550
+ event.project = project
551
+ event.should be_valid
112
552
  end
113
553
 
114
554
  it "should not be valid with invalid version qualifier" do
115
- gem = ManagedGem.create :name => 'valid-event-test-gem2', :source_id => 1
555
+ project = Project.create! :name => 'valid-event-test-project2'
116
556
 
117
- event = Event.new :managed_gem_id => gem.id, :process => 'create_repo', :version_qualifier => ">", :gem_version => 5
118
- event.valid?.should be(true)
557
+ event = Event.new :project_id => project.id, :process => 'create_repo', :version_qualifier => ">", :version => 5
558
+ event.should be_valid
119
559
 
120
560
  event.version_qualifier = '=='
121
- event.valid?.should be(false)
561
+ event.should_not be_valid
122
562
  end
123
563
 
124
564
  it "should not be valid if version/qualifier are not both present or nil" do
125
- gem = ManagedGem.create :name => 'valid-event-test-gem3', :source_id => 1
126
-
127
- event = Event.new :managed_gem_id => gem.id, :process => 'create_repo', :version_qualifier => ">"
128
- event.valid?.should be(false)
129
-
130
- event = Event.new :managed_gem_id => gem.id, :process => 'create_repo', :gem_version => 5
131
- event.valid?.should be(false)
132
-
133
- event = Event.new :managed_gem_id => gem.id, :process => 'create_repo', :gem_version => 5, :version_qualifier => '<='
134
- event.valid?.should be(true)
565
+ project = Project.create! :name => 'valid-event-test-project3'
566
+
567
+ event = Event.new :project_id => project.id, :process => 'create_repo', :version_qualifier => ">"
568
+ event.should_not be_valid
569
+
570
+ event = Event.new :project_id => project.id, :process => 'create_repo', :version => 5
571
+ event.should_not be_valid
572
+
573
+ event = Event.new :project_id => project.id, :process => 'create_repo', :version => 5, :version_qualifier => '<='
574
+ event.should be_valid
135
575
  end
136
576
 
137
577
  it "should correctly resolve version qualifiers" do
138
- event = Event.new :version_qualifier => nil
578
+ event = Event.new :version_qualifier => nil, :version => "5"
139
579
  event.applies_to_version?('1.1').should be(true)
580
+ event.applies_to_version?('1.5.3').should be(true)
140
581
 
141
- event = Event.new :version_qualifier => "=", :gem_version => "5.3"
582
+ event = Event.new :version_qualifier => "=", :version => "5.3"
142
583
  event.applies_to_version?('1.2').should be(false)
143
584
  event.applies_to_version?('5.3').should be(true)
585
+ event.applies_to_version?('5.3.0').should be(false)
586
+ event.applies_to_version?('5.3.1').should be(false)
144
587
  event.applies_to_version?('7.9').should be(false)
145
588
 
146
- event = Event.new :version_qualifier => ">", :gem_version => "1.9"
147
- event.applies_to_version?('1.8').should be(false)
148
- event.applies_to_version?('1.9').should be(false)
589
+ event = Event.new :version_qualifier => ">", :version => "1.9.2"
590
+ event.applies_to_version?('1.8.1').should be(false)
591
+ event.applies_to_version?('1.9.1').should be(false)
592
+ event.applies_to_version?('1.9.3').should be(true)
149
593
  event.applies_to_version?('2.0').should be(true)
150
594
 
151
- event = Event.new :version_qualifier => "<", :gem_version => "0.6"
595
+ event = Event.new :version_qualifier => "<", :version => "0.6"
152
596
  event.applies_to_version?('0.5').should be(true)
153
597
  event.applies_to_version?('0.6').should be(false)
154
598
  event.applies_to_version?('0.7').should be(false)
155
599
 
156
- event = Event.new :version_qualifier => ">=", :gem_version => "1.9"
600
+ event = Event.new :version_qualifier => ">=", :version => "1.9"
157
601
  event.applies_to_version?('1.8').should be(false)
158
602
  event.applies_to_version?('1.9').should be(true)
159
603
  event.applies_to_version?('2.0').should be(true)
160
604
 
161
- event = Event.new :version_qualifier => "<=", :gem_version => "0.6"
162
- event.applies_to_version?('0.5').should be(true)
163
- event.applies_to_version?('0.6').should be(true)
164
- event.applies_to_version?('0.7').should be(false)
605
+ event = Event.new :version_qualifier => "<=", :version => "0.6.4"
606
+ event.applies_to_version?('0.5.2').should be(true)
607
+ event.applies_to_version?('0.6.1').should be(true)
608
+ event.applies_to_version?('0.6.6').should be(false)
609
+ event.applies_to_version?('0.7.4').should be(false)
610
+ end
611
+
612
+ it "should raise error if trying to compare invalid versions" do
613
+ event = Event.new
614
+
615
+ # nil event version and version_qualifier is permitted
616
+ #lambda {
617
+ # event.applies_to_version?('0.5.2')
618
+ #}.should raise_error(ArgumentError)
619
+
620
+ event.version = '0.7'
621
+ lambda {
622
+ event.applies_to_version?(111)
623
+ }.should raise_error(ArgumentError)
165
624
  end
166
625
 
167
626
  it "should successfully run event process" do
168
- gem = ManagedGem.new :name => "foobar"
169
- event = Event.new :managed_gem => gem, :process => "test_event_run_method", :process_options => "a;b;c"
170
- event.run
171
-
172
- $test_event_run_hash[:gem].should_not be_nil
173
- $test_event_run_hash[:first].should_not be_nil
174
- $test_event_run_hash[:second].should_not be_nil
175
- $test_event_run_hash[:third].should_not be_nil
176
-
177
- $test_event_run_hash[:gem].name.should == "foobar"
178
- $test_event_run_hash[:first].should == "a"
179
- $test_event_run_hash[:second].should == "b"
180
- $test_event_run_hash[:third].should == "c"
627
+ project = Project.new :name => "foobar"
628
+ event = Event.new :project => project, :process => "test_event_run_method"
629
+ event.run(:version => "5.0", :key1 => "val1", :some => "thing", :answer => 42)
630
+
631
+ $test_event_run_hash[:event].should_not be_nil
632
+ $test_event_run_hash[:project].should_not be_nil
633
+ $test_event_run_hash[:version].should_not be_nil
634
+ $test_event_run_hash[:key1].should_not be_nil
635
+ $test_event_run_hash[:some].should_not be_nil
636
+ $test_event_run_hash[:answer].should_not be_nil
637
+
638
+ $test_event_run_hash[:event].process == "test_event_run_method"
639
+ $test_event_run_hash[:project].name.should == "foobar"
640
+ $test_event_run_hash[:version].should == "5.0"
641
+ $test_event_run_hash[:key1].should == "val1"
642
+ $test_event_run_hash[:some].should == "thing"
643
+ $test_event_run_hash[:answer].should == 42
644
+ end
645
+
646
+ it "should raise an exception if running event w/out specifying version" do
647
+ project = Project.new :name => "foobar"
648
+ event = Event.new :project => project, :process => "test_event_run_method"
649
+ lambda {
650
+ event.run
651
+ }.should raise_error(ArgumentError)
652
+ end
653
+
654
+ it "should raise an exception if running event process that doesn't correspond to a method" do
655
+ project = Project.new :name => "foobar"
656
+ event = Event.new :project => project, :process => "non_existant_method"
657
+ lambda {
658
+ event.run :version => "5"
659
+ }.should raise_error(ArgumentError)
660
+ end
661
+
662
+ it "should raise an exception if event process being run does" do
663
+ project = Project.new :name => "foobar"
664
+ event = Event.new :project => project, :process => "error_generating_method"
665
+ lambda {
666
+ event.run :version => "5"
667
+ }.should raise_error(RuntimeError)
181
668
  end
182
669
  end
183
670
 
@@ -185,9 +672,50 @@ end
185
672
  $test_event_run_hash = {}
186
673
 
187
674
  # helper method, invoked in Event::run spec
188
- def test_event_run_method(gem, first, second, third)
189
- $test_event_run_hash[:gem] = gem
190
- $test_event_run_hash[:first] = first
191
- $test_event_run_hash[:second] = second
192
- $test_event_run_hash[:third] = third
675
+ def test_event_run_method(event, version, args = {})
676
+ $test_event_run_hash[:event] = event
677
+ $test_event_run_hash[:project] = event.project
678
+ $test_event_run_hash[:version] = version
679
+ $test_event_run_hash[:key1] = args[:key1]
680
+ $test_event_run_hash[:some] = args[:some]
681
+ $test_event_run_hash[:answer] = args[:answer]
682
+ end
683
+
684
+ def error_generating_method(event, version, args = {})
685
+ raise RuntimeError
686
+ end
687
+
688
+ $project_released_test_handler_flags = []
689
+
690
+ def project_released_test_handlerAAA(event, version, args = {})
691
+ $project_released_test_handler_flags << "AAA"
692
+ end
693
+
694
+ def project_released_test_handlerBBB(event, version, args = {})
695
+ $project_released_test_handler_flags << "BBB"
696
+ end
697
+
698
+ def project_released_test_handlerCCC(event, version, args = {})
699
+ $project_released_test_handler_flags << "CCC"
700
+ end
701
+
702
+ def project_released_test_handlerDDD(event, version, args = {})
703
+ $project_released_test_handler_flags << "DDD"
704
+
705
+ args.each { |k,v|
706
+ $project_released_test_handler_flags << "#{k}=#{v}"
707
+ }
193
708
  end
709
+
710
+ def project_released_test_handlerEEE(event, version, args = {})
711
+ $project_released_test_handler_flags << "EEE"
712
+ end
713
+
714
+ def project_released_test_handlerFFF(event, version, args = {})
715
+ $project_released_test_handler_flags << "FFF"
716
+ end
717
+
718
+ def project_released_test_handlerGGG(event, version, args = {})
719
+ $project_released_test_handler_flags << "GGG"
720
+ end
721
+