summaryrefslogtreecommitdiff
path: root/core/lib
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2012-12-07 08:28:23 +0100
committerAzul <azul@leap.se>2012-12-07 08:28:23 +0100
commit1ec55c4f562a4fdd57c50077ff286ef08e9978a1 (patch)
tree16203d2ca4f32e24d38fef6062aa9534cecb3bfe /core/lib
parenteffa6b0f84cfe954cc9dd73f592663b743b0d857 (diff)
parenta3dce077881c7e97090e5e560b1fb004952d5b23 (diff)
Merge branch 'develop'
Diffstat (limited to 'core/lib')
-rw-r--r--core/lib/extensions/testing.rb23
1 files changed, 19 insertions, 4 deletions
diff --git a/core/lib/extensions/testing.rb b/core/lib/extensions/testing.rb
index 14a5698..925c023 100644
--- a/core/lib/extensions/testing.rb
+++ b/core/lib/extensions/testing.rb
@@ -1,17 +1,32 @@
module LeapWebCore
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}"),
- @response.headers["Content-Disposition"]
+ get_response.headers["Content-Disposition"]
end
-
def assert_json_response(object)
- object.stringify_keys! if object.respond_to? :stringify_keys!
- assert_equal object, JSON.parse(@response.body)
+ if object.is_a? Hash
+ object.stringify_keys! if object.respond_to? :stringify_keys!
+ assert_equal object, JSON.parse(get_response.body)
+ 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
end