Merge pull request #32605 from composerinteralia/assert-not

Add RuboCop for `assert_not` over `assert !`
This commit is contained in:
Rafael França 2018-04-19 15:03:28 -04:00 committed by GitHub
commit 6fec9c27e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
104 changed files with 429 additions and 338 deletions

@ -16,6 +16,11 @@ CustomCops/RefuteNot:
Include:
- '**/*_test.rb'
# Prefer assert_not over assert !
CustomCops/AssertNot:
Include:
- '**/*_test.rb'
# Prefer &&/|| over and/or.
Style/AndOr:
Enabled: true

@ -83,7 +83,7 @@ def send_async(method, *args)
connection.subscriptions.expects(:unsubscribe_from_all)
connection.send :handle_close
assert ! connection.connected
assert_not connection.connected
assert_equal [], @server.connections
end
end

@ -40,14 +40,14 @@ def test_read_fragment_with_caching_disabled
def test_fragment_exist_with_caching_enabled
@store.write("views/name", "value")
assert @mailer.fragment_exist?("name")
assert !@mailer.fragment_exist?("other_name")
assert_not @mailer.fragment_exist?("other_name")
end
def test_fragment_exist_with_caching_disabled
@mailer.perform_caching = false
@store.write("views/name", "value")
assert !@mailer.fragment_exist?("name")
assert !@mailer.fragment_exist?("other_name")
assert_not @mailer.fragment_exist?("name")
assert_not @mailer.fragment_exist?("other_name")
end
def test_write_fragment_with_caching_enabled
@ -90,7 +90,7 @@ def test_fragment_for
buffer = "generated till now -> ".html_safe
buffer << view_context.send(:fragment_for, "expensive") { fragment_computed = true }
assert !fragment_computed
assert_not fragment_computed
assert_equal "generated till now -> fragment content", buffer
end

@ -154,7 +154,7 @@ def setup
test "when :except is specified, an after action is not triggered on that action" do
@controller.process(:index)
assert !@controller.instance_variable_defined?("@authenticated")
assert_not @controller.instance_variable_defined?("@authenticated")
end
end
@ -198,7 +198,7 @@ def setup
test "when :except is specified with an array, an after action is not triggered on that action" do
@controller.process(:index)
assert !@controller.instance_variable_defined?("@authenticated")
assert_not @controller.instance_variable_defined?("@authenticated")
end
end

@ -290,13 +290,13 @@ def test_assert_redirect_failure_message_with_protocol_relative_url
def test_template_objects_exist
process :assign_this
assert !@controller.instance_variable_defined?(:"@hi")
assert_not @controller.instance_variable_defined?(:"@hi")
assert @controller.instance_variable_get(:"@howdy")
end
def test_template_objects_missing
process :nothing
assert !@controller.instance_variable_defined?(:@howdy)
assert_not @controller.instance_variable_defined?(:@howdy)
end
def test_empty_flash
@ -366,7 +366,7 @@ def test_redirect_url_match
process :redirect_external
assert_predicate @response, :redirect?
assert_match(/rubyonrails/, @response.redirect_url)
assert !/perloffrails/.match(@response.redirect_url)
assert_not /perloffrails/.match(@response.redirect_url)
end
def test_redirection

@ -94,14 +94,14 @@ def test_read_fragment_with_versioned_model
def test_fragment_exist_with_caching_enabled
@store.write("views/name", "value")
assert @controller.fragment_exist?("name")
assert !@controller.fragment_exist?("other_name")
assert_not @controller.fragment_exist?("other_name")
end
def test_fragment_exist_with_caching_disabled
@controller.perform_caching = false
@store.write("views/name", "value")
assert !@controller.fragment_exist?("name")
assert !@controller.fragment_exist?("other_name")
assert_not @controller.fragment_exist?("name")
assert_not @controller.fragment_exist?("other_name")
end
def test_write_fragment_with_caching_enabled
@ -144,7 +144,7 @@ def test_fragment_for
buffer = "generated till now -> ".html_safe
buffer << view_context.send(:fragment_for, "expensive") { fragment_computed = true }
assert !fragment_computed
assert_not fragment_computed
assert_equal "generated till now -> fragment content", buffer
end

@ -787,7 +787,7 @@ def test_conditional_skipping_of_actions
assert_equal %w( ensure_login find_user ), @controller.instance_variable_get(:@ran_filter)
test_process(ConditionalSkippingController, "login")
assert !@controller.instance_variable_defined?("@ran_after_action")
assert_not @controller.instance_variable_defined?("@ran_after_action")
test_process(ConditionalSkippingController, "change_password")
assert_equal %w( clean_up ), @controller.instance_variable_get("@ran_after_action")
end

@ -44,7 +44,7 @@ def test_delete
@hash["foo"] = "bar"
@hash.delete "foo"
assert !@hash.key?("foo")
assert_not @hash.key?("foo")
assert_nil @hash["foo"]
end
@ -53,7 +53,7 @@ def test_to_hash
assert_equal({ "foo" => "bar" }, @hash.to_hash)
@hash.to_hash["zomg"] = "aaron"
assert !@hash.key?("zomg")
assert_not @hash.key?("zomg")
assert_equal({ "foo" => "bar" }, @hash.to_hash)
end

@ -202,7 +202,7 @@ def authenticate_with_request
test "validate_digest_response should fail with nil returning password_procedure" do
@request.env["HTTP_AUTHORIZATION"] = encode_credentials(username: nil, password: nil)
assert !ActionController::HttpAuthentication::Digest.validate_digest_response(@request, "SuperSecret") { nil }
assert_not ActionController::HttpAuthentication::Digest.validate_digest_response(@request, "SuperSecret") { nil }
end
test "authentication request with request-uri ending in '/'" do

@ -135,7 +135,7 @@ def test_opens_new_session
session1 = @test.open_session { |sess| }
session2 = @test.open_session # implicit session
assert !session1.equal?(session2)
assert_not session1.equal?(session2)
end
# RSpec mixes Matchers (which has a #method_missing) into

@ -136,7 +136,7 @@ def walk_permitted(params)
test "key: it is not assigned if not present in params" do
params = ActionController::Parameters.new(name: "Joe")
permitted = params.permit(:id)
assert !permitted.has_key?(:id)
assert_not permitted.has_key?(:id)
end
test "key to empty array: empty arrays pass" do

@ -65,8 +65,8 @@ def test_enumerable
end
def test_key_methods
assert !request.cookie_jar.key?(:foo)
assert !request.cookie_jar.has_key?("foo")
assert_not request.cookie_jar.key?(:foo)
assert_not request.cookie_jar.has_key?("foo")
request.cookie_jar[:foo] = :bar
assert request.cookie_jar.key?(:foo)

@ -81,7 +81,7 @@ def test_run_callbacks_are_called_before_close
running = false
body.close
assert !running
assert_not running
end
def test_complete_callbacks_are_called_on_close
@ -89,7 +89,7 @@ def test_complete_callbacks_are_called_on_close
executor.to_complete { completed = true }
body = call_and_return_body
assert !completed
assert_not completed
body.close
assert completed
@ -116,7 +116,7 @@ def test_callbacks_execute_in_shared_context
call_and_return_body.close
assert result
assert !defined?(@in_shared_context) # it's not in the test itself
assert_not defined?(@in_shared_context) # it's not in the test itself
end
private

@ -180,8 +180,8 @@ class MimeTypeTest < ActiveSupport::TestCase
assert Mime[:js] =~ "text/javascript"
assert Mime[:js] =~ "application/javascript"
assert Mime[:js] !~ "text/html"
assert !(Mime[:js] !~ "text/javascript")
assert !(Mime[:js] !~ "application/javascript")
assert_not (Mime[:js] !~ "text/javascript")
assert_not (Mime[:js] !~ "application/javascript")
assert Mime[:html] =~ "application/xhtml+xml"
end
end

@ -115,7 +115,7 @@ def test_complete_callbacks_are_called_when_body_is_closed
reloader.to_complete { completed = true }
body = call_and_return_body
assert !completed
assert_not completed
body.close
assert completed
@ -129,7 +129,7 @@ def test_prepare_callbacks_arent_called_when_body_is_closed
prepared = false
body.close
assert !prepared
assert_not prepared
end
def test_complete_callbacks_are_called_on_exceptions

@ -191,7 +191,7 @@ def test_only_set_charset_still_defaults_to_text_html
test "does not include Status header" do
@response.status = "200 OK"
_, headers, _ = @response.to_a
assert !headers.has_key?("Status")
assert_not headers.has_key?("Status")
end
test "response code" do

@ -3166,7 +3166,7 @@ def test_explicitly_avoiding_the_named_route
end
end
assert !respond_to?(:routes_no_collision_path)
assert_not respond_to?(:routes_no_collision_path)
end
def test_controller_name_with_leading_slash_raise_error

@ -49,21 +49,21 @@ def test_capture_used_for_read
end
def test_content_for_with_multiple_calls
assert ! content_for?(:title)
assert_not content_for?(:title)
content_for :title, "foo"
content_for :title, "bar"
assert_equal "foobar", content_for(:title)
end
def test_content_for_with_multiple_calls_and_flush
assert ! content_for?(:title)
assert_not content_for?(:title)
content_for :title, "foo"
content_for :title, "bar", flush: true
assert_equal "bar", content_for(:title)
end
def test_content_for_with_block
assert ! content_for?(:title)
assert_not content_for?(:title)
content_for :title do
output_buffer << "foo"
output_buffer << "bar"
@ -73,7 +73,7 @@ def test_content_for_with_block
end
def test_content_for_with_block_and_multiple_calls_with_flush
assert ! content_for?(:title)
assert_not content_for?(:title)
content_for :title do
"foo"
end
@ -84,7 +84,7 @@ def test_content_for_with_block_and_multiple_calls_with_flush
end
def test_content_for_with_block_and_multiple_calls_with_flush_nil_content
assert ! content_for?(:title)
assert_not content_for?(:title)
content_for :title do
"foo"
end
@ -95,7 +95,7 @@ def test_content_for_with_block_and_multiple_calls_with_flush_nil_content
end
def test_content_for_with_block_and_multiple_calls_without_flush
assert ! content_for?(:title)
assert_not content_for?(:title)
content_for :title do
"foo"
end
@ -106,7 +106,7 @@ def test_content_for_with_block_and_multiple_calls_without_flush
end
def test_content_for_with_whitespace_block
assert ! content_for?(:title)
assert_not content_for?(:title)
content_for :title, "foo"
content_for :title do
output_buffer << " \n "
@ -117,7 +117,7 @@ def test_content_for_with_whitespace_block
end
def test_content_for_with_whitespace_block_and_flush
assert ! content_for?(:title)
assert_not content_for?(:title)
content_for :title, "foo"
content_for :title, flush: true do
output_buffer << " \n "
@ -128,7 +128,7 @@ def test_content_for_with_whitespace_block_and_flush
end
def test_content_for_returns_nil_when_writing
assert ! content_for?(:title)
assert_not content_for?(:title)
assert_nil content_for(:title, "foo")
assert_nil content_for(:title) { output_buffer << "bar"; nil }
assert_nil content_for(:title) { output_buffer << " \n "; nil }
@ -144,14 +144,14 @@ def test_content_for_returns_nil_when_content_missing
end
def test_content_for_question_mark
assert ! content_for?(:title)
assert_not content_for?(:title)
content_for :title, "title"
assert content_for?(:title)
assert ! content_for?(:something_else)
assert_not content_for?(:something_else)
end
def test_content_for_should_be_html_safe_after_flush_empty
assert ! content_for?(:title)
assert_not content_for?(:title)
content_for :title do
content_tag(:p, "title")
end
@ -164,7 +164,7 @@ def test_content_for_should_be_html_safe_after_flush_empty
end
def test_provide
assert !content_for?(:title)
assert_not content_for?(:title)
provide :title, "hi"
assert content_for?(:title)
assert_equal "hi", content_for(:title)

