mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 15:20:13 +01:00
Isolate SITE_CONFIG in tests using minitest-stub-const
This commit is contained in:
parent
3de582f436
commit
58e2b82315
6 changed files with 130 additions and 96 deletions
1
Gemfile
1
Gemfile
|
|
@ -75,6 +75,7 @@ group :test do
|
|||
gem "rspec-expectations"
|
||||
gem "database_cleaner"
|
||||
gem "mocha", :require => false
|
||||
gem "minitest-stub-const"
|
||||
|
||||
gem "aruba", ">=0.5.4", :require => false
|
||||
|
||||
|
|
|
|||
|
|
@ -143,6 +143,7 @@ GEM
|
|||
mimemagic (0.3.0)
|
||||
mini_portile2 (2.0.0)
|
||||
minitest (5.9.0)
|
||||
minitest-stub-const (0.5)
|
||||
mocha (1.1.0)
|
||||
metaclass (~> 0.0.1)
|
||||
multi_json (1.11.2)
|
||||
|
|
@ -283,6 +284,7 @@ DEPENDENCIES
|
|||
htmlentities
|
||||
jquery-rails
|
||||
jquery-ui-rails
|
||||
minitest-stub-const
|
||||
mocha
|
||||
mysql2 (~> 0.3.17)
|
||||
paperclip
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
require 'test_helper'
|
||||
require 'support/stub_site_config_helper'
|
||||
|
||||
class IntegrationsControllerTest < ActionController::TestCase
|
||||
include StubSiteConfigHelper
|
||||
|
||||
def setup
|
||||
end
|
||||
|
|
@ -12,6 +14,7 @@ class IntegrationsControllerTest < ActionController::TestCase
|
|||
end
|
||||
|
||||
def test_cloudmailin_integration_success
|
||||
stub_site_config do
|
||||
SITE_CONFIG['cloudmailin'] = "123456789"
|
||||
SITE_CONFIG['email_dispatch'] = 'from'
|
||||
post :cloudmailin, {
|
||||
|
|
@ -29,8 +32,10 @@ class IntegrationsControllerTest < ActionController::TestCase
|
|||
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
def test_cloudmailin_integration_invalid_signature
|
||||
stub_site_config do
|
||||
SITE_CONFIG['cloudmailin'] = "12345678901234567890"
|
||||
post :cloudmailin, {
|
||||
"html"=>"",
|
||||
|
|
@ -47,8 +52,10 @@ class IntegrationsControllerTest < ActionController::TestCase
|
|||
|
||||
assert_response 403
|
||||
end
|
||||
end
|
||||
|
||||
def test_cloudmailin_integration_unknown_address
|
||||
stub_site_config do
|
||||
SITE_CONFIG['cloudmailin'] = "123456789"
|
||||
post :cloudmailin, {
|
||||
"html"=>"",
|
||||
|
|
@ -65,5 +72,6 @@ class IntegrationsControllerTest < ActionController::TestCase
|
|||
|
||||
assert_response 404
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
require 'test_helper'
|
||||
require 'support/stub_site_config_helper'
|
||||
|
||||
class MailgunControllerTest < ActionController::TestCase
|
||||
include StubSiteConfigHelper
|
||||
|
||||
def setup
|
||||
@user = users(:sms_user)
|
||||
|
|
@ -12,6 +14,7 @@ class MailgunControllerTest < ActionController::TestCase
|
|||
end
|
||||
|
||||
def test_mailgun_signature_verifies
|
||||
stub_site_config do
|
||||
SITE_CONFIG['mailgun_api_key'] = "123456789"
|
||||
SITE_CONFIG['email_dispatch'] = 'from'
|
||||
|
||||
|
|
@ -24,8 +27,10 @@ class MailgunControllerTest < ActionController::TestCase
|
|||
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
def test_mailgun_creates_todo_with_mailmap
|
||||
stub_site_config do
|
||||
SITE_CONFIG['mailgun_api_key'] = "123456789"
|
||||
SITE_CONFIG['email_dispatch'] = 'to'
|
||||
SITE_CONFIG['mailmap'] = {
|
||||
|
|
@ -48,8 +53,10 @@ class MailgunControllerTest < ActionController::TestCase
|
|||
assert_equal(@inbox, message_todo.context)
|
||||
assert_equal(@user, message_todo.user)
|
||||
end
|
||||
end
|
||||
|
||||
def test_mailgun_signature_fails
|
||||
stub_site_config do
|
||||
SITE_CONFIG['mailgun_api_key'] = "invalidkey"
|
||||
SITE_CONFIG['email_dispatch'] = 'from'
|
||||
|
||||
|
|
@ -62,5 +69,6 @@ class MailgunControllerTest < ActionController::TestCase
|
|||
|
||||
assert_response 406
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
require 'test_helper'
|
||||
require 'support/stub_site_config_helper'
|
||||
|
||||
class StoriesTest < ActionDispatch::IntegrationTest
|
||||
include StubSiteConfigHelper
|
||||
|
||||
# ####################################################
|
||||
# Testing login and signup by different kinds of users
|
||||
|
|
@ -14,12 +16,15 @@ class StoriesTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
def test_signup_new_user_by_nonadmin
|
||||
stub_site_config do
|
||||
SITE_CONFIG['open_signups'] = false
|
||||
other_user = new_session_as(:other_user,"sesame")
|
||||
other_user.goes_to_signup_as_nonadmin
|
||||
end
|
||||
end
|
||||
|
||||
def test_open_signup_new_user
|
||||
stub_site_config do
|
||||
SITE_CONFIG['open_signups'] = true
|
||||
get "/signup"
|
||||
assert_response :success
|
||||
|
|
@ -32,6 +37,7 @@ class StoriesTest < ActionDispatch::IntegrationTest
|
|||
assert_response :success
|
||||
assert_template "todos/index"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
|
|
|||
9
test/support/stub_site_config_helper.rb
Normal file
9
test/support/stub_site_config_helper.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
require 'minitest/stub_const'
|
||||
|
||||
module StubSiteConfigHelper
|
||||
def stub_site_config
|
||||
Object.stub_const(:SITE_CONFIG, SITE_CONFIG.clone) do
|
||||
yield
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue