Skip to content

Commit

Permalink
Differentiate exception behavior in Rails 4.0 vs. others
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bf4 committed Feb 11, 2016
1 parent 002292a commit 47669f5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions test/action_controller/serialization_scope_name_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,17 @@ def test_nil_serialization_scope_object
# 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
Expand Down

0 comments on commit 47669f5

Please sign in to comment.