@ -195,7 +195,7 @@ def teardown
assert @lookup_context.cache
template = @lookup_context.disable_cache do
assert !@lookup_context.cache
assert_not @lookup_context.cache
@lookup_context.find("foo", %w(test), true)
end
assert @lookup_context.cache

@ -192,7 +192,7 @@ def help_me
helper HelperThatInvokesProtectAgainstForgery
test "protect_from_forgery? in any helpers returns false" do
assert !view.help_me
assert_not view.help_me
end
end

@ -508,16 +508,16 @@ def test_current_page_ignoring_params
def test_current_page_considering_params
@request = request_for_url("/?order=desc&page=1")
assert !current_page?(url_hash, check_parameters: true)
assert !current_page?(url_hash.merge(check_parameters: true))
assert !current_page?(ActionController::Parameters.new(url_hash.merge(check_parameters: true)).permit!)
assert !current_page?("http://www.example.com/", check_parameters: true)
assert_not current_page?(url_hash, check_parameters: true)
assert_not current_page?(url_hash.merge(check_parameters: true))
assert_not current_page?(ActionController::Parameters.new(url_hash.merge(check_parameters: true)).permit!)
assert_not current_page?("http://www.example.com/", check_parameters: true)
end
def test_current_page_considering_params_when_options_does_not_respond_to_to_hash
@request = request_for_url("/?order=desc&page=1")
assert !current_page?(:back, check_parameters: false)
assert_not current_page?(:back, check_parameters: false)
end
def test_current_page_with_params_that_match
@ -562,7 +562,7 @@ def test_current_page_with_trailing_slash
def test_current_page_with_not_get_verb
@request = request_for_url("/events", method: :post)
assert !current_page?("/events")
assert_not current_page?("/events")
end
def test_link_unless_current

@ -39,7 +39,7 @@ def reload
end
test "changes to attribute values" do
assert !@model.changes["name"]
assert_not @model.changes["name"]
@model.name = "John"
assert_equal [nil, "John"], @model.changes["name"]
end

@ -78,7 +78,7 @@ def reload
end
test "changes to attribute values" do
assert !@model.changes["name"]
assert_not @model.changes["name"]
@model.name = "John"
assert_equal [nil, "John"], @model.changes["name"]
end

@ -207,26 +207,26 @@ def test_no_key
test "added? returns false when no errors are present" do
person = Person.new
assert !person.errors.added?(:name)
assert_not person.errors.added?(:name)
end
test "added? returns false when checking a nonexisting error and other errors are present for the given attribute" do
person = Person.new
person.errors.add(:name, "is invalid")
assert !person.errors.added?(:name, "cannot be blank")
assert_not person.errors.added?(:name, "cannot be blank")
end
test "added? returns false when checking for an error, but not providing message arguments" do
person = Person.new
person.errors.add(:name, "cannot be blank")
assert !person.errors.added?(:name)
assert_not person.errors.added?(:name)
end
test "added? returns false when checking for an error by symbol and a different error with same message is present" do
I18n.backend.store_translations("en", errors: { attributes: { name: { wrong: "is wrong", used: "is wrong" } } })
person = Person.new
person.errors.add(:name, :wrong)
assert !person.errors.added?(:name, :used)
assert_not person.errors.added?(:name, :used)
end
test "size calculates the number of error messages" do

@ -187,7 +187,7 @@ class SecurePasswordTest < ActiveModel::TestCase
test "authenticate" do
@user.password = "secret"
assert !@user.authenticate("wrong")
assert_not @user.authenticate("wrong")
assert @user.authenticate("secret")
end

@ -84,7 +84,7 @@ def test_indexes
indexes = @connection.indexes("accounts")
assert_equal "accounts", indexes.first.table
assert_equal idx_name, indexes.first.name
assert !indexes.first.unique
assert_not indexes.first.unique
assert_equal ["firm_id"], indexes.first.columns
ensure
@connection.remove_index(:accounts, name: idx_name) rescue nil

@ -148,8 +148,8 @@ def test_remove_timestamps
t.timestamps null: true
end
ActiveRecord::Base.connection.remove_timestamps :delete_me, null: true
assert !column_present?("delete_me", "updated_at", "datetime")
assert !column_present?("delete_me", "created_at", "datetime")
assert_not column_present?("delete_me", "updated_at", "datetime")
assert_not column_present?("delete_me", "created_at", "datetime")
ensure
ActiveRecord::Base.connection.drop_table :delete_me rescue nil
end

@ -116,8 +116,8 @@ def test_timestamps_without_null_set_null_to_false_on_create_table
end
end
assert !@connection.columns(:has_timestamps).find { |c| c.name == "created_at" }.null
assert !@connection.columns(:has_timestamps).find { |c| c.name == "updated_at" }.null
assert_not @connection.columns(:has_timestamps).find { |c| c.name == "created_at" }.null
assert_not @connection.columns(:has_timestamps).find { |c| c.name == "updated_at" }.null
end
def test_timestamps_without_null_set_null_to_false_on_change_table
@ -129,8 +129,8 @@ def test_timestamps_without_null_set_null_to_false_on_change_table
end
end
assert !@connection.columns(:has_timestamps).find { |c| c.name == "created_at" }.null
assert !@connection.columns(:has_timestamps).find { |c| c.name == "updated_at" }.null
assert_not @connection.columns(:has_timestamps).find { |c| c.name == "created_at" }.null
assert_not @connection.columns(:has_timestamps).find { |c| c.name == "updated_at" }.null
end
def test_timestamps_without_null_set_null_to_false_on_add_timestamps
@ -139,7 +139,7 @@ def test_timestamps_without_null_set_null_to_false_on_add_timestamps
add_timestamps :has_timestamps, default: Time.now
end
assert !@connection.columns(:has_timestamps).find { |c| c.name == "created_at" }.null
assert !@connection.columns(:has_timestamps).find { |c| c.name == "updated_at" }.null
assert_not @connection.columns(:has_timestamps).find { |c| c.name == "created_at" }.null
assert_not @connection.columns(:has_timestamps).find { |c| c.name == "updated_at" }.null
end
end

@ -569,7 +569,7 @@ def test_include_returns_false_for_non_matching_record_to_verify_scoping
developer = Developer.create name: "Bryan", salary: 50_000
assert_not_predicate project.developers, :loaded?
assert ! project.developers.include?(developer)
assert_not project.developers.include?(developer)
end
def test_find_with_merged_options

@ -2009,7 +2009,7 @@ def test_calling_none_should_count_instead_of_loading_association
def test_calling_none_on_loaded_association_should_not_use_query
firm = companies(:first_firm)
firm.clients.load # force load
assert_no_queries { assert ! firm.clients.none? }
assert_no_queries { assert_not firm.clients.none? }
end
def test_calling_none_should_defer_to_collection_if_using_a_block
@ -2044,7 +2044,7 @@ def test_calling_one_should_count_instead_of_loading_association
def test_calling_one_on_loaded_association_should_not_use_query
firm = companies(:first_firm)
firm.clients.load # force load
assert_no_queries { assert ! firm.clients.one? }
assert_no_queries { assert_not firm.clients.one? }
end
def test_calling_one_should_defer_to_collection_if_using_a_block

@ -866,7 +866,7 @@ def test_collection_delete_with_nonstandard_primary_key_on_belongs_to
author = authors(:mary)
category = author.named_categories.create(name: "Primary")
author.named_categories.delete(category)
assert !Categorization.exists?(author_id: author.id, named_category_name: category.name)
assert_not Categorization.exists?(author_id: author.id, named_category_name: category.name)
assert_empty author.named_categories.reload
end

@ -452,7 +452,7 @@ def test_creation_failure_without_dependent_option
assert_equal new_ship, pirate.ship
assert_predicate new_ship, :new_record?
assert_nil orig_ship.pirate_id
assert !orig_ship.changed? # check it was saved
assert_not orig_ship.changed? # check it was saved
end
def test_creation_failure_with_dependent_option

@ -732,7 +732,7 @@ def test_has_many_through_include_returns_false_for_non_matching_record_to_verif
category = Category.create!(name: "Not Associated")
assert_not_predicate david.categories, :loaded?
assert ! david.categories.include?(category)
assert_not david.categories.include?(category)
end
def test_has_many_through_goes_through_all_sti_classes

@ -63,8 +63,8 @@ def setup
t.author_name = ""
assert t.attribute_present?("title")
assert t.attribute_present?("written_on")
assert !t.attribute_present?("content")
assert !t.attribute_present?("author_name")
assert_not t.attribute_present?("content")
assert_not t.attribute_present?("author_name")
end
test "attribute_present with booleans" do
@ -77,7 +77,7 @@ def setup
assert b2.attribute_present?(:value)
b3 = Boolean.new
assert !b3.attribute_present?(:value)
assert_not b3.attribute_present?(:value)
b4 = Boolean.new
b4.value = false
@ -827,7 +827,7 @@ def name
self.table_name = "computers"
end
assert !klass.instance_method_already_implemented?(:system)
assert_not klass.instance_method_already_implemented?(:system)
computer = klass.new
assert_nil computer.system
end
@ -841,8 +841,8 @@ def name
self.table_name = "computers"
end
assert !klass.instance_method_already_implemented?(:system)
assert !subklass.instance_method_already_implemented?(:system)
assert_not klass.instance_method_already_implemented?(:system)
assert_not subklass.instance_method_already_implemented?(:system)
computer = subklass.new
assert_nil computer.system
end

