Improve tests found by assert_nil

This commit is contained in:
Benjamin Fleischer
2017-01-06 23:09:52 -06:00
parent 4dfbe2747b
commit c52af54b4e
2 changed files with 21 additions and 16 deletions

View File

@@ -33,7 +33,8 @@ module SerializationScopeTesting
end
end
class PostTestController < ActionController::Base
attr_accessor :current_user
attr_writer :current_user
def render_post_by_non_admin
self.current_user = User.new(id: 3, name: 'Pete', admin: false)
render json: new_post, serializer: serializer, adapter: :json
@@ -44,6 +45,10 @@ module SerializationScopeTesting
render json: new_post, serializer: serializer, adapter: :json
end
def current_user
defined?(@current_user) ? @current_user : :current_user_not_set
end
private
def new_post
@@ -75,10 +80,8 @@ module SerializationScopeTesting
end
def test_default_serialization_scope_object
expected = @controller.current_user
actual = @controller.serialization_scope
assert_nil expected
assert_nil actual
assert_equal :current_user_not_set, @controller.current_user
assert_equal :current_user_not_set, @controller.serialization_scope
end
def test_default_scope_non_admin
@@ -128,7 +131,7 @@ module SerializationScopeTesting
end
def test_defined_serialization_scope_object
assert_equal @controller.view_context.class, @controller.serialization_scope.class
assert_equal @controller.view_context.controller, @controller.serialization_scope.controller
end
def test_serialization_scope_non_admin