Skip to content

Commit fb6b805

Browse files
committed
code gardening: we have assert_(nil|blank|present), more concise, with better default failure messages - let's use them
1 parent d14e298 commit fb6b805

19 files changed

+37
-35
lines changed

actionpack/test/controller/output_escaping_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class OutputEscapingTest < ActiveSupport::TestCase
44

55
test "escape_html shouldn't die when passed nil" do
6-
assert ERB::Util.h(nil).blank?
6+
assert_blank ERB::Util.h(nil)
77
end
88

99
test "escapeHTML should escape strings" do

actionpack/test/controller/render_test.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ def test_overwritting_rendering_relative_file_with_extension
11131113

11141114
def test_head_with_location_header
11151115
get :head_with_location_header
1116-
assert @response.body.blank?
1116+
assert_blank @response.body
11171117
assert_equal "/foo", @response.headers["Location"]
11181118
assert_response :ok
11191119
end
@@ -1126,15 +1126,15 @@ def test_head_with_location_object
11261126
end
11271127

11281128
get :head_with_location_object
1129-
assert @response.body.blank?
1129+
assert_blank @response.body
11301130
assert_equal "http://www.nextangle.com/customers/1", @response.headers["Location"]
11311131
assert_response :ok
11321132
end
11331133
end
11341134

11351135
def test_head_with_custom_header
11361136
get :head_with_custom_header
1137-
assert @response.body.blank?
1137+
assert_blank @response.body
11381138
assert_equal "something", @response.headers["X-Custom-Header"]
11391139
assert_response :ok
11401140
end
@@ -1414,7 +1414,7 @@ def test_render_should_not_set_etag_when_last_modified_has_been_specified
14141414
assert_equal 200, @response.status.to_i
14151415
assert_not_nil @response.last_modified
14161416
assert_nil @response.etag
1417-
assert @response.body.present?
1417+
assert_present @response.body
14181418
end
14191419

14201420
def test_render_with_etag
@@ -1499,7 +1499,7 @@ def test_request_not_modified
14991499
@request.if_modified_since = @last_modified
15001500
get :conditional_hello
15011501
assert_equal 304, @response.status.to_i
1502-
assert @response.body.blank?, @response.body
1502+
assert_blank @response.body
15031503
assert_equal @last_modified, @response.headers['Last-Modified']
15041504
end
15051505

@@ -1514,7 +1514,7 @@ def test_request_modified
15141514
@request.if_modified_since = 'Thu, 16 Jul 2008 00:00:00 GMT'
15151515
get :conditional_hello
15161516
assert_equal 200, @response.status.to_i
1517-
assert !@response.body.blank?
1517+
assert_present @response.body
15181518
assert_equal @last_modified, @response.headers['Last-Modified']
15191519
end
15201520

actionpack/test/controller/request_forgery_protection_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def test_should_allow_all_methods_without_token
251251

252252
test 'should not emit a csrf-token meta tag' do
253253
get :meta
254-
assert @response.body.blank?
254+
assert_blank @response.body
255255
end
256256
end
257257

actionpack/test/controller/test_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ def test_params_reset_after_post_request
546546
assert_equal "bar", @request.params[:foo]
547547
@request.recycle!
548548
post :no_op
549-
assert @request.params[:foo].blank?
549+
assert_blank @request.params[:foo]
550550
end
551551

552552
def test_should_have_knowledge_of_client_side_cookie_state_even_if_they_are_not_set

actionpack/test/controller/webservice_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def setup
2929
def test_check_parameters
3030
with_test_route_set do
3131
get "/"
32-
assert @controller.response.body.blank?
32+
assert_blank @controller.response.body
3333
end
3434
end
3535

@@ -161,7 +161,7 @@ def test_register_and_use_xml_simple
161161
def test_use_xml_ximple_with_empty_request
162162
with_test_route_set do
163163
assert_nothing_raised { post "/", "", {'CONTENT_TYPE' => 'application/xml'} }
164-
assert @controller.response.body.blank?
164+
assert_blank @controller.response.body
165165
end
166166
end
167167

actionpack/test/template/atom_feed_helper_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def test_providing_builder_to_atom_feed
226226
get :index, :id=>"provide_builder"
227227
# because we pass in the non-default builder, the content generated by the
228228
# helper should go 'nowhere'. Leaving the response body blank.
229-
assert @response.body.blank?
229+
assert_blank @response.body
230230
end
231231
end
232232

activemodel/test/cases/mass_assignment_security_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ def test_attributes_protected_by_default
2525
end
2626

2727
def test_mass_assignment_protection_inheritance
28-
assert LoosePerson.accessible_attributes.blank?
28+
assert_blank LoosePerson.accessible_attributes
2929
assert_equal Set.new([ 'credit_rating', 'administrator']), LoosePerson.protected_attributes
3030

31-
assert LooseDescendant.accessible_attributes.blank?
31+
assert_blank LooseDescendant.accessible_attributes
3232
assert_equal Set.new([ 'credit_rating', 'administrator', 'phone_number']), LooseDescendant.protected_attributes
3333

34-
assert LooseDescendantSecond.accessible_attributes.blank?
34+
assert_blank LooseDescendantSecond.accessible_attributes
3535
assert_equal Set.new([ 'credit_rating', 'administrator', 'phone_number', 'name']), LooseDescendantSecond.protected_attributes,
3636
'Running attr_protected twice in one class should merge the protections'
3737

activerecord/test/cases/aggregations_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_allow_nil_address_loaded_when_only_some_attributes_are_nil
9999
customers(:zaphod).save
100100
customers(:zaphod).reload
101101
assert_kind_of Address, customers(:zaphod).address
102-
assert customers(:zaphod).address.street.nil?
102+
assert_nil customers(:zaphod).address.street
103103
end
104104

105105
def test_nil_assignment_results_in_nil

activerecord/test/cases/associations/belongs_to_associations_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
2222
def test_belongs_to
2323
Client.find(3).firm.name
2424
assert_equal companies(:first_firm).name, Client.find(3).firm.name
25-
assert !Client.find(3).firm.nil?, "Microsoft should have a firm"
25+
assert_not_nil Client.find(3).firm, "Microsoft should have a firm"
2626
end
2727

2828
def test_belongs_to_with_primary_key

activerecord/test/cases/associations/has_many_associations_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ def test_clearing_an_association_collection
633633

634634
# Should not be destroyed since the association is not dependent.
635635
assert_nothing_raised do
636-
assert Client.find(client_id).firm.nil?
636+
assert_nil Client.find(client_id).firm
637637
end
638638
end
639639

@@ -658,7 +658,7 @@ def test_clearing_a_dependent_association_collection
658658
assert_equal [client_id], Client.destroyed_client_ids[firm.id]
659659

660660
# Should be destroyed since the association is dependent.
661-
assert Client.find_by_id(client_id).nil?
661+
assert_nil Client.find_by_id(client_id)
662662
end
663663

664664
def test_clearing_an_exclusively_dependent_association_collection

0 commit comments

Comments
 (0)