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 "rspec-expectations"
|
||||||
gem "database_cleaner"
|
gem "database_cleaner"
|
||||||
gem "mocha", :require => false
|
gem "mocha", :require => false
|
||||||
|
gem "minitest-stub-const"
|
||||||
|
|
||||||
gem "aruba", ">=0.5.4", :require => false
|
gem "aruba", ">=0.5.4", :require => false
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,7 @@ GEM
|
||||||
mimemagic (0.3.0)
|
mimemagic (0.3.0)
|
||||||
mini_portile2 (2.0.0)
|
mini_portile2 (2.0.0)
|
||||||
minitest (5.9.0)
|
minitest (5.9.0)
|
||||||
|
minitest-stub-const (0.5)
|
||||||
mocha (1.1.0)
|
mocha (1.1.0)
|
||||||
metaclass (~> 0.0.1)
|
metaclass (~> 0.0.1)
|
||||||
multi_json (1.11.2)
|
multi_json (1.11.2)
|
||||||
|
|
@ -283,6 +284,7 @@ DEPENDENCIES
|
||||||
htmlentities
|
htmlentities
|
||||||
jquery-rails
|
jquery-rails
|
||||||
jquery-ui-rails
|
jquery-ui-rails
|
||||||
|
minitest-stub-const
|
||||||
mocha
|
mocha
|
||||||
mysql2 (~> 0.3.17)
|
mysql2 (~> 0.3.17)
|
||||||
paperclip
|
paperclip
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
require 'support/stub_site_config_helper'
|
||||||
|
|
||||||
class IntegrationsControllerTest < ActionController::TestCase
|
class IntegrationsControllerTest < ActionController::TestCase
|
||||||
|
include StubSiteConfigHelper
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
end
|
end
|
||||||
|
|
@ -12,58 +14,64 @@ class IntegrationsControllerTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_cloudmailin_integration_success
|
def test_cloudmailin_integration_success
|
||||||
SITE_CONFIG['cloudmailin'] = "123456789"
|
stub_site_config do
|
||||||
SITE_CONFIG['email_dispatch'] = 'from'
|
SITE_CONFIG['cloudmailin'] = "123456789"
|
||||||
post :cloudmailin, {
|
SITE_CONFIG['email_dispatch'] = 'from'
|
||||||
"html"=>"",
|
post :cloudmailin, {
|
||||||
"plain"=>"asdasd",
|
"html"=>"",
|
||||||
"x_to_header"=>"[\"81496ecea21032d35a7a@cloudmailin.net\"]",
|
"plain"=>"asdasd",
|
||||||
"disposable"=>"",
|
"x_to_header"=>"[\"81496ecea21032d35a7a@cloudmailin.net\"]",
|
||||||
"from"=>"5555555555@tmomail.net",
|
"disposable"=>"",
|
||||||
"signature"=>"e85e908fb893394762047c21e54ce248",
|
"from"=>"5555555555@tmomail.net",
|
||||||
"to"=>"<123123@cloudmailin.net>",
|
"signature"=>"e85e908fb893394762047c21e54ce248",
|
||||||
"subject"=>"asd",
|
"to"=>"<123123@cloudmailin.net>",
|
||||||
"x_cc_header"=>"",
|
"subject"=>"asd",
|
||||||
"message"=>"Received: from VMBX103.ihostexchange.net ([192.168.3.3]) by\r\n HUB103.ihostexchange.net ([66.46.182.53]) with mapi; Wed, 5 Oct 2011 17:12:44\r\n -0400\r\nFrom: SMS User <5555555555@tmomail.net>\r\nTo: Tracks <123123@cloudmailin.net>\r\nDate: Wed, 5 Oct 2011 17:12:43 -0400\r\nSubject: asd\r\nThread-Topic: asd\r\nThread-Index: AcyDo4aig2wghvcsTAOkleWqi4t/FQ==\r\nMessage-ID: <7D7CB176-7559-4997-A301-8DF9726264C7@tmomail.net>\r\nAccept-Language: de-DE, en-US\r\nContent-Language: en-US\r\nX-MS-Has-Attach:\r\nX-MS-TNEF-Correlator:\r\nacceptlanguage: de-DE, en-US\r\nContent-Type: text/plain; charset=\"us-ascii\"\r\nContent-Transfer-Encoding: quoted-printable\r\nMIME-Version: 1.0\r\n\r\nasdasd\r\n"
|
"x_cc_header"=>"",
|
||||||
}
|
"message"=>"Received: from VMBX103.ihostexchange.net ([192.168.3.3]) by\r\n HUB103.ihostexchange.net ([66.46.182.53]) with mapi; Wed, 5 Oct 2011 17:12:44\r\n -0400\r\nFrom: SMS User <5555555555@tmomail.net>\r\nTo: Tracks <123123@cloudmailin.net>\r\nDate: Wed, 5 Oct 2011 17:12:43 -0400\r\nSubject: asd\r\nThread-Topic: asd\r\nThread-Index: AcyDo4aig2wghvcsTAOkleWqi4t/FQ==\r\nMessage-ID: <7D7CB176-7559-4997-A301-8DF9726264C7@tmomail.net>\r\nAccept-Language: de-DE, en-US\r\nContent-Language: en-US\r\nX-MS-Has-Attach:\r\nX-MS-TNEF-Correlator:\r\nacceptlanguage: de-DE, en-US\r\nContent-Type: text/plain; charset=\"us-ascii\"\r\nContent-Transfer-Encoding: quoted-printable\r\nMIME-Version: 1.0\r\n\r\nasdasd\r\n"
|
||||||
|
}
|
||||||
assert_response :success
|
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_cloudmailin_integration_invalid_signature
|
def test_cloudmailin_integration_invalid_signature
|
||||||
SITE_CONFIG['cloudmailin'] = "12345678901234567890"
|
stub_site_config do
|
||||||
post :cloudmailin, {
|
SITE_CONFIG['cloudmailin'] = "12345678901234567890"
|
||||||
"html"=>"",
|
post :cloudmailin, {
|
||||||
"plain"=>"asdasd",
|
"html"=>"",
|
||||||
"x_to_header"=>"[\"81496ecea21032d35a7a@cloudmailin.net\"]",
|
"plain"=>"asdasd",
|
||||||
"disposable"=>"",
|
"x_to_header"=>"[\"81496ecea21032d35a7a@cloudmailin.net\"]",
|
||||||
"from"=>"5555555555@tmomail.net",
|
"disposable"=>"",
|
||||||
"signature"=>"e85e908fb893394762047c21e54ce248",
|
"from"=>"5555555555@tmomail.net",
|
||||||
"to"=>"<123123@cloudmailin.net>",
|
"signature"=>"e85e908fb893394762047c21e54ce248",
|
||||||
"subject"=>"asd",
|
"to"=>"<123123@cloudmailin.net>",
|
||||||
"x_cc_header"=>"",
|
"subject"=>"asd",
|
||||||
"message"=>"Received: from VMBX103.ihostexchange.net ([192.168.3.3]) by\r\n HUB103.ihostexchange.net ([66.46.182.53]) with mapi; Wed, 5 Oct 2011 17:12:44\r\n -0400\r\nFrom: SMS User <5555555555@tmomail.net>\r\nTo: Tracks <123123@cloudmailin.net>\r\nDate: Wed, 5 Oct 2011 17:12:43 -0400\r\nSubject: asd\r\nThread-Topic: asd\r\nThread-Index: AcyDo4aig2wghvcsTAOkleWqi4t/FQ==\r\nMessage-ID: <7D7CB176-7559-4997-A301-8DF9726264C7@tmomail.net>\r\nAccept-Language: de-DE, en-US\r\nContent-Language: en-US\r\nX-MS-Has-Attach:\r\nX-MS-TNEF-Correlator:\r\nacceptlanguage: de-DE, en-US\r\nContent-Type: text/plain; charset=\"us-ascii\"\r\nContent-Transfer-Encoding: quoted-printable\r\nMIME-Version: 1.0\r\n\r\nasdasd\r\n"
|
"x_cc_header"=>"",
|
||||||
}
|
"message"=>"Received: from VMBX103.ihostexchange.net ([192.168.3.3]) by\r\n HUB103.ihostexchange.net ([66.46.182.53]) with mapi; Wed, 5 Oct 2011 17:12:44\r\n -0400\r\nFrom: SMS User <5555555555@tmomail.net>\r\nTo: Tracks <123123@cloudmailin.net>\r\nDate: Wed, 5 Oct 2011 17:12:43 -0400\r\nSubject: asd\r\nThread-Topic: asd\r\nThread-Index: AcyDo4aig2wghvcsTAOkleWqi4t/FQ==\r\nMessage-ID: <7D7CB176-7559-4997-A301-8DF9726264C7@tmomail.net>\r\nAccept-Language: de-DE, en-US\r\nContent-Language: en-US\r\nX-MS-Has-Attach:\r\nX-MS-TNEF-Correlator:\r\nacceptlanguage: de-DE, en-US\r\nContent-Type: text/plain; charset=\"us-ascii\"\r\nContent-Transfer-Encoding: quoted-printable\r\nMIME-Version: 1.0\r\n\r\nasdasd\r\n"
|
||||||
|
}
|
||||||
assert_response 403
|
|
||||||
|
assert_response 403
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_cloudmailin_integration_unknown_address
|
def test_cloudmailin_integration_unknown_address
|
||||||
SITE_CONFIG['cloudmailin'] = "123456789"
|
stub_site_config do
|
||||||
post :cloudmailin, {
|
SITE_CONFIG['cloudmailin'] = "123456789"
|
||||||
"html"=>"",
|
post :cloudmailin, {
|
||||||
"plain"=>"asdasd",
|
"html"=>"",
|
||||||
"x_to_header"=>"[\"81496ecea21032d35a7a@cloudmailin.net\"]",
|
"plain"=>"asdasd",
|
||||||
"disposable"=>"",
|
"x_to_header"=>"[\"81496ecea21032d35a7a@cloudmailin.net\"]",
|
||||||
"from"=>"444444444444@tmomail.net",
|
"disposable"=>"",
|
||||||
"signature"=>"6d2df0e807bfa9b77d24c31dce6d4515",
|
"from"=>"444444444444@tmomail.net",
|
||||||
"to"=>"<123123@cloudmailin.net>",
|
"signature"=>"6d2df0e807bfa9b77d24c31dce6d4515",
|
||||||
"subject"=>"asd",
|
"to"=>"<123123@cloudmailin.net>",
|
||||||
"x_cc_header"=>"",
|
"subject"=>"asd",
|
||||||
"message"=>"Received: from VMBX103.ihostexchange.net ([192.168.3.3]) by\r\n HUB103.ihostexchange.net ([66.46.182.53]) with mapi; Wed, 5 Oct 2011 17:12:44\r\n -0400\r\nFrom: SMS User <444444444444@tmomail.net>\r\nTo: Tracks <123123@cloudmailin.net>\r\nDate: Wed, 5 Oct 2011 17:12:43 -0400\r\nSubject: asd\r\nThread-Topic: asd\r\nThread-Index: AcyDo4aig2wghvcsTAOkleWqi4t/FQ==\r\nMessage-ID: <7D7CB176-7559-4997-A301-8DF9726264C7@tmomail.net>\r\nAccept-Language: de-DE, en-US\r\nContent-Language: en-US\r\nX-MS-Has-Attach:\r\nX-MS-TNEF-Correlator:\r\nacceptlanguage: de-DE, en-US\r\nContent-Type: text/plain; charset=\"us-ascii\"\r\nContent-Transfer-Encoding: quoted-printable\r\nMIME-Version: 1.0\r\n\r\nasdasd\r\n"
|
"x_cc_header"=>"",
|
||||||
}
|
"message"=>"Received: from VMBX103.ihostexchange.net ([192.168.3.3]) by\r\n HUB103.ihostexchange.net ([66.46.182.53]) with mapi; Wed, 5 Oct 2011 17:12:44\r\n -0400\r\nFrom: SMS User <444444444444@tmomail.net>\r\nTo: Tracks <123123@cloudmailin.net>\r\nDate: Wed, 5 Oct 2011 17:12:43 -0400\r\nSubject: asd\r\nThread-Topic: asd\r\nThread-Index: AcyDo4aig2wghvcsTAOkleWqi4t/FQ==\r\nMessage-ID: <7D7CB176-7559-4997-A301-8DF9726264C7@tmomail.net>\r\nAccept-Language: de-DE, en-US\r\nContent-Language: en-US\r\nX-MS-Has-Attach:\r\nX-MS-TNEF-Correlator:\r\nacceptlanguage: de-DE, en-US\r\nContent-Type: text/plain; charset=\"us-ascii\"\r\nContent-Transfer-Encoding: quoted-printable\r\nMIME-Version: 1.0\r\n\r\nasdasd\r\n"
|
||||||
|
}
|
||||||
assert_response 404
|
|
||||||
|
assert_response 404
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
require 'support/stub_site_config_helper'
|
||||||
|
|
||||||
class MailgunControllerTest < ActionController::TestCase
|
class MailgunControllerTest < ActionController::TestCase
|
||||||
|
include StubSiteConfigHelper
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@user = users(:sms_user)
|
@user = users(:sms_user)
|
||||||
|
|
@ -12,55 +14,61 @@ class MailgunControllerTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_mailgun_signature_verifies
|
def test_mailgun_signature_verifies
|
||||||
SITE_CONFIG['mailgun_api_key'] = "123456789"
|
stub_site_config do
|
||||||
SITE_CONFIG['email_dispatch'] = 'from'
|
SITE_CONFIG['mailgun_api_key'] = "123456789"
|
||||||
|
SITE_CONFIG['email_dispatch'] = 'from'
|
||||||
|
|
||||||
post :mailgun, {
|
post :mailgun, {
|
||||||
"timestamp" => "1379539674",
|
"timestamp" => "1379539674",
|
||||||
"token" => "5km6cwo0e3bfvg78hw4s69znro09xhk1h8u6-s633yasc8hcr5",
|
"token" => "5km6cwo0e3bfvg78hw4s69znro09xhk1h8u6-s633yasc8hcr5",
|
||||||
"signature" => "da92708b8f2c9dcd7ecdc91d52946c01802833e6683e46fc00b3f081920dd5b1",
|
"signature" => "da92708b8f2c9dcd7ecdc91d52946c01802833e6683e46fc00b3f081920dd5b1",
|
||||||
"body-mime" => load_message('mailgun_message1.txt')
|
"body-mime" => load_message('mailgun_message1.txt')
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_mailgun_creates_todo_with_mailmap
|
def test_mailgun_creates_todo_with_mailmap
|
||||||
SITE_CONFIG['mailgun_api_key'] = "123456789"
|
stub_site_config do
|
||||||
SITE_CONFIG['email_dispatch'] = 'to'
|
SITE_CONFIG['mailgun_api_key'] = "123456789"
|
||||||
SITE_CONFIG['mailmap'] = {
|
SITE_CONFIG['email_dispatch'] = 'to'
|
||||||
'5555555555@tmomail.net' => ['incoming@othermail.com', 'notused@foo.org']
|
SITE_CONFIG['mailmap'] = {
|
||||||
}
|
'5555555555@tmomail.net' => ['incoming@othermail.com', 'notused@foo.org']
|
||||||
|
}
|
||||||
|
|
||||||
todo_count = Todo.count
|
todo_count = Todo.count
|
||||||
post :mailgun, {
|
post :mailgun, {
|
||||||
"timestamp" => "1379539674",
|
"timestamp" => "1379539674",
|
||||||
"token" => "5km6cwo0e3bfvg78hw4s69znro09xhk1h8u6-s633yasc8hcr5",
|
"token" => "5km6cwo0e3bfvg78hw4s69znro09xhk1h8u6-s633yasc8hcr5",
|
||||||
"signature" => "da92708b8f2c9dcd7ecdc91d52946c01802833e6683e46fc00b3f081920dd5b1",
|
"signature" => "da92708b8f2c9dcd7ecdc91d52946c01802833e6683e46fc00b3f081920dd5b1",
|
||||||
"body-mime" => load_message('mailgun_message2.txt')
|
"body-mime" => load_message('mailgun_message2.txt')
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
|
||||||
assert_equal(todo_count+1, Todo.count)
|
assert_equal(todo_count+1, Todo.count)
|
||||||
message_todo = Todo.where(:description => "test").first
|
message_todo = Todo.where(:description => "test").first
|
||||||
assert_not_nil(message_todo)
|
assert_not_nil(message_todo)
|
||||||
assert_equal(@inbox, message_todo.context)
|
assert_equal(@inbox, message_todo.context)
|
||||||
assert_equal(@user, message_todo.user)
|
assert_equal(@user, message_todo.user)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_mailgun_signature_fails
|
def test_mailgun_signature_fails
|
||||||
SITE_CONFIG['mailgun_api_key'] = "invalidkey"
|
stub_site_config do
|
||||||
SITE_CONFIG['email_dispatch'] = 'from'
|
SITE_CONFIG['mailgun_api_key'] = "invalidkey"
|
||||||
|
SITE_CONFIG['email_dispatch'] = 'from'
|
||||||
|
|
||||||
post :mailgun, {
|
post :mailgun, {
|
||||||
"timestamp" => "1379539674",
|
"timestamp" => "1379539674",
|
||||||
"token" => "5km6cwo0e3bfvg78hw4s69znro09xhk1h8u6-s633yasc8hcr5",
|
"token" => "5km6cwo0e3bfvg78hw4s69znro09xhk1h8u6-s633yasc8hcr5",
|
||||||
"signature" => "da92708b8f2c9dcd7ecdc91d52946c01802833e6683e46fc00b3f081920dd5b1",
|
"signature" => "da92708b8f2c9dcd7ecdc91d52946c01802833e6683e46fc00b3f081920dd5b1",
|
||||||
"body-mime" => load_message('mailgun_message1.txt')
|
"body-mime" => load_message('mailgun_message1.txt')
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_response 406
|
assert_response 406
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
require 'support/stub_site_config_helper'
|
||||||
|
|
||||||
class StoriesTest < ActionDispatch::IntegrationTest
|
class StoriesTest < ActionDispatch::IntegrationTest
|
||||||
|
include StubSiteConfigHelper
|
||||||
|
|
||||||
# ####################################################
|
# ####################################################
|
||||||
# Testing login and signup by different kinds of users
|
# Testing login and signup by different kinds of users
|
||||||
|
|
@ -14,23 +16,27 @@ class StoriesTest < ActionDispatch::IntegrationTest
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_signup_new_user_by_nonadmin
|
def test_signup_new_user_by_nonadmin
|
||||||
SITE_CONFIG['open_signups'] = false
|
stub_site_config do
|
||||||
other_user = new_session_as(:other_user,"sesame")
|
SITE_CONFIG['open_signups'] = false
|
||||||
other_user.goes_to_signup_as_nonadmin
|
other_user = new_session_as(:other_user,"sesame")
|
||||||
|
other_user.goes_to_signup_as_nonadmin
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_open_signup_new_user
|
def test_open_signup_new_user
|
||||||
SITE_CONFIG['open_signups'] = true
|
stub_site_config do
|
||||||
get "/signup"
|
SITE_CONFIG['open_signups'] = true
|
||||||
assert_response :success
|
get "/signup"
|
||||||
assert_template "users/new"
|
assert_response :success
|
||||||
post "/users", :user => {:login => "newbie",
|
assert_template "users/new"
|
||||||
:password => "newbiepass",
|
post "/users", :user => {:login => "newbie",
|
||||||
:password_confirmation => "newbiepass"}
|
:password => "newbiepass",
|
||||||
assert_response :redirect
|
:password_confirmation => "newbiepass"}
|
||||||
follow_redirect!
|
assert_response :redirect
|
||||||
assert_response :success
|
follow_redirect!
|
||||||
assert_template "todos/index"
|
assert_response :success
|
||||||
|
assert_template "todos/index"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
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