forked from appelier/bigtuna
/
hooks_test.rb
74 lines (65 loc) · 2.18 KB
/
hooks_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require "integration_test_helper"
module BigTuna
class Hooks::NoConfig
NAME = "no_config"
end
end
class HooksTest < ActionController::IntegrationTest
def setup
super
`cd test/files; mkdir repo; cd repo; git init; echo "my file" > file; git add file; git commit -m "my file added"`
end
def teardown
FileUtils.rm_rf("test/files/repo")
FileUtils.rm_rf("builds/*")
super
end
test "hooks config renders hook config partial if it's present" do
project = Project.make(:steps => "ls", :name => "Koss", :vcs_source => "test/files/repo", :vcs_type => "git", :max_builds => 2, :hooks => {"mailer" => "mailer"}, :hook_update => true)
visit edit_project_path(project)
within("#hook_mailer") do
click_link "Configure"
end
assert page.has_content?("Recipients")
end
test "hooks with no config print out this info to user" do
with_hook_enabled(BigTuna::Hooks::NoConfig) do
project = Project.make(:steps => "ls", :name => "Koss", :vcs_source => "test/files/repo", :vcs_type => "git", :max_builds => 2, :hooks => {"no_config" => "no_config"}, :hook_update => true)
visit edit_project_path(project)
within("#hook_no_config") do
click_link "Configure"
end
assert page.has_content?("This hook doesn't have any configuration.")
end
end
test "xmpp hook has a valid configuration form" do
project = Project.make(
:steps => "ls",
:name => "Koss",
:vcs_source => "test/files/repo",
:vcs_type => "git",
:max_builds => 2,
:hooks => {"xmpp" => "xmpp"},
:hook_update => true
)
visit edit_project_path(project)
within("#hook_xmpp") do
click_link "Configure"
end
assert page.has_field?("configuration_sender_full_jid")
assert page.has_field?("configuration_sender_password")
assert page.has_field?("configuration_recipients")
end
private
def with_hook_enabled(hook, &blk)
old_hooks = BigTuna::HOOKS.clone
Kernel.silence_stream(STDERR) do
BigTuna.const_set("HOOKS", old_hooks + [hook])
end
blk.call
ensure
Kernel.silence_stream(STDERR) do
BigTuna.const_set("HOOKS", old_hooks)
end
end
end