integrity 0.1.9.2 → 0.1.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,8 @@
1
1
  require File.dirname(__FILE__) + "/../helpers"
2
+
3
+ gem "foca-storyteller"
4
+ require "storyteller"
5
+
2
6
  require "helpers/acceptance/git_helper"
3
7
 
4
8
  module AcceptanceHelper
@@ -0,0 +1,47 @@
1
+ module NotifierHelper
2
+ def fill_in_email_notifier
3
+ fill_in "notifiers[Email][to]", :with => "quentin@example.com"
4
+ fill_in "notifiers[Email][from]", :with => "ci@example.com"
5
+ fill_in "notifiers[Email][user]", :with => "inspector"
6
+ fill_in "notifiers[Email][pass]", :with => "gadget"
7
+ fill_in "notifiers[Email][auth]", :with => "simple"
8
+ fill_in "notifiers[Email][domain]", :with => "example.com"
9
+ end
10
+
11
+ def fill_in_project_info(name, repo)
12
+ fill_in "Name", :with => name
13
+ fill_in "Git repository", :with => repo
14
+ fill_in "Branch to track", :with => "master"
15
+ fill_in "Build script", :with => "rake"
16
+ check "Public project"
17
+
18
+ fill_in_email_notifier
19
+ end
20
+
21
+ def assert_have_email_notifier
22
+ assert_have_tag "input#email_notifier_to[@value='quentin@example.com']"
23
+ assert_have_tag "input#email_notifier_from[@value='ci@example.com']"
24
+ assert_have_tag "input#email_notifier_user[@value='inspector']"
25
+ assert_have_tag "input#email_notifier_pass[@value='gadget']"
26
+ assert_have_tag "input#email_notifier_auth[@value='simple']"
27
+ assert_have_tag "input#email_notifier_domain[@value='example.com']"
28
+ end
29
+
30
+ def add_project(name, repo)
31
+ visit "/new"
32
+ fill_in_project_info(name, repo)
33
+ click_button "Create Project"
34
+
35
+ assert_have_tag("h1", :content => name)
36
+ click_link 'Edit Project'
37
+ assert_have_email_notifier
38
+ end
39
+
40
+ def edit_project(name)
41
+ visit "/#{name}"
42
+ click_link "Edit Project"
43
+ assert_have_email_notifier
44
+ fill_in :branch, :with => "testing"
45
+ click_button "Update Project"
46
+ end
47
+ end
@@ -36,16 +36,6 @@ class BuildTest < Test::Unit::TestCase
36
36
  @build.successful = false
37
37
  @build.status.should be(:failed)
38
38
  end
39
-
40
- test "deprecated properties" do
41
- @build.short_commit_identifier.should == @build.commit.short_identifier
42
- @build.commit_identifier.should == @build.commit.identifier
43
- @build.commit_author.should == @build.commit.author
44
- @build.commit_message.should == @build.commit.message
45
- @build.commited_at.should == @build.commit.committed_at
46
- @build.project_id.should == @build.commit.project_id
47
- @build.should respond_to(:commit_metadata)
48
- end
49
39
  end
50
40
 
51
41
  describe "Pending builds" do
@@ -58,4 +48,25 @@ class BuildTest < Test::Unit::TestCase
58
48
  Build.should have(3).pending
59
49
  end
60
50
  end
51
+
52
+ describe "Queueing a build" do
53
+ before(:each) do
54
+ @commit = Commit.gen
55
+ stub.instance_of(ProjectBuilder).build(@commit)
56
+ end
57
+
58
+ it "creates an empty Build" do
59
+ @commit.build.should be_nil
60
+ Build.queue(@commit)
61
+ @commit.build.should_not be_nil
62
+ end
63
+
64
+ it "ensures the build is saved" do
65
+ @commit.build.should be_nil
66
+ Build.queue(@commit)
67
+
68
+ commit = Commit.first(:identifier => @commit.identifier)
69
+ commit.build.should_not be_nil
70
+ end
71
+ end
61
72
  end
@@ -32,6 +32,8 @@ class CommitTest < Test::Unit::TestCase
32
32
  commit.author.name.should == "Nicolás Sanguinetti"
33
33
  commit.author.email.should == "contacto@nicolassanguinetti.info"
34
34
  commit.author.full.should == "Nicolás Sanguinetti <contacto@nicolassanguinetti.info>"
35
+
36
+ Commit.gen(:author => nil).author.to_s.should =~ /not loaded/
35
37
  end
36
38
 