@ -116,7 +116,7 @@ def test_save_fails_for_invalid_has_one
assert_not_predicate firm.account, :valid?
assert_not_predicate firm, :valid?
assert !firm.save
assert_not firm.save
assert_equal ["is invalid"], firm.errors["account"]
end
@ -237,7 +237,7 @@ def test_save_fails_for_invalid_belongs_to
log.developer = Developer.new
assert_not_predicate log.developer, :valid?
assert_not_predicate log, :valid?
assert !log.save
assert_not log.save
assert_equal ["is invalid"], log.errors["developer"]
end
@ -499,10 +499,10 @@ class TestDefaultAutosaveAssociationOnAHasManyAssociation < ActiveRecord::TestCa
def test_invalid_adding
firm = Firm.find(1)
assert !(firm.clients_of_firm << c = Client.new)
assert_not (firm.clients_of_firm << c = Client.new)
assert_not_predicate c, :persisted?
assert_not_predicate firm, :valid?
assert !firm.save
assert_not firm.save
assert_not_predicate c, :persisted?
end
@ -512,7 +512,7 @@ def test_invalid_adding_before_save
assert_not_predicate c, :persisted?
assert_not_predicate c, :valid?
assert_not_predicate new_firm, :valid?
assert !new_firm.save
assert_not new_firm.save
assert_not_predicate c, :persisted?
assert_not_predicate new_firm, :persisted?
end
@ -550,7 +550,7 @@ def test_invalid_build
assert_not_predicate new_client, :persisted?
assert_not_predicate new_client, :valid?
assert_equal new_client, companies(:first_firm).clients_of_firm.last
assert !companies(:first_firm).save
assert_not companies(:first_firm).save
assert_not_predicate new_client, :persisted?
assert_equal 2, companies(:first_firm).clients_of_firm.reload.size
end
@ -795,7 +795,7 @@ def save(*args)
@ship.pirate.catchphrase = "Changed Catchphrase"
@ship.name_will_change!
assert_raise(RuntimeError) { assert !@pirate.save }
assert_raise(RuntimeError) { assert_not @pirate.save }
assert_not_nil @pirate.reload.ship
end
@ -855,7 +855,7 @@ def save(*args)
@ship.pirate.catchphrase = "Changed Catchphrase"
assert_raise(RuntimeError) { assert !@ship.save }
assert_raise(RuntimeError) { assert_not @ship.save }
assert_not_nil @ship.reload.pirate
end
@ -871,7 +871,7 @@ def test_should_save_changed_child_objects_if_parent_is_saved
def test_should_destroy_has_many_as_part_of_the_save_transaction_if_they_were_marked_for_destruction
2.times { |i| @pirate.birds.create!(name: "birds_#{i}") }
assert !@pirate.birds.any?(&:marked_for_destruction?)
assert_not @pirate.birds.any?(&:marked_for_destruction?)
@pirate.birds.each(&:mark_for_destruction)
klass = @pirate.birds.first.class
@ -937,7 +937,7 @@ def destroy(*args)
end
end
assert_raise(RuntimeError) { assert !@pirate.save }
assert_raise(RuntimeError) { assert_not @pirate.save }
assert_equal before, @pirate.reload.birds
end
@ -1003,7 +1003,7 @@ def test_should_save_new_record_that_has_same_value_as_existing_record_marked_fo
def test_should_destroy_habtm_as_part_of_the_save_transaction_if_they_were_marked_for_destruction
2.times { |i| @pirate.parrots.create!(name: "parrots_#{i}") }
assert !@pirate.parrots.any?(&:marked_for_destruction?)
assert_not @pirate.parrots.any?(&:marked_for_destruction?)
@pirate.parrots.each(&:mark_for_destruction)
assert_no_difference "Parrot.count" do
@ -1065,7 +1065,7 @@ def destroy(*args)
end
end
assert_raise(RuntimeError) { assert !@pirate.save }
assert_raise(RuntimeError) { assert_not @pirate.save }
assert_equal before, @pirate.reload.parrots
end
@ -1213,7 +1213,7 @@ def test_should_not_save_and_return_false_if_a_callback_cancelled_saving
assert_no_difference "Pirate.count" do
assert_no_difference "Ship.count" do
assert !pirate.save
assert_not pirate.save
end
end
end
@ -1232,7 +1232,7 @@ def save(*args)
end
end
assert_raise(RuntimeError) { assert !@pirate.save }
assert_raise(RuntimeError) { assert_not @pirate.save }
assert_equal before, [@pirate.reload.catchphrase, @pirate.ship.name]
end
@ -1337,7 +1337,7 @@ def test_should_not_save_and_return_false_if_a_callback_cancelled_saving
assert_no_difference "Ship.count" do
assert_no_difference "Pirate.count" do
assert !ship.save
assert_not ship.save
end
end
end
@ -1356,7 +1356,7 @@ def save(*args)
end
end
assert_raise(RuntimeError) { assert !@ship.save }
assert_raise(RuntimeError) { assert_not @ship.save }
assert_equal before, [@ship.pirate.reload.catchphrase, @ship.reload.name]
end
@ -1480,7 +1480,7 @@ def test_should_not_save_and_return_false_if_a_callback_cancelled_saving_in_eith
@child_1.name = "Changed"
@child_1.cancel_save_from_callback = true
assert !@pirate.save
assert_not @pirate.save
assert_equal "Don' botharrr talkin' like one, savvy?", @pirate.reload.catchphrase
assert_equal "Posideons Killer", @child_1.reload.name
@ -1490,7 +1490,7 @@ def test_should_not_save_and_return_false_if_a_callback_cancelled_saving_in_eith
assert_no_difference "Pirate.count" do
assert_no_difference "#{new_child.class.name}.count" do
assert !new_pirate.save
assert_not new_pirate.save
end
end
end
@ -1510,7 +1510,7 @@ def save(*args)
end
end
assert_raise(RuntimeError) { assert !@pirate.save }
assert_raise(RuntimeError) { assert_not @pirate.save }
assert_equal before, [@pirate.reload.catchphrase, *@pirate.send(@association_name).map(&:name)]
end

@ -307,7 +307,7 @@ def test_create_after_initialize_with_array_param
assert_equal "Dude", cbs[0].name
assert_equal "Bob", cbs[1].name
assert cbs[0].frickinawesome
assert !cbs[1].frickinawesome
assert_not cbs[1].frickinawesome
end
def test_load
@ -856,11 +856,11 @@ def test_clone_of_new_object_marks_attributes_as_dirty
def test_clone_of_new_object_marks_as_dirty_only_changed_attributes
developer = Developer.new name: "Bjorn"
assert developer.name_changed? # obviously
assert !developer.salary_changed? # attribute has non-nil default value, so treated as not changed
assert_not developer.salary_changed? # attribute has non-nil default value, so treated as not changed
cloned_developer = developer.clone
assert_predicate cloned_developer, :name_changed?
assert !cloned_developer.salary_changed? # ... and cloned instance should behave same
assert_not cloned_developer.salary_changed? # ... and cloned instance should behave same
end
def test_dup_of_saved_object_marks_attributes_as_dirty
@ -875,12 +875,12 @@ def test_dup_of_saved_object_marks_attributes_as_dirty
def test_dup_of_saved_object_marks_as_dirty_only_changed_attributes
developer = Developer.create! name: "Bjorn"
assert !developer.name_changed? # both attributes of saved object should be treated as not changed
assert_not developer.name_changed? # both attributes of saved object should be treated as not changed
assert_not_predicate developer, :salary_changed?
cloned_developer = developer.dup
assert cloned_developer.name_changed? # ... but on cloned object should be
assert !cloned_developer.salary_changed? # ... BUT salary has non-nil default which should be treated as not changed on cloned instance
assert_not cloned_developer.salary_changed? # ... BUT salary has non-nil default which should be treated as not changed on cloned instance
end
def test_bignum

@ -385,9 +385,9 @@ def test_delete
end
def assert_save_callbacks_not_called(someone)
assert !someone.after_save_called
assert !someone.after_create_called
assert !someone.after_update_called
assert_not someone.after_save_called
assert_not someone.after_create_called
assert_not someone.after_update_called
end
private :assert_save_callbacks_not_called
@ -395,27 +395,27 @@ def test_before_create_throwing_abort
someone = CallbackHaltedDeveloper.new
someone.cancel_before_create = true
assert_predicate someone, :valid?
assert !someone.save
assert_not someone.save
assert_save_callbacks_not_called(someone)
end
def test_before_save_throwing_abort
david = DeveloperWithCanceledCallbacks.find(1)
assert_predicate david, :valid?
assert !david.save
assert_not david.save
exc = assert_raise(ActiveRecord::RecordNotSaved) { david.save! }
assert_equal david, exc.record
david = DeveloperWithCanceledCallbacks.find(1)
david.salary = 10_000_000
assert_not_predicate david, :valid?
assert !david.save
assert_not david.save
assert_raise(ActiveRecord::RecordInvalid) { david.save! }
someone = CallbackHaltedDeveloper.find(1)
someone.cancel_before_save = true
assert_predicate someone, :valid?
assert !someone.save
assert_not someone.save
assert_save_callbacks_not_called(someone)
end
@ -423,22 +423,22 @@ def test_before_update_throwing_abort
someone = CallbackHaltedDeveloper.find(1)
someone.cancel_before_update = true
assert_predicate someone, :valid?
assert !someone.save
assert_not someone.save
assert_save_callbacks_not_called(someone)
end
def test_before_destroy_throwing_abort
david = DeveloperWithCanceledCallbacks.find(1)
assert !david.destroy
assert_not david.destroy
exc = assert_raise(ActiveRecord::RecordNotDestroyed) { david.destroy! }
assert_equal david, exc.record
assert_not_nil ImmutableDeveloper.find_by_id(1)
someone = CallbackHaltedDeveloper.find(1)
someone.cancel_before_destroy = true
assert !someone.destroy
assert_not someone.destroy
assert_raise(ActiveRecord::RecordNotDestroyed) { someone.destroy! }
assert !someone.after_destroy_called
assert_not someone.after_destroy_called
end
def test_callback_throwing_abort
@ -467,12 +467,12 @@ def test_callback_throwing_abort
def test_inheritance_of_callbacks
parent = ParentDeveloper.new
assert !parent.after_save_called
assert_not parent.after_save_called
parent.save
assert parent.after_save_called
child = ChildDeveloper.new
assert !child.after_save_called
assert_not child.after_save_called
child.save
assert child.after_save_called
end

