Skip to content
Browse files

Fix that notifiers are always enabled

I swear, I wasn't drunk.
  • Loading branch information...
1 parent 15ba26a commit 4a99c9e26bbd77cd2e65325cd855c4d4c6677d58 @sr sr committed Mar 30, 2009
Showing with 20 additions and 17 deletions.
  1. +4 −12 lib/integrity/project/notifiers.rb
  2. +16 −5 test/unit/project_test.rb
View
16 lib/integrity/project/notifiers.rb
@@ -3,7 +3,9 @@ class Project
module Helpers
module Notifiers
def notifies?(notifier)
- !! notifiers.first(:name => notifier)
+ return false unless notifier = notifiers.first(:name => notifier)
+
+ notifier.enabled?
end
def enabled_notifiers
@@ -16,25 +18,15 @@ def config_for(notifier)
end
def update_notifiers(to_enable, config)
- disable_notifiers(to_enable)
-
config.each_pair { |name, config|
notifier = notifiers.first(:name => name)
notifier ||= notifiers.new(:name => name)
- notifier.enabled = true
+ notifier.enabled = to_enable.include?(name)
notifier.config = config
notifier.save
}
end
-
- private
- def disable_notifiers(to_enable)
- enabled_notifiers.select { |notifier|
- ! to_enable.include?(notifier.name) }.
- each { |notifier|
- notifier.update_attributes(:enabled => false) }
- end
end
end
end
View
21 test/unit/project_test.rb
@@ -237,8 +237,17 @@ class ProjectTest < Test::Unit::TestCase
"Twitter" => {"username" => "john"}})
assert_equal 2, Notifier.count
+ assert_equal 2, project.enabled_notifiers.count
assert_equal "IRC", project.notifiers.first.name
assert_equal "Twitter", project.notifiers.last.name
+
+ project.update_notifiers(["Twitter"],
+ {"IRC" => {"uri" => "irc://irc.freenode.net/integrity"},
+ "Twitter" => {"username" => "john"}})
+
+ assert_equal 2, Notifier.count
+ assert ! project.notifies?("IRC")
+ assert project.notifies?("Twitter")
end
it "creates notifiers present in config even when they're disabled" do
@@ -309,13 +318,15 @@ class ProjectTest < Test::Unit::TestCase
@project.config_for("IRC").should == {}
end
- specify "#notifies? is true if it uses the notifier" do
- assert_equal false, @project.notifies?("UndefinedNotifier")
- assert_equal false, @project.notifies?("IRC")
+ specify "#notifies? is true if the notifier exists and is enabled" do
+ assert ! @project.notifies?("UndefinedNotifier")
- @project.update_attributes(:notifiers => [@irc])
+ @project.update_attributes(:notifiers =>
+ [ Notifier.gen(:irc, :enabled => true),
+ Notifier.gen(:twitter, :enabled => false) ])
- assert_equal true, @project.notifies?("IRC")
+ assert @project.notifies?("IRC")
+ assert ! @project.notifies?("Twitter")
end
end

0 comments on commit 4a99c9e

Please sign in to comment.
Something went wrong with that request. Please try again.