37
39
  it "raises ArgumentError with invalid author" do
@@ -41,6 +43,8 @@ class CommitTest < Test::Unit::TestCase
41
43
  it "has a commit message" do
42
44
  commit = Commit.gen(:message => "This commit rocks")
43
45
  commit.message.should == "This commit rocks"
46
+
47
+ Commit.gen(:message => nil).message.should =~ /not loaded/
44
48
  end
45
49
 
46
50
  it "has a commit date" do
@@ -59,25 +63,4 @@ class CommitTest < Test::Unit::TestCase
59
63
  commit.human_readable_status.should be("658ba96 hasn't been built yet")
60
64
  end
61
65
  end
62
-
63
- describe "Queueing a build" do
64
- before(:each) do
65
- @commit = Commit.gen
66
- stub.instance_of(ProjectBuilder).build(@commit)
67
- end
68
-
69
- it "creates an empty Build" do
70
- @commit.build.should be_nil
71
- @commit.queue_build
72
- @commit.build.should_not be_nil
73
- end
74
-
75
- it "ensures the build is saved" do
76
- @commit.build.should be_nil
77
- @commit.queue_build
78
-
79
- commit = Commit.first(:identifier => @commit.identifier)
80
- commit.build.should_not be_nil
81
- end
82
- end
83
66
  end
@@ -53,15 +53,19 @@ class BrowsePublicProjectsTest < Test::Unit::TestCase
53
53
  end
54
54
 
55
55
  test "commit" do
56
- assert_equal "/ci/foo-bar/commits/#{@commit.identifier}",
57
- @h.commit_path(@build.commit)
58
- assert_equal "http://example.org/ci/foo-bar/commits/#{@commit.identifier}",
59
- @h.commit_url(@build.commit).to_s
56
+ silence_warnings {
57
+ assert_equal "/ci/foo-bar/commits/#{@commit.identifier}",
58
+ @h.commit_path(@build.commit)
59
+ assert_equal "http://example.org/ci/foo-bar/commits/#{@commit.identifier}",
60
+ @h.commit_url(@build.commit).to_s
61
+ }
60
62
  end
61
63
 
62
64
  test "compat" do
63
- assert_equal @h.build_path(@build), @h.commit_path(@build.commit)
64
- assert_equal @h.build_url(@build), @h.commit_url(@build.commit)
65
+ silence_warnings {
66
+ assert_equal @h.build_path(@build), @h.commit_path(@build.commit)
67
+ assert_equal @h.build_url(@build), @h.commit_url(@build.commit)
68
+ }
65
69
  end
66
70
  end
67
71
 
@@ -24,13 +24,14 @@ class MigrationsTest < Test::Unit::TestCase
24
24
 
25
25
  before(:each) do
26
26
  [Project, Build, Commit, Notifier].each(&:auto_migrate_down!)
27
+ database_adapter.execute("DROP TABLE migration_info")
27
28
  assert !table_exists?("migration_info") # just to be sure
28
29
  end
29
30
 
30
31
  test "upgrading a pre migration database" do
31
- util_capture { Integrity.migrate_db }
32
+ capture_stdout { Integrity.migrate_db }
32
33
 
33
- current_migrations.should == ["initial", "add_commits"]
34
+ current_migrations.should == ["initial", "add_commits", "add_enabled_column"]
34
35
  assert table_exists?("integrity_projects")
35
36
  assert table_exists?("integrity_builds")
36
37
  assert table_exists?("integrity_notifiers")
@@ -40,8 +41,8 @@ class MigrationsTest < Test::Unit::TestCase
40
41
  test "migrating data from initial to add_commits migration" do
41
42
  load_initial_migration_fixture
42
43
 
43
- util_capture { Integrity.migrate_db }
44
- current_migrations.should == ["initial", "add_commits"]
44
+ capture_stdout { Integrity.migrate_db }
45
+ current_migrations.should == ["initial", "add_commits", "add_enabled_column"]
45
46
 
46
47
  sinatra = Project.first(:name => "Sinatra")
47
48
  sinatra.should have(1).commits
