Permalink
Browse files

Slight refactoring of notifier state methods

  • Loading branch information...
1 parent 1ee89e6 commit cb6a5d9bc2213d8a1e2352cab1546f4f30ee17ed @sr sr committed Mar 29, 2009
@@ -18,7 +18,7 @@ def checkbox(name, condition, extras={})
def notifier_form(notifier)
haml(notifier.to_haml, :layout => :notifier, :locals => {
- :config => current_project.config_for(notifier),
+ :config => current_project.config_for(notifier.to_s.split(/::/).last),
:notifier => "#{notifier.to_s.split(/::/).last}",
:enabled => current_project.notifies?(notifier)
})
View
@@ -85,19 +85,19 @@ def public=(flag)
end)
end
- def config_for(notifier)
- notifier = notifiers.first(:name => notifier.to_s.split(/::/).last, :project_id => id)
- notifier.blank? ? {} : notifier.config
- end
-
def notifies?(notifier)
- !notifiers.first(:name => notifier.to_s.split(/::/).last, :project_id => id).blank?
+ !! notifiers.first(:name => notifier)
end
def enabled_notifiers
notifiers.all(:enabled => true)
end
+ def config_for(notifier)
+ notifier = notifiers.first(:name => notifier)
+ notifier ? notifier.config : {}
+ end
+
def update_notifiers(to_enable, config)
to_enable = Array(to_enable)
config ||= {}
@@ -45,12 +45,11 @@ class BuildNotificationsTest < Test::Unit::AcceptanceTestCase
end
scenario "an admin can setup a notifier without enabling it" do
- login_as "admin", "test"
+ Project.gen(:integrity)
- visit "/new"
- fill_in_project_info("Integrity", "git://github.com/foca/integrity.git")
- click_button "Create Project"
+ login_as "admin", "test"
+ visit "/integrity"
click_link "Edit Project"
fill_in_email_notifier
click_button "Update Project"
View
@@ -288,7 +288,7 @@ class ProjectTest < Test::Unit::TestCase
describe "When retrieving state about its notifier" do
before(:each) do
- @project = Project.generate
+ @project = Project.gen
@irc = Notifier.generate(:irc)
end
@@ -305,20 +305,17 @@ class ProjectTest < Test::Unit::TestCase
@project.config_for("IRC").should == {:uri => "irc://irc.freenode.net/integrity"}
end
- specify "#config_for returns an empty hash if no such notifier" do
+ specify "#config_for returns an empty hash for unknown notifier" do
@project.config_for("IRC").should == {}
end
- specify "#notifies? is true if it uses the given notifier" do
- @project.update_attributes(:notifiers => [@irc])
- @project.notifies?("IRC").should == true
- 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 false if it doesnt use the given notifier" do
- @project.update_attributes(:notifiers => [])
+ @project.update_attributes(:notifiers => [@irc])
- @project.notifies?("IRC").should == false
- @project.notifies?("UndefinedNotifier").should == false
+ assert_equal true, @project.notifies?("IRC")
end
end

0 comments on commit cb6a5d9

Please sign in to comment.