diff options
author | Azul <azul@leap.se> | 2014-04-08 09:58:41 +0200 |
---|---|---|
committer | Azul <azul@leap.se> | 2014-04-08 10:08:26 +0200 |
commit | 045237ff88ffd5f1fe23d9621b043a9e604e54fa (patch) | |
tree | 59bbfc5a4855a73789118ebe994acc03158e20fe /test/support | |
parent | 53808b073f539ba2b442738b6abf97228488e311 (diff) |
fix requiring core extensions - most tests pass
some message tests are failing for me right now.
Diffstat (limited to 'test/support')
-rw-r--r-- | test/support/assert_responses.rb | 46 | ||||
-rw-r--r-- | test/support/rack_test.rb | 2 |
2 files changed, 47 insertions, 1 deletions
diff --git a/test/support/assert_responses.rb b/test/support/assert_responses.rb new file mode 100644 index 0000000..b01166f --- /dev/null +++ b/test/support/assert_responses.rb @@ -0,0 +1,46 @@ +module AssertResponses + + # response that works with different TestCases: + # ActionController::TestCase has @response + # ActionDispatch::IntegrationTest has @response + # Rack::Test::Methods defines last_response + def get_response + @response || last_response + end + + def assert_attachement_filename(name) + assert_equal %Q(attachment; filename="#{name}"), + get_response.headers["Content-Disposition"] + end + + def json_response + response = JSON.parse(get_response.body) + response.respond_to?(:with_indifferent_access) ? + response.with_indifferent_access : + response + end + + def assert_json_response(object) + assert_equal 'application/json', + get_response.content_type.to_s.split(';').first + if object.is_a? Hash + object.stringify_keys! if object.respond_to? :stringify_keys! + assert_equal object, json_response + else + assert_equal object.to_json, get_response.body + end + end + + def assert_json_error(object) + object.stringify_keys! if object.respond_to? :stringify_keys! + assert_json_response :errors => object + end +end + +class ::ActionController::TestCase + include AssertResponses +end + +class ::ActionDispatch::IntegrationTest + include AssertResponses +end diff --git a/test/support/rack_test.rb b/test/support/rack_test.rb index 2d8e5c4..35d191b 100644 --- a/test/support/rack_test.rb +++ b/test/support/rack_test.rb @@ -1,7 +1,7 @@ class RackTest < ActiveSupport::TestCase include Rack::Test::Methods include Warden::Test::Helpers - include LeapWebCore::AssertResponses + include AssertResponses CONFIG_RU = (Rails.root + 'config.ru').to_s OUTER_APP = Rack::Builder.parse_file(CONFIG_RU).first |