Skip to content

Commit

Permalink
Slight refactoring of notifier state methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sr committed Mar 29, 2009
1 parent 1ee89e6 commit cb6a5d9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/integrity/helpers/forms.rb
Expand Up @@ -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)
})
Expand Down
12 changes: 6 additions & 6 deletions lib/integrity/project.rb
Expand Up @@ -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 ||= {}
Expand Down
7 changes: 3 additions & 4 deletions test/acceptance/build_notifications_test.rb
Expand Up @@ -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"
Expand Down
17 changes: 7 additions & 10 deletions test/unit/project_test.rb
Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit cb6a5d9

Please sign in to comment.