From 758b9a3c30a73fd985943fb7a887f0373be3a833 Mon Sep 17 00:00:00 2001 From: Azul Date: Sat, 8 Feb 2014 12:29:08 +0100 Subject: split up and expand account integration test --- core/lib/extensions/testing.rb | 2 ++ core/test/support/rack_test.rb | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) (limited to 'core') 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 -- cgit v1.2.3