Skip to content

Commit

Permalink
Fix notifier information being lost on project editing
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Rozet <simon@rozet.name>
  • Loading branch information
atmos authored and sr committed Feb 27, 2009
1 parent 57c546e commit 72e9fa4
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/integrity/app.rb
Expand Up @@ -50,7 +50,7 @@ class App < Sinatra::Default
@project = Project.new(params[:project_data])

if @project.save
@project.enable_notifiers(params["enabled_notifiers[]"], params["notifiers"])
@project.enable_notifiers(params['notifiers'].keys, params['notifiers']) if params['notifiers']
redirect project_url(@project)
else
show :new, :title => ["projects", "new project"]
Expand All @@ -72,7 +72,7 @@ class App < Sinatra::Default
login_required

if current_project.update_attributes(params[:project_data])
current_project.enable_notifiers(params["enabled_notifiers"], params["notifiers"])
current_project.enable_notifiers(params['notifiers'].keys, params['notifiers']) if params['notifiers']
redirect project_url(current_project)
else
show :new, :title => ["projects", current_project.permalink, "edit"]
Expand Down
2 changes: 1 addition & 1 deletion lib/integrity/notifier.rb
Expand Up @@ -12,7 +12,7 @@ class Notifier
validates_present :project_id

def self.available
@available ||= constants.map { |name| const_get(name) }.select { |notifier| valid_notifier?(notifier) }
constants.map { |name| const_get(name) }.select { |notifier| valid_notifier?(notifier) }
end

def self.enable_notifiers(project, enabled, config={})
Expand Down
103 changes: 103 additions & 0 deletions test/acceptance/notifier_test.rb
@@ -0,0 +1,103 @@
require File.dirname(__FILE__) + "/helpers"
require File.dirname(__FILE__) + "/../helpers/acceptance/email_notifier"

class NotifierConfigIssues < Test::Unit::AcceptanceTestCase
story <<-EOS
As an administrator,
I want to add multiple projects to Integrity,
So that I can be certain notifiers remain functional (cf #43)
EOS
def fill_in_email_notifier
fill_in "notifiers[Email][to]", :with => "quentin@example.com"
fill_in "notifiers[Email][from]", :with => "ci@example.com"
fill_in "notifiers[Email][user]", :with => "inspector"
fill_in "notifiers[Email][pass]", :with => "gadget"
fill_in "notifiers[Email][auth]", :with => "simple"
fill_in "notifiers[Email][domain]", :with => "example.com"
end

def fill_in_project_info(name, repo)
fill_in "Name", :with => name
fill_in "Git repository", :with => repo
fill_in "Branch to track", :with => "master"
fill_in "Build script", :with => "rake"
check "Public project"

fill_in_email_notifier
end

def assert_have_email_notifier
assert_have_tag "input#email_notifier_to[@value='quentin@example.com']"
assert_have_tag "input#email_notifier_from[@value='ci@example.com']"
assert_have_tag "input#email_notifier_user[@value='inspector']"
assert_have_tag "input#email_notifier_pass[@value='gadget']"
assert_have_tag "input#email_notifier_auth[@value='simple']"
assert_have_tag "input#email_notifier_domain[@value='example.com']"
end

def add_project(name, repo)
visit "/new"
fill_in_project_info(name, repo)
click_button "Create Project"

assert_have_tag("h1", :content => name)
click_link 'Edit Project'
assert_have_email_notifier
end

def edit_project(name)
visit "/#{name}"
click_link "Edit Project"
assert_have_email_notifier
fill_in :branch, :with => "testing"
click_button "Update Project"
end

scenario "an admin can create a public project and retain mailer info" do
Project.first(:permalink => "integrity").should be_nil

login_as "admin", "test"

visit "/"
add_project "Integrity", "git://github.com/foca/integrity.git"
edit_project "integrity"

visit "/integrity"
click_link "Edit Project"

assert_have_email_notifier
end

scenario "an admin can create multiple public projects" do
Project.first(:permalink => "integrity").should be_nil

login_as "admin", "test"

visit "/"

add_project "Integrity", "git://github.com/foca/integrity.git"
click_link "projects"

add_project "Webrat", "git://github.com/brynary/webrat.git"
click_link "projects"

add_project "Rails", "git://github.com/rails/rails.git"
click_link "projects"

edit_project "integrity"
edit_project "webrat"
edit_project "rails"

visit "/integrity"
click_link "Edit Project"
assert_have_email_notifier

visit "/webrat"
click_link "Edit Project"
assert_have_email_notifier

visit "/rails"
click_link "Edit Project"
assert_have_email_notifier
end
end
55 changes: 55 additions & 0 deletions test/helpers/acceptance/email_notifier.rb
@@ -0,0 +1,55 @@
require 'rubygems'
require 'integrity'

module Integrity
class Notifier
class Email < Notifier::Base
attr_reader :to, :from

def self.to_haml
<<-EOF
%p.normal
%label{ :for => "email_notifier_to" } Send to
%input.text#email_notifier_to{ :name => "notifiers[Email][to]", :type => "text", :value => config["to"] }
%p.normal
%label{ :for => "email_notifier_from" } Send from
%input.text#email_notifier_from{ :name => "notifiers[Email][from]", :type => "text", :value => config["from"] }
%h3 SMTP Server Configuration
%p.normal
%label{ :for => "email_notifier_host" } Host : Port
= succeed " : " do
%input.text#email_notifier_host{ :name => "notifiers[Email][host]", :value => config["host"], :style => "width: 24.5em;", :type => "text" }
%input.text#email_notifier_port{ :name => "notifiers[Email][port]", :value => config["port"], :style => "width: 3.5em;", :type => "text" }
%p.normal
%label{ :for => "email_notifier_user" } User
%input.text#email_notifier_user{ :name => "notifiers[Email][user]", :value => config["user"], :type => "text" }
%p.normal
%label{ :for => "email_notifier_pass" } Password
%input.text#email_notifier_pass{ :name => "notifiers[Email][pass]", :value => config["pass"], :type => "text" }
%p.normal
%label{ :for => "email_notifier_auth" } Auth type
%input.text#email_notifier_auth{ :name => "notifiers[Email][auth]", :value => (config["auth"] || "plain"), :type => "text" }
%p.normal
%label{ :for => "email_notifier_domain" } Domain
%input.text#email_notifier_domain{ :name => "notifiers[Email][domain]", :value => config["domain"], :type => "text" }
EOF
end

def initialize(build, config={})
@to = config.delete("to")
@from = config.delete("from")
super
end

def deliver!
end
end
end
end
1 change: 1 addition & 0 deletions test/helpers/acceptance/textfile_notifier.rb
Expand Up @@ -15,6 +15,7 @@ def initialize(build, config={})
end

def deliver!
return if @file =~ /^\s*$/
File.open(@file, "a") do |f|
f.puts "=== #{short_message} ==="
f.puts
Expand Down

0 comments on commit 72e9fa4

Please sign in to comment.