@ -366,7 +366,7 @@ def test_partial_update_with_optimistic_locking
def test_changed_attributes_should_be_preserved_if_save_failure
pirate = Pirate.new
pirate.parrot_id = 1
assert !pirate.save
assert_not pirate.save
check_pirate_after_save_failure(pirate)
pirate = Pirate.new
@ -496,7 +496,7 @@ def test_previous_changes
assert_not_nil pirate.previous_changes["updated_on"][1]
assert_nil pirate.previous_changes["created_on"][0]
assert_not_nil pirate.previous_changes["created_on"][1]
assert !pirate.previous_changes.key?("parrot_id")
assert_not pirate.previous_changes.key?("parrot_id")
# original values should be in previous_changes
pirate = Pirate.new
@ -510,7 +510,7 @@ def test_previous_changes
assert_equal [nil, pirate.id], pirate.previous_changes["id"]
assert_includes pirate.previous_changes, "updated_on"
assert_includes pirate.previous_changes, "created_on"
assert !pirate.previous_changes.key?("parrot_id")
assert_not pirate.previous_changes.key?("parrot_id")
pirate.catchphrase = "Yar!!"
pirate.reload
@ -527,8 +527,8 @@ def test_previous_changes
assert_equal ["arrr", "Me Maties!"], pirate.previous_changes["catchphrase"]
assert_not_nil pirate.previous_changes["updated_on"][0]
assert_not_nil pirate.previous_changes["updated_on"][1]
assert !pirate.previous_changes.key?("parrot_id")
assert !pirate.previous_changes.key?("created_on")
assert_not pirate.previous_changes.key?("parrot_id")
assert_not pirate.previous_changes.key?("created_on")
pirate = Pirate.find_by_catchphrase("Me Maties!")
@ -541,8 +541,8 @@ def test_previous_changes
assert_equal ["Me Maties!", "Thar She Blows!"], pirate.previous_changes["catchphrase"]
assert_not_nil pirate.previous_changes["updated_on"][0]
assert_not_nil pirate.previous_changes["updated_on"][1]
assert !pirate.previous_changes.key?("parrot_id")
assert !pirate.previous_changes.key?("created_on")
assert_not pirate.previous_changes.key?("parrot_id")
assert_not pirate.previous_changes.key?("created_on")
travel(1.second)
@ -553,8 +553,8 @@ def test_previous_changes
assert_equal ["Thar She Blows!", "Ahoy!"], pirate.previous_changes["catchphrase"]
assert_not_nil pirate.previous_changes["updated_on"][0]
assert_not_nil pirate.previous_changes["updated_on"][1]
assert !pirate.previous_changes.key?("parrot_id")
assert !pirate.previous_changes.key?("created_on")
assert_not pirate.previous_changes.key?("parrot_id")
assert_not pirate.previous_changes.key?("created_on")
travel(1.second)
@ -565,8 +565,8 @@ def test_previous_changes
assert_equal ["Ahoy!", "Ninjas suck!"], pirate.previous_changes["catchphrase"]
assert_not_nil pirate.previous_changes["updated_on"][0]
assert_not_nil pirate.previous_changes["updated_on"][1]
assert !pirate.previous_changes.key?("parrot_id")
assert !pirate.previous_changes.key?("created_on")
assert_not pirate.previous_changes.key?("parrot_id")
assert_not pirate.previous_changes.key?("created_on")
ensure
travel_back
end

@ -171,7 +171,7 @@ def test_dup_record_not_persisted_after_rollback_transaction
end
end
assert !movie.persisted?
assert_not movie.persisted?
end
end
end

@ -727,8 +727,8 @@ def test_find_only_some_columns
assert_raise(ActiveModel::MissingAttributeError) { topic.title? }
assert_nil topic.read_attribute("title")
assert_equal "David", topic.author_name
assert !topic.attribute_present?("title")
assert !topic.attribute_present?(:title)
assert_not topic.attribute_present?("title")
assert_not topic.attribute_present?(:title)
assert topic.attribute_present?("author_name")
assert_respond_to topic, "author_name"
end

@ -592,10 +592,10 @@ class FixturesWithoutInstantiationTest < ActiveRecord::TestCase
fixtures :topics, :developers, :accounts
def test_without_complete_instantiation
assert !defined?(@first)
assert !defined?(@topics)
assert !defined?(@developers)
assert !defined?(@accounts)
assert_not defined?(@first)
assert_not defined?(@topics)
assert_not defined?(@developers)
assert_not defined?(@accounts)
end
def test_fixtures_from_root_yml_without_instantiation
@ -1082,13 +1082,13 @@ def test_supports_join_tables
def test_supports_inline_habtm
assert(parrots(:george).treasures.include?(treasures(:diamond)))
assert(parrots(:george).treasures.include?(treasures(:sapphire)))
assert(!parrots(:george).treasures.include?(treasures(:ruby)))
assert_not(parrots(:george).treasures.include?(treasures(:ruby)))
end
def test_supports_inline_habtm_with_specified_id
assert(parrots(:polly).treasures.include?(treasures(:ruby)))
assert(parrots(:polly).treasures.include?(treasures(:sapphire)))
assert(!parrots(:polly).treasures.include?(treasures(:diamond)))
assert_not(parrots(:polly).treasures.include?(treasures(:diamond)))
end
def test_supports_yaml_arrays

@ -215,7 +215,7 @@ def test_migrate_down
migration = InvertibleMigration.new
migration.migrate :up
migration.migrate :down
assert !migration.connection.table_exists?("horses")
assert_not migration.connection.table_exists?("horses")
end
def test_migrate_revert
@ -223,11 +223,11 @@ def test_migrate_revert
revert = InvertibleRevertMigration.new
migration.migrate :up
revert.migrate :up
assert !migration.connection.table_exists?("horses")
assert_not migration.connection.table_exists?("horses")
revert.migrate :down
assert migration.connection.table_exists?("horses")
migration.migrate :down
assert !migration.connection.table_exists?("horses")
assert_not migration.connection.table_exists?("horses")
end
def test_migrate_revert_by_part
@ -241,12 +241,12 @@ def test_migrate_revert_by_part
}
migration.migrate :up
assert_equal [:both, :up], received
assert !migration.connection.table_exists?("horses")
assert_not migration.connection.table_exists?("horses")
assert migration.connection.table_exists?("new_horses")
migration.migrate :down
assert_equal [:both, :up, :both, :down], received
assert migration.connection.table_exists?("horses")
assert !migration.connection.table_exists?("new_horses")
assert_not migration.connection.table_exists?("new_horses")
end
def test_migrate_revert_whole_migration
@ -255,11 +255,11 @@ def test_migrate_revert_whole_migration
revert = RevertWholeMigration.new(klass)
migration.migrate :up
revert.migrate :up
assert !migration.connection.table_exists?("horses")
assert_not migration.connection.table_exists?("horses")
revert.migrate :down
assert migration.connection.table_exists?("horses")
migration.migrate :down
assert !migration.connection.table_exists?("horses")
assert_not migration.connection.table_exists?("horses")
end
end
@ -268,7 +268,7 @@ def test_migrate_nested_revert_whole_migration
revert.migrate :down
assert revert.connection.table_exists?("horses")
revert.migrate :up
assert !revert.connection.table_exists?("horses")
assert_not revert.connection.table_exists?("horses")
end
def test_migrate_revert_change_column_default
@ -402,7 +402,7 @@ def test_up_only
UpOnlyMigration.new.migrate(:down) # should be no error
connection = ActiveRecord::Base.connection
assert !connection.column_exists?(:horses, :oldie)
assert_not connection.column_exists?(:horses, :oldie)
Horse.reset_column_information
end
end

@ -205,8 +205,8 @@ def test_create_table_with_timestamps_should_create_datetime_columns
created_at_column = created_columns.detect { |c| c.name == "created_at" }
updated_at_column = created_columns.detect { |c| c.name == "updated_at" }
assert !created_at_column.null
assert !updated_at_column.null
assert_not created_at_column.null
assert_not updated_at_column.null
end
def test_create_table_with_timestamps_should_create_datetime_columns_with_options
@ -408,7 +408,7 @@ def test_column_exists_on_table_with_no_options_parameter_supplied
end
connection.change_table :testings do |t|
assert t.column_exists?(:foo)
assert !(t.column_exists?(:bar))
assert_not (t.column_exists?(:bar))
end
end

@ -95,42 +95,42 @@ def test_drop_join_table
connection.create_join_table :artists, :musics
connection.drop_join_table :artists, :musics
assert !connection.table_exists?("artists_musics")
assert_not connection.table_exists?("artists_musics")
end
def test_drop_join_table_with_strings
connection.create_join_table :artists, :musics
connection.drop_join_table "artists", "musics"
assert !connection.table_exists?("artists_musics")
assert_not connection.table_exists?("artists_musics")
end
def test_drop_join_table_with_the_proper_order
connection.create_join_table :videos, :musics
connection.drop_join_table :videos, :musics
assert !connection.table_exists?("musics_videos")
assert_not connection.table_exists?("musics_videos")
end
def test_drop_join_table_with_the_table_name
connection.create_join_table :artists, :musics, table_name: :catalog
connection.drop_join_table :artists, :musics, table_name: :catalog
assert !connection.table_exists?("catalog")
assert_not connection.table_exists?("catalog")
end
def test_drop_join_table_with_the_table_name_as_string
connection.create_join_table :artists, :musics, table_name: "catalog"
connection.drop_join_table :artists, :musics, table_name: "catalog"
assert !connection.table_exists?("catalog")
assert_not connection.table_exists?("catalog")
end
def test_drop_join_table_with_column_options
connection.create_join_table :artists, :musics, column_options: { null: true }
connection.drop_join_table :artists, :musics, column_options: { null: true }
assert !connection.table_exists?("artists_musics")
assert_not connection.table_exists?("artists_musics")
end
def test_create_and_drop_join_table_with_common_prefix

