Skip to content

Commit 7bde3bc

Browse files
authored
Merge pull request #1141 from cerebris/fix_assert_nil_tests
update tests to use assert_nil
2 parents 4b8f55d + defe54d commit 7bde3bc

3 files changed

Lines changed: 19 additions & 20 deletions

File tree

test/controllers/controller_test.rb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ def test_show_does_not_include_records_count_in_meta
483483
JSONAPI.configuration.top_level_meta_include_record_count = true
484484
assert_cacheable_get :show, params: { id: Post.first.id }
485485
assert_response :success
486-
assert_equal json_response['meta'], nil
486+
assert_nil json_response['meta']
487487
ensure
488488
JSONAPI.configuration.top_level_meta_include_record_count = false
489489
end
@@ -492,7 +492,7 @@ def test_show_does_not_include_pages_count_in_meta
492492
JSONAPI.configuration.top_level_meta_include_page_count = true
493493
assert_cacheable_get :show, params: { id: Post.first.id }
494494
assert_response :success
495-
assert_equal json_response['meta'], nil
495+
assert_nil json_response['meta']
496496
ensure
497497
JSONAPI.configuration.top_level_meta_include_page_count = false
498498
end
@@ -596,7 +596,7 @@ def test_create_simple_id_not_allowed
596596

597597
assert_response :bad_request
598598
assert_match /id is not allowed/, response.body
599-
assert_equal nil,response.location
599+
assert_nil response.location
600600
end
601601

602602
def test_create_link_to_missing_object
@@ -618,7 +618,7 @@ def test_create_link_to_missing_object
618618
assert_response :unprocessable_entity
619619
# TODO: check if this validation is working
620620
assert_match /author - can't be blank/, response.body
621-
assert_equal nil, response.location
621+
assert_nil response.location
622622
end
623623

624624
def test_create_extra_param
@@ -640,7 +640,7 @@ def test_create_extra_param
640640

641641
assert_response :bad_request
642642
assert_match /asdfg is not allowed/, response.body
643-
assert_equal nil,response.location
643+
assert_nil response.location
644644
end
645645

646646
def test_create_extra_param_allow_extra_params
@@ -707,7 +707,7 @@ def test_create_with_invalid_data
707707
assert_equal "/data/attributes/title", json_response['errors'][1]['source']['pointer']
708708
assert_equal "is too long (maximum is 35 characters)", json_response['errors'][1]['title']
709709
assert_equal "title - is too long (maximum is 35 characters)", json_response['errors'][1]['detail']
710-
assert_equal nil, response.location
710+
assert_nil response.location
711711
end
712712

713713
def test_create_multiple
@@ -760,7 +760,7 @@ def test_create_simple_missing_posts
760760

761761
assert_response :bad_request
762762
assert_match /The required parameter, data, is missing./, json_response['errors'][0]['detail']
763-
assert_equal nil, response.location
763+
assert_nil response.location
764764
end
765765

766766
def test_create_simple_wrong_type
@@ -781,7 +781,7 @@ def test_create_simple_wrong_type
781781

782782
assert_response :bad_request
783783
assert_match /posts_spelled_wrong is not a valid resource./, json_response['errors'][0]['detail']
784-
assert_equal nil, response.location
784+
assert_nil response.location
785785
end
786786

787787
def test_create_simple_missing_type
@@ -801,7 +801,7 @@ def test_create_simple_missing_type
801801

802802
assert_response :bad_request
803803
assert_match /The required parameter, type, is missing./, json_response['errors'][0]['detail']
804-
assert_equal nil, response.location
804+
assert_nil response.location
805805
end
806806

807807
def test_create_simple_unpermitted_attributes
@@ -822,7 +822,7 @@ def test_create_simple_unpermitted_attributes
822822

823823
assert_response :bad_request
824824
assert_match /subject/, json_response['errors'][0]['detail']
825-
assert_equal nil, response.location
825+
assert_nil response.location
826826
end
827827

