diff options
author | Azul <azul@leap.se> | 2014-02-08 12:29:08 +0100 |
---|---|---|
committer | Azul <azul@leap.se> | 2014-02-10 14:26:30 +0100 |
commit | 758b9a3c30a73fd985943fb7a887f0373be3a833 (patch) | |
tree | 935bf639bb17ea034d7864205d087f6cd3497175 /core | |
parent | 67f17e65b9e9e8ad2991b9c4002dba5203baa77f (diff) |
split up and expand account integration test
Diffstat (limited to 'core')
-rw-r--r-- | core/lib/extensions/testing.rb | 2 | ||||
-rw-r--r-- | core/test/support/rack_test.rb | 24 |
2 files changed, 26 insertions, 0 deletions
diff --git a/core/lib/extensions/testing.rb b/core/lib/extensions/testing.rb index aad7fc1..d9b6da8 100644 --- a/core/lib/extensions/testing.rb +++ b/core/lib/extensions/testing.rb @@ -22,6 +22,8 @@ module LeapWebCore end def assert_json_response(object) + assert_equal 'application/json', + get_response.content_type.split(';').first if object.is_a? Hash object.stringify_keys! if object.respond_to? :stringify_keys! assert_equal object, json_response diff --git a/core/test/support/rack_test.rb b/core/test/support/rack_test.rb index 0476cf7..2d8e5c4 100644 --- a/core/test/support/rack_test.rb +++ b/core/test/support/rack_test.rb @@ -10,4 +10,28 @@ class RackTest < ActiveSupport::TestCase 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 |