summaryrefslogtreecommitdiff
path: root/test/support/rack_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/support/rack_test.rb')
-rw-r--r--test/support/rack_test.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/support/rack_test.rb b/test/support/rack_test.rb
new file mode 100644
index 0000000..806339a
--- /dev/null
+++ b/test/support/rack_test.rb
@@ -0,0 +1,38 @@
+require_relative 'assert_responses'
+
+class RackTest < ActiveSupport::TestCase
+ include Rack::Test::Methods
+ include Warden::Test::Helpers
+
+ CONFIG_RU = (Rails.root + 'config.ru').to_s
+ OUTER_APP = Rack::Builder.parse_file(CONFIG_RU).first
+
+ def app
+ OUTER_APP
+ end
+
+ def assert_access_denied
+ assert_json_response('error' => I18n.t(:not_authorized))
+ assert_response :unprocessable_entity
+ end
+
+ # inspired by rails 4
+ # -> actionpack/lib/action_dispatch/testing/assertions/response.rb
+ def assert_response(type, message = nil)
+ # RackTest does not know @response
+ response_code = last_response.status
+ message ||= "Expected response to be a <#{type}>, but was <#{response_code}>"
+
+ if Symbol === type
+ if [:success, :missing, :redirect, :error].include?(type)
+ assert last_response.send("#{type}?"), message
+ else
+ code = Rack::Utils::SYMBOL_TO_STATUS_CODE[type]
+ assert_equal code, response_code, message
+ end
+ else
+ assert_equal type, response_code, message
+ end
+ end
+
+end