@@ -0,0 +1,43 @@
1
+ require File.dirname(__FILE__) + "/../../helpers"
2
+
3
+ class BaseNotifierTest < Test::Unit::TestCase
4
+ before(:each) do
5
+ @commit = Commit.gen(:successful)
6
+ @base = Notifier::Base.new(@commit, {})
7
+ end
8
+
9
+ it "requires to implement .to_haml" do
10
+ assert_raise(NotImplementedError) { Notifier::Base.to_haml }
11
+ end
12
+
13
+ it "requires to implement #deliver!" do
14
+ assert_raise(NotImplementedError) { @base.deliver! }
15
+ end
16
+
17
+ it "provides a short message" do
18
+ assert_equal "Built #{@commit.short_identifier} successfully", @base.short_message
19
+ end
20
+
21
+ it "provides a full message" do
22
+ assert @base.full_message.include?("Commit Message: #{@commit.message}")
23
+ assert @base.full_message.include?("Commit Date: #{@commit.committed_at}")
24
+ assert @base.full_message.include?("Commit Author: #{@commit.author.name}")
25
+ assert @base.full_message.include?("Link: #{@base.commit_url}")
26
+ assert @base.full_message.include?("Build Output")
27
+ assert @base.full_message.include?(@commit.build.output)
28
+ end
29
+
30
+ it "provides a commit url" do
31
+ assert_equal "http://localhost:8910/#{@commit.project.name}" +
32
+ "/commits/#{@commit.identifier}", @base.commit_url
33
+ end
34
+
35
+ test "deprecated methods" do
36
+ silence_warnings {
37
+ assert_equal @base.commit, @base.build
38
+ assert_equal @base.commit_url, @base.build_url
39
+ assert_equal @base.send(:stripped_commit_output),
40
+ @base.send(:stripped_build_output)
41
+ }
42
+ end
43
+ end
@@ -1,11 +1,6 @@
1
1
  require File.dirname(__FILE__) + "/../helpers"
2
2
 
3
3
  class NotifierTest < Test::Unit::TestCase
4
- test "deprecated methods" do
5
- Notifier::Base.new(Build.gen, {}).should respond_to(:build)
6
- Notifier::Base.new(Build.gen, {}).should respond_to(:build_url)
7
- end
8
-
9
4
  specify "IRC fixture is valid and can be saved" do
10
5
  lambda do
11
6
  Notifier.generate(:irc).tap do |project|
@@ -71,58 +66,32 @@ class NotifierTest < Test::Unit::TestCase
71
66
  end
72
67
  end
73
68
 
74
- it "knows which notifiers are available" do
75
- Notifier.gen(:irc)
76
- Notifier.gen(:twitter)
77
- Notifier.should have(2).available
78
- Notifier.available.should include(Integrity::Notifier::IRC)
79
- Notifier.available.should include(Integrity::Notifier::Twitter)
80
- end
69
+ describe "Registering a notifier" do
70
+ it "registers given notifier class" do
71
+ load "helpers/acceptance/textfile_notifier.rb"
81
72
 
82
- it "knows how to notify the world of a build" do
83
- irc = Notifier.generate(:irc)
84
- build = Integrity::Build.generate
85
- Notifier::IRC.expects(:notify_of_build).with(build, irc.config)
86
- irc.notify_of_build(build)
87
- end
73
+ Notifier.register(Integrity::Notifier::Textfile)
88
74
 
89
- describe "Enabling a list of notifiers for a project" do
90
- it "creates new notifiers for the project" do
91
- project = Project.generate
92
- lambda do
93
- project.enable_notifiers(["IRC", "Twitter"],
94
- {"IRC" => {"uri" => "irc://irc.freenode.net/integrity"},
95
- "Twitter" => {"username" => "john"}})
96
- end.should change(project.notifiers, :count).from(0).to(2)
75
+ assert_equal Integrity::Notifier::Textfile,
76
+ Notifier.available["Textfile"]
97
77
  end
98
78
 
99
- it "deletes all of previous notifiers" do
100
- project = Project.generate(:notifiers => [Notifier.gen(:irc), Notifier.gen(:twitter)])
101
- lambda do
102
- project.enable_notifiers("IRC", {"IRC" => {:foo => "bar"}})
103
- project.reload
104
- end.should change(project.notifiers, :count).from(2).to(1)
105
- end
79
+ it "raises ArgumentError if given class is not a valid notifier" do
80
+ assert_raise(ArgumentError) {
81
+ Notifier.register(Class.new)
82
+ }
106
83
 
107
- it "does nothing if given nil as the list of notifiers to enable" do
108
- lambda { Project.gen.enable_notifiers(nil, {}) }.should_not change(Notifier, :count)
84
+ assert Notifier.available.empty?
109
85
  end
86
+ end
110
87
 