@ -99,7 +99,7 @@ def test_index_exists
connection.add_index :testings, :foo
assert connection.index_exists?(:testings, :foo)
assert !connection.index_exists?(:testings, :bar)
assert_not connection.index_exists?(:testings, :bar)
end
def test_index_exists_on_multiple_columns
@ -131,7 +131,7 @@ def test_named_index_exists
assert connection.index_exists?(:testings, :foo)
assert connection.index_exists?(:testings, :foo, name: "custom_index_name")
assert !connection.index_exists?(:testings, :foo, name: "other_index_name")
assert_not connection.index_exists?(:testings, :foo, name: "other_index_name")
end
def test_remove_named_index
@ -139,7 +139,7 @@ def test_remove_named_index
assert connection.index_exists?(:testings, :foo)
connection.remove_index :testings, :foo
assert !connection.index_exists?(:testings, :foo)
assert_not connection.index_exists?(:testings, :foo)
end
def test_add_index_attribute_length_limit
@ -203,7 +203,7 @@ def test_add_partial_index
assert connection.index_exists?("testings", "last_name")
connection.remove_index("testings", "last_name")
assert !connection.index_exists?("testings", "last_name")
assert_not connection.index_exists?("testings", "last_name")
end
end

@ -548,7 +548,7 @@ def test_allows_sqlite3_rollback_on_invalid_column_type
end
assert Person.connection.column_exists?(:something, :foo)
assert_nothing_raised { Person.connection.remove_column :something, :foo, :bar }
assert !Person.connection.column_exists?(:something, :foo)
assert_not Person.connection.column_exists?(:something, :foo)
assert Person.connection.column_exists?(:something, :name)
assert Person.connection.column_exists?(:something, :number)
ensure
@ -822,7 +822,7 @@ def test_removing_columns
end
end
[:qualification, :experience].each { |c| assert ! column(c) }
[:qualification, :experience].each { |c| assert_not column(c) }
assert column(:qualification_experience)
end
@ -852,7 +852,7 @@ def test_adding_indexes
name_age_index = index(:index_delete_me_on_name_and_age)
assert_equal ["name", "age"].sort, name_age_index.columns.sort
assert ! name_age_index.unique
assert_not name_age_index.unique
assert index(:awesome_username_index).unique
end
@ -880,7 +880,7 @@ def test_removing_index
end
end
assert ! index(:index_delete_me_on_name)
assert_not index(:index_delete_me_on_name)
new_name_index = index(:new_name_index)
assert new_name_index.unique
@ -892,7 +892,7 @@ def test_changing_columns
t.date :birthdate
end
assert ! column(:name).default
assert_not column(:name).default
assert_equal :date, column(:birthdate).type
classname = ActiveRecord::Base.connection.class.name[/[^:]*$/]

@ -83,7 +83,7 @@ def test_should_disable_allow_destroy_by_default
def test_a_model_should_respond_to_underscore_destroy_and_return_if_it_is_marked_for_destruction
ship = Ship.create!(name: "Nights Dirty Lightning")
assert !ship._destroy
assert_not ship._destroy
ship.mark_for_destruction
assert ship._destroy
end
@ -835,7 +835,7 @@ def test_numeric_column_changes_from_zero_to_no_empty_string
man = Man.create(name: "John")
interest = man.interests.create(topic: "bar", zine_id: 0)
assert interest.save
assert !man.update(interests_attributes: { id: interest.id, zine_id: "foo" })
assert_not man.update(interests_attributes: { id: interest.id, zine_id: "foo" })
end
end

@ -48,7 +48,7 @@ def test_update_all_doesnt_ignore_order
end
if test_update_with_order_succeeds.call("id DESC")
assert !test_update_with_order_succeeds.call("id ASC") # test that this wasn't a fluke and using an incorrect order results in an exception
assert_not test_update_with_order_succeeds.call("id ASC") # test that this wasn't a fluke and using an incorrect order results in an exception
else
# test that we're failing because the current Arel's engine doesn't support UPDATE ORDER BY queries is using subselects instead
assert_sql(/\AUPDATE .+ \(SELECT .* ORDER BY id DESC\)\z/i) do

@ -518,19 +518,19 @@ def test_cache_gets_cleared_after_migration
def test_find
assert_called(Task.connection, :clear_query_cache) do
assert !Task.connection.query_cache_enabled
assert_not Task.connection.query_cache_enabled
Task.cache do
assert Task.connection.query_cache_enabled
Task.find(1)
Task.uncached do
assert !Task.connection.query_cache_enabled
assert_not Task.connection.query_cache_enabled
Task.find(1)
end
assert Task.connection.query_cache_enabled
end
assert !Task.connection.query_cache_enabled
assert_not Task.connection.query_cache_enabled
end
end

@ -23,7 +23,7 @@ def test_cant_save_readonly_record
assert_nothing_raised do
dev.name = "Luscious forbidden fruit."
assert !dev.save
assert_not dev.save
dev.name = "Forbidden."
end
@ -38,8 +38,8 @@ def test_cant_save_readonly_record
end
def test_find_with_readonly_option
Developer.all.each { |d| assert !d.readonly? }
Developer.readonly(false).each { |d| assert !d.readonly? }
Developer.all.each { |d| assert_not d.readonly? }
Developer.readonly(false).each { |d| assert_not d.readonly? }
Developer.readonly(true).each { |d| assert d.readonly? }
Developer.readonly.each { |d| assert d.readonly? }
end
@ -55,14 +55,14 @@ def test_find_with_joins_option_does_not_imply_readonly
def test_has_many_find_readonly
post = Post.find(1)
assert_not_empty post.comments
assert !post.comments.any?(&:readonly?)
assert !post.comments.to_a.any?(&:readonly?)
assert_not post.comments.any?(&:readonly?)
assert_not post.comments.to_a.any?(&:readonly?)
assert post.comments.readonly(true).all?(&:readonly?)
end
def test_has_many_with_through_is_not_implicitly_marked_readonly
assert people = Post.find(1).people
assert !people.any?(&:readonly?)
assert_not people.any?(&:readonly?)
end
def test_has_many_with_through_is_not_implicitly_marked_readonly_while_finding_by_id

@ -36,15 +36,15 @@ def flush
# A reaper with nil time should never reap connections
def test_nil_time
fp = FakePool.new
assert !fp.reaped
assert_not fp.reaped
reaper = ConnectionPool::Reaper.new(fp, nil)
reaper.run
assert !fp.reaped
assert_not fp.reaped
end
def test_some_time
fp = FakePool.new
assert !fp.reaped
assert_not fp.reaped
reaper = ConnectionPool::Reaper.new(fp, 0.0001)
reaper.run

@ -75,7 +75,7 @@ def test_column_string_type_and_limit
def test_column_null_not_null
subscriber = Subscriber.first
assert subscriber.column_for_attribute("name").null
assert !subscriber.column_for_attribute("nick").null
assert_not subscriber.column_for_attribute("nick").null
end
def test_human_name_for_column

@ -511,7 +511,7 @@ def test_respond_to_class_methods_and_scopes
end
def test_find_with_readonly_option
Developer.all.each { |d| assert !d.readonly? }
Developer.all.each { |d| assert_not d.readonly? }
Developer.all.readonly.each { |d| assert d.readonly? }
end
@ -1097,7 +1097,7 @@ def test_any
assert_not_predicate posts.where(id: nil), :any?
assert posts.any? { |p| p.id > 0 }
assert ! posts.any? { |p| p.id <= 0 }
assert_not posts.any? { |p| p.id <= 0 }
end
assert_predicate posts, :loaded?
@ -1109,7 +1109,7 @@ def test_many
assert_queries(2) do
assert posts.many? # Uses COUNT()
assert posts.many? { |p| p.id > 0 }
assert ! posts.many? { |p| p.id < 2 }
assert_not posts.many? { |p| p.id < 2 }
end
assert_predicate posts, :loaded?
@ -1125,14 +1125,14 @@ def test_many_with_limits
def test_none?
posts = Post.all
assert_queries(1) do
assert ! posts.none? # Uses COUNT()
assert_not posts.none? # Uses COUNT()
end
assert_not_predicate posts, :loaded?
assert_queries(1) do
assert posts.none? { |p| p.id < 0 }
assert ! posts.none? { |p| p.id == 1 }
assert_not posts.none? { |p| p.id == 1 }
end
assert_predicate posts, :loaded?
@ -1141,13 +1141,13 @@ def test_none?
def test_one
posts = Post.all
assert_queries(1) do
assert ! posts.one? # Uses COUNT()
assert_not posts.one? # Uses COUNT()
end
assert_not_predicate posts, :loaded?
assert_queries(1) do
assert ! posts.one? { |p| p.id < 3 }
assert_not posts.one? { |p| p.id < 3 }
assert posts.one? { |p| p.id == 1 }
end
@ -1696,7 +1696,7 @@ def test_presence
# checking if there are topics is used before you actually display them,
# thus it shouldn't invoke an extra count query.
assert_no_queries { assert topics.present? }
assert_no_queries { assert !topics.blank? }
assert_no_queries { assert_not topics.blank? }
# shows count of topics and loops after loading the query should not trigger extra queries either.
assert_no_queries { topics.size }

@ -193,7 +193,7 @@ def test_unscope_with_limit_in_query
def test_order_to_unscope_reordering
scope = DeveloperOrderedBySalary.order("salary DESC, name ASC").reverse_order.unscope(:order)
assert !/order/i.match?(scope.to_sql)
assert_not /order/i.match?(scope.to_sql)
end
def test_unscope_reverse_order

@ -86,7 +86,7 @@ def test_scopes_with_string_name_can_be_composed
def test_scopes_are_composable
assert_equal((approved = Topic.all.merge!(where: { approved: true }).to_a), Topic.approved)
assert_equal((replied = Topic.all.merge!(where: "replies_count > 0").to_a), Topic.replied)
assert !(approved == replied)
assert_not (approved == replied)
assert_not_empty (approved & replied)
assert_equal approved & replied, Topic.approved.replied

@ -105,7 +105,7 @@ def test_scoped_find_select
Developer.select("id, name").scoping do
developer = Developer.where("name = 'David'").first
assert_equal "David", developer.name
assert !developer.has_attribute?(:salary)
assert_not developer.has_attribute?(:salary)
end
end

@ -67,8 +67,8 @@ def test_include_root_in_json_allows_inheritance
klazz.include_root_in_json = false
assert ActiveRecord::Base.include_root_in_json
assert !klazz.include_root_in_json
assert !klazz.new.include_root_in_json
assert_not klazz.include_root_in_json
assert_not klazz.new.include_root_in_json
ensure
ActiveRecord::Base.include_root_in_json = original_root_in_json
end

