-
Notifications
You must be signed in to change notification settings - Fork 73
/
test_helper.rb
74 lines (58 loc) · 1.49 KB
/
test_helper.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 'rubygems'
begin
require 'test/unit'
rescue LoadError
end
RAILS_ENV = ENV["RAILS_ENV"] = "test"
require 'active_support'
require 'active_support/test_case'
require 'action_controller'
require 'action_controller/test_case'
require 'action_mailer'
ActionMailer::Base.delivery_method = :test
$:.unshift File.dirname(__FILE__) + '/../lib'
require 'mail_form'
class ContactForm < MailForm::Base
attribute :name, :validate => true
attribute :email, :validate => /[^@]+@[^\.]+\.[\w\.\-]+/
attribute :category, :validate => ["Interface bug", "General"], :allow_blank => true
attribute :nickname, :captcha => true
attributes :created_at, :message, :validate => :callback
before_deliver :set_created_at
def headers
{ :to => 'my.email@my.domain.com' }
end
def set_created_at
created_at = Date.today
end
def callback
@_callback_run = true
end
end
class AdvancedForm < ContactForm
append :remote_ip, :user_agent, :session
def headers
{ :to => [ 'my.first@email.com', 'my.second@email.com' ],
:subject => "My Advanced Form",
:from => %{"#{name}" <#{email}>},
"return-path" => "mypath"
}
end
end
class FileForm < ContactForm
attribute :file, :attachment => true, :validate => true
def headers
to = if file
"contact_file@my.domain.com"
else
"contact@my.domain.com"
end
{ :to => to }
end
end
# Needed to correctly test an uploaded file
class Rack::Test::UploadedFile
def read
@tempfile.read
end
end