111
- it "doesn't destroy any of the other notifiers that exist for other projects" do
112
- irc = Notifier.generate(:irc)
113
-
114
- project = Project.gen
115
- project.enable_notifiers("IRC", {"IRC" => irc.config})
88
+ it "knows how to notify the world of a build" do
89
+ irc = Notifier.gen(:irc)
90
+ Notifier.register(Integrity::Notifier::IRC)
91
+ build = Build.gen
116
92
 
117
- lambda do
118
- Project.gen.enable_notifiers("IRC", {"IRC" => irc.config})
119
- end.should_not change(project.notifiers, :count)
120
- end
121
- end
93
+ mock(Notifier::IRC).notify_of_build(build, irc.config) { nil }
122
94
 
123
- it "requires notifier classes to implement Notifier.to_haml and Notifier#deliver!" do
124
- class Blah < Notifier::Base; end
125
- lambda { Blah.to_haml }.should raise_error(NoMethodError)
126
- lambda { Blah.new(Build.gen, {}).deliver! }.should raise_error(NoMethodError)
95
+ irc.notify_of_build(build)
127
96
  end
128
97
  end
@@ -52,7 +52,6 @@ class ProjectBuilderTest < Test::Unit::TestCase
52
52
  }.should raise_error
53
53
  end
54
54
 
55
-
56
55
  it "sets the build status to failure when the build command exits with a non-zero status" do
57
56
  @project.update_attributes(:command => "exit 1")
58
57
  SCM::Git.any_instance.expects(:with_revision).with(@commit.identifier).yields
@@ -94,6 +93,14 @@ class ProjectBuilderTest < Test::Unit::TestCase
94
93
  @project.update_attributes(:uri => "scm://example.org")
95
94
  lambda { ProjectBuilder.new(@project) }.should raise_error(SCM::SCMUnknownError)
96
95
  end
96
+
97
+ it "doesn't fail if the commit identifier can't be retrieved" do
98
+ SCM::Git.any_instance.expects(:with_revision).with(@commit.identifier).yields
99
+ SCM::Git.any_instance.expects(:info).returns(false)
100
+ lambda {
101
+ ProjectBuilder.new(@project).build(@commit)
102
+ }.should_not raise_error
103
+ end
97
104
  end
98
105
 
99
106
  describe "When deleting the code from disk" do
@@ -110,11 +110,6 @@ class ProjectTest < Test::Unit::TestCase
110
110
  project = Project.gen(:commits => commits)
111
111
  project.last_commit.should == commits.sort_by {|c| c.committed_at }.last
112
112
  end
113
-
114
- test "deprecated properties" do
115
- @project.last_build.should == @project.last_commit
116
- @project.previous_builds.should == @project.previous_commits
117
- end
118
113
  end
119
114
 
120
115
  describe "Validation" do
@@ -218,31 +213,113 @@ class ProjectTest < Test::Unit::TestCase
218
213
  end
219
214
  end
220
215
 