@ -159,7 +159,7 @@ def test_rolling_back_in_a_callback_rollbacks_before_save
def @first.before_save_for_transaction
raise ActiveRecord::Rollback
end
assert !@first.approved
assert_not @first.approved
Topic.transaction do
@first.approved = true
@ -194,7 +194,7 @@ def test_update_should_rollback_on_failure
posts_count = author.posts.size
assert posts_count > 0
status = author.update(name: nil, post_ids: [])
assert !status
assert_not status
assert_equal posts_count, author.posts.reload.size
end
@ -212,7 +212,7 @@ def test_cancellation_from_before_destroy_rollbacks_in_destroy
add_cancelling_before_destroy_with_db_side_effect_to_topic @first
nbooks_before_destroy = Book.count
status = @first.destroy
assert !status
assert_not status
@first.reload
assert_equal nbooks_before_destroy, Book.count
end
@ -224,7 +224,7 @@ def test_cancellation_from_before_destroy_rollbacks_in_destroy
original_author_name = @first.author_name
@first.author_name += "_this_should_not_end_up_in_the_db"
status = @first.save
assert !status
assert_not status
assert_equal original_author_name, @first.reload.author_name
assert_equal nbooks_before_save, Book.count
end

@ -17,7 +17,7 @@ def self.name; "Owner"; end
def test_validates_size_of_association
assert_nothing_raised { @owner.validates_size_of :pets, minimum: 1 }
o = @owner.new("name" => "nopets")
assert !o.save
assert_not o.save
assert_predicate o.errors[:pets], :any?
o.pets.build("name" => "apet")
assert_predicate o, :valid?
@ -26,21 +26,21 @@ def test_validates_size_of_association
def test_validates_size_of_association_using_within
assert_nothing_raised { @owner.validates_size_of :pets, within: 1..2 }
o = @owner.new("name" => "nopets")
assert !o.save
assert_not o.save
assert_predicate o.errors[:pets], :any?
o.pets.build("name" => "apet")
assert_predicate o, :valid?
2.times { o.pets.build("name" => "apet") }
assert !o.save
assert_not o.save
assert_predicate o.errors[:pets], :any?
end
def test_validates_size_of_association_utf8
@owner.validates_size_of :pets, minimum: 1
o = @owner.new("name" => "あいうえおかきくけこ")
assert !o.save
assert_not o.save
assert_predicate o.errors[:pets], :any?
o.pets.build("name" => "あいうえおかきくけこ")
assert_predicate o, :valid?

@ -39,7 +39,7 @@ def test_valid_uses_update_context_when_persisted
def test_valid_using_special_context
r = WrongReply.new(title: "Valid title")
assert !r.valid?(:special_case)
assert_not r.valid?(:special_case)
assert_equal "Invalid", r.errors[:author_name].join
r.author_name = "secret"
@ -125,7 +125,7 @@ def test_exception_on_create_bang_many_with_block
def test_save_without_validation
reply = WrongReply.new
assert !reply.save
assert_not reply.save
assert reply.save(validate: false)
end

@ -25,7 +25,7 @@ def test_delete_matched_key_start
cache.write("foo", "bar")
cache.write("fu", "baz")
cache.delete_matched(/^fo/)
assert !cache.exist?("foo")
assert_not cache.exist?("foo")
assert cache.exist?("fu")
end
@ -34,7 +34,7 @@ def test_delete_matched_key
cache.write("foo", "bar")
cache.write("fu", "baz")
cache.delete_matched(/OO/i)
assert !cache.exist?("foo")
assert_not cache.exist?("foo")
assert cache.exist?("fu")
end
end

@ -104,7 +104,7 @@ def @cache.delete_entry(*args)
assert @cache.exist?(4)
assert @cache.exist?(3)
assert @cache.exist?(2)
assert !@cache.exist?(1)
assert_not @cache.exist?(1)
end
def test_write_with_unless_exist

@ -211,7 +211,7 @@ class DeleteMatchedTest < StoreTest
@cache.write("foo", "bar")
@cache.write("fu", "baz")
@cache.delete_matched("foo*")
assert !@cache.exist?("foo")
assert_not @cache.exist?("foo")
assert @cache.exist?("fu")
end
@ -227,15 +227,15 @@ class ClearTest < StoreTest
@cache.write("foo", "bar")
@cache.write("fu", "baz")
@cache.clear
assert !@cache.exist?("foo")
assert !@cache.exist?("fu")
assert_not @cache.exist?("foo")
assert_not @cache.exist?("fu")
end
test "only clear namespace cache key" do
@cache.write("foo", "bar")
@cache.redis.set("fu", "baz")
@cache.clear
assert !@cache.exist?("foo")
assert_not @cache.exist?("foo")
assert @cache.redis.exists("fu")
end
end

@ -829,7 +829,7 @@ def test_termination_invokes_hook
def test_block_never_called_if_terminated
obj = CallbackTerminator.new
obj.save
assert !obj.saved
assert_not obj.saved
end
end
@ -857,7 +857,7 @@ def test_default_termination_invokes_hook
def test_block_never_called_if_abort_is_thrown
obj = CallbackDefaultTerminator.new
obj.save
assert !obj.saved
assert_not obj.saved
end
end

@ -68,7 +68,7 @@ def test_safe_get_constantizes_doesnt_fail_on_invalid_names
def test_new_rejects_strings
@cache.store ClassCacheTest.name
assert !@cache.key?(ClassCacheTest.name)
assert_not @cache.key?(ClassCacheTest.name)
end
def test_store_returns_self

@ -16,30 +16,30 @@ def test_is_a
assert_kind_of ActiveSupport::Duration, d
assert_kind_of Numeric, d
assert_kind_of Integer, d
assert !d.is_a?(Hash)
assert_not d.is_a?(Hash)
k = Class.new
class << k; undef_method :== end
assert !d.is_a?(k)
assert_not d.is_a?(k)
end
def test_instance_of
assert 1.minute.instance_of?(Integer)
assert 2.days.instance_of?(ActiveSupport::Duration)
assert !3.second.instance_of?(Numeric)
assert_not 3.second.instance_of?(Numeric)
end
def test_threequals
assert ActiveSupport::Duration === 1.day
assert !(ActiveSupport::Duration === 1.day.to_i)
assert !(ActiveSupport::Duration === "foo")
assert_not (ActiveSupport::Duration === 1.day.to_i)
assert_not (ActiveSupport::Duration === "foo")
end
def test_equals
assert 1.day == 1.day
assert 1.day == 1.day.to_i
assert 1.day.to_i == 1.day
assert !(1.day == "foo")
assert_not (1.day == "foo")
end
def test_to_s
@ -53,11 +53,11 @@ def test_eql
assert 1.minute.eql?(1.minute)
assert 1.minute.eql?(60.seconds)
assert 2.days.eql?(48.hours)
assert !1.second.eql?(1)
assert !1.eql?(1.second)
assert_not 1.second.eql?(1)
assert_not 1.eql?(1.second)
assert 1.minute.eql?(180.seconds - 2.minutes)
assert !1.minute.eql?(60)
assert !1.minute.eql?("foo")
assert_not 1.minute.eql?(60)
assert_not 1.minute.eql?("foo")
end
def test_inspect

@ -8,7 +8,7 @@ def test_atomic_write_without_errors
contents = "Atomic Text"
File.atomic_write(file_name, Dir.pwd) do |file|
file.write(contents)
assert !File.exist?(file_name)
assert_not File.exist?(file_name)
end
assert File.exist?(file_name)
assert_equal contents, File.read(file_name)
@ -22,7 +22,7 @@ def test_atomic_write_doesnt_write_when_block_raises
raise "something bad"
end
rescue
assert !File.exist?(file_name)
assert_not File.exist?(file_name)
end
def test_atomic_write_preserves_file_permissions
@ -50,7 +50,7 @@ def test_atomic_write_preserves_default_file_permissions
contents = "Atomic Text"
File.atomic_write(file_name, Dir.pwd) do |file|
file.write(contents)
assert !File.exist?(file_name)
assert_not File.exist?(file_name)
end
assert File.exist?(file_name)
assert_equal File.probe_stat_in(Dir.pwd).mode, file_mode

@ -8,14 +8,14 @@ class IntegerExtTest < ActiveSupport::TestCase
def test_multiple_of
[ -7, 0, 7, 14 ].each { |i| assert i.multiple_of?(7) }
[ -7, 7, 14 ].each { |i| assert ! i.multiple_of?(6) }
[ -7, 7, 14 ].each { |i| assert_not i.multiple_of?(6) }
# test the 0 edge case
assert 0.multiple_of?(0)
assert !5.multiple_of?(0)
assert_not 5.multiple_of?(0)
# test with a prime
[2, 3, 5, 7].each { |i| assert !PRIME.multiple_of?(i) }
[2, 3, 5, 7].each { |i| assert_not PRIME.multiple_of?(i) }
end
def test_ordinalize

@ -12,7 +12,7 @@ def setup
def test_reader
assert_nothing_raised { @target.attr_internal_reader :foo }
assert !@instance.instance_variable_defined?("@_foo")
assert_not @instance.instance_variable_defined?("@_foo")
assert_raise(NoMethodError) { @instance.foo = 1 }
@instance.instance_variable_set("@_foo", 1)
@ -22,7 +22,7 @@ def test_reader
def test_writer
assert_nothing_raised { @target.attr_internal_writer :foo }
assert !@instance.instance_variable_defined?("@_foo")
assert_not @instance.instance_variable_defined?("@_foo")
assert_nothing_raised { assert_equal 1, @instance.foo = 1 }
assert_equal 1, @instance.instance_variable_get("@_foo")
@ -32,7 +32,7 @@ def test_writer
def test_accessor
assert_nothing_raised { @target.attr_internal :foo }
assert !@instance.instance_variable_defined?("@_foo")
assert_not @instance.instance_variable_defined?("@_foo")
assert_nothing_raised { assert_equal 1, @instance.foo = 1 }
assert_equal 1, @instance.instance_variable_get("@_foo")
@ -44,10 +44,10 @@ def test_naming_format
assert_nothing_raised { Module.attr_internal_naming_format = "@abc%sdef" }
@target.attr_internal :foo
assert !@instance.instance_variable_defined?("@_foo")
assert !@instance.instance_variable_defined?("@abcfoodef")
assert_not @instance.instance_variable_defined?("@_foo")
assert_not @instance.instance_variable_defined?("@abcfoodef")
assert_nothing_raised { @instance.foo = 1 }
assert !@instance.instance_variable_defined?("@_foo")
assert_not @instance.instance_variable_defined?("@_foo")
assert @instance.instance_variable_defined?("@abcfoodef")
ensure
Module.attr_internal_naming_format = "@_%s"