828828
def test_create_simple_unpermitted_attributes_allow_extra_params
@@ -1086,7 +1086,7 @@ def test_update_remove_links
10861086
assert_response :success
10871087
assert json_response['data'].is_a?(Hash)
10881088
assert_equal '3', json_response['data']['relationships']['author']['data']['id']
1089-
assert_equal nil, json_response['data']['relationships']['section']['data']
1089+
assert_nil json_response['data']['relationships']['section']['data']
10901090
assert_equal 'A great new Post', json_response['data']['attributes']['title']
10911091
assert_equal 'AAAA', json_response['data']['attributes']['body']
10921092
assert matches_array?([],
@@ -1116,7 +1116,7 @@ def test_update_relationship_to_one_nil
11161116

11171117
assert_response :no_content
11181118
post_object = Post.find(4)
1119-
assert_equal nil, post_object.section_id
1119+
assert_nil post_object.section_id
11201120
end
11211121

11221122
def test_update_relationship_to_one_invalid_links_hash_keys_ids
@@ -1233,7 +1233,7 @@ def test_update_relationship_to_one_singular_param_id_nil
12331233
put :update_relationship, params: {post_id: 3, relationship: 'section', data: {type: 'sections', id: nil}}
12341234

12351235
assert_response :no_content
1236-
assert_equal nil, post_object.reload.section_id
1236+
assert_nil post_object.reload.section_id
12371237
end
12381238

12391239
def test_update_relationship_to_one_data_nil
@@ -1246,7 +1246,7 @@ def test_update_relationship_to_one_data_nil
12461246
put :update_relationship, params: {post_id: 3, relationship: 'section', data: nil}
12471247

12481248
assert_response :no_content
1249-
assert_equal nil, post_object.reload.section_id
1249+
assert_nil post_object.reload.section_id
12501250
end
12511251

12521252
def test_remove_relationship_to_one
@@ -1260,7 +1260,7 @@ def test_remove_relationship_to_one
12601260

12611261
assert_response :no_content
12621262
post_object = Post.find(3)
1263-
assert_equal nil, post_object.section_id
1263+
assert_nil post_object.section_id
12641264
end
12651265

12661266
def test_update_relationship_to_one_singular_param
@@ -2585,7 +2585,7 @@ def test_get_person_as_author
25852585
assert_equal '1', json_response['data'][0]['id']
25862586
assert_equal 'authors', json_response['data'][0]['type']
25872587
assert_equal 'Joe Author', json_response['data'][0]['attributes']['name']
2588-
assert_equal nil, json_response['data'][0]['attributes']['email']
2588+
assert_nil json_response['data'][0]['attributes']['email']
25892589
end
25902590

25912591
def test_show_person_as_author
@@ -2594,7 +2594,7 @@ def test_show_person_as_author
25942594
assert_equal '1', json_response['data']['id']
25952595
assert_equal 'authors', json_response['data']['type']
25962596
assert_equal 'Joe Author', json_response['data']['attributes']['name']
2597-
assert_equal nil, json_response['data']['attributes']['email']
2597+
assert_nil json_response['data']['attributes']['email']
25982598
end
25992599

26002600
def test_get_person_as_author_by_name_filter

test/unit/operation/operation_dispatcher_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def test_replace_to_one_relationship
8585

8686
op.process(operations)
8787
saturn.reload
88-
assert_equal(saturn.planet_type_id, nil)
88+
assert_nil saturn.planet_type_id
8989

9090
# Reset
9191
operations = [

test/unit/serializer/link_builder_test.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ def test_engine_name
3939
primary_resource_klass: ApiV2Engine::PersonResource
4040
).engine_name
4141

42-
assert_equal nil,
43-
JSONAPI::LinkBuilder.new(
42+
assert_nil JSONAPI::LinkBuilder.new(
4443
primary_resource_klass: Api::V1::PersonResource
4544
).engine_name
4645
end

0 commit comments

Comments
 (0)