summaryrefslogtreecommitdiff
path: root/test/unit
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/request_handlers/local_email_handler_test.rb45
1 files changed, 8 insertions, 37 deletions
diff --git a/test/unit/request_handlers/local_email_handler_test.rb b/test/unit/request_handlers/local_email_handler_test.rb
index 8f303ec..1bfe264 100644
--- a/test/unit/request_handlers/local_email_handler_test.rb
+++ b/test/unit/request_handlers/local_email_handler_test.rb
@@ -1,7 +1,9 @@
require 'test_helper'
+require 'support/request_handler_test_helper'
require 'nickserver/request_handlers/local_email_handler'
class LocalEmailHandlerTest < MiniTest::Test
+ include RequestHandlerTestHelper
def test_no_email
assert_refuses
@@ -12,14 +14,13 @@ class LocalEmailHandlerTest < MiniTest::Test
end
def test_local_email
- assert_handles email: 'me@local.tld', domain: 'local.tld'
+ assert_queries_for Nickserver::EmailAddress do
+ assert_handles email: 'me@local.tld', domain: 'local.tld'
+ end
end
def test_missing_host_header
- Nickserver::Config.stub :domain, nil do
- assert_responds_with_error "HTTP request must include a Host header.",
- email: 'me@local.tld'
- end
+ assert_refuses email: 'me@local.tld'
end
protected
@@ -28,38 +29,8 @@ class LocalEmailHandlerTest < MiniTest::Test
Nickserver::RequestHandlers::LocalEmailHandler.new
end
- def source
- source = Minitest::Mock.new
- source.expect :query,
- 'response',
- [Nickserver::EmailAddress]
- source
- end
-
- def assert_handles(opts)
- Nickserver::CouchDB::Source.stub :new, source do
- assert_equal 'response', handle(request(opts))
- end
- end
-
- def assert_responds_with_error(msg, opts)
- response = handle(request(opts))
- assert_equal 500, response.status
- assert_equal "500 #{msg}\n", response.content
- end
-
- def assert_refuses(opts = {})
- assert_nil handle(request(opts))
- end
-
- def handle(request)
- handler.call(request)
- end
-
- def request(opts = {})
- params = {'address' => [opts[:email]]}
- headers = {'Host' => opts[:domain]}
- Nickserver::Request.new params, headers
+ def source_class
+ Nickserver::CouchDB::Source
end
end