@ -21,7 +21,7 @@ def should_be_public; end
# Declares a concern but doesn't include it
assert klass.const_defined?(:Baz, false)
assert !ModuleConcernTest.const_defined?(:Baz)
assert_not ModuleConcernTest.const_defined?(:Baz)
assert_kind_of ActiveSupport::Concern, klass::Baz
assert_not_includes klass.ancestors, klass::Baz, klass.ancestors.inspect

@ -17,7 +17,7 @@ def test_missing_method_should_ignore_missing_name
exc = assert_raise NameError do
some_method_that_does_not_exist
end
assert !exc.missing_name?(:Foo)
assert_not exc.missing_name?(:Foo)
assert_nil exc.missing_name
end
end

@ -17,19 +17,19 @@ def test_duck_typing
dt = DateTime.new
duck = DuckTime.new
assert !object.acts_like?(:time)
assert !object.acts_like?(:date)
assert_not object.acts_like?(:time)
assert_not object.acts_like?(:date)
assert time.acts_like?(:time)
assert !time.acts_like?(:date)
assert_not time.acts_like?(:date)
assert !date.acts_like?(:time)
assert_not date.acts_like?(:time)
assert date.acts_like?(:date)
assert dt.acts_like?(:time)
assert dt.acts_like?(:date)
assert duck.acts_like?(:time)
assert !duck.acts_like?(:date)
assert_not duck.acts_like?(:date)
end
end

@ -47,7 +47,7 @@ def test_object_deep_dup
object = Object.new
dup = object.deep_dup
dup.instance_variable_set(:@a, 1)
assert !object.instance_variable_defined?(:@a)
assert_not object.instance_variable_defined?(:@a)
assert dup.instance_variable_defined?(:@a)
end

@ -6,30 +6,30 @@
class InTest < ActiveSupport::TestCase
def test_in_array
assert 1.in?([1, 2])
assert !3.in?([1, 2])
assert_not 3.in?([1, 2])
end
def test_in_hash
h = { "a" => 100, "b" => 200 }
assert "a".in?(h)
assert !"z".in?(h)
assert_not "z".in?(h)
end
def test_in_string
assert "lo".in?("hello")
assert !"ol".in?("hello")
assert_not "ol".in?("hello")
assert ?h.in?("hello")
end
def test_in_range
assert 25.in?(1..50)
assert !75.in?(1..50)
assert_not 75.in?(1..50)
end
def test_in_set
s = Set.new([1, 2])
assert 1.in?(s)
assert !3.in?(s)
assert_not 3.in?(s)
end
module A
@ -45,8 +45,8 @@ class D
def test_in_module
assert A.in?(B)
assert A.in?(C)
assert !A.in?(A)
assert !A.in?(D)
assert_not A.in?(A)
assert_not A.in?(D)
end
def test_no_method_catching

@ -37,7 +37,7 @@ def test_overlaps_last_inclusive
end
def test_overlaps_last_exclusive
assert !(1...5).overlaps?(5..10)
assert_not (1...5).overlaps?(5..10)
end
def test_overlaps_first_inclusive
@ -45,7 +45,7 @@ def test_overlaps_first_inclusive
end
def test_overlaps_first_exclusive
assert !(5..10).overlaps?(1...5)
assert_not (5..10).overlaps?(1...5)
end
def test_should_include_identical_inclusive
@ -102,7 +102,7 @@ def test_overlaps_on_time
def test_no_overlaps_on_time
time_range_1 = Time.utc(2005, 12, 10, 15, 30)..Time.utc(2005, 12, 10, 17, 30)
time_range_2 = Time.utc(2005, 12, 10, 17, 31)..Time.utc(2005, 12, 10, 18, 00)
assert !time_range_1.overlaps?(time_range_2)
assert_not time_range_1.overlaps?(time_range_2)
end
def test_each_on_time_with_zone

@ -237,11 +237,11 @@ def test_starts_ends_with_alias
s = "hello"
assert s.starts_with?("h")
assert s.starts_with?("hel")
assert !s.starts_with?("el")
assert_not s.starts_with?("el")
assert s.ends_with?("o")
assert s.ends_with?("lo")
assert !s.ends_with?("el")
assert_not s.ends_with?("el")
end
def test_string_squish

@ -535,9 +535,9 @@ def test_qualified_const_defined
def test_qualified_const_defined_should_not_call_const_missing
ModuleWithMissing.missing_count = 0
assert ! ActiveSupport::Dependencies.qualified_const_defined?("ModuleWithMissing::A")
assert_not ActiveSupport::Dependencies.qualified_const_defined?("ModuleWithMissing::A")
assert_equal 0, ModuleWithMissing.missing_count
assert ! ActiveSupport::Dependencies.qualified_const_defined?("ModuleWithMissing::A::B")
assert_not ActiveSupport::Dependencies.qualified_const_defined?("ModuleWithMissing::A::B")
assert_equal 0, ModuleWithMissing.missing_count
end
@ -547,13 +547,13 @@ def test_qualified_const_defined_explodes_with_invalid_const_name
def test_autoloaded?
with_autoloading_fixtures do
assert ! ActiveSupport::Dependencies.autoloaded?("ModuleFolder")
assert ! ActiveSupport::Dependencies.autoloaded?("ModuleFolder::NestedClass")
assert_not ActiveSupport::Dependencies.autoloaded?("ModuleFolder")
assert_not ActiveSupport::Dependencies.autoloaded?("ModuleFolder::NestedClass")
assert ActiveSupport::Dependencies.autoloaded?(ModuleFolder)
assert ActiveSupport::Dependencies.autoloaded?("ModuleFolder")
assert ! ActiveSupport::Dependencies.autoloaded?("ModuleFolder::NestedClass")
assert_not ActiveSupport::Dependencies.autoloaded?("ModuleFolder::NestedClass")
assert ActiveSupport::Dependencies.autoloaded?(ModuleFolder::NestedClass)
@ -564,11 +564,11 @@ def test_autoloaded?
assert ActiveSupport::Dependencies.autoloaded?(:ModuleFolder)
# Anonymous modules aren't autoloaded.
assert !ActiveSupport::Dependencies.autoloaded?(Module.new)
assert_not ActiveSupport::Dependencies.autoloaded?(Module.new)
nil_name = Module.new
def nil_name.name() nil end
assert !ActiveSupport::Dependencies.autoloaded?(nil_name)
assert_not ActiveSupport::Dependencies.autoloaded?(nil_name)
end
ensure
remove_constants(:ModuleFolder)
@ -778,7 +778,7 @@ def test_unloadable
M.unloadable
ActiveSupport::Dependencies.clear
assert ! defined?(M)
assert_not defined?(M)
Object.const_set :M, Module.new
ActiveSupport::Dependencies.clear
@ -809,7 +809,7 @@ def test_unloadable_constants_should_receive_callback
assert_called(C, :before_remove_const, times: 1) do
assert_respond_to C, :before_remove_const
ActiveSupport::Dependencies.clear
assert !defined?(C)
assert_not defined?(C)
end
ensure
remove_constants(:C)
@ -1023,7 +1023,7 @@ def test_autoload_doesnt_shadow_name_error
assert !defined?(::RaisesNameError), "::RaisesNameError is defined but it should have failed!"
end
assert !defined?(::RaisesNameError)
assert_not defined?(::RaisesNameError)
2.times do
assert_raise(NameError) { ::RaisesNameError }
assert !defined?(::RaisesNameError), "::RaisesNameError is defined but it should have failed!"

@ -9,16 +9,16 @@ class ProxyWrappersTest < ActiveSupport::TestCase
def test_deprecated_object_proxy_doesnt_wrap_falsy_objects
proxy = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(nil, "message")
assert !proxy
assert_not proxy
end
def test_deprecated_instance_variable_proxy_doesnt_wrap_falsy_objects
proxy = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(nil, :waffles)
assert !proxy
assert_not proxy
end
def test_deprecated_constant_proxy_doesnt_wrap_falsy_objects
proxy = ActiveSupport::Deprecation::DeprecatedConstantProxy.new(Waffles, NewWaffles)
assert !proxy
assert_not proxy
end
end

@ -13,7 +13,7 @@ def test_clear_without_autoloaded_singleton_parent
parent_instance = Parent.new
parent_instance.singleton_class.descendants
ActiveSupport::DescendantsTracker.clear
assert !ActiveSupport::DescendantsTracker.class_variable_get(:@@direct_descendants).key?(parent_instance.singleton_class)
assert_not ActiveSupport::DescendantsTracker.class_variable_get(:@@direct_descendants).key?(parent_instance.singleton_class)
end
end
end

@ -280,7 +280,7 @@ def test_indifferent_replace
replaced = hash.replace(b: 12)
assert hash.key?("b")
assert !hash.key?(:a)
assert_not hash.key?(:a)
assert_equal 12, hash[:b]
assert_same hash, replaced
end
@ -292,7 +292,7 @@ def test_replace_with_to_hash_conversion
replaced = hash.replace(HashByConversion.new(b: 12))
assert hash.key?("b")
assert !hash.key?(:a)
assert_not hash.key?(:a)
assert_equal 12, hash[:b]
assert_same hash, replaced
end

@ -25,12 +25,12 @@ def setup
def test_valid_message
data, hash = @verifier.generate(@data).split("--")
assert !@verifier.valid_message?(nil)
assert !@verifier.valid_message?("")
assert !@verifier.valid_message?("\xff") # invalid encoding
assert !@verifier.valid_message?("#{data.reverse}--#{hash}")
assert !@verifier.valid_message?("#{data}--#{hash.reverse}")
assert !@verifier.valid_message?("purejunk")
assert_not @verifier.valid_message?(nil)
assert_not @verifier.valid_message?("")
assert_not @verifier.valid_message?("\xff") # invalid encoding
assert_not @verifier.valid_message?("#{data.reverse}--#{hash}")
assert_not @verifier.valid_message?("#{data}--#{hash.reverse}")
assert_not @verifier.valid_message?("purejunk")
end
def test_simple_round_tripping
@ -40,7 +40,7 @@ def test_simple_round_tripping
end
def test_verified_returns_false_on_invalid_message
assert !@verifier.verified("purejunk")
assert_not @verifier.verified("purejunk")
end
def test_verify_exception_on_invalid_message

