Permalink
Browse files

Post-refactoring project test comsetics

  • Loading branch information...
1 parent e640d6f commit 1ee89e68beb72acfbc11f7120ec5dd7b4f1d7164 @sr sr committed Mar 29, 2009
Showing with 40 additions and 57 deletions.
  1. +1 −1 lib/integrity/project.rb
  2. +3 −2 test/acceptance/build_notifications_test.rb
  3. +36 −54 test/unit/project_test.rb
View
@@ -108,7 +108,7 @@ def update_notifiers(to_enable, config)
config.each_pair { |name, config|
notifier = notifiers.first(:name => name)
- notifier ||= notifiers.new(:name => name, :config => config)
+ notifier ||= notifiers.new(:name => name)
notifier.enabled = true
notifier.config = config
@@ -19,7 +19,7 @@ class BuildNotificationsTest < Test::Unit::AcceptanceTestCase
scenario "an admin sets up a notifier and issue a manual build" do
git_repo(:my_test_project).add_successful_commit
- Project.gen(:my_test_project, :notifiers => [], :uri => git_repo(:my_test_project).path)
+ Project.gen(:my_test_project, :uri => git_repo(:my_test_project).path)
rm_f "/tmp/textfile_notifications.txt"
login_as "admin", "test"
@@ -36,7 +36,8 @@ class BuildNotificationsTest < Test::Unit::AcceptanceTestCase
notification = File.read("/tmp/textfile_notifications.txt")
notification.should =~ /=== Built #{git_repo(:my_test_project).short_head} successfully ===/
notification.should =~ /Build #{git_repo(:my_test_project).head} was successful/
- notification.should =~ %r(http://www.example.com/my-test-project/commits/#{git_repo(:my_test_project).head})
+ notification.should =~
+ %r(http://www.example.com/my-test-project/commits/#{git_repo(:my_test_project).head})
notification.should =~ /Commit Author: John Doe/
notification.should =~ /Commit Date: (.+)/
notification.should =~ /Commit Message: This commit will work/
View
@@ -220,40 +220,17 @@ class ProjectTest < Test::Unit::TestCase
end
end
- context "Dealing with notifiers" do
- it "knows which notifiers are enabled" do
- notifiers = [Notifier.gen(:irc, :enabled => false),
- Notifier.gen(:twitter, :enabled => true)]
- project = Project.gen(:notifiers => notifiers)
+ describe "When updating its notifiers" do
+ setup do
+ twitter = Notifier.gen(:twitter, :enabled => true)
+ irc = Notifier.gen(:irc, :enabled => false)
- assert_equal 1, project.enabled_notifiers.size
+ @project = Project.gen(:notifiers => [twitter, irc])
end
- it "preserves config of notifiers that are being disabled" do
- notifiers = [Notifier.gen(:irc, :enabled => false),
- Notifier.gen(:twitter, :enabled => true)]
- project = Project.gen(:notifiers => notifiers)
+ it "creates and enable the given notifiers" do
+ Notifier.all.destroy!
- project.update_notifiers(["IRC"],
- {"IRC" => {"uri" => "irc://irc.freenode.net/integrity"},
- "Twitter" => {"username" => "john"}})
- assert_equal "john",
- project.notifiers.first(:name => "Twitter").config["username"]
- end
-
- it "creates notifiers present in config even if not supplied in the to_enable list" do
- notifiers = [Notifier.gen(:irc, :enabled => false),
- Notifier.gen(:twitter, :enabled => true)]
- project = Project.gen(:notifiers => notifiers)
-
- project.update_notifiers(["IRC"],
- {"IRC" => {"uri" => "irc://irc.freenode.net/integrity"},
- "Twitter" => {"username" => "john"}})
-
- assert_equal 2, project.notifiers.count
- end
-
- it "creates and enable given notifiers" do
project = Project.gen
project.update_notifiers(["IRC", "Twitter"],
{"IRC" => {"uri" => "irc://irc.freenode.net/integrity"},
@@ -264,36 +241,33 @@ class ProjectTest < Test::Unit::TestCase
assert_equal "Twitter", project.notifiers.last.name
end
+ it "creates notifiers present in config even when they're disabled" do
+ @project.update_notifiers(["IRC"],
+ {"IRC" => {"uri" => "irc://irc.freenode.net/integrity"},
+ "Twitter" => {"username" => "john"}})
+
+ assert_equal 2, @project.notifiers.count
+ end
+
it "disables notifiers that are not included in the list" do
- project = Project.gen
- project.update_notifiers(["IRC", "Twitter"],
+ @project.update_notifiers(["IRC"],
{"IRC" => {"uri" => "irc://irc.freenode.net/integrity"},
"Twitter" => {"username" => "john"}})
- lambda {
- project.update_notifiers(["IRC"],
- {"IRC" => {"uri" => "irc://irc.freenode.net/integrity"}})
- }.should change(project.enabled_notifiers, :count).from(2).to(1)
+ @project.update_notifiers(["IRC"],
+ {"IRC" => {"uri" => "irc://irc.freenode.net/integrity"}})
- assert ! project.notifiers.first(:name => "Twitter").enabled?
- assert project.notifiers.first(:name => "IRC").enabled?
+ assert ! @project.notifiers.first(:name => "Twitter").enabled?
+ assert @project.notifiers.first(:name => "IRC").enabled?
end
- it "creates new notifiers for the project" do
- project = Project.generate
- lambda do
- project.update_notifiers(["IRC", "Twitter"],
- {"IRC" => {"uri" => "irc://irc.freenode.net/integrity"},
- "Twitter" => {"username" => "john"}})
- end.should change(project.notifiers, :count).from(0).to(2)
- end
+ it "preserves config of notifiers that are being disabled" do
+ @project.update_notifiers(["IRC"],
+ {"IRC" => {"uri" => "irc://irc.freenode.net/integrity"},
+ "Twitter" => {"username" => "john"}})
- it "don't deletes all of previous notifiers" do
- project = Project.generate(:notifiers => [Notifier.gen(:irc), Notifier.gen(:twitter)])
- lambda do
- project.update_notifiers("IRC", {"IRC" => {:foo => "bar"}})
- project.reload
- end.should_not change(project.notifiers, :count)
+ assert_equal "john",
+ @project.notifiers.first(:name => "Twitter").config["username"]
end
it "does nothing if given nil as the list of notifiers to enable" do
@@ -306,9 +280,9 @@ class ProjectTest < Test::Unit::TestCase
project = Project.gen
project.update_notifiers("IRC", {"IRC" => irc.config})
- lambda do
+ lambda {
Project.gen.update_notifiers("IRC", {"IRC" => irc.config})
- end.should_not change(project.notifiers, :count)
+ }.should_not change(project.notifiers, :count)
end
end
@@ -318,6 +292,14 @@ class ProjectTest < Test::Unit::TestCase
@irc = Notifier.generate(:irc)
end
+ it "knows which notifiers are enabled" do
+ notifiers = [Notifier.gen(:irc, :enabled => false),
+ Notifier.gen(:twitter, :enabled => true)]
+ project = Project.gen(:notifiers => notifiers)
+
+ assert_equal 1, project.enabled_notifiers.size
+ end
+
specify "#config_for returns given notifier's configuration" do
@project.update_attributes(:notifiers => [@irc])
@project.config_for("IRC").should == {:uri => "irc://irc.freenode.net/integrity"}

0 comments on commit 1ee89e6

Please sign in to comment.