216
+ describe "When updating its notifiers" do
217
+ setup do
218
+ twitter = Notifier.gen(:twitter, :enabled => true)
219
+ irc = Notifier.gen(:irc, :enabled => false)
220
+
221
+ @project = Project.gen(:notifiers => [twitter, irc])
222
+ end
223
+
224
+ it "creates and enable the given notifiers" do
225
+ Notifier.all.destroy!
226
+
227
+ project = Project.gen
228
+ project.update_notifiers(["IRC", "Twitter"],
229
+ {"IRC" => {"uri" => "irc://irc.freenode.net/integrity"},
230
+ "Twitter" => {"username" => "john"}})
231
+
232
+ assert_equal 2, Notifier.count
233
+ assert_equal 2, project.enabled_notifiers.count
234
+ assert_equal "IRC", project.notifiers.first.name
235
+ assert_equal "Twitter", project.notifiers.last.name
236
+
237
+ project.update_notifiers(["Twitter"],
238
+ {"IRC" => {"uri" => "irc://irc.freenode.net/integrity"},
239
+ "Twitter" => {"username" => "john"}})
240
+
241
+ assert_equal 2, Notifier.count
242
+ assert ! project.notifies?("IRC")
243
+ assert project.notifies?("Twitter")
244
+ end
245
+
246
+ it "creates notifiers present in config even when they're disabled" do
247
+ @project.update_notifiers(["IRC"],
248
+ {"IRC" => {"uri" => "irc://irc.freenode.net/integrity"},
249
+ "Twitter" => {"username" => "john"}})
250
+
251
+ assert_equal 2, @project.notifiers.count
252
+ end
253
+
254
+ it "disables notifiers that are not included in the list" do
255
+ @project.update_notifiers(["IRC"],
256
+ {"IRC" => {"uri" => "irc://irc.freenode.net/integrity"},
257
+ "Twitter" => {"username" => "john"}})
258
+
259
+ @project.update_notifiers(["IRC"],
260
+ {"IRC" => {"uri" => "irc://irc.freenode.net/integrity"}})
261
+
262
+ assert ! @project.notifiers.first(:name => "Twitter").enabled?
263
+ assert @project.notifiers.first(:name => "IRC").enabled?
264
+ end
265
+
266
+ it "preserves config of notifiers that are being disabled" do
267
+ @project.update_notifiers(["IRC"],
268
+ {"IRC" => {"uri" => "irc://irc.freenode.net/integrity"},
269
+ "Twitter" => {"username" => "john"}})
270
+
271
+ assert_equal "john",
272
+ @project.notifiers.first(:name => "Twitter").config["username"]
273
+ end
274
+
275
+ it "does nothing if given nil as the list of notifiers to enable" do
276
+ lambda { Project.gen.update_notifiers(nil, {}) }.should_not change(Notifier, :count)
277
+ end
278
+
279
+ it "doesn't destroy any of the other notifiers that exist for other projects" do
280
+ irc = Notifier.generate(:irc)
281
+
282
+ project = Project.gen
283
+ project.update_notifiers("IRC", {"IRC" => irc.config})
284
+
285
+ lambda {
286
+ Project.gen.update_notifiers("IRC", {"IRC" => irc.config})
287
+ }.should_not change(project.notifiers, :count)
288
+ end
289
+ end
290
+
221
291
  describe "When retrieving state about its notifier" do
222
292
  before(:each) do
223
- @project = Project.generate
293
+ @project = Project.gen
224
294
  @irc = Notifier.generate(:irc)
225
295
  end
226
296
 
297
+ it "knows which notifiers are enabled" do
298
+ notifiers = [Notifier.gen(:irc, :enabled => false),
299
+ Notifier.gen(:twitter, :enabled => true)]
300
+ project = Project.gen(:notifiers => notifiers)
301
+
302
+ assert_equal 1, project.enabled_notifiers.size
303
+ end
304
+
227
305
  specify "#config_for returns given notifier's configuration" do
228
306
  @project.update_attributes(:notifiers => [@irc])
229
307
  @project.config_for("IRC").should == {:uri => "irc://irc.freenode.net/integrity"}
230
308
  end
231
309
 
232
- specify "#config_for returns an empty hash if no such notifier" do
310
+ specify "#config_for returns an empty hash for unknown notifier" do
233
311
  @project.config_for("IRC").should == {}
234
312
  end
235
313
 
236
- specify "#notifies? is true if it uses the given notifier" do
237
- @project.update_attributes(:notifiers => [@irc])
238
- @project.notifies?("IRC").should == true
239
- end
314
+ specify "#notifies? is true if the notifier exists and is enabled" do
315
+ assert ! @project.notifies?("UndefinedNotifier")
240
316
 
241
- specify "#notifies? is false if it doesnt use the given notifier" do
242
- @project.update_attributes(:notifiers => [])
317
+ @project.update_attributes(:notifiers =>
318
+ [ Notifier.gen(:irc, :enabled => true),
319
+ Notifier.gen(:twitter, :enabled => false) ])
243
320
 
244
- @project.notifies?("IRC").should == false
245
- @project.notifies?("UndefinedNotifier").should == false
321
+ assert @project.notifies?("IRC")
322
+ assert ! @project.notifies?("Twitter")
246
323
  end
247
324
  end
248
325
 
@@ -275,13 +352,12 @@ class ProjectTest < Test::Unit::TestCase
275
352
  }.should change(Commit, :count).by(1)
276
353
 
277
354
  build = Build.all.last
278
- build.commit.should be(@project.last_commit)
355
+ build.commit.should == @project.last_commit
279
356
 
280
357
  @project.last_commit.should be_pending
281
- @project.last_commit.identifier.should be("FOOBAR")
282
-
358
+ @project.last_commit.identifier.should == "FOOBAR"
283
359
  @project.last_commit.author.name.should == "<Commit author not loaded>"
284
- @project.last_commit.message.should == "<Commit message not loaded>"
360
+ @project.last_commit.message.should == "<Commit message not loaded>"
285
361
  end
286
362
  end
287
363
  end