@ -75,7 +75,7 @@ def test_should_concatenate
def test_consumes_utf8_strings
assert @proxy_class.consumes?(UNICODE_STRING)
assert @proxy_class.consumes?(ASCII_STRING)
assert !@proxy_class.consumes?(BYTE_STRING)
assert_not @proxy_class.consumes?(BYTE_STRING)
end
def test_concatenation_should_return_a_proxy_class_instance
@ -148,7 +148,7 @@ def test_unicode_string_should_have_utf8_encoding
def test_identity
assert_equal @chars, @chars
assert @chars.eql?(@chars)
assert !@chars.eql?(UNICODE_STRING)
assert_not @chars.eql?(UNICODE_STRING)
end
def test_string_methods_are_chainable

@ -270,9 +270,9 @@ def test_event_is_parent_based_on_children
parent.children << child
assert parent.parent_of?(child)
assert !child.parent_of?(parent)
assert !parent.parent_of?(not_child)
assert !not_child.parent_of?(parent)
assert_not child.parent_of?(parent)
assert_not parent.parent_of?(not_child)
assert_not not_child.parent_of?(parent)
end
private

@ -15,7 +15,7 @@ def test_usage
a[:allow_concurrency] = false
assert_equal 1, a.size
assert !a[:allow_concurrency]
assert_not a[:allow_concurrency]
a["else_where"] = 56
assert_equal 2, a.size
@ -47,7 +47,7 @@ def test_method_access
a.allow_concurrency = false
assert_equal 1, a.size
assert !a.allow_concurrency
assert_not a.allow_concurrency
a.else_where = 56
assert_equal 2, a.size

@ -8,18 +8,18 @@ def test_prepare_callback
reloader.to_prepare { prepared = true }
reloader.to_complete { completed = true }
assert !prepared
assert !completed
assert_not prepared
assert_not completed
reloader.prepare!
assert prepared
assert !completed
assert_not completed
prepared = false
reloader.wrap do
assert prepared
prepared = false
end
assert !prepared
assert_not prepared
end
def test_prepend_prepare_callback
@ -42,7 +42,7 @@ def test_only_run_when_check_passes
invoked = false
r.to_run { invoked = true }
r.wrap {}
assert !invoked
assert_not invoked
end
def test_full_reload_sequence

@ -11,7 +11,7 @@ def test_secure_compare_should_perform_string_comparison
def test_fixed_length_secure_compare_should_perform_string_comparison
assert ActiveSupport::SecurityUtils.fixed_length_secure_compare("a", "a")
assert !ActiveSupport::SecurityUtils.fixed_length_secure_compare("a", "b")
assert_not ActiveSupport::SecurityUtils.fixed_length_secure_compare("a", "b")
end
def test_fixed_length_secure_compare_raise_on_length_mismatch

@ -1,3 +1,4 @@
# frozen_string_literal: true
require_relative "custom_cops/refute_not"
require_relative "custom_cops/assert_not"

@ -0,0 +1,40 @@
# frozen_string_literal: true
module CustomCops
# Enforces the use of `assert_not` over `assert !`.
#
# @example
# # bad
# assert !x
# assert ! x
#
# # good
# assert_not x
#
class AssertNot < RuboCop::Cop::Cop
MSG = "Prefer `assert_not` over `assert !`"
def_node_matcher :offensive?, "(send nil? :assert (send ... :!))"
def on_send(node)
add_offense(node) if offensive?(node)
end
def autocorrect(node)
expression = node.loc.expression
->(corrector) do
corrector.replace(
expression,
corrected_source(expression.source)
)
end
end
private
def corrected_source(source)
source.gsub(/^assert(\(| ) *! */, "assert_not\\1")
end
end
end

@ -0,0 +1,42 @@
# frozen_string_literal: true
require "support/cop_helper"
require_relative "../../lib/custom_cops/assert_not"
class AssertNotTest < ActiveSupport::TestCase
include CopHelper
setup do
@cop = CustomCops::AssertNot.new
end
test "rejects 'assert !'" do
inspect_source @cop, "assert !x"
assert_offense @cop, "^^^^^^^^^ Prefer `assert_not` over `assert !`"
end
test "rejects 'assert !' with a complex value" do
inspect_source @cop, "assert !a.b(c)"
assert_offense @cop, "^^^^^^^^^^^^^^ Prefer `assert_not` over `assert !`"
end
test "autocorrects `assert !`" do
corrected = autocorrect_source(@cop, "assert !false")
assert_equal "assert_not false", corrected
end
test "autocorrects `assert !` with extra spaces" do
corrected = autocorrect_source(@cop, "assert ! false")
assert_equal "assert_not false", corrected
end
test "autocorrects `assert !` with parentheses" do
corrected = autocorrect_source(@cop, "assert(!false)")
assert_equal "assert_not(false)", corrected
end
test "accepts `assert_not`" do
inspect_source @cop, "assert_not x"
assert_empty @cop.offenses
end
end

@ -1,7 +1,7 @@
# frozen_string_literal: true
require "support/cop_helper"
require "./lib/custom_cops/refute_not"
require_relative "../../lib/custom_cops/refute_not"
class RefuteNotTest < ActiveSupport::TestCase
include CopHelper
@ -59,15 +59,6 @@ class RefuteNotTest < ActiveSupport::TestCase
private
def assert_offense(cop, expected_message)
assert_not_empty cop.offenses
offense = cop.offenses.first
carets = "^" * offense.column_length
assert_equal expected_message, "#{carets} #{offense.message}"
end
def offense_message(refute_method, assert_method)
carets = "^" * refute_method.to_s.length
"#{carets} Prefer `#{assert_method}` over `#{refute_method}`"

@ -16,6 +16,18 @@ def autocorrect_source(cop, source)
rewrite(cop, processed_source)
end
def assert_offense(cop, expected_message)
assert_not_empty(
cop.offenses,
"Expected offense with message \"#{expected_message}\", but got no offense"
)
offense = cop.offenses.first
carets = "^" * offense.column_length
assert_equal expected_message, "#{carets} #{offense.message}"
end
private
TARGET_RUBY_VERSION = 2.4

@ -40,13 +40,13 @@ def expects_exec(exe)
test "is not in a Rails application if #{exe} is not found in the current or parent directories" do
def loader.find_executables; end
assert !loader.exec_app
assert_not loader.exec_app
end
test "is not in a Rails application if #{exe} exists but is a folder" do
FileUtils.mkdir_p(exe)
assert !loader.exec_app
assert_not loader.exec_app
end
["APP_PATH", "ENGINE_PATH"].each do |keyword|
@ -61,7 +61,7 @@ def loader.find_executables; end
test "is not in a Rails application if #{exe} exists but doesn't contain #{keyword}" do
write exe
assert !loader.exec_app
assert_not loader.exec_app
end
test "is in a Rails application if parent directory has #{exe} containing #{keyword} and chdirs to the root directory" do

@ -76,7 +76,7 @@ def assert_no_file_exists(filename)
# Load app env
app "production"
assert !defined?(Uglifier)
assert_not defined?(Uglifier)
get "/assets/demo.js"
assert_match "alert()", last_response.body
assert defined?(Uglifier)
@ -270,10 +270,10 @@ class User < ActiveRecord::Base; raise 'should not be reached'; end
app "production"
# Checking if Uglifier is defined we can know if Sprockets was reached or not
assert !defined?(Uglifier)
assert_not defined?(Uglifier)
get "/assets/#{asset_path}"
assert_match "alert()", last_response.body
assert !defined?(Uglifier)
assert_not defined?(Uglifier)
end
test "precompile properly refers files referenced with asset_path" do

@ -361,7 +361,7 @@ def noop_email;end
end
RUBY
assert !$prepared
assert_not $prepared
app "development"

@ -226,7 +226,7 @@ def show
rails %w(generate model post title:string)
rails %w(db:migrate db:schema:cache:dump db:rollback)
require "#{app_path}/config/environment"
assert !ActiveRecord::Base.connection.schema_cache.data_sources("posts")
assert_not ActiveRecord::Base.connection.schema_cache.data_sources("posts")
end
test "active record establish_connection uses Rails.env if DATABASE_URL is not set" do

@ -29,7 +29,7 @@ def index
simple_controller
get "/"
assert !last_response.headers["X-Sendfile"]
assert_not last_response.headers["X-Sendfile"]
assert_equal File.read(__FILE__), last_response.body
end

@ -31,7 +31,7 @@ def app
add_to_config "config.force_ssl = true"
add_to_config "config.ssl_options = { secure_cookies: false }"
require "#{app_path}/config/environment"
assert !app.config.session_options[:secure]
assert_not app.config.session_options[:secure]
end
test "session is not loaded if it's not used" do
@ -51,7 +51,7 @@ def index
get "/"
assert last_request.env["HTTP_COOKIE"]
assert !last_response.headers["Set-Cookie"]
assert_not last_response.headers["Set-Cookie"]
end
test "session is empty and isn't saved on unverified request when using :null_session protect method" do

@ -34,7 +34,7 @@ def db_create_and_drop(expected_database, environment_loaded: true)
assert_equal expected_database, ActiveRecord::Base.connection_config[:database] if environment_loaded
output = rails("db:drop")
assert_match(/Dropped database/, output)
assert !File.exist?(expected_database)
assert_not File.exist?(expected_database)
end
end

@ -26,7 +26,7 @@ def db_create_and_drop(namespace, expected_database, environment_loaded: true)
output = rails("db:drop")
assert_match(/Dropped database/, output)
assert_match_namespace(namespace, output)
assert !File.exist?(expected_database)
assert_not File.exist?(expected_database)
end
end
@ -40,7 +40,7 @@ def db_create_and_drop_namespace(namespace, expected_database, environment_loade
output = rails("db:drop:#{namespace}")
assert_match(/Dropped database/, output)
assert_match_namespace(namespace, output)
assert !File.exist?(expected_database)
assert_not File.exist?(expected_database)
end
end

@ -229,7 +229,7 @@ def test_rake_dump_schema_cache
def test_rake_clear_schema_cache
rails "db:schema:cache:dump", "db:schema:cache:clear"
assert !File.exist?(File.join(app_path, "db", "schema_cache.yml"))
assert_not File.exist?(File.join(app_path, "db", "schema_cache.yml"))
end
def test_copy_templates

Some files were not shown because too many files have changed in this diff Show More