mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Differentiate exception behavior in Rails 4.0 vs. others
NoMethodError is current_user is nil, so nil.admin? NameError is a superclass of NoMethodError (which Rails 4.0 won't allow) and means current_user might not be defined
This commit is contained in:
parent
85658c0230
commit
1b2f5ec774
@ -158,6 +158,8 @@ module SerializationScopeTesting
|
||||
assert_equal expected_json, @response.body
|
||||
end
|
||||
end
|
||||
# FIXME: Has bugs. See comments below and
|
||||
# https://github.com/rails-api/active_model_serializers/issues/1509
|
||||
class NilSerializationScopeTest < ActionController::TestCase
|
||||
class PostViewContextTestController < ActionController::Base
|
||||
serialization_scope nil
|
||||
@ -195,10 +197,17 @@ module SerializationScopeTesting
|
||||
# TODO: change to NoMethodError and match 'admin?' when the
|
||||
# global state in Serializer._serializer_instance_methods is fixed
|
||||
def test_nil_scope
|
||||
exception = assert_raises(NameError) do
|
||||
if Rails.version.start_with?('4.0')
|
||||
exception_class = NoMethodError
|
||||
exception_matcher = 'admin?'
|
||||
else
|
||||
exception_class = NameError
|
||||
exception_matcher = /admin|current_user/
|
||||
end
|
||||
exception = assert_raises(exception_class) do
|
||||
get :render_post_with_no_scope
|
||||
end
|
||||
assert_match(/admin|current_user/, exception.message)
|
||||
assert_match exception_matcher, exception.message
|
||||
end
|
||||
|
||||
# TODO: run test when
|
||||
|
||||
Loading…
Reference in New Issue
Block a user