Skip to content
Browse files

Allow to configure disabled notifiers

  • Loading branch information...
1 parent b8b783d commit e640d6fd979141dfee3120f322996acfe23b46f2 @sr sr committed
View
2 lib/integrity/helpers/resources.rb
@@ -11,7 +11,7 @@ def current_commit
def update_notifiers_of(project)
if params["notifiers"]
- project.update_notifiers(params["notifiers"].keys, params["notifiers"])
+ project.update_notifiers(params["enabled_notifiers"], params["notifiers"])
end
end
end
View
14 lib/integrity/project.rb
@@ -98,16 +98,20 @@ def enabled_notifiers
notifiers.all(:enabled => true)
end
- def update_notifiers(to_enable, config={})
+ def update_notifiers(to_enable, config)
+ to_enable = Array(to_enable)
+ config ||= {}
+
to_disable = enabled_notifiers.select { |notifier| ! to_enable.include?(notifier.name) }
to_disable.each { |notifier| notifier.update_attributes(:enabled => false) }
- Array(to_enable).each { |name|
- notifier = notifiers.first(:name => name, :project_id => id)
- notifier ||= notifiers.new(:name => name, :config => config, :project_id => id)
+
+ config.each_pair { |name, config|
+ notifier = notifiers.first(:name => name)
+ notifier ||= notifiers.new(:name => name, :config => config)
notifier.enabled = true
- notifier.config = config[name] || {}
+ notifier.config = config
notifier.save
}
end
View
18 test/acceptance/build_notifications_test.rb
@@ -17,7 +17,7 @@ class BuildNotificationsTest < Test::Unit::AcceptanceTestCase
load "helpers/acceptance/email_notifier.rb"
end
- scenario "an admin sets up a notifier for a project that didn't have any" do
+ 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)
rm_f "/tmp/textfile_notifications.txt"
@@ -43,22 +43,22 @@ class BuildNotificationsTest < Test::Unit::AcceptanceTestCase
notification.should =~ /Build Output:\n\nRunning tests...\n/
end
- scenario "an admin can create a public project and retain mailer info" do
- Project.first(:permalink => "integrity").should be_nil
-
+ scenario "an admin can setup a notifier without enabling it" do
login_as "admin", "test"
- visit "/"
- add_project "Integrity", "git://github.com/foca/integrity.git"
- edit_project "integrity"
+ visit "/new"
+ fill_in_project_info("Integrity", "git://github.com/foca/integrity.git")
+ click_button "Create Project"
- visit "/integrity"
click_link "Edit Project"
+ fill_in_email_notifier
+ click_button "Update Project"
+ visit "/integrity/edit"
assert_have_email_notifier
end
- scenario "an admin can create multiple public projects" do
+ scenario "an admin configures various notifiers accros multiple projects" do
Project.first(:permalink => "integrity").should be_nil
login_as "admin", "test"
View
24 test/unit/project_test.rb
@@ -229,6 +229,30 @@ class ProjectTest < Test::Unit::TestCase
assert_equal 1, project.enabled_notifiers.size
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)
+
+ 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"],

0 comments on commit e640d6f

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