Use assert_predicate and assert_not_predicate

This commit is contained in:
Daniel Colson 2018-01-25 18:14:09 -05:00
parent 211adb47e7
commit 94333a4c31
209 changed files with 1982 additions and 1982 deletions

@ -97,12 +97,12 @@ def rm_rf
@channel.subscribe_to_channel
assert @channel.room
assert @channel.subscribed?
assert_predicate @channel, :subscribed?
@channel.unsubscribe_from_channel
assert ! @channel.room
assert ! @channel.subscribed?
assert_not @channel.room
assert_not_predicate @channel, :subscribed?
end
test "connection identifiers" do

@ -192,10 +192,10 @@ def open_connection
Connection.new(@server, env).tap do |connection|
connection.process
assert connection.websocket.possible?
assert_predicate connection.websocket, :possible?
wait_for_async
assert connection.websocket.alive?
assert_predicate connection.websocket, :alive?
end
end

@ -307,7 +307,7 @@ def test_server_restart
ActionCable.server.restart
c.wait_for_close
assert c.closed?
assert_predicate c, :closed?
end
end
end

@ -39,10 +39,10 @@ def send_async(method, *args)
connection = open_connection
connection.process
assert connection.websocket.possible?
assert_predicate connection.websocket, :possible?
wait_for_async
assert connection.websocket.alive?
assert_predicate connection.websocket, :alive?
end
end
@ -95,7 +95,7 @@ def send_async(method, *args)
statistics = connection.statistics
assert statistics[:identifier].blank?
assert_predicate statistics[:identifier], :blank?
assert_kind_of Time, statistics[:started_at]
assert_equal [], statistics[:subscriptions]
end

@ -45,7 +45,7 @@ def speak(data)
setup_connection
@subscriptions.execute_command "command" => "subscribe"
assert @subscriptions.identifiers.empty?
assert_predicate @subscriptions.identifiers, :empty?
end
end
@ -58,7 +58,7 @@ def speak(data)
channel.expects(:unsubscribe_from_channel)
@subscriptions.execute_command "command" => "unsubscribe", "identifier" => @chat_identifier
assert @subscriptions.identifiers.empty?
assert_predicate @subscriptions.identifiers, :empty?
end
end
@ -67,7 +67,7 @@ def speak(data)
setup_connection
@subscriptions.execute_command "command" => "unsubscribe"
assert @subscriptions.identifiers.empty?
assert_predicate @subscriptions.identifiers, :empty?
end
end

@ -32,7 +32,7 @@ def subscribe_as_queue(channel, adapter = @rx_adapter)
subscribed = Concurrent::Event.new
adapter.subscribe(channel, callback, Proc.new { subscribed.set })
subscribed.wait(WAIT_WHEN_EXPECTING_EVENT)
assert subscribed.set?
assert_predicate subscribed, :set?
yield queue

@ -105,7 +105,7 @@ def test_html_safety
html_safe = @mailer.read_fragment("name")
assert_equal content, html_safe
assert html_safe.html_safe?
assert_predicate html_safe, :html_safe?
end
end
@ -262,7 +262,7 @@ class HasDependenciesMailer < ActionMailer::Base
end
def test_view_cache_dependencies_are_empty_by_default
assert NoDependenciesMailer.new.view_cache_dependencies.empty?
assert_predicate NoDependenciesMailer.new.view_cache_dependencies, :empty?
end
def test_view_cache_dependencies_are_listed_in_declaration_order

@ -301,18 +301,18 @@ def test_template_objects_missing
def test_empty_flash
process :flash_me_naked
assert flash.empty?
assert_predicate flash, :empty?
end
def test_flash_exist
process :flash_me
assert flash.any?
assert flash["hello"].present?
assert_predicate flash, :any?
assert_predicate flash["hello"], :present?
end
def test_flash_does_not_exist
process :nothing
assert flash.empty?
assert_predicate flash, :empty?
end
def test_session_exist
@ -322,7 +322,7 @@ def test_session_exist
def session_does_not_exist
process :nothing
assert session.empty?
assert_predicate session, :empty?
end
def test_redirection_location
@ -343,46 +343,46 @@ def test_no_redirect_url
def test_server_error_response_code
process :response500
assert @response.server_error?
assert_predicate @response, :server_error?
process :response599
assert @response.server_error?
assert_predicate @response, :server_error?
process :response404
assert !@response.server_error?
assert_not_predicate @response, :server_error?
end
def test_missing_response_code
process :response404
assert @response.not_found?
assert_predicate @response, :not_found?
end
def test_client_error_response_code
process :response404
assert @response.client_error?
assert_predicate @response, :client_error?
end
def test_redirect_url_match
process :redirect_external
assert @response.redirect?
assert_predicate @response, :redirect?
assert_match(/rubyonrails/, @response.redirect_url)
assert !/perloffrails/.match(@response.redirect_url)
end
def test_redirection
process :redirect_internal
assert @response.redirect?
assert_predicate @response, :redirect?
process :redirect_external
assert @response.redirect?
assert_predicate @response, :redirect?
process :nothing
assert !@response.redirect?
assert_not_predicate @response, :redirect?
end
def test_successful_response_code
process :nothing
assert @response.successful?
assert_predicate @response, :successful?
end
def test_response_object

@ -53,7 +53,7 @@ def test_request_not_modified
@request.if_modified_since = @last_modified
get :one
assert_equal 304, @response.status.to_i
assert @response.body.blank?
assert_predicate @response.body, :blank?
assert_equal @last_modified, @response.headers["Last-Modified"]
end
end

@ -107,9 +107,9 @@ def setup
end
def test_performed?
assert !@empty.performed?
assert_not_predicate @empty, :performed?
@empty.response_body = ["sweet"]
assert @empty.performed?
assert_predicate @empty, :performed?
end
def test_action_methods

@ -159,7 +159,7 @@ def test_html_safety
html_safe = @controller.read_fragment("name")
assert_equal content, html_safe
assert html_safe.html_safe?
assert_predicate html_safe, :html_safe?
end
end
@ -382,7 +382,7 @@ class HasDependenciesController < ActionController::Base
end
def test_view_cache_dependencies_are_empty_by_default
assert NoDependenciesController.new.view_cache_dependencies.empty?
assert_predicate NoDependenciesController.new.view_cache_dependencies, :empty?
end
def test_view_cache_dependencies_are_listed_in_declaration_order

@ -819,7 +819,7 @@ def test_a_rescuing_around_action
response = test_process(RescuedController)
end
assert response.successful?
assert_predicate response, :successful?
assert_equal("I rescued this: #<FilterTest::ErrorToRescue: Something made the bad noise.>", response.body)
end

@ -92,11 +92,11 @@ def test_from_session_value_on_json_serializer
end
def test_empty?
assert @hash.empty?
assert_predicate @hash, :empty?
@hash["zomg"] = "bears"
assert !@hash.empty?
assert_not_predicate @hash, :empty?
@hash.clear
assert @hash.empty?
assert_predicate @hash, :empty?
end
def test_each

@ -14,11 +14,11 @@ def setup
end
def test_https_bang_works_and_sets_truth_by_default
assert !@session.https?
assert_not_predicate @session, :https?
@session.https!
assert @session.https?
assert_predicate @session, :https?
@session.https! false
assert !@session.https?
assert_not_predicate @session, :https?
end
def test_host!
@ -412,11 +412,11 @@ def test_post_then_get_with_parameters_do_not_leak_across_requests
get "/get_with_params", params: { foo: "bar" }
assert request.env["rack.input"].string.empty?
assert_predicate request.env["rack.input"].string, :empty?
assert_equal "foo=bar", request.env["QUERY_STRING"]
assert_equal "foo=bar", request.query_string
assert_equal "bar", request.parameters["foo"]
assert request.parameters["leaks"].nil?
assert_predicate request.parameters["leaks"], :nil?
end
end

@ -4,7 +4,7 @@
class OutputEscapingTest < ActiveSupport::TestCase
test "escape_html shouldn't die when passed nil" do
assert ERB::Util.h(nil).blank?
assert_predicate ERB::Util.h(nil), :blank?
end
test "escapeHTML should escape strings" do

@ -22,13 +22,13 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
test "[] retains permitted status" do
@params.permit!
assert @params[:person].permitted?
assert @params[:person][:name].permitted?
assert_predicate @params[:person], :permitted?
assert_predicate @params[:person][:name], :permitted?
end
test "[] retains unpermitted status" do
assert_not @params[:person].permitted?
assert_not @params[:person][:name].permitted?
assert_not_predicate @params[:person], :permitted?
assert_not_predicate @params[:person][:name], :permitted?
end
test "as_json returns the JSON representation of the parameters hash" do
@ -78,33 +78,33 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
test "empty? returns true when params contains no key/value pairs" do
params = ActionController::Parameters.new
assert params.empty?
assert_predicate params, :empty?
end
test "empty? returns false when any params are present" do
assert_not @params.empty?
assert_not_predicate @params, :empty?
end
test "except retains permitted status" do
@params.permit!
assert @params.except(:person).permitted?
assert @params[:person].except(:name).permitted?
assert_predicate @params.except(:person), :permitted?
assert_predicate @params[:person].except(:name), :permitted?
end
test "except retains unpermitted status" do
assert_not @params.except(:person).permitted?
assert_not @params[:person].except(:name).permitted?
assert_not_predicate @params.except(:person), :permitted?
assert_not_predicate @params[:person].except(:name), :permitted?
end
test "fetch retains permitted status" do
@params.permit!
assert @params.fetch(:person).permitted?
assert @params[:person].fetch(:name).permitted?
assert_predicate @params.fetch(:person), :permitted?
assert_predicate @params[:person].fetch(:name), :permitted?
end
test "fetch retains unpermitted status" do
assert_not @params.fetch(:person).permitted?
assert_not @params[:person].fetch(:name).permitted?
assert_not_predicate @params.fetch(:person), :permitted?
assert_not_predicate @params[:person].fetch(:name), :permitted?
end
test "has_key? returns true if the given key is present in the params" do
@ -147,48 +147,48 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
end
test "reject retains permitted status" do
assert_not @params.reject { |k| k == "person" }.permitted?
assert_not_predicate @params.reject { |k| k == "person" }, :permitted?
end
test "reject retains unpermitted status" do
@params.permit!
assert @params.reject { |k| k == "person" }.permitted?
assert_predicate @params.reject { |k| k == "person" }, :permitted?
end
test "select retains permitted status" do
@params.permit!
assert @params.select { |k| k == "person" }.permitted?
assert_predicate @params.select { |k| k == "person" }, :permitted?
end
test "select retains unpermitted status" do
assert_not @params.select { |k| k == "person" }.permitted?
assert_not_predicate @params.select { |k| k == "person" }, :permitted?
end
test "slice retains permitted status" do
@params.permit!
assert @params.slice(:person).permitted?
assert_predicate @params.slice(:person), :permitted?
end
test "slice retains unpermitted status" do
assert_not @params.slice(:person).permitted?
assert_not_predicate @params.slice(:person), :permitted?
end
test "transform_keys retains permitted status" do
@params.permit!
assert @params.transform_keys { |k| k }.permitted?
assert_predicate @params.transform_keys { |k| k }, :permitted?
end
test "transform_keys retains unpermitted status" do
assert_not @params.transform_keys { |k| k }.permitted?
assert_not_predicate @params.transform_keys { |k| k }, :permitted?
end
test "transform_values retains permitted status" do
@params.permit!
assert @params.transform_values { |v| v }.permitted?
assert_predicate @params.transform_values { |v| v }, :permitted?
end
test "transform_values retains unpermitted status" do
assert_not @params.transform_values { |v| v }.permitted?
assert_not_predicate @params.transform_values { |v| v }, :permitted?
end
test "value? returns true if the given value is present in the params" do
@ -208,13 +208,13 @@ class ParametersAccessorsTest < ActiveSupport::TestCase
test "values_at retains permitted status" do
@params.permit!
assert @params.values_at(:person).first.permitted?
assert @params[:person].values_at(:name).first.permitted?
assert_predicate @params.values_at(:person).first, :permitted?
assert_predicate @params[:person].values_at(:name).first, :permitted?
end
test "values_at retains unpermitted status" do
assert_not @params.values_at(:person).first.permitted?
assert_not @params[:person].values_at(:name).first.permitted?
assert_not_predicate @params.values_at(:person).first, :permitted?
assert_not_predicate @params[:person].values_at(:name).first, :permitted?
end
test "is equal to Parameters instance with same params" do

@ -25,6 +25,6 @@ def teardown
book: { pages: 65 },
format: "json")
permitted = params.permit book: [:pages]
assert permitted.permitted?
assert_predicate permitted, :permitted?
end
end

@ -23,7 +23,7 @@ class ParametersDupTest < ActiveSupport::TestCase
test "a duplicate maintains the original's permitted status" do
@params.permit!
dupped_params = @params.dup
assert dupped_params.permitted?
assert_predicate dupped_params, :permitted?
end
test "a duplicate maintains the original's parameters" do
@ -57,11 +57,11 @@ class ParametersDupTest < ActiveSupport::TestCase
dupped_params = @params.deep_dup
dupped_params.permit!
assert_not @params.permitted?
assert_not_predicate @params, :permitted?
end
test "deep_dup @permitted is being copied" do
@params.permit!
assert @params.deep_dup.permitted?
assert_predicate @params.deep_dup, :permitted?
end
end

@ -21,7 +21,7 @@ class MultiParameterAttributesTest < ActiveSupport::TestCase
permitted = params.permit book: [ :shipped_at, :price ]
assert permitted.permitted?
assert_predicate permitted, :permitted?
assert_equal "2012", permitted[:book]["shipped_at(1i)"]
assert_equal "3", permitted[:book]["shipped_at(2i)"]

@ -20,11 +20,11 @@ class ParametersMutatorsTest < ActiveSupport::TestCase
test "delete retains permitted status" do
@params.permit!
assert @params.delete(:person).permitted?
assert_predicate @params.delete(:person), :permitted?
end
test "delete retains unpermitted status" do
assert_not @params.delete(:person).permitted?
assert_not_predicate @params.delete(:person), :permitted?
end
test "delete returns the value when the key is present" do
@ -50,73 +50,73 @@ class ParametersMutatorsTest < ActiveSupport::TestCase
test "delete_if retains permitted status" do
@params.permit!
assert @params.delete_if { |k| k == "person" }.permitted?
assert_predicate @params.delete_if { |k| k == "person" }, :permitted?
end
test "delete_if retains unpermitted status" do
assert_not @params.delete_if { |k| k == "person" }.permitted?
assert_not_predicate @params.delete_if { |k| k == "person" }, :permitted?
end
test "extract! retains permitted status" do
@params.permit!
assert @params.extract!(:person).permitted?
assert_predicate @params.extract!(:person), :permitted?
end
test "extract! retains unpermitted status" do
assert_not @params.extract!(:person).permitted?
assert_not_predicate @params.extract!(:person), :permitted?
end
test "keep_if retains permitted status" do
@params.permit!
assert @params.keep_if { |k, v| k == "person" }.permitted?
assert_predicate @params.keep_if { |k, v| k == "person" }, :permitted?
end
test "keep_if retains unpermitted status" do
assert_not @params.keep_if { |k, v| k == "person" }.permitted?
assert_not_predicate @params.keep_if { |k, v| k == "person" }, :permitted?
end
test "reject! retains permitted status" do
@params.permit!
assert @params.reject! { |k| k == "person" }.permitted?
assert_predicate @params.reject! { |k| k == "person" }, :permitted?
end
test "reject! retains unpermitted status" do
assert_not @params.reject! { |k| k == "person" }.permitted?
assert_not_predicate @params.reject! { |k| k == "person" }, :permitted?
end
test "select! retains permitted status" do
@params.permit!
assert @params.select! { |k| k != "person" }.permitted?
assert_predicate @params.select! { |k| k != "person" }, :permitted?
end
test "select! retains unpermitted status" do
assert_not @params.select! { |k| k != "person" }.permitted?
assert_not_predicate @params.select! { |k| k != "person" }, :permitted?
end
test "slice! retains permitted status" do
@params.permit!
assert @params.slice!(:person).permitted?
assert_predicate @params.slice!(:person), :permitted?
end
test "slice! retains unpermitted status" do
assert_not @params.slice!(:person).permitted?
assert_not_predicate @params.slice!(:person), :permitted?
end
test "transform_keys! retains permitted status" do
@params.permit!
assert @params.transform_keys! { |k| k }.permitted?
assert_predicate @params.transform_keys! { |k| k }, :permitted?
end
test "transform_keys! retains unpermitted status" do
assert_not @params.transform_keys! { |k| k }.permitted?
assert_not_predicate @params.transform_keys! { |k| k }, :permitted?
end
test "transform_values! retains permitted status" do
@params.permit!
assert @params.transform_values! { |v| v }.permitted?
assert_predicate @params.transform_values! { |v| v }, :permitted?
end
test "transform_values! retains unpermitted status" do
assert_not @params.transform_values! { |v| v }.permitted?
assert_not_predicate @params.transform_values! { |v| v }, :permitted?
end
end

@ -32,7 +32,7 @@ def assert_filtered_out(params, key)
permitted = params.permit book: [ :title, { authors: [ :name ] }, { details: :pages }, :id ]
assert permitted.permitted?
assert_predicate permitted, :permitted?
assert_equal "Romeo and Juliet", permitted[:book][:title]
assert_equal "William Shakespeare", permitted[:book][:authors][0][:name]
assert_equal "Christopher Marlowe", permitted[:book][:authors][1][:name]

@ -53,8 +53,8 @@ def walk_permitted(params)
test "if nothing is permitted, the hash becomes empty" do
params = ActionController::Parameters.new(id: "1234")
permitted = params.permit
assert permitted.permitted?
assert permitted.empty?
assert_predicate permitted, :permitted?
assert_predicate permitted, :empty?
end
test "key: permitted scalar values" do
@ -227,7 +227,7 @@ def walk_permitted(params)
test "hashes in array values get wrapped" do
params = ActionController::Parameters.new(foo: [{}, {}])
params[:foo].each do |hash|
assert !hash.permitted?
assert_not_predicate hash, :permitted?
end
end
@ -250,7 +250,7 @@ def walk_permitted(params)
permitted = params.permit(users: [:id])
permitted[:users] << { injected: 1 }
assert_not permitted[:users].last.permitted?
assert_not_predicate permitted[:users].last, :permitted?
end
test "fetch doesnt raise ParameterMissing exception if there is a default" do
@ -272,12 +272,12 @@ def walk_permitted(params)
end
test "not permitted is sticky beyond merges" do
assert !@params.merge(a: "b").permitted?
assert_not_predicate @params.merge(a: "b"), :permitted?
end
test "permitted is sticky beyond merges" do
@params.permit!
assert @params.merge(a: "b").permitted?
assert_predicate @params.merge(a: "b"), :permitted?
end
test "merge with parameters" do
@ -288,12 +288,12 @@ def walk_permitted(params)
end
test "not permitted is sticky beyond merge!" do
assert_not @params.merge!(a: "b").permitted?
assert_not_predicate @params.merge!(a: "b"), :permitted?
end
test "permitted is sticky beyond merge!" do
@params.permit!
assert @params.merge!(a: "b").permitted?
assert_predicate @params.merge!(a: "b"), :permitted?
end
test "merge! with parameters" do
@ -355,10 +355,10 @@ def walk_permitted(params)
test "permit is recursive" do
@params.permit!
assert @params.permitted?
assert @params[:person].permitted?
assert @params[:person][:name].permitted?
assert @params[:person][:addresses][0].permitted?
assert_predicate @params, :permitted?
assert_predicate @params[:person], :permitted?
assert_predicate @params[:person][:name], :permitted?
assert_predicate @params[:person][:addresses][0], :permitted?
end
test "permitted takes a default value when Parameters.permit_all_parameters is set" do
@ -368,8 +368,8 @@ def walk_permitted(params)
age: "32", name: { first: "David", last: "Heinemeier Hansson" }
})
assert params.slice(:person).permitted?
assert params[:person][:name].permitted?
assert_predicate params.slice(:person), :permitted?
assert_predicate params[:person][:name], :permitted?
ensure
ActionController::Parameters.permit_all_parameters = false
end

@ -27,7 +27,7 @@ class ParametersSerializationTest < ActiveSupport::TestCase
roundtripped = YAML.load(YAML.dump(params))
assert_equal params, roundtripped
assert_not roundtripped.permitted?
assert_not_predicate roundtripped, :permitted?
end
test "yaml backwardscompatible with psych 2.0.8 format" do
@ -37,7 +37,7 @@ class ParametersSerializationTest < ActiveSupport::TestCase
end_of_yaml
assert_equal :value, params[:key]
assert_not params.permitted?
assert_not_predicate params, :permitted?
end
test "yaml backwardscompatible with psych 2.0.9+ format" do
@ -50,6 +50,6 @@ class ParametersSerializationTest < ActiveSupport::TestCase
end_of_yaml
assert_equal :value, params[:key]
assert_not params.permitted?
assert_not_predicate params, :permitted?
end
end

@ -415,7 +415,7 @@ def test_request_not_modified
@request.if_modified_since = @last_modified
get :conditional_hello
assert_equal 304, @response.status.to_i
assert @response.body.blank?
assert_predicate @response.body, :blank?
assert_equal @last_modified, @response.headers["Last-Modified"]
end
@ -430,7 +430,7 @@ def test_request_modified
@request.if_modified_since = "Thu, 16 Jul 2008 00:00:00 GMT"
get :conditional_hello
assert_equal 200, @response.status.to_i
assert @response.body.present?
assert_predicate @response.body, :present?
assert_equal @last_modified, @response.headers["Last-Modified"]
end
@ -443,7 +443,7 @@ def test_request_not_modified_with_record
@request.if_modified_since = @last_modified
get :conditional_hello_with_record
assert_equal 304, @response.status.to_i
assert @response.body.blank?
assert_predicate @response.body, :blank?
assert_not_nil @response.etag
assert_equal @last_modified, @response.headers["Last-Modified"]
end
@ -459,7 +459,7 @@ def test_request_modified_with_record
@request.if_modified_since = "Thu, 16 Jul 2008 00:00:00 GMT"
get :conditional_hello_with_record
assert_equal 200, @response.status.to_i
assert @response.body.present?
assert_predicate @response.body, :present?
assert_equal @last_modified, @response.headers["Last-Modified"]
end
@ -472,7 +472,7 @@ def test_request_not_modified_with_collection_of_records
@request.if_modified_since = @last_modified
get :conditional_hello_with_collection_of_records
assert_equal 304, @response.status.to_i
assert @response.body.blank?
assert_predicate @response.body, :blank?
assert_equal @last_modified, @response.headers["Last-Modified"]
end
@ -487,7 +487,7 @@ def test_request_modified_with_collection_of_records
@request.if_modified_since = "Thu, 16 Jul 2008 00:00:00 GMT"
get :conditional_hello_with_collection_of_records
assert_equal 200, @response.status.to_i
assert @response.body.present?
assert_predicate @response.body, :present?
assert_equal @last_modified, @response.headers["Last-Modified"]
end
@ -682,27 +682,27 @@ def setup
def test_head_created
post :head_created
assert @response.body.blank?
assert_predicate @response.body, :blank?
assert_response :created
end
def test_head_created_with_application_json_content_type
post :head_created_with_application_json_content_type
assert @response.body.blank?
assert_predicate @response.body, :blank?
assert_equal "application/json", @response.header["Content-Type"]
assert_response :created
end
def test_head_ok_with_image_png_content_type
post :head_ok_with_image_png_content_type
assert @response.body.blank?
assert_predicate @response.body, :blank?
assert_equal "image/png", @response.header["Content-Type"]
assert_response :ok
end
def test_head_with_location_header
get :head_with_location_header
assert @response.body.blank?
assert_predicate @response.body, :blank?
assert_equal "/foo", @response.headers["Location"]
assert_response :ok
end
@ -718,7 +718,7 @@ def test_head_with_location_object
end
get :head_with_location_object
assert @response.body.blank?
assert_predicate @response.body, :blank?
assert_equal "http://www.nextangle.com/customers/1", @response.headers["Location"]
assert_response :ok
end
@ -726,14 +726,14 @@ def test_head_with_location_object
def test_head_with_custom_header
get :head_with_custom_header
assert @response.body.blank?
assert_predicate @response.body, :blank?
assert_equal "something", @response.headers["X-Custom-Header"]
assert_response :ok
end
def test_head_with_www_authenticate_header
get :head_with_www_authenticate_header
assert @response.body.blank?
assert_predicate @response.body, :blank?
assert_equal "something", @response.headers["WWW-Authenticate"]
assert_response :ok
end
@ -812,7 +812,7 @@ def test_cache_with_public
assert_response :ok
assert_equal "max-age=#{100.years}, public", @response.headers["Cache-Control"]
assert_not_nil @response.etag
assert @response.weak_etag?
assert_predicate @response, :weak_etag?
end
def test_cache_with_private
@ -820,7 +820,7 @@ def test_cache_with_private
assert_response :ok
assert_equal "max-age=#{100.years}, private", @response.headers["Cache-Control"]
assert_not_nil @response.etag
assert @response.weak_etag?
assert_predicate @response, :weak_etag?
end
def test_cache_response_code_with_if_modified_since

@ -746,7 +746,7 @@ def test_should_allow_all_methods_without_token
test "should not emit a csrf-token meta tag" do
SecureRandom.stub :base64, @token do
get :meta
assert @response.body.blank?
assert_predicate @response.body, :blank?
end
end
end

@ -670,7 +670,7 @@ def test_params_reset_between_post_requests
assert_equal "bar", @request.params[:foo]
post :no_op
assert @request.params[:foo].blank?
assert_predicate @request.params[:foo], :blank?
end
def test_filtered_parameters_reset_between_requests

@ -73,7 +73,7 @@ def test_headers_cannot_be_written_after_webserver_reads
}
latch.wait
assert @response.headers.frozen?
assert_predicate @response.headers, :frozen?
e = assert_raises(ActionDispatch::IllegalStateError) do
@response.headers["Content-Length"] = "zomg"
end

@ -329,20 +329,20 @@ class RequestPort < BaseRequestTest
test "standard_port?" do
request = stub_request
assert !request.ssl?
assert request.standard_port?
assert_not_predicate request, :ssl?
assert_predicate request, :standard_port?
request = stub_request "HTTPS" => "on"
assert request.ssl?
assert request.standard_port?
assert_predicate request, :ssl?
assert_predicate request, :standard_port?
request = stub_request "HTTP_HOST" => "www.example.org:8080"
assert !request.ssl?
assert !request.standard_port?
assert_not_predicate request, :ssl?
assert_not_predicate request, :standard_port?
request = stub_request "HTTP_HOST" => "www.example.org:8443", "HTTPS" => "on"
assert request.ssl?
assert !request.standard_port?
assert_predicate request, :ssl?
assert_not_predicate request, :standard_port?
end
test "optional port" do
@ -571,7 +571,7 @@ class RequestCGI < BaseRequestTest
class LocalhostTest < BaseRequestTest
test "IPs that match localhost" do
request = stub_request("REMOTE_IP" => "127.1.1.1", "REMOTE_ADDR" => "127.1.1.1")
assert request.local?
assert_predicate request, :local?
end
end
@ -643,37 +643,37 @@ class RequestProtocol < BaseRequestTest
test "xml http request" do
request = stub_request
assert !request.xml_http_request?
assert !request.xhr?
assert_not_predicate request, :xml_http_request?
assert_not_predicate request, :xhr?
request = stub_request "HTTP_X_REQUESTED_WITH" => "DefinitelyNotAjax1.0"
assert !request.xml_http_request?
assert !request.xhr?
assert_not_predicate request, :xml_http_request?
assert_not_predicate request, :xhr?
request = stub_request "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest"
assert request.xml_http_request?
assert request.xhr?
assert_predicate request, :xml_http_request?
assert_predicate request, :xhr?
end
test "reports ssl" do
assert !stub_request.ssl?
assert stub_request("HTTPS" => "on").ssl?
assert_not_predicate stub_request, :ssl?
assert_predicate stub_request("HTTPS" => "on"), :ssl?
end
test "reports ssl when proxied via lighttpd" do
assert stub_request("HTTP_X_FORWARDED_PROTO" => "https").ssl?
assert_predicate stub_request("HTTP_X_FORWARDED_PROTO" => "https"), :ssl?
end
test "scheme returns https when proxied" do
request = stub_request "rack.url_scheme" => "http"
assert !request.ssl?
assert_not_predicate request, :ssl?
assert_equal "http", request.scheme
request = stub_request(
"rack.url_scheme" => "http",
"HTTP_X_FORWARDED_PROTO" => "https"
)
assert request.ssl?
assert_predicate request, :ssl?
assert_equal "https", request.scheme
end
end
@ -700,7 +700,7 @@ class RequestMethod < BaseRequestTest
assert_equal "GET", request.request_method
assert_equal "GET", request.env["REQUEST_METHOD"]
assert request.get?
assert_predicate request, :get?
end
test "invalid http method raises exception" do
@ -748,7 +748,7 @@ class RequestMethod < BaseRequestTest
assert_equal "POST", request.method
assert_equal "PATCH", request.request_method
assert request.patch?
assert_predicate request, :patch?
end
test "post masquerading as put" do
@ -758,7 +758,7 @@ class RequestMethod < BaseRequestTest
)
assert_equal "POST", request.method
assert_equal "PUT", request.request_method
assert request.put?
assert_predicate request, :put?
end
test "post uneffected by local inflections" do
@ -772,7 +772,7 @@ class RequestMethod < BaseRequestTest
request = stub_request "REQUEST_METHOD" => "POST"
assert_equal :post, ActionDispatch::Request::HTTP_METHOD_LOOKUP["POST"]
assert_equal :post, request.method_symbol
assert request.post?
assert_predicate request, :post?
ensure
# Reset original acronym set
ActiveSupport::Inflector.inflections do |inflect|
@ -809,20 +809,20 @@ class RequestFormat < BaseRequestTest
"QUERY_STRING" => ""
)
assert request.xhr?
assert_predicate request, :xhr?
assert_equal Mime[:js], request.format
end
test "can override format with parameter negative" do
request = stub_request("QUERY_STRING" => "format=txt")
assert !request.format.xml?
assert_not_predicate request.format, :xml?
end
test "can override format with parameter positive" do
request = stub_request("QUERY_STRING" => "format=xml")
assert request.format.xml?
assert_predicate request.format, :xml?
end
test "formats text/html with accept header" do
@ -862,15 +862,15 @@ class RequestFormat < BaseRequestTest
request = stub_request("QUERY_STRING" => "format=hello")
assert_nil request.format
assert_not request.format.html?
assert_not request.format.xml?
assert_not request.format.json?
assert_not_predicate request.format, :html?
assert_not_predicate request.format, :xml?
assert_not_predicate request.format, :json?
end
test "format does not throw exceptions when malformed parameters" do
request = stub_request("QUERY_STRING" => "x[y]=1&x[y][][w]=2")
assert request.formats
assert request.format.html?
assert_predicate request.format, :html?
end
test "formats with xhr request" do
@ -1234,8 +1234,8 @@ def setup
test "setting variant to a symbol" do
@request.variant = :phone
assert @request.variant.phone?
assert_not @request.variant.tablet?
assert_predicate @request.variant, :phone?
assert_not_predicate @request.variant, :tablet?
assert @request.variant.any?(:phone, :tablet)
assert_not @request.variant.any?(:tablet, :desktop)
end
@ -1243,9 +1243,9 @@ def setup
test "setting variant to an array of symbols" do
@request.variant = [:phone, :tablet]
assert @request.variant.phone?
assert @request.variant.tablet?
assert_not @request.variant.desktop?
assert_predicate @request.variant, :phone?
assert_predicate @request.variant, :tablet?
assert_not_predicate @request.variant, :desktop?
assert @request.variant.any?(:tablet, :desktop)
assert_not @request.variant.any?(:desktop, :watch)
end
@ -1253,8 +1253,8 @@ def setup
test "clearing variant" do
@request.variant = nil
assert @request.variant.empty?
assert_not @request.variant.phone?
assert_predicate @request.variant, :empty?
assert_not_predicate @request.variant, :phone?
assert_not @request.variant.any?(:phone, :tablet)
end
@ -1273,13 +1273,13 @@ def setup
class RequestFormData < BaseRequestTest
test "media_type is from the FORM_DATA_MEDIA_TYPES array" do
assert stub_request("CONTENT_TYPE" => "application/x-www-form-urlencoded").form_data?
assert stub_request("CONTENT_TYPE" => "multipart/form-data").form_data?
assert_predicate stub_request("CONTENT_TYPE" => "application/x-www-form-urlencoded"), :form_data?
assert_predicate stub_request("CONTENT_TYPE" => "multipart/form-data"), :form_data?
end
test "media_type is not from the FORM_DATA_MEDIA_TYPES array" do
assert !stub_request("CONTENT_TYPE" => "application/xml").form_data?
assert !stub_request("CONTENT_TYPE" => "multipart/related").form_data?
assert_not_predicate stub_request("CONTENT_TYPE" => "application/xml"), :form_data?
assert_not_predicate stub_request("CONTENT_TYPE" => "multipart/related"), :form_data?
end
test "no Content-Type header is provided and the request_method is POST" do
@ -1287,7 +1287,7 @@ class RequestFormData < BaseRequestTest
assert_equal "", request.media_type
assert_equal "POST", request.request_method
assert !request.form_data?
assert_not_predicate request, :form_data?
end
end

@ -15,13 +15,13 @@ def test_can_wait_until_commit
@response.await_commit
}
@response.commit!
assert @response.committed?
assert_predicate @response, :committed?
assert t.join(0.5)
end
def test_stream_close
@response.stream.close
assert @response.stream.closed?
assert_predicate @response.stream, :closed?
end
def test_stream_write
@ -257,9 +257,9 @@ def test_only_set_charset_still_defaults_to_text_html
}
resp.to_a
assert resp.etag?
assert resp.weak_etag?
assert_not resp.strong_etag?
assert_predicate resp, :etag?
assert_predicate resp, :weak_etag?
assert_not_predicate resp, :strong_etag?
assert_equal('W/"202cb962ac59075b964b07152d234b70"', resp.etag)
assert_equal({ public: true }, resp.cache_control)
@ -275,9 +275,9 @@ def test_only_set_charset_still_defaults_to_text_html
}
resp.to_a
assert resp.etag?
assert_not resp.weak_etag?
assert resp.strong_etag?
assert_predicate resp, :etag?
assert_not_predicate resp, :weak_etag?
assert_predicate resp, :strong_etag?
assert_equal('"202cb962ac59075b964b07152d234b70"', resp.etag)
end

@ -3313,7 +3313,7 @@ def test_action_from_path_is_not_frozen
end
get "/search"
assert !@request.params[:action].frozen?
assert_not_predicate @request.params[:action], :frozen?
end
def test_multiple_positional_args_with_the_same_name
@ -4267,7 +4267,7 @@ class TestOptimizedNamedRoutes < ActionDispatch::IntegrationTest
def app; APP end
test "enabled when not mounted and default_url_options is empty" do
assert Routes.url_helpers.optimize_routes_generation?
assert_predicate Routes.url_helpers, :optimize_routes_generation?
end
test "named route called as singleton method" do

@ -100,7 +100,7 @@ def test_delegate_respects_respond_to?
def test_delegate_eof_to_tempfile
tf = Class.new { def eof?; true end; }
uf = Http::UploadedFile.new(tempfile: tf.new)
assert uf.eof?
assert_predicate uf, :eof?
end
def test_respond_to?

@ -8,10 +8,10 @@ module Nodes
class TestSymbol < ActiveSupport::TestCase
def test_default_regexp?
sym = Symbol.new "foo"
assert sym.default_regexp?
assert_predicate sym, :default_regexp?
sym.regexp = nil
assert_not sym.default_regexp?
assert_not_predicate sym, :default_regexp?
end
end
end

@ -21,7 +21,7 @@ def test_clear
assert_equal 1, routes.length
routes.clear
assert routes.empty?
assert_predicate routes, :empty?
assert_equal 0, routes.length
end

@ -407,7 +407,7 @@ def test_javascript_include_tag_with_missing_source
end
def test_javascript_include_tag_is_html_safe
assert javascript_include_tag("prototype").html_safe?
assert_predicate javascript_include_tag("prototype"), :html_safe?
end
def test_javascript_include_tag_relative_protocol
@ -460,8 +460,8 @@ def test_stylesheet_link_tag_without_request
end
def test_stylesheet_link_tag_is_html_safe
assert stylesheet_link_tag("dir/file").html_safe?
assert stylesheet_link_tag("dir/other/file", "dir/file2").html_safe?
assert_predicate stylesheet_link_tag("dir/file"), :html_safe?
assert_predicate stylesheet_link_tag("dir/other/file", "dir/file2"), :html_safe?
end
def test_stylesheet_link_tag_escapes_options

@ -257,7 +257,7 @@ def test_providing_builder_to_atom_feed
get :index, params: { id: "provide_builder" }
# because we pass in the non-default builder, the content generated by the
# helper should go 'nowhere'. Leaving the response body blank.
assert @response.body.blank?
assert_predicate @response.body, :blank?
end
end

@ -155,12 +155,12 @@ def test_content_for_should_be_html_safe_after_flush_empty
content_for :title do
content_tag(:p, "title")
end
assert content_for(:title).html_safe?
assert_predicate content_for(:title), :html_safe?
content_for :title, "", flush: true
content_for(:title) do
content_tag(:p, "title")
end
assert content_for(:title).html_safe?
assert_predicate content_for(:title), :html_safe?
end
def test_provide

@ -3593,25 +3593,25 @@ def test_select_time_should_not_change_passed_options_hash
end
def test_select_html_safety
assert select_day(16).html_safe?
assert select_month(8).html_safe?
assert select_year(Time.mktime(2003, 8, 16, 8, 4, 18)).html_safe?
assert select_minute(Time.mktime(2003, 8, 16, 8, 4, 18)).html_safe?
assert select_second(Time.mktime(2003, 8, 16, 8, 4, 18)).html_safe?
assert_predicate select_day(16), :html_safe?
assert_predicate select_month(8), :html_safe?
assert_predicate select_year(Time.mktime(2003, 8, 16, 8, 4, 18)), :html_safe?
assert_predicate select_minute(Time.mktime(2003, 8, 16, 8, 4, 18)), :html_safe?
assert_predicate select_second(Time.mktime(2003, 8, 16, 8, 4, 18)), :html_safe?
assert select_minute(8, use_hidden: true).html_safe?
assert select_month(8, prompt: "Choose month").html_safe?
assert_predicate select_minute(8, use_hidden: true), :html_safe?
assert_predicate select_month(8, prompt: "Choose month"), :html_safe?
assert select_time(Time.mktime(2003, 8, 16, 8, 4, 18), {}, { class: "selector" }).html_safe?
assert select_date(Time.mktime(2003, 8, 16), date_separator: " / ", start_year: 2003, end_year: 2005, prefix: "date[first]").html_safe?
assert_predicate select_time(Time.mktime(2003, 8, 16, 8, 4, 18), {}, { class: "selector" }), :html_safe?
assert_predicate select_date(Time.mktime(2003, 8, 16), date_separator: " / ", start_year: 2003, end_year: 2005, prefix: "date[first]"), :html_safe?
end
def test_object_select_html_safety
@post = Post.new
@post.written_on = Date.new(2004, 6, 15)
assert date_select("post", "written_on", default: Time.local(2006, 9, 19, 15, 16, 35), include_blank: true).html_safe?
assert time_select("post", "written_on", ignore_date: true).html_safe?
assert_predicate date_select("post", "written_on", default: Time.local(2006, 9, 19, 15, 16, 35), include_blank: true), :html_safe?
assert_predicate time_select("post", "written_on", ignore_date: true), :html_safe?
end
def test_time_tag_with_date

@ -70,24 +70,24 @@ def test_json_escape_is_idempotent
def test_json_escape_returns_unsafe_strings_when_passed_unsafe_strings
value = json_escape("asdf")
assert !value.html_safe?
assert_not_predicate value, :html_safe?
end
def test_json_escape_returns_safe_strings_when_passed_safe_strings
value = json_escape("asdf".html_safe)
assert value.html_safe?
assert_predicate value, :html_safe?
end
def test_html_escape_is_html_safe
escaped = h("<p>")
assert_equal "&lt;p&gt;", escaped
assert escaped.html_safe?
assert_predicate escaped, :html_safe?
end
def test_html_escape_passes_html_escape_unmodified
escaped = h("<p>".html_safe)
assert_equal "<p>", escaped
assert escaped.html_safe?
assert_predicate escaped, :html_safe?
end
def test_rest_in_ascii
@ -104,11 +104,11 @@ def test_html_escape_once
def test_html_escape_once_returns_unsafe_strings_when_passed_unsafe_strings
value = html_escape_once("1 < 2 &amp; 3")
assert !value.html_safe?
assert_not_predicate value, :html_safe?
end
def test_html_escape_once_returns_safe_strings_when_passed_safe_strings
value = html_escape_once("1 < 2 &amp; 3".html_safe)
assert value.html_safe?
assert_predicate value, :html_safe?
end
end

@ -108,7 +108,7 @@ def test_form_with_skip_enforcing_utf8_true
actual = form_with(skip_enforcing_utf8: true)
expected = whole_form("http://www.example.com", skip_enforcing_utf8: true)
assert_dom_equal expected, actual
assert actual.html_safe?
assert_predicate actual, :html_safe?
end
def test_form_with_with_block_in_erb

@ -612,7 +612,7 @@ def test_text_field_with_custom_type
end
def test_check_box_is_html_safe
assert check_box("post", "secret").html_safe?
assert_predicate check_box("post", "secret"), :html_safe?
end
def test_check_box_checked_if_object_value_is_same_that_check_value
@ -775,7 +775,7 @@ def test_check_box_with_nil_unchecked_value
end
def test_check_box_with_nil_unchecked_value_is_html_safe
assert check_box("post", "secret", {}, "on", nil).html_safe?
assert_predicate check_box("post", "secret", {}, "on", nil), :html_safe?
end
def test_check_box_with_multiple_behavior

@ -354,7 +354,7 @@ def test_option_groups_from_collection_for_select_with_callable_group_label_meth
end
def test_option_groups_from_collection_for_select_returns_html_safe_string
assert option_groups_from_collection_for_select(dummy_continents, "countries", "continent_name", "country_id", "country_name", "dk").html_safe?
assert_predicate option_groups_from_collection_for_select(dummy_continents, "countries", "continent_name", "country_id", "country_name", "dk"), :html_safe?
end
def test_grouped_options_for_select_with_array
@ -402,7 +402,7 @@ def test_grouped_options_for_select_with_selected_and_prompt_true
end
def test_grouped_options_for_select_returns_html_safe_string
assert grouped_options_for_select([["Hats", ["Baseball Cap", "Cowboy Hat"]]]).html_safe?
assert_predicate grouped_options_for_select([["Hats", ["Baseball Cap", "Cowboy Hat"]]]), :html_safe?
end
def test_grouped_options_for_select_with_prompt_returns_html_escaped_string
@ -492,7 +492,7 @@ def test_time_zone_options_with_priority_zones_does_not_mutate_time_zones
end
def test_time_zone_options_returns_html_safe_string
assert time_zone_options_for_select.html_safe?
assert_predicate time_zone_options_for_select, :html_safe?
end
def test_select

@ -142,14 +142,14 @@ def test_form_tag_enforce_utf8_true
actual = form_tag({}, { enforce_utf8: true })
expected = whole_form("http://www.example.com", enforce_utf8: true)
assert_dom_equal expected, actual
assert actual.html_safe?
assert_predicate actual, :html_safe?
end
def test_form_tag_enforce_utf8_false
actual = form_tag({}, { enforce_utf8: false })
expected = whole_form("http://www.example.com", enforce_utf8: false)
assert_dom_equal expected, actual
assert actual.html_safe?
assert_predicate actual, :html_safe?
end
def test_form_tag_with_block_in_erb

@ -35,7 +35,7 @@ def teardown
test "allows me to freeze and retrieve frozen formats" do
@lookup_context.formats.freeze
assert @lookup_context.formats.frozen?
assert_predicate @lookup_context.formats, :frozen?
end
test "provides getters and setters for variants" do

@ -126,43 +126,43 @@ def test_number_to_human_with_custom_translation_scope
end
def test_number_helpers_outputs_are_html_safe
assert number_to_human(1).html_safe?
assert !number_to_human("<script></script>").html_safe?
assert number_to_human("asdf".html_safe).html_safe?
assert number_to_human("1".html_safe).html_safe?
assert_predicate number_to_human(1), :html_safe?
assert_not_predicate number_to_human("<script></script>"), :html_safe?
assert_predicate number_to_human("asdf".html_safe), :html_safe?
assert_predicate number_to_human("1".html_safe), :html_safe?
assert number_to_human_size(1).html_safe?
assert number_to_human_size(1000000).html_safe?
assert !number_to_human_size("<script></script>").html_safe?
assert number_to_human_size("asdf".html_safe).html_safe?
assert number_to_human_size("1".html_safe).html_safe?
assert_predicate number_to_human_size(1), :html_safe?
assert_predicate number_to_human_size(1000000), :html_safe?
assert_not_predicate number_to_human_size("<script></script>"), :html_safe?
assert_predicate number_to_human_size("asdf".html_safe), :html_safe?
assert_predicate number_to_human_size("1".html_safe), :html_safe?
assert number_with_precision(1, strip_insignificant_zeros: false).html_safe?
assert number_with_precision(1, strip_insignificant_zeros: true).html_safe?
assert !number_with_precision("<script></script>").html_safe?
assert number_with_precision("asdf".html_safe).html_safe?
assert number_with_precision("1".html_safe).html_safe?
assert_predicate number_with_precision(1, strip_insignificant_zeros: false), :html_safe?
assert_predicate number_with_precision(1, strip_insignificant_zeros: true), :html_safe?
assert_not_predicate number_with_precision("<script></script>"), :html_safe?
assert_predicate number_with_precision("asdf".html_safe), :html_safe?
assert_predicate number_with_precision("1".html_safe), :html_safe?
assert number_to_currency(1).html_safe?
assert !number_to_currency("<script></script>").html_safe?
assert number_to_currency("asdf".html_safe).html_safe?
assert number_to_currency("1".html_safe).html_safe?
assert_predicate number_to_currency(1), :html_safe?
assert_not_predicate number_to_currency("<script></script>"), :html_safe?
assert_predicate number_to_currency("asdf".html_safe), :html_safe?
assert_predicate number_to_currency("1".html_safe), :html_safe?
assert number_to_percentage(1).html_safe?
assert !number_to_percentage("<script></script>").html_safe?
assert number_to_percentage("asdf".html_safe).html_safe?
assert number_to_percentage("1".html_safe).html_safe?
assert_predicate number_to_percentage(1), :html_safe?
assert_not_predicate number_to_percentage("<script></script>"), :html_safe?
assert_predicate number_to_percentage("asdf".html_safe), :html_safe?
assert_predicate number_to_percentage("1".html_safe), :html_safe?
assert number_to_phone(1).html_safe?
assert_predicate number_to_phone(1), :html_safe?
assert_equal "&lt;script&gt;&lt;/script&gt;", number_to_phone("<script></script>")
assert number_to_phone("<script></script>").html_safe?
assert number_to_phone("asdf".html_safe).html_safe?
assert number_to_phone("1".html_safe).html_safe?
assert_predicate number_to_phone("<script></script>"), :html_safe?
assert_predicate number_to_phone("asdf".html_safe), :html_safe?
assert_predicate number_to_phone("1".html_safe), :html_safe?
assert number_with_delimiter(1).html_safe?
assert !number_with_delimiter("<script></script>").html_safe?
assert number_with_delimiter("asdf".html_safe).html_safe?
assert number_with_delimiter("1".html_safe).html_safe?
assert_predicate number_with_delimiter(1), :html_safe?
assert_not_predicate number_with_delimiter("<script></script>"), :html_safe?
assert_predicate number_with_delimiter("asdf".html_safe), :html_safe?
assert_predicate number_with_delimiter("1".html_safe), :html_safe?
end
def test_number_helpers_should_raise_error_if_invalid_when_specified

@ -12,7 +12,7 @@ def setup
test "raw returns the safe string" do
result = raw(@string)
assert_equal @string, result
assert result.html_safe?
assert_predicate result, :html_safe?
end
test "raw handles nil values correctly" do
@ -53,11 +53,11 @@ def setup
test "to_sentence should escape non-html_safe values" do
actual = to_sentence(%w(< > & ' "))
assert actual.html_safe?
assert_predicate actual, :html_safe?
assert_equal("&lt;, &gt;, &amp;, &#39;, and &quot;", actual)
actual = to_sentence(%w(<script>))
assert actual.html_safe?
assert_predicate actual, :html_safe?
assert_equal("&lt;script&gt;", actual)
end
@ -80,19 +80,19 @@ def setup
url = "https://example.com"
expected = %(<a href="#{url}">#{url}</a> and <p>&lt;marquee&gt;shady stuff&lt;/marquee&gt;<br /></p>)
actual = to_sentence([link_to(url, url), ptag])
assert actual.html_safe?
assert_predicate actual, :html_safe?
assert_equal(expected, actual)
end
test "to_sentence handles blank strings" do
actual = to_sentence(["", "two", "three"])
assert actual.html_safe?
assert_predicate actual, :html_safe?
assert_equal ", two, and three", actual
end
test "to_sentence handles nil values" do
actual = to_sentence([nil, "two", "three"])
assert actual.html_safe?
assert_predicate actual, :html_safe?
assert_equal ", two, and three", actual
end

@ -38,6 +38,6 @@ def test_strip_tags_will_not_encode_special_characters
end
def test_sanitize_is_marked_safe
assert sanitize("<html><script></script></html>").html_safe?
assert_predicate sanitize("<html><script></script></html>"), :html_safe?
end
end

@ -81,7 +81,7 @@ def test_tag_builder_options_converts_boolean_option
def test_content_tag
assert_equal "<a href=\"create\">Create</a>", content_tag("a", "Create", "href" => "create")
assert content_tag("a", "Create", "href" => "create").html_safe?
assert_predicate content_tag("a", "Create", "href" => "create"), :html_safe?
assert_equal content_tag("a", "Create", "href" => "create"),
content_tag("a", "Create", href: "create")
assert_equal "<p>&lt;script&gt;evil_js&lt;/script&gt;</p>",
@ -92,7 +92,7 @@ def test_content_tag
def test_tag_builder_with_content
assert_equal "<div id=\"post_1\">Content</div>", tag.div("Content", id: "post_1")
assert tag.div("Content", id: "post_1").html_safe?
assert_predicate tag.div("Content", id: "post_1"), :html_safe?
assert_equal tag.div("Content", id: "post_1"),
tag.div("Content", "id": "post_1")
assert_equal "<p>&lt;script&gt;evil_js&lt;/script&gt;</p>",

@ -19,12 +19,12 @@ def test_concat
end
def test_simple_format_should_be_html_safe
assert simple_format("<b> test with html tags </b>").html_safe?
assert_predicate simple_format("<b> test with html tags </b>"), :html_safe?
end
def test_simple_format_included_in_isolation
helper_klass = Class.new { include ActionView::Helpers::TextHelper }
assert helper_klass.new.simple_format("<b> test with html tags </b>").html_safe?
assert_predicate helper_klass.new.simple_format("<b> test with html tags </b>"), :html_safe?
end
def test_simple_format
@ -123,7 +123,7 @@ def test_truncate_with_link_options
end
def test_truncate_should_be_html_safe
assert truncate("Hello World!", length: 12).html_safe?
assert_predicate truncate("Hello World!", length: 12), :html_safe?
end
def test_truncate_should_escape_the_input
@ -136,12 +136,12 @@ def test_truncate_should_not_escape_the_input_with_escape_false
def test_truncate_with_escape_false_should_be_html_safe
truncated = truncate("Hello <script>code!</script>World!!", length: 12, escape: false)
assert truncated.html_safe?
assert_predicate truncated, :html_safe?
end
def test_truncate_with_block_should_be_html_safe
truncated = truncate("Here's a long test and I need a continue to read link", length: 27) { link_to "Continue", "#" }
assert truncated.html_safe?
assert_predicate truncated, :html_safe?
end
def test_truncate_with_block_should_escape_the_input
@ -156,7 +156,7 @@ def test_truncate_with_block_should_not_escape_the_input_with_escape_false
def test_truncate_with_block_with_escape_false_should_be_html_safe
truncated = truncate("<script>code!</script>Here's a long test and I need a continue to read link", length: 27, escape: false) { link_to "Continue", "#" }
assert truncated.html_safe?
assert_predicate truncated, :html_safe?
end
def test_truncate_with_block_should_escape_the_block
@ -165,7 +165,7 @@ def test_truncate_with_block_should_escape_the_block
end
def test_highlight_should_be_html_safe
assert highlight("This is a beautiful morning", "beautiful").html_safe?
assert_predicate highlight("This is a beautiful morning", "beautiful"), :html_safe?
end
def test_highlight
@ -297,7 +297,7 @@ def test_excerpt_with_regex
end
def test_excerpt_should_not_be_html_safe
assert !excerpt("This is a beautiful! morning", "beautiful", radius: 5).html_safe?
assert_not_predicate excerpt("This is a beautiful! morning", "beautiful", radius: 5), :html_safe?
end
def test_excerpt_in_borderline_cases

@ -75,7 +75,7 @@ def test_returns_missing_translation_message_wrapped_into_span
def test_returns_missing_translation_message_with_unescaped_interpolation
expected = '<span class="translation_missing" title="translation missing: en.translations.missing, name: Kir, year: 2015, vulnerable: &amp;quot; onclick=&amp;quot;alert()&amp;quot;">Missing</span>'
assert_equal expected, translate(:"translations.missing", name: "Kir", year: "2015", vulnerable: %{" onclick="alert()"})
assert translate(:"translations.missing").html_safe?
assert_predicate translate(:"translations.missing"), :html_safe?
end
def test_returns_missing_translation_message_does_filters_out_i18n_options
@ -145,11 +145,11 @@ def test_translate_does_not_mark_plain_text_as_safe_html
end
def test_translate_marks_translations_named_html_as_safe_html
assert translate(:'translations.html').html_safe?
assert_predicate translate(:'translations.html'), :html_safe?
end
def test_translate_marks_translations_with_a_html_suffix_as_safe_html
assert translate(:'translations.hello_html').html_safe?
assert_predicate translate(:'translations.hello_html'), :html_safe?
end
def test_translate_escapes_interpolations_in_translations_with_a_html_suffix

@ -663,7 +663,7 @@ def test_mail_to_with_nil
end
def test_mail_to_returns_html_safe_string
assert mail_to("david@loudthinking.com").html_safe?
assert_predicate mail_to("david@loudthinking.com"), :html_safe?
end
def test_mail_to_with_block

@ -74,8 +74,8 @@ class AttributeSetTest < ActiveModel::TestCase
clone.freeze
assert clone.frozen?
assert_not attributes.frozen?
assert_predicate clone, :frozen?
assert_not_predicate attributes, :frozen?
end
test "to_hash returns a hash of the type cast values" do
@ -105,8 +105,8 @@ class AttributeSetTest < ActiveModel::TestCase
test "known columns are built with uninitialized attributes" do
attributes = attributes_with_uninitialized_key
assert attributes[:foo].initialized?
assert_not attributes[:bar].initialized?
assert_predicate attributes[:foo], :initialized?
assert_not_predicate attributes[:bar], :initialized?
end
test "uninitialized attributes are not included in the attributes hash" do
@ -169,7 +169,7 @@ class AttributeSetTest < ActiveModel::TestCase
assert attributes.key?(:foo)
assert_equal [:foo], attributes.keys
assert attributes[:foo].initialized?
assert_predicate attributes[:foo], :initialized?
end
class MyType

@ -175,33 +175,33 @@ def assert_valid_value(*)
test "an attribute has not been read by default" do
attribute = Attribute.from_database(:foo, 1, Type::Value.new)
assert_not attribute.has_been_read?
assert_not_predicate attribute, :has_been_read?
end
test "an attribute has been read when its value is calculated" do
attribute = Attribute.from_database(:foo, 1, Type::Value.new)
attribute.value
assert attribute.has_been_read?
assert_predicate attribute, :has_been_read?
end
test "an attribute is not changed if it hasn't been assigned or mutated" do
attribute = Attribute.from_database(:foo, 1, Type::Value.new)
assert_not attribute.changed?
assert_not_predicate attribute, :changed?
end
test "an attribute is changed if it's been assigned a new value" do
attribute = Attribute.from_database(:foo, 1, Type::Value.new)
changed = attribute.with_value_from_user(2)
assert changed.changed?
assert_predicate changed, :changed?
end
test "an attribute is not changed if it's assigned the same value" do
attribute = Attribute.from_database(:foo, 1, Type::Value.new)
unchanged = attribute.with_value_from_user(1)
assert_not unchanged.changed?
assert_not_predicate unchanged, :changed?
end
test "an attribute can not be mutated if it has not been read,
@ -209,15 +209,15 @@ def assert_valid_value(*)
type_which_raises_from_all_methods = Object.new
attribute = Attribute.from_database(:foo, "bar", type_which_raises_from_all_methods)
assert_not attribute.changed_in_place?
assert_not_predicate attribute, :changed_in_place?
end
test "an attribute is changed if it has been mutated" do
attribute = Attribute.from_database(:foo, "bar", Type::String.new)
attribute.value << "!"
assert attribute.changed_in_place?
assert attribute.changed?
assert_predicate attribute, :changed_in_place?
assert_predicate attribute, :changed?
end
test "an attribute can forget its changes" do
@ -226,7 +226,7 @@ def assert_valid_value(*)
forgotten = changed.forgetting_assignment
assert changed.changed? # sanity check
assert_not forgotten.changed?
assert_not_predicate forgotten, :changed?
end
test "with_value_from_user validates the value" do

@ -25,11 +25,11 @@ def reload
end
test "setting attribute will result in change" do
assert !@model.changed?
assert !@model.name_changed?
assert_not_predicate @model, :changed?
assert_not_predicate @model, :name_changed?
@model.name = "Ringo"
assert @model.changed?
assert @model.name_changed?
assert_predicate @model, :changed?
assert_predicate @model, :name_changed?
end
test "list of changed attribute keys" do
@ -71,35 +71,35 @@ def reload
test "attribute mutation" do
@model.name = "Yam"
@model.save
assert !@model.name_changed?
assert_not_predicate @model, :name_changed?
@model.name.replace("Hadad")
assert @model.name_changed?
assert_predicate @model, :name_changed?
end
test "resetting attribute" do
@model.name = "Bob"
@model.restore_name!
assert_nil @model.name
assert !@model.name_changed?
assert_not_predicate @model, :name_changed?
end
test "setting color to same value should not result in change being recorded" do
@model.color = "red"
assert @model.color_changed?
assert_predicate @model, :color_changed?
@model.save
assert !@model.color_changed?
assert !@model.changed?
assert_not_predicate @model, :color_changed?
assert_not_predicate @model, :changed?
@model.color = "red"
assert !@model.color_changed?
assert !@model.changed?
assert_not_predicate @model, :color_changed?
assert_not_predicate @model, :changed?
end
test "saving should reset model's changed status" do
@model.name = "Alf"
assert @model.changed?
assert_predicate @model, :changed?
@model.save
assert !@model.changed?
assert !@model.name_changed?
assert_not_predicate @model, :changed?
assert_not_predicate @model, :name_changed?
end
test "saving should preserve previous changes" do
@ -118,7 +118,7 @@ def reload
test "saving should preserve model's previous changed status" do
@model.name = "Jericho Cane"
@model.save
assert @model.name_previously_changed?
assert_predicate @model, :name_previously_changed?
end
test "previous value is preserved when changed after save" do
@ -143,7 +143,7 @@ def reload
test "using attribute_will_change! with a symbol" do
@model.size = 1
assert @model.size_changed?
assert_predicate @model, :size_changed?
end
test "reload should reset all changes" do
@ -170,7 +170,7 @@ def reload
@model.restore_attributes
assert_not @model.changed?
assert_not_predicate @model, :changed?
assert_equal "Dmitry", @model.name
assert_equal "Red", @model.color
end
@ -184,7 +184,7 @@ def reload
@model.restore_attributes(["name"])
assert @model.changed?
assert_predicate @model, :changed?
assert_equal "Dmitry", @model.name
assert_equal "White", @model.color
end

@ -64,11 +64,11 @@ def reload
end
test "setting attribute will result in change" do
assert !@model.changed?
assert !@model.name_changed?
assert_not_predicate @model, :changed?
assert_not_predicate @model, :name_changed?
@model.name = "Ringo"
assert @model.changed?
assert @model.name_changed?
assert_predicate @model, :changed?
assert_predicate @model, :name_changed?
end
test "list of changed attribute keys" do
@ -109,38 +109,38 @@ def reload
test "attribute mutation" do
@model.instance_variable_set("@name", "Yam".dup)
assert !@model.name_changed?
assert_not_predicate @model, :name_changed?
@model.name.replace("Hadad")
assert !@model.name_changed?
assert_not_predicate @model, :name_changed?
@model.name_will_change!
@model.name.replace("Baal")
assert @model.name_changed?
assert_predicate @model, :name_changed?
end
test "resetting attribute" do
@model.name = "Bob"
@model.restore_name!
assert_nil @model.name
assert !@model.name_changed?
assert_not_predicate @model, :name_changed?
end
test "setting color to same value should not result in change being recorded" do
@model.color = "red"
assert @model.color_changed?
assert_predicate @model, :color_changed?
@model.save
assert !@model.color_changed?
assert !@model.changed?
assert_not_predicate @model, :color_changed?
assert_not_predicate @model, :changed?
@model.color = "red"
assert !@model.color_changed?
assert !@model.changed?
assert_not_predicate @model, :color_changed?
assert_not_predicate @model, :changed?
end
test "saving should reset model's changed status" do
@model.name = "Alf"
assert @model.changed?
assert_predicate @model, :changed?
@model.save
assert !@model.changed?
assert !@model.name_changed?
assert_not_predicate @model, :changed?
assert_not_predicate @model, :name_changed?
end
test "saving should preserve previous changes" do
@ -164,7 +164,7 @@ def reload
test "saving should preserve model's previous changed status" do
@model.name = "Jericho Cane"
@model.save
assert @model.name_previously_changed?
assert_predicate @model, :name_previously_changed?
end
test "previous value is preserved when changed after save" do
@ -195,7 +195,7 @@ def reload
test "using attribute_will_change! with a symbol" do
@model.size = 1
assert @model.size_changed?
assert_predicate @model, :size_changed?
end
test "reload should reset all changes" do
@ -222,7 +222,7 @@ def reload
@model.restore_attributes
assert_not @model.changed?
assert_not_predicate @model, :changed?
assert_equal "Dmitry", @model.name
assert_equal "Red", @model.color
end
@ -236,7 +236,7 @@ def reload
@model.restore_attributes(["name"])
assert @model.changed?
assert_predicate @model, :changed?
assert_equal "Dmitry", @model.name
assert_equal "White", @model.color
end

@ -83,7 +83,7 @@ def test_no_key
assert_equal 1, person.errors.count
person.errors.clear
assert person.errors.empty?
assert_predicate person.errors, :empty?
end
test "error access is indifferent" do
@ -128,8 +128,8 @@ def test_no_key
test "detecting whether there are errors with empty?, blank?, include?" do
person = Person.new
person.errors[:foo]
assert person.errors.empty?
assert person.errors.blank?
assert_predicate person.errors, :empty?
assert_predicate person.errors, :blank?
assert_not_includes person.errors, :foo
end
@ -371,7 +371,7 @@ def test_no_key
assert_equal 1, person.errors.details.count
person.errors.clear
assert person.errors.details.empty?
assert_predicate person.errors.details, :empty?
end
test "copy errors" do

@ -7,8 +7,8 @@ module Type
class BooleanTest < ActiveModel::TestCase
def test_type_cast_boolean
type = Type::Boolean.new
assert type.cast("").nil?
assert type.cast(nil).nil?
assert_predicate type.cast(""), :nil?
assert_predicate type.cast(nil), :nil?
assert type.cast(true)
assert type.cast(1)

@ -17,16 +17,16 @@ def test_validates_absence_of
t = Topic.new
t.title = "foo"
t.content = "bar"
assert t.invalid?
assert_predicate t, :invalid?
assert_equal ["must be blank"], t.errors[:title]
assert_equal ["must be blank"], t.errors[:content]
t.title = ""
t.content = "something"
assert t.invalid?
assert_predicate t, :invalid?
assert_equal ["must be blank"], t.errors[:content]
assert_equal [], t.errors[:title]
t.content = ""
assert t.valid?
assert_predicate t, :valid?
end
def test_validates_absence_of_with_array_arguments
@ -34,7 +34,7 @@ def test_validates_absence_of_with_array_arguments
t = Topic.new
t.title = "foo"
t.content = "bar"
assert t.invalid?
assert_predicate t, :invalid?
assert_equal ["must be blank"], t.errors[:title]
assert_equal ["must be blank"], t.errors[:content]
end
@ -43,7 +43,7 @@ def test_validates_absence_of_with_custom_error_using_quotes
Person.validates_absence_of :karma, message: "This string contains 'single' and \"double\" quotes"
p = Person.new
p.karma = "good"
assert p.invalid?
assert_predicate p, :invalid?
assert_equal "This string contains 'single' and \"double\" quotes", p.errors[:karma].last
end
@ -51,19 +51,19 @@ def test_validates_absence_of_for_ruby_class
Person.validates_absence_of :karma
p = Person.new
p.karma = "good"
assert p.invalid?
assert_predicate p, :invalid?
assert_equal ["must be blank"], p.errors[:karma]
p.karma = nil
assert p.valid?
assert_predicate p, :valid?
end
def test_validates_absence_of_for_ruby_class_with_custom_reader
CustomReader.validates_absence_of :karma
p = CustomReader.new
p[:karma] = "excellent"
assert p.invalid?
assert_predicate p, :invalid?
assert_equal ["must be blank"], p.errors[:karma]
p[:karma] = ""
assert p.valid?
assert_predicate p, :valid?
end
end

@ -15,54 +15,54 @@ def test_terms_of_service_agreement_no_acceptance
Topic.validates_acceptance_of(:terms_of_service)
t = Topic.new("title" => "We should not be confirmed")
assert t.valid?
assert_predicate t, :valid?
end
def test_terms_of_service_agreement
Topic.validates_acceptance_of(:terms_of_service)
t = Topic.new("title" => "We should be confirmed", "terms_of_service" => "")
assert t.invalid?
assert_predicate t, :invalid?
assert_equal ["must be accepted"], t.errors[:terms_of_service]
t.terms_of_service = "1"
assert t.valid?
assert_predicate t, :valid?
end
def test_eula
Topic.validates_acceptance_of(:eula, message: "must be abided")
t = Topic.new("title" => "We should be confirmed", "eula" => "")
assert t.invalid?
assert_predicate t, :invalid?
assert_equal ["must be abided"], t.errors[:eula]
t.eula = "1"
assert t.valid?
assert_predicate t, :valid?
end
def test_terms_of_service_agreement_with_accept_value
Topic.validates_acceptance_of(:terms_of_service, accept: "I agree.")
t = Topic.new("title" => "We should be confirmed", "terms_of_service" => "")
assert t.invalid?
assert_predicate t, :invalid?
assert_equal ["must be accepted"], t.errors[:terms_of_service]
t.terms_of_service = "I agree."
assert t.valid?
assert_predicate t, :valid?
end
def test_terms_of_service_agreement_with_multiple_accept_values
Topic.validates_acceptance_of(:terms_of_service, accept: [1, "I concur."])
t = Topic.new("title" => "We should be confirmed", "terms_of_service" => "")
assert t.invalid?
assert_predicate t, :invalid?
assert_equal ["must be accepted"], t.errors[:terms_of_service]
t.terms_of_service = 1
assert t.valid?
assert_predicate t, :valid?
t.terms_of_service = "I concur."
assert t.valid?
assert_predicate t, :valid?
end
def test_validates_acceptance_of_for_ruby_class
@ -71,11 +71,11 @@ def test_validates_acceptance_of_for_ruby_class
p = Person.new
p.karma = ""
assert p.invalid?
assert_predicate p, :invalid?
assert_equal ["must be accepted"], p.errors[:karma]
p.karma = "1"
assert p.valid?
assert_predicate p, :valid?
ensure
Person.clear_validators!
end
@ -83,6 +83,6 @@ def test_validates_acceptance_of_for_ruby_class
def test_validates_acceptance_of_true
Topic.validates_acceptance_of(:terms_of_service)
assert Topic.new(terms_of_service: true).valid?
assert_predicate Topic.new(terms_of_service: true), :valid?
end
end

@ -13,24 +13,24 @@ def test_if_validation_using_method_true
# When the method returns true
Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}", if: :condition_is_true)
t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["hoo 5"], t.errors["title"]
end
def test_if_validation_using_array_of_true_methods
Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}", if: [:condition_is_true, :condition_is_true])
t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["hoo 5"], t.errors["title"]
end
def test_unless_validation_using_array_of_false_methods
Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}", unless: [:condition_is_false, :condition_is_false])
t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["hoo 5"], t.errors["title"]
end
@ -38,21 +38,21 @@ def test_unless_validation_using_method_true
# When the method returns true
Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}", unless: :condition_is_true)
t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
assert t.valid?
assert_predicate t, :valid?
assert_empty t.errors[:title]
end
def test_if_validation_using_array_of_true_and_false_methods
Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}", if: [:condition_is_true, :condition_is_false])
t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
assert t.valid?
assert_predicate t, :valid?
assert_empty t.errors[:title]
end
def test_unless_validation_using_array_of_true_and_felse_methods
Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}", unless: [:condition_is_true, :condition_is_false])
t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
assert t.valid?
assert_predicate t, :valid?
assert_empty t.errors[:title]
end
@ -60,7 +60,7 @@ def test_if_validation_using_method_false
# When the method returns false
Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}", if: :condition_is_false)
t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
assert t.valid?
assert_predicate t, :valid?
assert_empty t.errors[:title]
end
@ -68,8 +68,8 @@ def test_unless_validation_using_method_false
# When the method returns false
Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}", unless: :condition_is_false)
t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["hoo 5"], t.errors["title"]
end
@ -78,8 +78,8 @@ def test_if_validation_using_block_true
Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}",
if: Proc.new { |r| r.content.size > 4 })
t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["hoo 5"], t.errors["title"]
end
@ -88,7 +88,7 @@ def test_unless_validation_using_block_true
Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}",
unless: Proc.new { |r| r.content.size > 4 })
t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
assert t.valid?
assert_predicate t, :valid?
assert_empty t.errors[:title]
end
@ -97,7 +97,7 @@ def test_if_validation_using_block_false
Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}",
if: Proc.new { |r| r.title != "uhohuhoh" })
t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
assert t.valid?
assert_predicate t, :valid?
assert_empty t.errors[:title]
end
@ -106,23 +106,23 @@ def test_unless_validation_using_block_false
Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}",
unless: Proc.new { |r| r.title != "uhohuhoh" })
t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["hoo 5"], t.errors["title"]
end
def test_validation_using_conbining_if_true_and_unless_true_conditions
Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}", if: :condition_is_true, unless: :condition_is_true)
t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
assert t.valid?
assert_predicate t, :valid?
assert_empty t.errors[:title]
end
def test_validation_using_conbining_if_true_and_unless_false_conditions
Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}", if: :condition_is_true, unless: :condition_is_false)
t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["hoo 5"], t.errors["title"]
end
end

@ -14,40 +14,40 @@ def test_no_title_confirmation
Topic.validates_confirmation_of(:title)
t = Topic.new(author_name: "Plutarch")
assert t.valid?
assert_predicate t, :valid?
t.title_confirmation = "Parallel Lives"
assert t.invalid?
assert_predicate t, :invalid?
t.title_confirmation = nil
t.title = "Parallel Lives"
assert t.valid?
assert_predicate t, :valid?
t.title_confirmation = "Parallel Lives"
assert t.valid?
assert_predicate t, :valid?
end
def test_title_confirmation
Topic.validates_confirmation_of(:title)
t = Topic.new("title" => "We should be confirmed", "title_confirmation" => "")
assert t.invalid?
assert_predicate t, :invalid?
t.title_confirmation = "We should be confirmed"
assert t.valid?
assert_predicate t, :valid?
end
def test_validates_confirmation_of_with_boolean_attribute
Topic.validates_confirmation_of(:approved)
t = Topic.new(approved: true, approved_confirmation: nil)
assert t.valid?
assert_predicate t, :valid?
t.approved_confirmation = false
assert t.invalid?
assert_predicate t, :invalid?
t.approved_confirmation = true
assert t.valid?
assert_predicate t, :valid?
end
def test_validates_confirmation_of_for_ruby_class
@ -55,12 +55,12 @@ def test_validates_confirmation_of_for_ruby_class
p = Person.new
p.karma_confirmation = "None"
assert p.invalid?
assert_predicate p, :invalid?
assert_equal ["doesn't match Karma"], p.errors[:karma_confirmation]
p.karma = "None"
assert p.valid?
assert_predicate p, :valid?
ensure
Person.clear_validators!
end
@ -77,7 +77,7 @@ def test_title_confirmation_with_i18n_attribute
Topic.validates_confirmation_of(:title)
t = Topic.new("title" => "We should be confirmed", "title_confirmation" => "")
assert t.invalid?
assert_predicate t, :invalid?
assert_equal ["doesn't match Test Title"], t.errors[:title_confirmation]
ensure
I18n.load_path.replace @old_load_path
@ -122,13 +122,13 @@ def test_title_confirmation_with_case_sensitive_option_true
Topic.validates_confirmation_of(:title, case_sensitive: true)
t = Topic.new(title: "title", title_confirmation: "Title")
assert t.invalid?
assert_predicate t, :invalid?
end
def test_title_confirmation_with_case_sensitive_option_false
Topic.validates_confirmation_of(:title, case_sensitive: false)
t = Topic.new(title: "title", title_confirmation: "Title")
assert t.valid?
assert_predicate t, :valid?
end
end

@ -14,8 +14,8 @@ def teardown
def test_validates_exclusion_of
Topic.validates_exclusion_of(:title, in: %w( abe monkey ))
assert Topic.new("title" => "something", "content" => "abc").valid?
assert Topic.new("title" => "monkey", "content" => "abc").invalid?
assert_predicate Topic.new("title" => "something", "content" => "abc"), :valid?
assert_predicate Topic.new("title" => "monkey", "content" => "abc"), :invalid?
end
def test_validates_exclusion_of_with_formatted_message
@ -24,8 +24,8 @@ def test_validates_exclusion_of_with_formatted_message
assert Topic.new("title" => "something", "content" => "abc")
t = Topic.new("title" => "monkey")
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["option monkey is restricted"], t.errors[:title]
end
@ -35,8 +35,8 @@ def test_validates_exclusion_of_with_within_option
assert Topic.new("title" => "something", "content" => "abc")
t = Topic.new("title" => "monkey")
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
end
def test_validates_exclusion_of_for_ruby_class
@ -44,12 +44,12 @@ def test_validates_exclusion_of_for_ruby_class
p = Person.new
p.karma = "abe"
assert p.invalid?
assert_predicate p, :invalid?
assert_equal ["is reserved"], p.errors[:karma]
p.karma = "Lifo"
assert p.valid?
assert_predicate p, :valid?
ensure
Person.clear_validators!
end
@ -60,26 +60,26 @@ def test_validates_exclusion_of_with_lambda
t = Topic.new
t.title = "elephant"
t.author_name = "sikachu"
assert t.invalid?
assert_predicate t, :invalid?
t.title = "wasabi"
assert t.valid?
assert_predicate t, :valid?
end
def test_validates_exclusion_of_with_range
Topic.validates_exclusion_of :content, in: ("a".."g")
assert Topic.new(content: "g").invalid?
assert Topic.new(content: "h").valid?
assert_predicate Topic.new(content: "g"), :invalid?
assert_predicate Topic.new(content: "h"), :valid?
end
def test_validates_exclusion_of_with_time_range
Topic.validates_exclusion_of :created_at, in: 6.days.ago..2.days.ago
assert Topic.new(created_at: 5.days.ago).invalid?
assert Topic.new(created_at: 3.days.ago).invalid?
assert Topic.new(created_at: 7.days.ago).valid?
assert Topic.new(created_at: 1.day.ago).valid?
assert_predicate Topic.new(created_at: 5.days.ago), :invalid?
assert_predicate Topic.new(created_at: 3.days.ago), :invalid?
assert_predicate Topic.new(created_at: 7.days.ago), :valid?
assert_predicate Topic.new(created_at: 1.day.ago), :valid?
end
def test_validates_inclusion_of_with_symbol
@ -92,7 +92,7 @@ def p.reserved_karmas
%w(abe)
end
assert p.invalid?
assert_predicate p, :invalid?
assert_equal ["is reserved"], p.errors[:karma]
p = Person.new
@ -102,7 +102,7 @@ def p.reserved_karmas
%w()
end
assert p.valid?
assert_predicate p, :valid?
ensure
Person.clear_validators!
end

@ -16,22 +16,22 @@ def test_validate_format
t = Topic.new("title" => "i'm incorrect", "content" => "Validation macros rule!")
assert t.invalid?, "Shouldn't be valid"
assert_equal ["is bad data"], t.errors[:title]
assert t.errors[:content].empty?
assert_predicate t.errors[:content], :empty?
t.title = "Validation macros rule!"
assert t.valid?
assert t.errors[:title].empty?
assert_predicate t, :valid?
assert_predicate t.errors[:title], :empty?
assert_raise(ArgumentError) { Topic.validates_format_of(:title, :content) }
end
def test_validate_format_with_allow_blank
Topic.validates_format_of(:title, with: /\AValidation\smacros \w+!\z/, allow_blank: true)
assert Topic.new("title" => "Shouldn't be valid").invalid?
assert Topic.new("title" => "").valid?
assert Topic.new("title" => nil).valid?
assert Topic.new("title" => "Validation macros rule!").valid?
assert_predicate Topic.new("title" => "Shouldn't be valid"), :invalid?
assert_predicate Topic.new("title" => ""), :valid?
assert_predicate Topic.new("title" => nil), :valid?
assert_predicate Topic.new("title" => "Validation macros rule!"), :valid?
end
# testing ticket #3142
@ -42,7 +42,7 @@ def test_validate_format_numeric
assert t.invalid?, "Shouldn't be valid"
assert_equal ["is bad data"], t.errors[:title]
assert t.errors[:content].empty?
assert_predicate t.errors[:content], :empty?
t.title = "-11"
assert t.invalid?, "Shouldn't be valid"
@ -58,14 +58,14 @@ def test_validate_format_numeric
t.title = "1"
assert t.valid?
assert t.errors[:title].empty?
assert_predicate t, :valid?
assert_predicate t.errors[:title], :empty?
end
def test_validate_format_with_formatted_message
Topic.validates_format_of(:title, with: /\AValid Title\z/, message: "can't be %{value}")
t = Topic.new(title: "Invalid title")
assert t.invalid?
assert_predicate t, :invalid?
assert_equal ["can't be Invalid title"], t.errors[:title]
end
@ -114,10 +114,10 @@ def test_validates_format_of_with_lambda
t = Topic.new
t.title = "digit"
t.content = "Pixies"
assert t.invalid?
assert_predicate t, :invalid?
t.content = "1234"
assert t.valid?
assert_predicate t, :valid?
end
def test_validates_format_of_without_lambda
@ -126,10 +126,10 @@ def test_validates_format_of_without_lambda
t = Topic.new
t.title = "characters"
t.content = "1234"
assert t.invalid?
assert_predicate t, :invalid?
t.content = "Pixies"
assert t.valid?
assert_predicate t, :valid?
end
def test_validates_format_of_for_ruby_class
@ -137,12 +137,12 @@ def test_validates_format_of_for_ruby_class
p = Person.new
p.karma = "Pixies"
assert p.invalid?
assert_predicate p, :invalid?
assert_equal ["is invalid"], p.errors[:karma]
p.karma = "1234"
assert p.valid?
assert_predicate p, :valid?
ensure
Person.clear_validators!
end

@ -13,61 +13,61 @@ def teardown
def test_validates_inclusion_of_range
Topic.validates_inclusion_of(:title, in: "aaa".."bbb")
assert Topic.new("title" => "bbc", "content" => "abc").invalid?
assert Topic.new("title" => "aa", "content" => "abc").invalid?
assert Topic.new("title" => "aaab", "content" => "abc").invalid?
assert Topic.new("title" => "aaa", "content" => "abc").valid?
assert Topic.new("title" => "abc", "content" => "abc").valid?
assert Topic.new("title" => "bbb", "content" => "abc").valid?
assert_predicate Topic.new("title" => "bbc", "content" => "abc"), :invalid?
assert_predicate Topic.new("title" => "aa", "content" => "abc"), :invalid?
assert_predicate Topic.new("title" => "aaab", "content" => "abc"), :invalid?
assert_predicate Topic.new("title" => "aaa", "content" => "abc"), :valid?
assert_predicate Topic.new("title" => "abc", "content" => "abc"), :valid?
assert_predicate Topic.new("title" => "bbb", "content" => "abc"), :valid?
end
def test_validates_inclusion_of_time_range
range_begin = 1.year.ago
range_end = Time.now
Topic.validates_inclusion_of(:created_at, in: range_begin..range_end)
assert Topic.new(title: "aaa", created_at: 2.years.ago).invalid?
assert Topic.new(title: "aaa", created_at: 3.months.ago).valid?
assert Topic.new(title: "aaa", created_at: 37.weeks.from_now).invalid?
assert Topic.new(title: "aaa", created_at: range_begin).valid?
assert Topic.new(title: "aaa", created_at: range_end).valid?
assert_predicate Topic.new(title: "aaa", created_at: 2.years.ago), :invalid?
assert_predicate Topic.new(title: "aaa", created_at: 3.months.ago), :valid?
assert_predicate Topic.new(title: "aaa", created_at: 37.weeks.from_now), :invalid?
assert_predicate Topic.new(title: "aaa", created_at: range_begin), :valid?
assert_predicate Topic.new(title: "aaa", created_at: range_end), :valid?
end
def test_validates_inclusion_of_date_range
range_begin = 1.year.until(Date.today)
range_end = Date.today
Topic.validates_inclusion_of(:created_at, in: range_begin..range_end)
assert Topic.new(title: "aaa", created_at: 2.years.until(Date.today)).invalid?
assert Topic.new(title: "aaa", created_at: 3.months.until(Date.today)).valid?
assert Topic.new(title: "aaa", created_at: 37.weeks.since(Date.today)).invalid?
assert Topic.new(title: "aaa", created_at: 1.year.until(Date.today)).valid?
assert Topic.new(title: "aaa", created_at: Date.today).valid?
assert Topic.new(title: "aaa", created_at: range_begin).valid?
assert Topic.new(title: "aaa", created_at: range_end).valid?
assert_predicate Topic.new(title: "aaa", created_at: 2.years.until(Date.today)), :invalid?
assert_predicate Topic.new(title: "aaa", created_at: 3.months.until(Date.today)), :valid?
assert_predicate Topic.new(title: "aaa", created_at: 37.weeks.since(Date.today)), :invalid?
assert_predicate Topic.new(title: "aaa", created_at: 1.year.until(Date.today)), :valid?
assert_predicate Topic.new(title: "aaa", created_at: Date.today), :valid?
assert_predicate Topic.new(title: "aaa", created_at: range_begin), :valid?
assert_predicate Topic.new(title: "aaa", created_at: range_end), :valid?
end
def test_validates_inclusion_of_date_time_range
range_begin = 1.year.until(DateTime.current)
range_end = DateTime.current
Topic.validates_inclusion_of(:created_at, in: range_begin..range_end)
assert Topic.new(title: "aaa", created_at: 2.years.until(DateTime.current)).invalid?
assert Topic.new(title: "aaa", created_at: 3.months.until(DateTime.current)).valid?
assert Topic.new(title: "aaa", created_at: 37.weeks.since(DateTime.current)).invalid?
assert Topic.new(title: "aaa", created_at: range_begin).valid?
assert Topic.new(title: "aaa", created_at: range_end).valid?
assert_predicate Topic.new(title: "aaa", created_at: 2.years.until(DateTime.current)), :invalid?
assert_predicate Topic.new(title: "aaa", created_at: 3.months.until(DateTime.current)), :valid?
assert_predicate Topic.new(title: "aaa", created_at: 37.weeks.since(DateTime.current)), :invalid?
assert_predicate Topic.new(title: "aaa", created_at: range_begin), :valid?
assert_predicate Topic.new(title: "aaa", created_at: range_end), :valid?
end
def test_validates_inclusion_of
Topic.validates_inclusion_of(:title, in: %w( a b c d e f g ))
assert Topic.new("title" => "a!", "content" => "abc").invalid?
assert Topic.new("title" => "a b", "content" => "abc").invalid?
assert Topic.new("title" => nil, "content" => "def").invalid?
assert_predicate Topic.new("title" => "a!", "content" => "abc"), :invalid?
assert_predicate Topic.new("title" => "a b", "content" => "abc"), :invalid?
assert_predicate Topic.new("title" => nil, "content" => "def"), :invalid?
t = Topic.new("title" => "a", "content" => "I know you are but what am I?")
assert t.valid?
assert_predicate t, :valid?
t.title = "uhoh"
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["is not included in the list"], t.errors[:title]
assert_raise(ArgumentError) { Topic.validates_inclusion_of(:title, in: nil) }
@ -81,30 +81,30 @@ def test_validates_inclusion_of
def test_validates_inclusion_of_with_allow_nil
Topic.validates_inclusion_of(:title, in: %w( a b c d e f g ), allow_nil: true)
assert Topic.new("title" => "a!", "content" => "abc").invalid?
assert Topic.new("title" => "", "content" => "abc").invalid?
assert Topic.new("title" => nil, "content" => "abc").valid?
assert_predicate Topic.new("title" => "a!", "content" => "abc"), :invalid?
assert_predicate Topic.new("title" => "", "content" => "abc"), :invalid?
assert_predicate Topic.new("title" => nil, "content" => "abc"), :valid?
end
def test_validates_inclusion_of_with_formatted_message
Topic.validates_inclusion_of(:title, in: %w( a b c d e f g ), message: "option %{value} is not in the list")
assert Topic.new("title" => "a", "content" => "abc").valid?
assert_predicate Topic.new("title" => "a", "content" => "abc"), :valid?
t = Topic.new("title" => "uhoh", "content" => "abc")
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["option uhoh is not in the list"], t.errors[:title]
end
def test_validates_inclusion_of_with_within_option
Topic.validates_inclusion_of(:title, within: %w( a b c d e f g ))
assert Topic.new("title" => "a", "content" => "abc").valid?
assert_predicate Topic.new("title" => "a", "content" => "abc"), :valid?
t = Topic.new("title" => "uhoh", "content" => "abc")
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
end
def test_validates_inclusion_of_for_ruby_class
@ -112,12 +112,12 @@ def test_validates_inclusion_of_for_ruby_class
p = Person.new
p.karma = "Lifo"
assert p.invalid?
assert_predicate p, :invalid?
assert_equal ["is not included in the list"], p.errors[:karma]
p.karma = "monkey"
assert p.valid?
assert_predicate p, :valid?
ensure
Person.clear_validators!
end
@ -128,10 +128,10 @@ def test_validates_inclusion_of_with_lambda
t = Topic.new
t.title = "wasabi"
t.author_name = "sikachu"
assert t.invalid?
assert_predicate t, :invalid?
t.title = "elephant"
assert t.valid?
assert_predicate t, :valid?
end
def test_validates_inclusion_of_with_symbol
@ -144,7 +144,7 @@ def p.available_karmas
%w()
end
assert p.invalid?
assert_predicate p, :invalid?
assert_equal ["is not included in the list"], p.errors[:karma]
p = Person.new
@ -154,7 +154,7 @@ def p.available_karmas
%w(Lifo)
end
assert p.valid?
assert_predicate p, :valid?
ensure
Person.clear_validators!
end

@ -13,153 +13,153 @@ def teardown
def test_validates_length_of_with_allow_nil
Topic.validates_length_of(:title, is: 5, allow_nil: true)
assert Topic.new("title" => "ab").invalid?
assert Topic.new("title" => "").invalid?
assert Topic.new("title" => nil).valid?
assert Topic.new("title" => "abcde").valid?
assert_predicate Topic.new("title" => "ab"), :invalid?
assert_predicate Topic.new("title" => ""), :invalid?
assert_predicate Topic.new("title" => nil), :valid?
assert_predicate Topic.new("title" => "abcde"), :valid?
end
def test_validates_length_of_with_allow_blank
Topic.validates_length_of(:title, is: 5, allow_blank: true)
assert Topic.new("title" => "ab").invalid?
assert Topic.new("title" => "").valid?
assert Topic.new("title" => nil).valid?
assert Topic.new("title" => "abcde").valid?
assert_predicate Topic.new("title" => "ab"), :invalid?
assert_predicate Topic.new("title" => ""), :valid?
assert_predicate Topic.new("title" => nil), :valid?
assert_predicate Topic.new("title" => "abcde"), :valid?
end
def test_validates_length_of_using_minimum
Topic.validates_length_of :title, minimum: 5
t = Topic.new("title" => "valid", "content" => "whatever")
assert t.valid?
assert_predicate t, :valid?
t.title = "not"
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["is too short (minimum is 5 characters)"], t.errors[:title]
t.title = ""
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["is too short (minimum is 5 characters)"], t.errors[:title]
t.title = nil
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["is too short (minimum is 5 characters)"], t.errors["title"]
end
def test_validates_length_of_using_maximum_should_allow_nil
Topic.validates_length_of :title, maximum: 10
t = Topic.new
assert t.valid?
assert_predicate t, :valid?
end
def test_optionally_validates_length_of_using_minimum
Topic.validates_length_of :title, minimum: 5, allow_nil: true
t = Topic.new("title" => "valid", "content" => "whatever")
assert t.valid?
assert_predicate t, :valid?
t.title = nil
assert t.valid?
assert_predicate t, :valid?
end
def test_validates_length_of_using_maximum
Topic.validates_length_of :title, maximum: 5
t = Topic.new("title" => "valid", "content" => "whatever")
assert t.valid?
assert_predicate t, :valid?
t.title = "notvalid"
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["is too long (maximum is 5 characters)"], t.errors[:title]
t.title = ""
assert t.valid?
assert_predicate t, :valid?
end
def test_optionally_validates_length_of_using_maximum
Topic.validates_length_of :title, maximum: 5, allow_nil: true
t = Topic.new("title" => "valid", "content" => "whatever")
assert t.valid?
assert_predicate t, :valid?
t.title = nil
assert t.valid?
assert_predicate t, :valid?
end
def test_validates_length_of_using_within
Topic.validates_length_of(:title, :content, within: 3..5)
t = Topic.new("title" => "a!", "content" => "I'm ooooooooh so very long")
assert t.invalid?
assert_predicate t, :invalid?
assert_equal ["is too short (minimum is 3 characters)"], t.errors[:title]
assert_equal ["is too long (maximum is 5 characters)"], t.errors[:content]
t.title = nil
t.content = nil
assert t.invalid?
assert_predicate t, :invalid?
assert_equal ["is too short (minimum is 3 characters)"], t.errors[:title]
assert_equal ["is too short (minimum is 3 characters)"], t.errors[:content]
t.title = "abe"
t.content = "mad"
assert t.valid?
assert_predicate t, :valid?
end
def test_validates_length_of_using_within_with_exclusive_range
Topic.validates_length_of(:title, within: 4...10)
t = Topic.new("title" => "9 chars!!")
assert t.valid?
assert_predicate t, :valid?
t.title = "Now I'm 10"
assert t.invalid?
assert_predicate t, :invalid?
assert_equal ["is too long (maximum is 9 characters)"], t.errors[:title]
t.title = "Four"
assert t.valid?
assert_predicate t, :valid?
end
def test_optionally_validates_length_of_using_within
Topic.validates_length_of :title, :content, within: 3..5, allow_nil: true
t = Topic.new("title" => "abc", "content" => "abcd")
assert t.valid?
assert_predicate t, :valid?
t.title = nil
assert t.valid?
assert_predicate t, :valid?
end
def test_validates_length_of_using_is
Topic.validates_length_of :title, is: 5
t = Topic.new("title" => "valid", "content" => "whatever")
assert t.valid?
assert_predicate t, :valid?
t.title = "notvalid"
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["is the wrong length (should be 5 characters)"], t.errors[:title]
t.title = ""
assert t.invalid?
assert_predicate t, :invalid?
t.title = nil
assert t.invalid?
assert_predicate t, :invalid?
end
def test_optionally_validates_length_of_using_is
Topic.validates_length_of :title, is: 5, allow_nil: true
t = Topic.new("title" => "valid", "content" => "whatever")
assert t.valid?
assert_predicate t, :valid?
t.title = nil
assert t.valid?
assert_predicate t, :valid?
end
def test_validates_length_of_using_bignum
@ -187,45 +187,45 @@ def test_validates_length_of_nasty_params
def test_validates_length_of_custom_errors_for_minimum_with_message
Topic.validates_length_of(:title, minimum: 5, message: "boo %{count}")
t = Topic.new("title" => "uhoh", "content" => "whatever")
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["boo 5"], t.errors[:title]
end
def test_validates_length_of_custom_errors_for_minimum_with_too_short
Topic.validates_length_of(:title, minimum: 5, too_short: "hoo %{count}")
t = Topic.new("title" => "uhoh", "content" => "whatever")
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["hoo 5"], t.errors[:title]
end
def test_validates_length_of_custom_errors_for_maximum_with_message
Topic.validates_length_of(:title, maximum: 5, message: "boo %{count}")
t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["boo 5"], t.errors[:title]
end
def test_validates_length_of_custom_errors_for_in
Topic.validates_length_of(:title, in: 10..20, message: "hoo %{count}")
t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["hoo 10"], t.errors["title"]
t = Topic.new("title" => "uhohuhohuhohuhohuhohuhohuhohuhoh", "content" => "whatever")
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["hoo 20"], t.errors["title"]
end
def test_validates_length_of_custom_errors_for_maximum_with_too_long
Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}")
t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["hoo 5"], t.errors["title"]
end
@ -233,29 +233,29 @@ def test_validates_length_of_custom_errors_for_both_too_short_and_too_long
Topic.validates_length_of :title, minimum: 3, maximum: 5, too_short: "too short", too_long: "too long"
t = Topic.new(title: "a")
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["too short"], t.errors["title"]
t = Topic.new(title: "aaaaaa")
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["too long"], t.errors["title"]
end
def test_validates_length_of_custom_errors_for_is_with_message
Topic.validates_length_of(:title, is: 5, message: "boo %{count}")
t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["boo 5"], t.errors["title"]
end
def test_validates_length_of_custom_errors_for_is_with_wrong_length
Topic.validates_length_of(:title, is: 5, wrong_length: "hoo %{count}")
t = Topic.new("title" => "uhohuhoh", "content" => "whatever")
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["hoo 5"], t.errors["title"]
end
@ -263,11 +263,11 @@ def test_validates_length_of_using_minimum_utf8
Topic.validates_length_of :title, minimum: 5
t = Topic.new("title" => "一二三四五", "content" => "whatever")
assert t.valid?
assert_predicate t, :valid?
t.title = "一二三四"
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["is too short (minimum is 5 characters)"], t.errors["title"]
end
@ -275,11 +275,11 @@ def test_validates_length_of_using_maximum_utf8
Topic.validates_length_of :title, maximum: 5
t = Topic.new("title" => "一二三四五", "content" => "whatever")
assert t.valid?
assert_predicate t, :valid?
t.title = "一二34五六"
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["is too long (maximum is 5 characters)"], t.errors["title"]
end
@ -287,12 +287,12 @@ def test_validates_length_of_using_within_utf8
Topic.validates_length_of(:title, :content, within: 3..5)
t = Topic.new("title" => "一二", "content" => "12三四五六七")
assert t.invalid?
assert_predicate t, :invalid?
assert_equal ["is too short (minimum is 3 characters)"], t.errors[:title]
assert_equal ["is too long (maximum is 5 characters)"], t.errors[:content]
t.title = "一二三"
t.content = "12三"
assert t.valid?
assert_predicate t, :valid?
end
def test_optionally_validates_length_of_using_within_utf8
@ -312,11 +312,11 @@ def test_validates_length_of_using_is_utf8
Topic.validates_length_of :title, is: 5
t = Topic.new("title" => "一二345", "content" => "whatever")
assert t.valid?
assert_predicate t, :valid?
t.title = "一二345六"
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["is the wrong length (should be 5 characters)"], t.errors["title"]
end
@ -324,11 +324,11 @@ def test_validates_length_of_for_integer
Topic.validates_length_of(:approved, is: 4)
t = Topic.new("title" => "uhohuhoh", "content" => "whatever", approved: 1)
assert t.invalid?
assert t.errors[:approved].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:approved], :any?
t = Topic.new("title" => "uhohuhoh", "content" => "whatever", approved: 1234)
assert t.valid?
assert_predicate t, :valid?
end
def test_validates_length_of_for_ruby_class
@ -336,12 +336,12 @@ def test_validates_length_of_for_ruby_class
p = Person.new
p.karma = "Pix"
assert p.invalid?
assert_predicate p, :invalid?
assert_equal ["is too short (minimum is 5 characters)"], p.errors[:karma]
p.karma = "The Smiths"
assert p.valid?
assert_predicate p, :valid?
ensure
Person.clear_validators!
end
@ -350,80 +350,80 @@ def test_validates_length_of_for_infinite_maxima
Topic.validates_length_of(:title, within: 5..Float::INFINITY)
t = Topic.new("title" => "1234")
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
t.title = "12345"
assert t.valid?
assert_predicate t, :valid?
Topic.validates_length_of(:author_name, maximum: Float::INFINITY)
assert t.valid?
assert_predicate t, :valid?
t.author_name = "A very long author name that should still be valid." * 100
assert t.valid?
assert_predicate t, :valid?
end
def test_validates_length_of_using_maximum_should_not_allow_nil_when_nil_not_allowed
Topic.validates_length_of :title, maximum: 10, allow_nil: false
t = Topic.new
assert t.invalid?
assert_predicate t, :invalid?
end
def test_validates_length_of_using_maximum_should_not_allow_nil_and_empty_string_when_blank_not_allowed
Topic.validates_length_of :title, maximum: 10, allow_blank: false
t = Topic.new
assert t.invalid?
assert_predicate t, :invalid?
t.title = ""
assert t.invalid?
assert_predicate t, :invalid?
end
def test_validates_length_of_using_both_minimum_and_maximum_should_not_allow_nil
Topic.validates_length_of :title, minimum: 5, maximum: 10
t = Topic.new
assert t.invalid?
assert_predicate t, :invalid?
end
def test_validates_length_of_using_minimum_0_should_not_allow_nil
Topic.validates_length_of :title, minimum: 0
t = Topic.new
assert t.invalid?
assert_predicate t, :invalid?
t.title = ""
assert t.valid?
assert_predicate t, :valid?
end
def test_validates_length_of_using_is_0_should_not_allow_nil
Topic.validates_length_of :title, is: 0
t = Topic.new
assert t.invalid?
assert_predicate t, :invalid?
t.title = ""
assert t.valid?
assert_predicate t, :valid?
end
def test_validates_with_diff_in_option
Topic.validates_length_of(:title, is: 5)
Topic.validates_length_of(:title, is: 5, if: Proc.new { false })
assert Topic.new("title" => "david").valid?
assert Topic.new("title" => "david2").invalid?
assert_predicate Topic.new("title" => "david"), :valid?
assert_predicate Topic.new("title" => "david2"), :invalid?
end
def test_validates_length_of_using_proc_as_maximum
Topic.validates_length_of :title, maximum: ->(model) { 5 }
t = Topic.new("title" => "valid", "content" => "whatever")
assert t.valid?
assert_predicate t, :valid?
t.title = "notvalid"
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["is too long (maximum is 5 characters)"], t.errors[:title]
t.title = ""
assert t.valid?
assert_predicate t, :valid?
end
def test_validates_length_of_using_proc_as_maximum_with_model_method
@ -431,14 +431,14 @@ def test_validates_length_of_using_proc_as_maximum_with_model_method
Topic.validates_length_of :title, maximum: Proc.new(&:max_title_length)
t = Topic.new("title" => "valid", "content" => "whatever")
assert t.valid?
assert_predicate t, :valid?
t.title = "notvalid"
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["is too long (maximum is 5 characters)"], t.errors[:title]
t.title = ""
assert t.valid?
assert_predicate t, :valid?
end
end

@ -237,13 +237,13 @@ def test_validates_numericality_with_numeric_message
Topic.validates_numericality_of :approved, less_than: 4, message: "smaller than %{count}"
topic = Topic.new("title" => "numeric test", "approved" => 10)
assert !topic.valid?
assert_not_predicate topic, :valid?
assert_equal ["smaller than 4"], topic.errors[:approved]
Topic.validates_numericality_of :approved, greater_than: 4, message: "greater than %{count}"
topic = Topic.new("title" => "numeric test", "approved" => 1)
assert !topic.valid?
assert_not_predicate topic, :valid?
assert_equal ["greater than 4"], topic.errors[:approved]
end
@ -252,12 +252,12 @@ def test_validates_numericality_of_for_ruby_class
p = Person.new
p.karma = "Pix"
assert p.invalid?
assert_predicate p, :invalid?
assert_equal ["is not a number"], p.errors[:karma]
p.karma = "1234"
assert p.valid?
assert_predicate p, :valid?
ensure
Person.clear_validators!
end
@ -268,7 +268,7 @@ def test_validates_numericality_with_exponent_number
topic = Topic.new
topic.approved = (base + 1).to_s
assert topic.invalid?
assert_predicate topic, :invalid?
end
def test_validates_numericality_with_invalid_args

@ -17,25 +17,25 @@ def test_validate_presences
Topic.validates_presence_of(:title, :content)
t = Topic.new
assert t.invalid?
assert_predicate t, :invalid?
assert_equal ["can't be blank"], t.errors[:title]
assert_equal ["can't be blank"], t.errors[:content]
t.title = "something"
t.content = " "
assert t.invalid?
assert_predicate t, :invalid?
assert_equal ["can't be blank"], t.errors[:content]
t.content = "like stuff"
assert t.valid?
assert_predicate t, :valid?
end
def test_accepts_array_arguments
Topic.validates_presence_of %w(title content)
t = Topic.new
assert t.invalid?
assert_predicate t, :invalid?
assert_equal ["can't be blank"], t.errors[:title]
assert_equal ["can't be blank"], t.errors[:content]
end
@ -43,7 +43,7 @@ def test_accepts_array_arguments
def test_validates_acceptance_of_with_custom_error_using_quotes
Person.validates_presence_of :karma, message: "This string contains 'single' and \"double\" quotes"
p = Person.new
assert p.invalid?
assert_predicate p, :invalid?
assert_equal "This string contains 'single' and \"double\" quotes", p.errors[:karma].last
end
@ -51,24 +51,24 @@ def test_validates_presence_of_for_ruby_class
Person.validates_presence_of :karma
p = Person.new
assert p.invalid?
assert_predicate p, :invalid?
assert_equal ["can't be blank"], p.errors[:karma]
p.karma = "Cold"
assert p.valid?
assert_predicate p, :valid?
end
def test_validates_presence_of_for_ruby_class_with_custom_reader
CustomReader.validates_presence_of :karma
p = CustomReader.new
assert p.invalid?
assert_predicate p, :invalid?
assert_equal ["can't be blank"], p.errors[:karma]
p[:karma] = "Cold"
assert p.valid?
assert_predicate p, :valid?
end
def test_validates_presence_of_with_allow_nil_option
@ -78,7 +78,7 @@ def test_validates_presence_of_with_allow_nil_option
assert t.valid?, t.errors.full_messages
t.title = ""
assert t.invalid?
assert_predicate t, :invalid?
assert_equal ["can't be blank"], t.errors[:title]
t.title = " "

@ -37,7 +37,7 @@ def test_validates_with_attribute_specified_as_string
person = Person.new
person.title = 123
assert person.valid?
assert_predicate person, :valid?
end
def test_validates_with_built_in_validation_and_options
@ -71,7 +71,7 @@ def test_validates_with_if_as_local_conditions
def test_validates_with_if_as_shared_conditions
Person.validates :karma, presence: true, email: true, if: :condition_is_false
person = Person.new
assert person.valid?
assert_predicate person, :valid?
end
def test_validates_with_unless_as_local_conditions
@ -84,40 +84,40 @@ def test_validates_with_unless_as_local_conditions
def test_validates_with_unless_shared_conditions
Person.validates :karma, presence: true, email: true, unless: :condition_is_true
person = Person.new
assert person.valid?
assert_predicate person, :valid?
end
def test_validates_with_allow_nil_shared_conditions
Person.validates :karma, length: { minimum: 20 }, email: true, allow_nil: true
person = Person.new
assert person.valid?
assert_predicate person, :valid?
end
def test_validates_with_regexp
Person.validates :karma, format: /positive|negative/
person = Person.new
assert person.invalid?
assert_predicate person, :invalid?
assert_equal ["is invalid"], person.errors[:karma]
person.karma = "positive"
assert person.valid?
assert_predicate person, :valid?
end
def test_validates_with_array
Person.validates :gender, inclusion: %w(m f)
person = Person.new
assert person.invalid?
assert_predicate person, :invalid?
assert_equal ["is not included in the list"], person.errors[:gender]
person.gender = "m"
assert person.valid?
assert_predicate person, :valid?
end
def test_validates_with_range
Person.validates :karma, length: 6..20
person = Person.new
assert person.invalid?
assert_predicate person, :invalid?
assert_equal ["is too short (minimum is 6 characters)"], person.errors[:karma]
person.karma = "something"
assert person.valid?
assert_predicate person, :valid?
end
def test_validates_with_validator_class_and_options
@ -159,7 +159,7 @@ def test_defining_extra_default_keys_for_validates
topic = Topic.new
topic.title = "What's happening"
topic.title_confirmation = "Not this"
assert !topic.valid?
assert_not_predicate topic, :valid?
assert_equal ["Y U NO CONFIRM"], topic.errors[:title_confirmation]
end
end

@ -65,7 +65,7 @@ def check_validity!
test "with multiple classes" do
Topic.validates_with(ValidatorThatAddsErrors, OtherValidatorThatAddsErrors)
topic = Topic.new
assert topic.invalid?
assert_predicate topic, :invalid?
assert_includes topic.errors[:base], ERROR_MESSAGE
assert_includes topic.errors[:base], OTHER_ERROR_MESSAGE
end
@ -79,21 +79,21 @@ def check_validity!
validator.expect(:is_a?, false, [String])
Topic.validates_with(validator, if: :condition_is_true, foo: :bar)
assert topic.valid?
assert_predicate topic, :valid?
validator.verify
end
test "validates_with with options" do
Topic.validates_with(ValidatorThatValidatesOptions, field: :first_name)
topic = Topic.new
assert topic.invalid?
assert_predicate topic, :invalid?
assert_includes topic.errors[:base], ERROR_MESSAGE
end
test "validates_with each validator" do
Topic.validates_with(ValidatorPerEachAttribute, attributes: [:title, :content])
topic = Topic.new title: "Title", content: "Content"
assert topic.invalid?
assert_predicate topic, :invalid?
assert_equal ["Value is Title"], topic.errors[:title]
assert_equal ["Value is Content"], topic.errors[:content]
end
@ -113,28 +113,28 @@ def check_validity!
test "each validator skip nil values if :allow_nil is set to true" do
Topic.validates_with(ValidatorPerEachAttribute, attributes: [:title, :content], allow_nil: true)
topic = Topic.new content: ""
assert topic.invalid?
assert topic.errors[:title].empty?
assert_predicate topic, :invalid?
assert_predicate topic.errors[:title], :empty?
assert_equal ["Value is "], topic.errors[:content]
end
test "each validator skip blank values if :allow_blank is set to true" do
Topic.validates_with(ValidatorPerEachAttribute, attributes: [:title, :content], allow_blank: true)
topic = Topic.new content: ""
assert topic.valid?
assert topic.errors[:title].empty?
assert topic.errors[:content].empty?
assert_predicate topic, :valid?
assert_predicate topic.errors[:title], :empty?
assert_predicate topic.errors[:content], :empty?
end
test "validates_with can validate with an instance method" do
Topic.validates :title, with: :my_validation
topic = Topic.new title: "foo"
assert topic.valid?
assert topic.errors[:title].empty?
assert_predicate topic, :valid?
assert_predicate topic.errors[:title], :empty?
topic = Topic.new
assert !topic.valid?
assert_not_predicate topic, :valid?
assert_equal ["is missing"], topic.errors[:title]
end
@ -142,8 +142,8 @@ def check_validity!
Topic.validates :title, :content, with: :my_validation_with_arg
topic = Topic.new title: "foo"
assert !topic.valid?
assert topic.errors[:title].empty?
assert_not_predicate topic, :valid?
assert_predicate topic.errors[:title], :empty?
assert_equal ["is missing"], topic.errors[:content]
end
end

@ -30,7 +30,7 @@ def test_single_field_validation
def test_single_attr_validation_and_error_msg
r = Reply.new
r.title = "There's no content!"
assert r.invalid?
assert_predicate r, :invalid?
assert r.errors[:content].any?, "A reply without content should mark that attribute as invalid"
assert_equal ["is Empty"], r.errors["content"], "A reply without content should contain an error"
assert_equal 1, r.errors.count
@ -38,7 +38,7 @@ def test_single_attr_validation_and_error_msg
def test_double_attr_validation_and_error_msg
r = Reply.new
assert r.invalid?
assert_predicate r, :invalid?
assert r.errors[:title].any?, "A reply without title should mark that attribute as invalid"
assert_equal ["is Empty"], r.errors["title"], "A reply without title should contain an error"
@ -111,8 +111,8 @@ def test_errors_on_base_with_symbol_message
def test_errors_empty_after_errors_on_check
t = Topic.new
assert t.errors[:id].empty?
assert t.errors.empty?
assert_predicate t.errors[:id], :empty?
assert_predicate t.errors, :empty?
end
def test_validates_each
@ -122,7 +122,7 @@ def test_validates_each
hits += 1
end
t = Topic.new("title" => "valid", "content" => "whatever")
assert t.invalid?
assert_predicate t, :invalid?
assert_equal 4, hits
assert_equal %w(gotcha gotcha), t.errors[:title]
assert_equal %w(gotcha gotcha), t.errors[:content]
@ -135,7 +135,7 @@ def test_validates_each_custom_reader
hits += 1
end
t = CustomReader.new("title" => "valid", "content" => "whatever")
assert t.invalid?
assert_predicate t, :invalid?
assert_equal 4, hits
assert_equal %w(gotcha gotcha), t.errors[:title]
assert_equal %w(gotcha gotcha), t.errors[:content]
@ -146,16 +146,16 @@ def test_validates_each_custom_reader
def test_validate_block
Topic.validate { errors.add("title", "will never be valid") }
t = Topic.new("title" => "Title", "content" => "whatever")
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["will never be valid"], t.errors["title"]
end
def test_validate_block_with_params
Topic.validate { |topic| topic.errors.add("title", "will never be valid") }
t = Topic.new("title" => "Title", "content" => "whatever")
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
assert_equal ["will never be valid"], t.errors["title"]
end
@ -214,7 +214,7 @@ def validator_c
def test_errors_conversions
Topic.validates_presence_of %w(title content)
t = Topic.new
assert t.invalid?
assert_predicate t, :invalid?
xml = t.errors.to_xml
assert_match %r{<errors>}, xml
@ -232,14 +232,14 @@ def test_validation_order
Topic.validates_length_of :title, minimum: 2
t = Topic.new("title" => "")
assert t.invalid?
assert_predicate t, :invalid?
assert_equal "can't be blank", t.errors["title"].first
Topic.validates_presence_of :title, :author_name
Topic.validate { errors.add("author_email_address", "will never be valid") }
Topic.validates_length_of :title, :content, minimum: 2
t = Topic.new title: ""
assert t.invalid?
assert_predicate t, :invalid?
assert_equal :title, key = t.errors.keys[0]
assert_equal "can't be blank", t.errors[key][0]
@ -258,8 +258,8 @@ def test_validation_with_if_and_on
t = Topic.new(title: "")
# If block should not fire
assert t.valid?
assert t.author_name.nil?
assert_predicate t, :valid?
assert_predicate t.author_name, :nil?
# If block should fire
assert t.invalid?(:update)
@ -270,18 +270,18 @@ def test_invalid_should_be_the_opposite_of_valid
Topic.validates_presence_of :title
t = Topic.new
assert t.invalid?
assert t.errors[:title].any?
assert_predicate t, :invalid?
assert_predicate t.errors[:title], :any?
t.title = "Things are going to change"
assert !t.invalid?
assert_not_predicate t, :invalid?
end
def test_validation_with_message_as_proc
Topic.validates_presence_of(:title, message: proc { "no blanks here".upcase })
t = Topic.new
assert t.invalid?
assert_predicate t, :invalid?
assert_equal ["NO BLANKS HERE"], t.errors[:title]
end
@ -331,13 +331,13 @@ def test_validations_on_the_instance_level
Topic.validates :content, length: { minimum: 10 }
topic = Topic.new
assert topic.invalid?
assert_predicate topic, :invalid?
assert_equal 3, topic.errors.size
topic.title = "Some Title"
topic.author_name = "Some Author"
topic.content = "Some Content Whose Length is more than 10."
assert topic.valid?
assert_predicate topic, :valid?
end
def test_validate
@ -381,7 +381,7 @@ def test_strict_validation_in_validates
def test_strict_validation_not_fails
Topic.validates :title, strict: true, presence: true
assert Topic.new(title: "hello").valid?
assert_predicate Topic.new(title: "hello"), :valid?
end
def test_strict_validation_particular_validator
@ -414,7 +414,7 @@ def test_validates_with_bang
def test_validates_with_false_hash_value
Topic.validates :title, presence: false
assert Topic.new.valid?
assert_predicate Topic.new, :valid?
end
def test_strict_validation_error_message
@ -439,19 +439,19 @@ def test_dup_validity_is_independent
duped = topic.dup
duped.title = nil
assert duped.invalid?
assert_predicate duped, :invalid?
topic.title = nil
duped.title = "Mathematics"
assert topic.invalid?
assert duped.valid?
assert_predicate topic, :invalid?
assert_predicate duped, :valid?
end
def test_validation_with_message_as_proc_that_takes_a_record_as_a_parameter
Topic.validates_presence_of(:title, message: proc { |record| "You have failed me for the last time, #{record.author_name}." })
t = Topic.new(author_name: "Admiral")
assert t.invalid?
assert_predicate t, :invalid?
assert_equal ["You have failed me for the last time, Admiral."], t.errors[:title]
end
@ -459,7 +459,7 @@ def test_validation_with_message_as_proc_that_takes_record_and_data_as_a_paramet
Topic.validates_presence_of(:title, message: proc { |record, data| "#{data[:attribute]} is missing. You have failed me for the last time, #{record.author_name}." })
t = Topic.new(author_name: "Admiral")
assert t.invalid?
assert_predicate t, :invalid?
assert_equal ["Title is missing. You have failed me for the last time, Admiral."], t.errors[:title]
end
end

@ -169,13 +169,13 @@ class FixtureClassNotFound < ActiveRecord::ActiveRecordError #:nodoc:
# self.use_transactional_tests = true
#
# test "godzilla" do
# assert !Foo.all.empty?
# assert_not_empty Foo.all
# Foo.destroy_all
# assert Foo.all.empty?
# assert_empty Foo.all
# end
#
# test "godzilla aftermath" do
# assert !Foo.all.empty?
# assert_not_empty Foo.all
# end
# end
#

@ -78,7 +78,7 @@ def test_indexes
idx_name = "accounts_idx"
indexes = @connection.indexes("accounts")
assert indexes.empty?
assert_predicate indexes, :empty?
@connection.add_index :accounts, :firm_id, name: idx_name
indexes = @connection.indexes("accounts")
@ -368,16 +368,16 @@ def setup
unless in_memory_db?
test "transaction state is reset after a reconnect" do
@connection.begin_transaction
assert @connection.transaction_open?
assert_predicate @connection, :transaction_open?
@connection.reconnect!
assert !@connection.transaction_open?
assert_not_predicate @connection, :transaction_open?
end
test "transaction state is reset after a disconnect" do
@connection.begin_transaction
assert @connection.transaction_open?
assert_predicate @connection, :transaction_open?
@connection.disconnect!
assert !@connection.transaction_open?
assert_not_predicate @connection, :transaction_open?
end
end

@ -14,8 +14,8 @@ def test_columns_include_collation_different_from_table
end
def test_case_sensitive
assert !CollationTest.columns_hash["string_ci_column"].case_sensitive?
assert CollationTest.columns_hash["string_cs_column"].case_sensitive?
assert_not_predicate CollationTest.columns_hash["string_ci_column"], :case_sensitive?
assert_predicate CollationTest.columns_hash["string_cs_column"], :case_sensitive?
end
def test_case_insensitive_comparison_for_ci_column

@ -40,29 +40,29 @@ def test_truncate
end
def test_no_automatic_reconnection_after_timeout
assert @connection.active?
assert_predicate @connection, :active?
@connection.update("set @@wait_timeout=1")
sleep 2
assert !@connection.active?
assert_not_predicate @connection, :active?
ensure
# Repair all fixture connections so other tests won't break.
@fixture_connections.each(&:verify!)
end
def test_successful_reconnection_after_timeout_with_manual_reconnect
assert @connection.active?
assert_predicate @connection, :active?
@connection.update("set @@wait_timeout=1")
sleep 2
@connection.reconnect!
assert @connection.active?
assert_predicate @connection, :active?
end
def test_successful_reconnection_after_timeout_with_verify
assert @connection.active?
assert_predicate @connection, :active?
@connection.update("set @@wait_timeout=1")
sleep 2
@connection.verify!
assert @connection.active?
assert_predicate @connection, :active?
end
def test_execute_after_disconnect

@ -13,11 +13,11 @@ def test_enum_limit
def test_should_not_be_unsigned
column = EnumTest.columns_hash["enum_column"]
assert_not column.unsigned?
assert_not_predicate column, :unsigned?
end
def test_should_not_be_bigint
column = EnumTest.columns_hash["enum_column"]
assert_not column.bigint?
assert_not_predicate column, :bigint?
end
end

@ -54,7 +54,7 @@ class UnsignedType < ActiveRecord::Base
end
@connection.columns("unsigned_types").select { |c| /^unsigned_/.match?(c.name) }.each do |column|
assert column.unsigned?
assert_predicate column, :unsigned?
end
end

@ -39,12 +39,12 @@ def setup
def test_column
assert_equal :string, @column.type
assert_equal "character varying(255)", @column.sql_type
assert @column.array?
assert_not @type.binary?
assert_predicate @column, :array?
assert_not_predicate @type, :binary?
ratings_column = PgArray.columns_hash["ratings"]
assert_equal :integer, ratings_column.type
assert ratings_column.array?
assert_predicate ratings_column, :array?
end
def test_not_compatible_with_serialize_array
@ -109,7 +109,7 @@ def test_change_column_with_array
assert_equal :text, column.type
assert_equal [], PgArray.column_defaults["snippets"]
assert column.array?
assert_predicate column, :array?
end
def test_change_column_cant_make_non_array_column_to_array
@ -257,7 +257,7 @@ def test_string_quoting_rules_match_pg_behavior
x = PgArray.create!(tags: tags)
x.reload
assert_not x.changed?
assert_not_predicate x, :changed?
end
def test_quoting_non_standard_delimiters
@ -279,7 +279,7 @@ def test_mutate_array
x.reload
assert_equal %w(one two three), x.tags
assert_not x.changed?
assert_not_predicate x, :changed?
end
def test_mutate_value_in_array
@ -290,7 +290,7 @@ def test_mutate_value_in_array
x.reload
assert_equal [{ "a" => "c" }, { "b" => "b" }], x.hstores
assert_not x.changed?
assert_not_predicate x, :changed?
end
def test_datetime_with_timezone_awareness

@ -29,20 +29,20 @@ def test_bit_string_column
column = PostgresqlBitString.columns_hash["a_bit"]
assert_equal :bit, column.type
assert_equal "bit(8)", column.sql_type
assert_not column.array?
assert_not_predicate column, :array?
type = PostgresqlBitString.type_for_attribute("a_bit")
assert_not type.binary?
assert_not_predicate type, :binary?
end
def test_bit_string_varying_column
column = PostgresqlBitString.columns_hash["a_bit_varying"]
assert_equal :bit_varying, column.type
assert_equal "bit varying(4)", column.sql_type
assert_not column.array?
assert_not_predicate column, :array?
type = PostgresqlBitString.type_for_attribute("a_bit_varying")
assert_not type.binary?
assert_not_predicate type, :binary?
end
def test_default

@ -75,7 +75,7 @@ def test_read_nil_value
def test_write_value
data = "\u001F"
record = ByteaDataType.create(payload: data)
assert_not record.new_record?
assert_not_predicate record, :new_record?
assert_equal(data, record.payload)
end
@ -101,14 +101,14 @@ def test_write_binary
data = File.read(File.join(__dir__, "..", "..", "..", "assets", "example.log"))
assert(data.size > 1)
record = ByteaDataType.create(payload: data)
assert_not record.new_record?
assert_not_predicate record, :new_record?
assert_equal(data, record.payload)
assert_equal(data, ByteaDataType.where(id: record.id).first.payload)
end
def test_write_nil
record = ByteaDataType.create(payload: nil)
assert_not record.new_record?
assert_not_predicate record, :new_record?
assert_nil(record.payload)
assert_nil(ByteaDataType.where(id: record.id).first.payload)
end

@ -33,7 +33,7 @@ def test_change_type_with_array
connection.change_column :strings, :somedate, :timestamp, array: true, cast_as: :timestamp
column = connection.columns(:strings).find { |c| c.name == "somedate" }
assert_equal :datetime, column.type
assert column.array?
assert_predicate column, :array?
end
end
end

@ -32,10 +32,10 @@ def test_column
column = Citext.columns_hash["cival"]
assert_equal :citext, column.type
assert_equal "citext", column.sql_type
assert_not column.array?
assert_not_predicate column, :array?
type = Citext.type_for_attribute("cival")
assert_not type.binary?
assert_not_predicate type, :binary?
end
def test_change_table_supports_json

@ -51,10 +51,10 @@ def test_column
column = PostgresqlComposite.columns_hash["address"]
assert_nil column.type
assert_equal "full_address", column.sql_type
assert_not column.array?
assert_not_predicate column, :array?
type = PostgresqlComposite.type_for_attribute("address")
assert_not type.binary?
assert_not_predicate type, :binary?
end
def test_composite_mapping
@ -113,10 +113,10 @@ def test_column
column = PostgresqlComposite.columns_hash["address"]
assert_equal :full_address, column.type
assert_equal "full_address", column.sql_type
assert_not column.array?
assert_not_predicate column, :array?
type = PostgresqlComposite.type_for_attribute("address")
assert_not type.binary?
assert_not_predicate type, :binary?
end
def test_composite_mapping

@ -157,7 +157,7 @@ def test_reconnection_after_actual_disconnection_with_verify
original_connection_pid = @connection.query("select pg_backend_pid()")
# Sanity check.
assert @connection.active?
assert_predicate @connection, :active?
if @connection.send(:postgresql_version) >= 90200
secondary_connection = ActiveRecord::Base.connection_pool.checkout
@ -176,7 +176,7 @@ def test_reconnection_after_actual_disconnection_with_verify
@connection.verify!
assert @connection.active?
assert_predicate @connection, :active?
# If we get no exception here, then either we re-connected successfully, or
# we never actually got disconnected.

@ -30,10 +30,10 @@ def test_column
column = PostgresqlDomain.columns_hash["price"]
assert_equal :decimal, column.type
assert_equal "custom_money", column.sql_type
assert_not column.array?
assert_not_predicate column, :array?
type = PostgresqlDomain.type_for_attribute("price")
assert_not type.binary?
assert_not_predicate type, :binary?
end
def test_domain_acts_like_basetype

@ -32,10 +32,10 @@ def test_column
column = PostgresqlEnum.columns_hash["current_mood"]
assert_equal :enum, column.type
assert_equal "mood", column.sql_type
assert_not column.array?
assert_not_predicate column, :array?
type = PostgresqlEnum.type_for_attribute("current_mood")
assert_not type.binary?
assert_not_predicate type, :binary?
end
def test_enum_defaults
@ -73,7 +73,7 @@ def test_no_oid_warning
@connection.execute "INSERT INTO postgresql_enums VALUES (1, 'sad');"
stderr_output = capture(:stderr) { PostgresqlEnum.first }
assert stderr_output.blank?
assert_predicate stderr_output, :blank?
end
def test_enum_type_cast

@ -22,10 +22,10 @@ def test_tsvector_column
column = Tsvector.columns_hash["text_vector"]
assert_equal :tsvector, column.type
assert_equal "tsvector", column.sql_type
assert_not column.array?
assert_not_predicate column, :array?
type = Tsvector.type_for_attribute("text_vector")
assert_not type.binary?
assert_not_predicate type, :binary?
end
def test_update_tsvector

@ -39,10 +39,10 @@ def test_column
column = PostgresqlPoint.columns_hash["x"]
assert_equal :point, column.type
assert_equal "point", column.sql_type
assert_not column.array?
assert_not_predicate column, :array?
type = PostgresqlPoint.type_for_attribute("x")
assert_not type.binary?
assert_not_predicate type, :binary?
end
def test_default
@ -79,7 +79,7 @@ def test_mutation
p.reload
assert_equal ActiveRecord::Point.new(10.0, 25.0), p.x
assert_not p.changed?
assert_not_predicate p, :changed?
end
def test_array_assignment
@ -117,10 +117,10 @@ def test_legacy_column
column = PostgresqlPoint.columns_hash["legacy_x"]
assert_equal :point, column.type
assert_equal "point", column.sql_type
assert_not column.array?
assert_not_predicate column, :array?
type = PostgresqlPoint.type_for_attribute("legacy_x")
assert_not type.binary?
assert_not_predicate type, :binary?
end
def test_legacy_default
@ -157,7 +157,7 @@ def test_legacy_mutation
p.reload
assert_equal [10.0, 25.0], p.legacy_x
assert_not p.changed?
assert_not_predicate p, :changed?
end
end

@ -58,9 +58,9 @@ def test_disable_enable_hstore
def test_column
assert_equal :hstore, @column.type
assert_equal "hstore", @column.sql_type
assert_not @column.array?
assert_not_predicate @column, :array?
assert_not @type.binary?
assert_not_predicate @type, :binary?
end
def test_default
@ -165,7 +165,7 @@ def test_changes_in_place
hstore.reload
assert_equal "four", hstore.settings["three"]
assert_not hstore.changed?
assert_not_predicate hstore, :changed?
end
def test_dirty_from_user_equal
@ -174,7 +174,7 @@ def test_dirty_from_user_equal
hstore.settings = { "key" => "value", "alongkey" => "anything" }
assert_equal settings, hstore.settings
assert_not hstore.changed?
assert_not_predicate hstore, :changed?
end
def test_hstore_dirty_from_database_equal
@ -184,7 +184,7 @@ def test_hstore_dirty_from_database_equal
assert_equal settings, hstore.settings
hstore.settings = settings
assert_not hstore.changed?
assert_not_predicate hstore, :changed?
end
def test_gen1

@ -31,10 +31,10 @@ def test_column
column = Ltree.columns_hash["path"]
assert_equal :ltree, column.type
assert_equal "ltree", column.sql_type
assert_not column.array?
assert_not_predicate column, :array?
type = Ltree.type_for_attribute("path")
assert_not type.binary?
assert_not_predicate type, :binary?
end
def test_write

@ -26,10 +26,10 @@ def test_column
assert_equal :money, column.type
assert_equal "money", column.sql_type
assert_equal 2, column.scale
assert_not column.array?
assert_not_predicate column, :array?
type = PostgresqlMoney.type_for_attribute("wealth")
assert_not type.binary?
assert_not_predicate type, :binary?
end
def test_default

@ -24,30 +24,30 @@ def test_cidr_column
column = PostgresqlNetworkAddress.columns_hash["cidr_address"]
assert_equal :cidr, column.type
assert_equal "cidr", column.sql_type
assert_not column.array?
assert_not_predicate column, :array?
type = PostgresqlNetworkAddress.type_for_attribute("cidr_address")
assert_not type.binary?
assert_not_predicate type, :binary?
end
def test_inet_column
column = PostgresqlNetworkAddress.columns_hash["inet_address"]
assert_equal :inet, column.type
assert_equal "inet", column.sql_type
assert_not column.array?
assert_not_predicate column, :array?
type = PostgresqlNetworkAddress.type_for_attribute("inet_address")
assert_not type.binary?
assert_not_predicate type, :binary?
end
def test_macaddr_column
column = PostgresqlNetworkAddress.columns_hash["mac_address"]
assert_equal :macaddr, column.type
assert_equal "macaddr", column.sql_type
assert_not column.array?
assert_not_predicate column, :array?
type = PostgresqlNetworkAddress.type_for_attribute("mac_address")
assert_not type.binary?
assert_not_predicate type, :binary?
end
def test_network_types

@ -24,14 +24,14 @@ def test_serial_column
column = PostgresqlSerial.columns_hash["seq"]
assert_equal :integer, column.type
assert_equal "integer", column.sql_type
assert column.serial?
assert_predicate column, :serial?
end
def test_not_serial_column
column = PostgresqlSerial.columns_hash["serials_id"]
assert_equal :integer, column.type
assert_equal "integer", column.sql_type
assert_not column.serial?
assert_not_predicate column, :serial?
end
def test_schema_dump_with_shorthand
@ -66,14 +66,14 @@ def test_bigserial_column
column = PostgresqlBigSerial.columns_hash["seq"]
assert_equal :integer, column.type
assert_equal "bigint", column.sql_type
assert column.serial?
assert_predicate column, :serial?
end
def test_not_bigserial_column
column = PostgresqlBigSerial.columns_hash["serials_id"]
assert_equal :integer, column.type
assert_equal "bigint", column.sql_type
assert_not column.serial?
assert_not_predicate column, :serial?
end
def test_schema_dump_with_shorthand
@ -111,7 +111,7 @@ def test_serial_columns
columns = @connection.columns(:foo)
columns.each do |column|
assert_equal :integer, column.type
assert column.serial?
assert_predicate column, :serial?
end
end
@ -142,7 +142,7 @@ def test_serial_columns
columns = @connection.columns(@table_name)
columns.each do |column|
assert_equal :integer, column.type
assert column.serial?
assert_predicate column, :serial?
end
end

@ -82,7 +82,7 @@ def test_add_column_with_default_array
UUIDType.reset_column_information
column = UUIDType.columns_hash["thingy"]
assert column.array?
assert_predicate column, :array?
assert_equal "{}", column.default
schema = dump_table_schema "uuid_data_type"
@ -93,10 +93,10 @@ def test_data_type_of_uuid_types
column = UUIDType.columns_hash["guid"]
assert_equal :uuid, column.type
assert_equal "uuid", column.sql_type
assert_not column.array?
assert_not_predicate column, :array?
type = UUIDType.type_for_attribute("guid")
assert_not type.binary?
assert_not_predicate type, :binary?
end
def test_treat_blank_uuid_as_nil
@ -178,7 +178,7 @@ def self.name
duplicate = klass.new(guid: record.guid)
assert record.guid.present? # Ensure we actually are testing a UUID
assert_not duplicate.valid?
assert_not_predicate duplicate, :valid?
end
end

@ -79,7 +79,7 @@ def self.name; "Temp"; end
end
account = model.new
assert account.valid?
assert_predicate account, :valid?
ensure
ActiveRecord::Base.belongs_to_required_by_default = original_value
end
@ -95,7 +95,7 @@ def self.name; "Temp"; end
end
account = model.new
assert_not account.valid?
assert_not_predicate account, :valid?
assert_equal [{ error: :blank }], account.errors.details[:company]
ensure
ActiveRecord::Base.belongs_to_required_by_default = original_value
@ -112,7 +112,7 @@ def self.name; "Temp"; end
end
account = model.new
assert_not account.valid?
assert_not_predicate account, :valid?
assert_equal [{ error: :blank }], account.errors.details[:company]
ensure
ActiveRecord::Base.belongs_to_required_by_default = original_value
@ -246,14 +246,14 @@ def test_eager_loading_with_primary_key
Firm.create("name" => "Apple")
Client.create("name" => "Citibank", :firm_name => "Apple")
citibank_result = Client.all.merge!(where: { name: "Citibank" }, includes: :firm_with_primary_key).first
assert citibank_result.association(:firm_with_primary_key).loaded?
assert_predicate citibank_result.association(:firm_with_primary_key), :loaded?
end
def test_eager_loading_with_primary_key_as_symbol
Firm.create("name" => "Apple")
Client.create("name" => "Citibank", :firm_name => "Apple")
citibank_result = Client.all.merge!(where: { name: "Citibank" }, includes: :firm_with_primary_key_symbols).first
assert citibank_result.association(:firm_with_primary_key_symbols).loaded?
assert_predicate citibank_result.association(:firm_with_primary_key_symbols), :loaded?
end
def test_creating_the_belonging_object
@ -320,7 +320,7 @@ def test_create!
client = Client.create!(name: "Jimmy")
account = client.create_account!(credit_limit: 10)
assert_equal account, client.account
assert account.persisted?
assert_predicate account, :persisted?
client.save
client.reload
assert_equal account, client.account
@ -330,7 +330,7 @@ def test_failing_create!
client = Client.create!(name: "Jimmy")
assert_raise(ActiveRecord::RecordInvalid) { client.create_account! }
assert_not_nil client.account
assert client.account.new_record?
assert_predicate client.account, :new_record?
end
def test_reloading_the_belonging_object
@ -627,10 +627,10 @@ def test_assignment_before_child_saved
final_cut = Client.new("name" => "Final Cut")
firm = Firm.find(1)
final_cut.firm = firm
assert !final_cut.persisted?
assert_not_predicate final_cut, :persisted?
assert final_cut.save
assert final_cut.persisted?
assert firm.persisted?
assert_predicate final_cut, :persisted?
assert_predicate firm, :persisted?
assert_equal firm, final_cut.firm
final_cut.association(:firm).reload
assert_equal firm, final_cut.firm
@ -640,10 +640,10 @@ def test_assignment_before_child_saved_with_primary_key
final_cut = Client.new("name" => "Final Cut")
firm = Firm.find(1)
final_cut.firm_with_primary_key = firm
assert !final_cut.persisted?
assert_not_predicate final_cut, :persisted?
assert final_cut.save
assert final_cut.persisted?
assert firm.persisted?
assert_predicate final_cut, :persisted?
assert_predicate firm, :persisted?
assert_equal firm, final_cut.firm_with_primary_key
final_cut.association(:firm_with_primary_key).reload
assert_equal firm, final_cut.firm_with_primary_key
@ -790,7 +790,7 @@ def test_association_assignment_sticks
def test_cant_save_readonly_association
assert_raise(ActiveRecord::ReadOnlyRecord) { companies(:first_client).readonly_firm.save! }
assert companies(:first_client).readonly_firm.readonly?
assert_predicate companies(:first_client).readonly_firm, :readonly?
end
def test_polymorphic_assignment_foreign_key_type_string
@ -949,15 +949,15 @@ def test_reassigning_the_parent_id_updates_the_object
firm_proxy = client.send(:association_instance_get, :firm)
firm_with_condition_proxy = client.send(:association_instance_get, :firm_with_condition)
assert !firm_proxy.stale_target?
assert !firm_with_condition_proxy.stale_target?
assert_not_predicate firm_proxy, :stale_target?
assert_not_predicate firm_with_condition_proxy, :stale_target?
assert_equal companies(:first_firm), client.firm
assert_equal companies(:first_firm), client.firm_with_condition
client.client_of = companies(:another_firm).id
assert firm_proxy.stale_target?
assert firm_with_condition_proxy.stale_target?
assert_predicate firm_proxy, :stale_target?
assert_predicate firm_with_condition_proxy, :stale_target?
assert_equal companies(:another_firm), client.firm
assert_equal companies(:another_firm), client.firm_with_condition
end
@ -968,12 +968,12 @@ def test_polymorphic_reassignment_of_associated_id_updates_the_object
sponsor.sponsorable
proxy = sponsor.send(:association_instance_get, :sponsorable)
assert !proxy.stale_target?
assert_not_predicate proxy, :stale_target?
assert_equal members(:groucho), sponsor.sponsorable
sponsor.sponsorable_id = members(:some_other_guy).id
assert proxy.stale_target?
assert_predicate proxy, :stale_target?
assert_equal members(:some_other_guy), sponsor.sponsorable
end
@ -983,12 +983,12 @@ def test_polymorphic_reassignment_of_associated_type_updates_the_object
sponsor.sponsorable
proxy = sponsor.send(:association_instance_get, :sponsorable)
assert !proxy.stale_target?
assert_not_predicate proxy, :stale_target?
assert_equal members(:groucho), sponsor.sponsorable
sponsor.sponsorable_type = "Firm"
assert proxy.stale_target?
assert_predicate proxy, :stale_target?
assert_equal companies(:first_firm), sponsor.sponsorable
end
@ -1122,7 +1122,7 @@ def self.name; "Temp"; end
comment.post_id = 9223372036854775808 # out of range in the bigint
assert_nil comment.post
assert_not comment.valid?
assert_not_predicate comment, :valid?
assert_equal [{ error: :blank }], comment.errors.details[:post]
end
@ -1142,7 +1142,7 @@ def test_polymorphic_with_custom_primary_key
citibank.firm_id = apple.id.to_s
assert !citibank.association(:firm).stale_target?
assert_not_predicate citibank.association(:firm), :stale_target?
end
def test_reflect_the_most_recent_change

@ -15,7 +15,7 @@ def setup
@david = authors(:david)
@thinking = posts(:thinking)
@authorless = posts(:authorless)
assert @david.post_log.empty?
assert_predicate @david.post_log, :empty?
end
def test_adding_macro_callbacks
@ -96,7 +96,7 @@ def test_has_many_callbacks_for_destroy_on_parent
def test_has_and_belongs_to_many_add_callback
david = developers(:david)
ar = projects(:active_record)
assert ar.developers_log.empty?
assert_predicate ar.developers_log, :empty?
ar.developers_with_callbacks << david
assert_equal ["before_adding#{david.id}", "after_adding#{david.id}"], ar.developers_log
ar.developers_with_callbacks << david
@ -122,12 +122,12 @@ def self.name; Project.name; end
assert_equal alice, dev
assert_not_nil new_dev
assert new_dev, "record should not have been saved"
assert_not alice.new_record?
assert_not_predicate alice, :new_record?
end
def test_has_and_belongs_to_many_after_add_called_after_save
ar = projects(:active_record)
assert ar.developers_log.empty?
assert_predicate ar.developers_log, :empty?
alice = Developer.new(name: "alice")
ar.developers_with_callbacks << alice
assert_equal "after_adding#{alice.id}", ar.developers_log.last
@ -143,7 +143,7 @@ def test_has_and_belongs_to_many_remove_callback
david = developers(:david)
jamis = developers(:jamis)
activerecord = projects(:active_record)
assert activerecord.developers_log.empty?
assert_predicate activerecord.developers_log, :empty?
activerecord.developers_with_callbacks.delete(david)
assert_equal ["before_removing#{david.id}", "after_removing#{david.id}"], activerecord.developers_log
@ -154,7 +154,7 @@ def test_has_and_belongs_to_many_remove_callback
def test_has_and_belongs_to_many_does_not_fire_callbacks_on_clear
activerecord = projects(:active_record)
assert activerecord.developers_log.empty?
assert_predicate activerecord.developers_log, :empty?
if activerecord.developers_with_callbacks.size == 0
activerecord.developers << developers(:david)
activerecord.developers << developers(:jamis)
@ -183,7 +183,7 @@ def test_dont_add_if_before_callback_raises_exception
@david.unchangeable_posts << @authorless
rescue Exception
end
assert @david.post_log.empty?
assert_predicate @david.post_log, :empty?
assert_not_includes @david.unchangeable_posts, @authorless
@david.reload
assert_not_includes @david.unchangeable_posts, @authorless

@ -284,7 +284,7 @@ def test_loading_from_an_association
end
def test_loading_from_an_association_that_has_a_hash_of_conditions
assert !Author.all.merge!(includes: :hello_posts_with_hash_conditions).find(authors(:david).id).hello_posts.empty?
assert_not_predicate Author.all.merge!(includes: :hello_posts_with_hash_conditions).find(authors(:david).id).hello_posts, :empty?
end
def test_loading_with_no_associations
@ -1444,51 +1444,51 @@ def test_preloading_has_many_through_with_custom_scope
test "preloading readonly association" do
# has-one
firm = Firm.where(id: "1").preload(:readonly_account).first!
assert firm.readonly_account.readonly?
assert_predicate firm.readonly_account, :readonly?
# has_and_belongs_to_many
project = Project.where(id: "2").preload(:readonly_developers).first!
assert project.readonly_developers.first.readonly?
assert_predicate project.readonly_developers.first, :readonly?
# has-many :through
david = Author.where(id: "1").preload(:readonly_comments).first!
assert david.readonly_comments.first.readonly?
assert_predicate david.readonly_comments.first, :readonly?
end
test "eager-loading non-readonly association" do
# has_one
firm = Firm.where(id: "1").eager_load(:account).first!
assert_not firm.account.readonly?
assert_not_predicate firm.account, :readonly?
# has_and_belongs_to_many
project = Project.where(id: "2").eager_load(:developers).first!
assert_not project.developers.first.readonly?
assert_not_predicate project.developers.first, :readonly?
# has_many :through
david = Author.where(id: "1").eager_load(:comments).first!
assert_not david.comments.first.readonly?
assert_not_predicate david.comments.first, :readonly?
# belongs_to
post = Post.where(id: "1").eager_load(:author).first!
assert_not post.author.readonly?
assert_not_predicate post.author, :readonly?
end
test "eager-loading readonly association" do
# has-one
firm = Firm.where(id: "1").eager_load(:readonly_account).first!
assert firm.readonly_account.readonly?
assert_predicate firm.readonly_account, :readonly?
# has_and_belongs_to_many
project = Project.where(id: "2").eager_load(:readonly_developers).first!
assert project.readonly_developers.first.readonly?
assert_predicate project.readonly_developers.first, :readonly?
# has-many :through
david = Author.where(id: "1").eager_load(:readonly_comments).first!
assert david.readonly_comments.first.readonly?
assert_predicate david.readonly_comments.first, :readonly?
# belongs_to
post = Post.where(id: "1").eager_load(:readonly_author).first!
assert post.readonly_author.readonly?
assert_predicate post.readonly_author, :readonly?
end
test "preloading a polymorphic association with references to the associated table" do

@ -180,11 +180,11 @@ def test_join_table_composite_primary_key_should_not_warn
def test_has_and_belongs_to_many
david = Developer.find(1)
assert !david.projects.empty?
assert_not_predicate david.projects, :empty?
assert_equal 2, david.projects.size
active_record = Project.find(1)
assert !active_record.developers.empty?
assert_not_predicate active_record.developers, :empty?
assert_equal 3, active_record.developers.size
assert_includes active_record.developers, david
end
@ -262,10 +262,10 @@ def test_habtm_adding_before_save
no_of_projects = Project.count
aredridel = Developer.new("name" => "Aredridel")
aredridel.projects.concat([Project.find(1), p = Project.new("name" => "Projekt")])
assert !aredridel.persisted?
assert !p.persisted?
assert_not_predicate aredridel, :persisted?
assert_not_predicate p, :persisted?
assert aredridel.save
assert aredridel.persisted?
assert_predicate aredridel, :persisted?
assert_equal no_of_devels + 1, Developer.count
assert_equal no_of_projects + 1, Project.count
assert_equal 2, aredridel.projects.size
@ -311,14 +311,14 @@ def test_habtm_collection_size_from_params
def test_build
devel = Developer.find(1)
proj = assert_no_queries(ignore_none: false) { devel.projects.build("name" => "Projekt") }
assert !devel.projects.loaded?
assert_not_predicate devel.projects, :loaded?
assert_equal devel.projects.last, proj
assert devel.projects.loaded?
assert_predicate devel.projects, :loaded?
assert !proj.persisted?
assert_not_predicate proj, :persisted?
devel.save
assert proj.persisted?
assert_predicate proj, :persisted?
assert_equal devel.projects.last, proj
assert_equal Developer.find(1).projects.sort_by(&:id).last, proj # prove join table is updated
end
@ -326,14 +326,14 @@ def test_build
def test_new_aliased_to_build
devel = Developer.find(1)
proj = assert_no_queries(ignore_none: false) { devel.projects.new("name" => "Projekt") }
assert !devel.projects.loaded?
assert_not_predicate devel.projects, :loaded?
assert_equal devel.projects.last, proj
assert devel.projects.loaded?
assert_predicate devel.projects, :loaded?
assert !proj.persisted?
assert_not_predicate proj, :persisted?
devel.save
assert proj.persisted?
assert_predicate proj, :persisted?
assert_equal devel.projects.last, proj
assert_equal Developer.find(1).projects.sort_by(&:id).last, proj # prove join table is updated
end
@ -343,10 +343,10 @@ def test_build_by_new_record
devel.projects.build(name: "Make bed")
proj2 = devel.projects.build(name: "Lie in it")
assert_equal devel.projects.last, proj2
assert !proj2.persisted?
assert_not_predicate proj2, :persisted?
devel.save
assert devel.persisted?
assert proj2.persisted?
assert_predicate devel, :persisted?
assert_predicate proj2, :persisted?
assert_equal devel.projects.last, proj2
assert_equal Developer.find_by_name("Marcel").projects.last, proj2 # prove join table is updated
end
@ -354,12 +354,12 @@ def test_build_by_new_record
def test_create
devel = Developer.find(1)
proj = devel.projects.create("name" => "Projekt")
assert !devel.projects.loaded?
assert_not_predicate devel.projects, :loaded?
assert_equal devel.projects.last, proj
assert !devel.projects.loaded?
assert_not_predicate devel.projects, :loaded?
assert proj.persisted?
assert_predicate proj, :persisted?
assert_equal Developer.find(1).projects.sort_by(&:id).last, proj # prove join table is updated
end
@ -373,7 +373,7 @@ def test_creation_respects_hash_condition
# in Oracle '' is saved as null therefore need to save ' ' in not null column
another_post = categories(:general).post_with_conditions.create(body: " ")
assert another_post.persisted?
assert_predicate another_post, :persisted?
assert_equal "Yet Another Testing Title", another_post.title
end
@ -441,10 +441,10 @@ def test_deleting_all
def test_removing_associations_on_destroy
david = DeveloperWithBeforeDestroyRaise.find(1)
assert !david.projects.empty?
assert_not_predicate david.projects, :empty?
david.destroy
assert david.projects.empty?
assert DeveloperWithBeforeDestroyRaise.connection.select_all("SELECT * FROM developers_projects WHERE developer_id = 1").empty?
assert_predicate david.projects, :empty?
assert_predicate DeveloperWithBeforeDestroyRaise.connection.select_all("SELECT * FROM developers_projects WHERE developer_id = 1"), :empty?
end
def test_destroying
@ -459,7 +459,7 @@ def test_destroying
end
join_records = Developer.connection.select_all("SELECT * FROM developers_projects WHERE developer_id = #{david.id} AND project_id = #{project.id}")
assert join_records.empty?
assert_predicate join_records, :empty?
assert_equal 1, david.reload.projects.size
assert_equal 1, david.projects.reload.size
@ -475,7 +475,7 @@ def test_destroying_many
end
join_records = Developer.connection.select_all("SELECT * FROM developers_projects WHERE developer_id = #{david.id}")
assert join_records.empty?
assert_predicate join_records, :empty?
assert_equal 0, david.reload.projects.size
assert_equal 0, david.projects.reload.size
@ -484,23 +484,23 @@ def test_destroying_many
def test_destroy_all
david = Developer.find(1)
david.projects.reload
assert !david.projects.empty?
assert_not_predicate david.projects, :empty?
assert_no_difference "Project.count" do
david.projects.destroy_all
end
join_records = Developer.connection.select_all("SELECT * FROM developers_projects WHERE developer_id = #{david.id}")
assert join_records.empty?
assert_predicate join_records, :empty?
assert david.projects.empty?
assert david.projects.reload.empty?
assert_predicate david.projects, :empty?
assert_predicate david.projects.reload, :empty?
end
def test_destroy_associations_destroys_multiple_associations
george = parrots(:george)
assert !george.pirates.empty?
assert !george.treasures.empty?
assert_not_predicate george.pirates, :empty?
assert_not_predicate george.treasures, :empty?
assert_no_difference "Pirate.count" do
assert_no_difference "Treasure.count" do
@ -509,12 +509,12 @@ def test_destroy_associations_destroys_multiple_associations
end
join_records = Parrot.connection.select_all("SELECT * FROM parrots_pirates WHERE parrot_id = #{george.id}")
assert join_records.empty?
assert george.pirates.reload.empty?
assert_predicate join_records, :empty?
assert_predicate george.pirates.reload, :empty?
join_records = Parrot.connection.select_all("SELECT * FROM parrots_treasures WHERE parrot_id = #{george.id}")
assert join_records.empty?
assert george.treasures.reload.empty?
assert_predicate join_records, :empty?
assert_predicate george.treasures.reload, :empty?
end
def test_associations_with_conditions
@ -547,7 +547,7 @@ def test_include_uses_array_include_after_loaded
developer = project.developers.first
assert_no_queries(ignore_none: false) do
assert project.developers.loaded?
assert_predicate project.developers, :loaded?
assert_includes project.developers, developer
end
end
@ -557,18 +557,18 @@ def test_include_checks_if_record_exists_if_target_not_loaded
developer = project.developers.first
project.reload
assert ! project.developers.loaded?
assert_not_predicate project.developers, :loaded?
assert_queries(1) do
assert_includes project.developers, developer
end
assert ! project.developers.loaded?
assert_not_predicate project.developers, :loaded?
end
def test_include_returns_false_for_non_matching_record_to_verify_scoping
project = projects(:active_record)
developer = Developer.create name: "Bryan", salary: 50_000
assert ! project.developers.loaded?
assert_not_predicate project.developers, :loaded?
assert ! project.developers.include?(developer)
end
@ -763,9 +763,9 @@ def test_get_ids_for_loaded_associations
def test_get_ids_for_unloaded_associations_does_not_load_them
developer = developers(:david)
assert !developer.projects.loaded?
assert_not_predicate developer.projects, :loaded?
assert_equal projects(:active_record, :action_controller).map(&:id).sort, developer.project_ids.sort
assert !developer.projects.loaded?
assert_not_predicate developer.projects, :loaded?
end
def test_assign_ids

@ -57,7 +57,7 @@ class HasManyAssociationsTestPrimaryKeys < ActiveRecord::TestCase
def test_custom_primary_key_on_new_record_should_fetch_with_query
subscriber = Subscriber.new(nick: "webster132")
assert !subscriber.subscriptions.loaded?
assert_not_predicate subscriber.subscriptions, :loaded?
assert_queries 1 do
assert_equal 2, subscriber.subscriptions.size
@ -68,7 +68,7 @@ def test_custom_primary_key_on_new_record_should_fetch_with_query
def test_association_primary_key_on_new_record_should_fetch_with_query
author = Author.new(name: "David")
assert !author.essays.loaded?
assert_not_predicate author.essays, :loaded?
assert_queries 1 do
assert_equal 1, author.essays.size
@ -103,7 +103,7 @@ def test_has_many_assignment_with_custom_primary_key
def test_blank_custom_primary_key_on_new_record_should_not_run_queries
author = Author.new
assert !author.essays.loaded?
assert_not_predicate author.essays, :loaded?
assert_queries 0 do
assert_equal 0, author.essays.size
@ -201,7 +201,7 @@ def test_clear_collection_should_not_change_updated_at
part.reload
assert_nil part.ship
assert !part.updated_at_changed?
assert_not_predicate part, :updated_at_changed?
end
def test_create_from_association_should_respect_default_scope
@ -444,7 +444,7 @@ def test_finder_method_with_dirty_target
new_clients << company.clients_of_firm.build(name: "Another Client III")
end
assert_not company.clients_of_firm.loaded?
assert_not_predicate company.clients_of_firm, :loaded?
assert_queries(1) do
assert_same new_clients[0], company.clients_of_firm.third
assert_same new_clients[1], company.clients_of_firm.fourth
@ -464,7 +464,7 @@ def test_finder_bang_method_with_dirty_target
new_clients << company.clients_of_firm.build(name: "Another Client III")
end
assert_not company.clients_of_firm.loaded?
assert_not_predicate company.clients_of_firm, :loaded?
assert_queries(1) do
assert_same new_clients[0], company.clients_of_firm.third!
assert_same new_clients[1], company.clients_of_firm.fourth!
@ -587,14 +587,14 @@ def self.name
# taking from unloaded Relation
bob = klass.find(authors(:bob).id)
new_post = bob.posts.build
assert_not bob.posts.loaded?
assert_not_predicate bob.posts, :loaded?
assert_equal [posts(:misc_by_bob)], bob.posts.take(1)
assert_equal [posts(:misc_by_bob), posts(:other_by_bob)], bob.posts.take(2)
assert_equal [posts(:misc_by_bob), posts(:other_by_bob), new_post], bob.posts.take(3)
# taking from loaded Relation
bob.posts.load
assert bob.posts.loaded?
assert_predicate bob.posts, :loaded?
assert_equal [posts(:misc_by_bob)], bob.posts.take(1)
assert_equal [posts(:misc_by_bob), posts(:other_by_bob)], bob.posts.take(2)
assert_equal [posts(:misc_by_bob), posts(:other_by_bob), new_post], bob.posts.take(3)
@ -713,13 +713,13 @@ def test_find_all
def test_find_each
firm = companies(:first_firm)
assert ! firm.clients.loaded?
assert_not_predicate firm.clients, :loaded?
assert_queries(4) do
firm.clients.find_each(batch_size: 1) { |c| assert_equal firm.id, c.firm_id }
end
assert ! firm.clients.loaded?
assert_not_predicate firm.clients, :loaded?
end
def test_find_each_with_conditions
@ -732,13 +732,13 @@ def test_find_each_with_conditions
end
end
assert ! firm.clients.loaded?
assert_not_predicate firm.clients, :loaded?
end
def test_find_in_batches
firm = companies(:first_firm)
assert ! firm.clients.loaded?
assert_not_predicate firm.clients, :loaded?
assert_queries(2) do
firm.clients.find_in_batches(batch_size: 2) do |clients|
@ -746,7 +746,7 @@ def test_find_in_batches
end
end
assert ! firm.clients.loaded?
assert_not_predicate firm.clients, :loaded?
end
def test_find_all_sanitized
@ -955,20 +955,20 @@ def test_inverse_on_before_validate
def test_new_aliased_to_build
company = companies(:first_firm)
new_client = assert_no_queries(ignore_none: false) { company.clients_of_firm.new("name" => "Another Client") }
assert !company.clients_of_firm.loaded?
assert_not_predicate company.clients_of_firm, :loaded?
assert_equal "Another Client", new_client.name
assert !new_client.persisted?
assert_not_predicate new_client, :persisted?
assert_equal new_client, company.clients_of_firm.last
end
def test_build
company = companies(:first_firm)
new_client = assert_no_queries(ignore_none: false) { company.clients_of_firm.build("name" => "Another Client") }
assert !company.clients_of_firm.loaded?
assert_not_predicate company.clients_of_firm, :loaded?
assert_equal "Another Client", new_client.name
assert !new_client.persisted?
assert_not_predicate new_client, :persisted?
assert_equal new_client, company.clients_of_firm.last
end
@ -1008,7 +1008,7 @@ def test_build_many
def test_build_followed_by_save_does_not_load_target
companies(:first_firm).clients_of_firm.build("name" => "Another Client")
assert companies(:first_firm).save
assert !companies(:first_firm).clients_of_firm.loaded?
assert_not_predicate companies(:first_firm).clients_of_firm, :loaded?
end
def test_build_without_loading_association
@ -1028,10 +1028,10 @@ def test_build_without_loading_association
def test_build_via_block
company = companies(:first_firm)
new_client = assert_no_queries(ignore_none: false) { company.clients_of_firm.build { |client| client.name = "Another Client" } }
assert !company.clients_of_firm.loaded?
assert_not_predicate company.clients_of_firm, :loaded?
assert_equal "Another Client", new_client.name
assert !new_client.persisted?
assert_not_predicate new_client, :persisted?
assert_equal new_client, company.clients_of_firm.last
end
@ -1069,7 +1069,7 @@ def test_create
assert_predicate companies(:first_firm).clients_of_firm, :loaded?
new_client = companies(:first_firm).clients_of_firm.create("name" => "Another Client")
assert new_client.persisted?
assert_predicate new_client, :persisted?
assert_equal new_client, companies(:first_firm).clients_of_firm.last
assert_equal new_client, companies(:first_firm).clients_of_firm.reload.last
end
@ -1082,7 +1082,7 @@ def test_create_many
def test_create_followed_by_save_does_not_load_target
companies(:first_firm).clients_of_firm.create("name" => "Another Client")
assert companies(:first_firm).save
assert !companies(:first_firm).clients_of_firm.loaded?
assert_not_predicate companies(:first_firm).clients_of_firm, :loaded?
end
def test_deleting
@ -1108,7 +1108,7 @@ def test_has_many_without_counter_cache_option
# option is not given on the association.
ship = Ship.create(name: "Countless", treasures_count: 10)
assert_not Ship.reflect_on_association(:treasures).has_cached_counter?
assert_not_predicate Ship.reflect_on_association(:treasures), :has_cached_counter?
# Count should come from sql count() of treasures rather than treasures_count attribute
assert_equal ship.treasures.size, 0
@ -1199,7 +1199,7 @@ def test_deleting_updates_counter_cache_with_dependent_destroy
def test_calling_empty_with_counter_cache
post = posts(:welcome)
assert_queries(0) do
assert_not post.comments.empty?
assert_not_predicate post.comments, :empty?
end
end
@ -1446,7 +1446,7 @@ def test_creation_respects_hash_condition
another_ms_client = companies(:first_firm).clients_like_ms_with_hash_conditions.create
assert another_ms_client.persisted?
assert_predicate another_ms_client, :persisted?
assert_equal "Microsoft", another_ms_client.name
end
@ -1570,7 +1570,7 @@ def test_dependence
firm = companies(:first_firm)
assert_equal 3, firm.clients.size
firm.destroy
assert Client.all.merge!(where: "firm_id=#{firm.id}").to_a.empty?
assert_predicate Client.all.merge!(where: "firm_id=#{firm.id}").to_a, :empty?
end
def test_dependence_for_associations_with_hash_condition
@ -1633,7 +1633,7 @@ def test_restrict_with_exception
firm = RestrictedWithExceptionFirm.create!(name: "restrict")
firm.companies.create(name: "child")
assert !firm.companies.empty?
assert_not_predicate firm.companies, :empty?
assert_raise(ActiveRecord::DeleteRestrictionError) { firm.destroy }
assert RestrictedWithExceptionFirm.exists?(name: "restrict")
assert firm.companies.exists?(name: "child")
@ -1643,11 +1643,11 @@ def test_restrict_with_error
firm = RestrictedWithErrorFirm.create!(name: "restrict")
firm.companies.create(name: "child")
assert !firm.companies.empty?
assert_not_predicate firm.companies, :empty?
firm.destroy
assert !firm.errors.empty?
assert_not_predicate firm.errors, :empty?
assert_equal "Cannot delete record because dependent companies exist", firm.errors[:base].first
assert RestrictedWithErrorFirm.exists?(name: "restrict")
@ -1660,11 +1660,11 @@ def test_restrict_with_error_with_locale
firm = RestrictedWithErrorFirm.create!(name: "restrict")
firm.companies.create(name: "child")
assert !firm.companies.empty?
assert_not_predicate firm.companies, :empty?
firm.destroy
assert !firm.errors.empty?
assert_not_predicate firm.errors, :empty?
assert_equal "Cannot delete record because dependent client companies exist", firm.errors[:base].first
assert RestrictedWithErrorFirm.exists?(name: "restrict")
@ -1716,8 +1716,8 @@ def test_replace_failure
account = Account.new
orig_accounts = firm.accounts.to_a
assert !account.valid?
assert !orig_accounts.empty?
assert_not_predicate account, :valid?
assert_not_predicate orig_accounts, :empty?
error = assert_raise ActiveRecord::RecordNotSaved do
firm.accounts = [account]
end
@ -1775,9 +1775,9 @@ def test_get_ids_for_loaded_associations
def test_get_ids_for_unloaded_associations_does_not_load_them
company = companies(:first_firm)
assert !company.clients.loaded?
assert_not_predicate company.clients, :loaded?
assert_equal [companies(:first_client).id, companies(:second_client).id, companies(:another_first_firm_client).id], company.client_ids
assert !company.clients.loaded?
assert_not_predicate company.clients, :loaded?
end
def test_counter_cache_on_unloaded_association
@ -1859,7 +1859,7 @@ def test_include_uses_array_include_after_loaded
client = firm.clients.first
assert_no_queries do
assert firm.clients.loaded?
assert_predicate firm.clients, :loaded?
assert_equal true, firm.clients.include?(client)
end
end
@ -1869,18 +1869,18 @@ def test_include_checks_if_record_exists_if_target_not_loaded
client = firm.clients.first
firm.reload
assert ! firm.clients.loaded?
assert_not_predicate firm.clients, :loaded?
assert_queries(1) do
assert_equal true, firm.clients.include?(client)
end
assert ! firm.clients.loaded?
assert_not_predicate firm.clients, :loaded?
end
def test_include_returns_false_for_non_matching_record_to_verify_scoping
firm = companies(:first_firm)
client = Client.create!(name: "Not Associated")
assert ! firm.clients.loaded?
assert_not_predicate firm.clients, :loaded?
assert_equal false, firm.clients.include?(client)
end
@ -1889,13 +1889,13 @@ def test_calling_first_nth_or_last_on_association_should_not_load_association
firm.clients.first
firm.clients.second
firm.clients.last
assert !firm.clients.loaded?
assert_not_predicate firm.clients, :loaded?
end
def test_calling_first_or_last_on_loaded_association_should_not_fetch_with_query
firm = companies(:first_firm)
firm.clients.load_target
assert firm.clients.loaded?
assert_predicate firm.clients, :loaded?
assert_no_queries(ignore_none: false) do
firm.clients.first
@ -1908,7 +1908,7 @@ def test_calling_first_or_last_on_loaded_association_should_not_fetch_with_query
def test_calling_first_or_last_on_existing_record_with_build_should_load_association
firm = companies(:first_firm)
firm.clients.build(name: "Foo")
assert !firm.clients.loaded?
assert_not_predicate firm.clients, :loaded?
assert_queries 1 do
firm.clients.first
@ -1916,13 +1916,13 @@ def test_calling_first_or_last_on_existing_record_with_build_should_load_associa
firm.clients.last
end
assert firm.clients.loaded?
assert_predicate firm.clients, :loaded?
end
def test_calling_first_nth_or_last_on_existing_record_with_create_should_not_load_association
firm = companies(:first_firm)
firm.clients.create(name: "Foo")
assert !firm.clients.loaded?
assert_not_predicate firm.clients, :loaded?
assert_queries 3 do
firm.clients.first
@ -1930,7 +1930,7 @@ def test_calling_first_nth_or_last_on_existing_record_with_create_should_not_loa
firm.clients.last
end
assert !firm.clients.loaded?
assert_not_predicate firm.clients, :loaded?
end
def test_calling_first_nth_or_last_on_new_record_should_not_run_queries
@ -1946,14 +1946,14 @@ def test_calling_first_nth_or_last_on_new_record_should_not_run_queries
def test_calling_first_or_last_with_integer_on_association_should_not_load_association
firm = companies(:first_firm)
firm.clients.create(name: "Foo")
assert !firm.clients.loaded?
assert_not_predicate firm.clients, :loaded?
assert_queries 2 do
firm.clients.first(2)
firm.clients.last(2)
end
assert !firm.clients.loaded?
assert_not_predicate firm.clients, :loaded?
end
def test_calling_many_should_count_instead_of_loading_association
@ -1961,7 +1961,7 @@ def test_calling_many_should_count_instead_of_loading_association
assert_queries(1) do
firm.clients.many? # use count query
end
assert !firm.clients.loaded?
assert_not_predicate firm.clients, :loaded?
end
def test_calling_many_on_loaded_association_should_not_use_query
@ -1976,22 +1976,22 @@ def test_calling_many_should_defer_to_collection_if_using_a_block
firm.clients.expects(:size).never
firm.clients.many? { true }
end
assert firm.clients.loaded?
assert_predicate firm.clients, :loaded?
end
def test_calling_many_should_return_false_if_none_or_one
firm = companies(:another_firm)
assert !firm.clients_like_ms.many?
assert_not_predicate firm.clients_like_ms, :many?
assert_equal 0, firm.clients_like_ms.size
firm = companies(:first_firm)
assert !firm.limited_clients.many?
assert_not_predicate firm.limited_clients, :many?
assert_equal 1, firm.limited_clients.size
end
def test_calling_many_should_return_true_if_more_than_one
firm = companies(:first_firm)
assert firm.clients.many?
assert_predicate firm.clients, :many?
assert_equal 3, firm.clients.size
end
@ -2000,7 +2000,7 @@ def test_calling_none_should_count_instead_of_loading_association
assert_queries(1) do
firm.clients.none? # use count query
end
assert !firm.clients.loaded?
assert_not_predicate firm.clients, :loaded?
end
def test_calling_none_on_loaded_association_should_not_use_query
@ -2015,18 +2015,18 @@ def test_calling_none_should_defer_to_collection_if_using_a_block
firm.clients.expects(:size).never
firm.clients.none? { true }
end
assert firm.clients.loaded?
assert_predicate firm.clients, :loaded?
end
def test_calling_none_should_return_true_if_none
firm = companies(:another_firm)
assert firm.clients_like_ms.none?
assert_predicate firm.clients_like_ms, :none?
assert_equal 0, firm.clients_like_ms.size
end
def test_calling_none_should_return_false_if_any
firm = companies(:first_firm)
assert !firm.limited_clients.none?
assert_not_predicate firm.limited_clients, :none?
assert_equal 1, firm.limited_clients.size
end
@ -2035,7 +2035,7 @@ def test_calling_one_should_count_instead_of_loading_association
assert_queries(1) do
firm.clients.one? # use count query
end
assert !firm.clients.loaded?
assert_not_predicate firm.clients, :loaded?
end
def test_calling_one_on_loaded_association_should_not_use_query
@ -2050,24 +2050,24 @@ def test_calling_one_should_defer_to_collection_if_using_a_block
firm.clients.expects(:size).never
firm.clients.one? { true }
end
assert firm.clients.loaded?
assert_predicate firm.clients, :loaded?
end
def test_calling_one_should_return_false_if_zero
firm = companies(:another_firm)
assert ! firm.clients_like_ms.one?
assert_not_predicate firm.clients_like_ms, :one?
assert_equal 0, firm.clients_like_ms.size
end
def test_calling_one_should_return_true_if_one
firm = companies(:first_firm)
assert firm.limited_clients.one?
assert_predicate firm.limited_clients, :one?
assert_equal 1, firm.limited_clients.size
end
def test_calling_one_should_return_false_if_more_than_one
firm = companies(:first_firm)
assert ! firm.clients.one?
assert_not_predicate firm.clients, :one?
assert_equal 3, firm.clients.size
end
@ -2287,7 +2287,7 @@ def test_collection_association_with_private_kernel_method
post = posts(:welcome)
assert post.taggings_with_delete_all.count > 0
assert !post.taggings_with_delete_all.loaded?
assert_not_predicate post.taggings_with_delete_all, :loaded?
# 2 queries: one DELETE and another to update the counter cache
assert_queries(2) do
@ -2309,7 +2309,7 @@ def test_collection_association_with_private_kernel_method
test "collection proxy respects default scope" do
author = authors(:mary)
assert !author.first_posts.exists?
assert_not_predicate author.first_posts, :exists?
end
test "association with extend option" do
@ -2428,7 +2428,7 @@ def test_collection_association_with_private_kernel_method
pirate = FamousPirate.new
pirate.famous_ships << ship = FamousShip.new
assert pirate.valid?
assert_predicate pirate, :valid?
assert_not pirate.valid?(:conference)
assert_equal "can't be blank", ship.errors[:name].first
end

@ -353,10 +353,10 @@ def test_delete_association
end
assert_queries(1) do
assert posts(:welcome).people.empty?
assert_predicate posts(:welcome).people, :empty?
end
assert posts(:welcome).reload.people.reload.empty?
assert_predicate posts(:welcome).reload.people.reload, :empty?
end
def test_destroy_association
@ -366,8 +366,8 @@ def test_destroy_association
end
end
assert posts(:welcome).reload.people.empty?
assert posts(:welcome).people.reload.empty?
assert_predicate posts(:welcome).reload.people, :empty?
assert_predicate posts(:welcome).people.reload, :empty?
end
def test_destroy_all
@ -377,8 +377,8 @@ def test_destroy_all
end
end
assert posts(:welcome).reload.people.empty?
assert posts(:welcome).people.reload.empty?
assert_predicate posts(:welcome).reload.people, :empty?
assert_predicate posts(:welcome).people.reload, :empty?
end
def test_should_raise_exception_for_destroying_mismatching_records
@ -685,10 +685,10 @@ def test_clear_associations
end
assert_queries(0) do
assert posts(:welcome).people.empty?
assert_predicate posts(:welcome).people, :empty?
end
assert posts(:welcome).reload.people.reload.empty?
assert_predicate posts(:welcome).reload.people.reload, :empty?
end
def test_association_callback_ordering
@ -770,9 +770,9 @@ def test_get_ids_for_loaded_associations
def test_get_ids_for_unloaded_associations_does_not_load_them
person = people(:michael)
assert !person.posts.loaded?
assert_not_predicate person.posts, :loaded?
assert_equal [posts(:welcome).id, posts(:authorless).id].sort, person.post_ids.sort
assert !person.posts.loaded?
assert_not_predicate person.posts, :loaded?
end
def test_association_proxy_transaction_method_starts_transaction_in_association_class
@ -862,7 +862,7 @@ def test_collection_delete_with_nonstandard_primary_key_on_belongs_to
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 author.named_categories.reload.empty?
assert_predicate author.named_categories.reload, :empty?
end
def test_collection_singular_ids_getter_with_string_primary_keys
@ -944,8 +944,8 @@ def test_include_method_in_association_through_should_return_true_for_instance_a
end
def test_through_association_readonly_should_be_false
assert !people(:michael).posts.first.readonly?
assert !people(:michael).posts.to_a.first.readonly?
assert_not_predicate people(:michael).posts.first, :readonly?
assert_not_predicate people(:michael).posts.to_a.first, :readonly?
end
def test_can_update_through_association
@ -1034,12 +1034,12 @@ def test_has_many_through_belongs_to_should_update_when_the_through_foreign_key_
post.author_categorizations
proxy = post.send(:association_instance_get, :author_categorizations)
assert !proxy.stale_target?
assert_not_predicate proxy, :stale_target?
assert_equal authors(:mary).categorizations.sort_by(&:id), post.author_categorizations.sort_by(&:id)
post.author_id = authors(:david).id
assert proxy.stale_target?
assert_predicate proxy, :stale_target?
assert_equal authors(:david).categorizations.sort_by(&:id), post.author_categorizations.sort_by(&:id)
end
@ -1056,7 +1056,7 @@ def test_deleting_from_has_many_through_a_belongs_to_should_not_try_to_update_co
assert_includes post.author_addresses, address
post.author_addresses.delete(address)
assert post[:author_count].nil?
assert_predicate post[:author_count], :nil?
end
def test_primary_key_option_on_source

@ -114,8 +114,8 @@ def test_nullification_on_destroyed_association
developer = Developer.create!(name: "Someone")
ship = Ship.create!(name: "Planet Caravan", developer: developer)
ship.destroy
assert !ship.persisted?
assert !developer.persisted?
assert_not_predicate ship, :persisted?
assert_not_predicate developer, :persisted?
end
def test_natural_assignment_to_nil_after_destroy
@ -186,7 +186,7 @@ def test_restrict_with_exception
assert_raise(ActiveRecord::DeleteRestrictionError) { firm.destroy }
assert RestrictedWithExceptionFirm.exists?(name: "restrict")
assert firm.account.present?
assert_predicate firm.account, :present?
end
def test_restrict_with_error
@ -197,10 +197,10 @@ def test_restrict_with_error
firm.destroy
assert !firm.errors.empty?
assert_not_predicate firm.errors, :empty?
assert_equal "Cannot delete record because a dependent account exists", firm.errors[:base].first
assert RestrictedWithErrorFirm.exists?(name: "restrict")
assert firm.account.present?
assert_predicate firm.account, :present?
end
def test_restrict_with_error_with_locale
@ -213,10 +213,10 @@ def test_restrict_with_error_with_locale
firm.destroy
assert !firm.errors.empty?
assert_not_predicate firm.errors, :empty?
assert_equal "Cannot delete record because a dependent firm account exists", firm.errors[:base].first
assert RestrictedWithErrorFirm.exists?(name: "restrict")
assert firm.account.present?
assert_predicate firm.account, :present?
ensure
I18n.backend.reload!
end
@ -377,7 +377,7 @@ def test_finding_with_interpolated_condition
def test_assignment_before_child_saved
firm = Firm.find(1)
firm.account = a = Account.new("credit_limit" => 1000)
assert a.persisted?
assert_predicate a, :persisted?
assert_equal a, firm.account
assert_equal a, firm.account
firm.association(:account).reload
@ -395,7 +395,7 @@ def test_save_still_works_after_accessing_nil_has_one
def test_cant_save_readonly_association
assert_raise(ActiveRecord::ReadOnlyRecord) { companies(:first_firm).readonly_account.save! }
assert companies(:first_firm).readonly_account.readonly?
assert_predicate companies(:first_firm).readonly_account, :readonly?
end
def test_has_one_proxy_should_not_respond_to_private_methods
@ -433,7 +433,7 @@ def test_build_respects_hash_condition
def test_create_respects_hash_condition
account = companies(:first_firm).create_account_limit_500_with_hash_conditions
assert account.persisted?
assert_predicate account, :persisted?
assert_equal 500, account.credit_limit
end
@ -450,7 +450,7 @@ def test_creation_failure_without_dependent_option
new_ship = pirate.create_ship
assert_not_equal ships(:black_pearl), new_ship
assert_equal new_ship, pirate.ship
assert new_ship.new_record?
assert_predicate new_ship, :new_record?
assert_nil orig_ship.pirate_id
assert !orig_ship.changed? # check it was saved
end
@ -460,8 +460,8 @@ def test_creation_failure_with_dependent_option
orig_ship = pirate.dependent_ship
new_ship = pirate.create_dependent_ship
assert new_ship.new_record?
assert orig_ship.destroyed?
assert_predicate new_ship, :new_record?
assert_predicate orig_ship, :destroyed?
end
def test_creation_failure_due_to_new_record_should_raise_error
@ -481,7 +481,7 @@ def test_replacement_failure_due_to_existing_record_should_raise_error
pirate = pirates(:blackbeard)
pirate.ship.name = nil
assert !pirate.ship.valid?
assert_not_predicate pirate.ship, :valid?
error = assert_raise(ActiveRecord::RecordNotSaved) do
pirate.ship = ships(:interceptor)
end
@ -588,7 +588,7 @@ def test_has_one_assignment_dont_trigger_save_on_change_of_same_object
ship.save!
ship.name = "new name"
assert ship.changed?
assert_predicate ship, :changed?
assert_queries(1) do
# One query for updating name, not triggering query for updating pirate_id
pirate.ship = ship

@ -47,11 +47,11 @@ def test_creating_association_builds_through_record
new_club = new_member.association(:club).build
assert new_member.current_membership
assert_equal new_club, new_member.club
assert new_club.new_record?
assert new_member.current_membership.new_record?
assert_predicate new_club, :new_record?
assert_predicate new_member.current_membership, :new_record?
assert new_member.save
assert new_club.persisted?
assert new_member.current_membership.persisted?
assert_predicate new_club, :persisted?
assert_predicate new_member.current_membership, :persisted?
end
def test_creating_association_builds_through_record_for_new
@ -241,7 +241,7 @@ def test_preloading_has_one_through_on_belongs_to
MemberDetail.all.merge!(includes: :member_type).to_a
end
@new_detail = @member_details[0]
assert @new_detail.send(:association, :member_type).loaded?
assert_predicate @new_detail.send(:association, :member_type), :loaded?
assert_no_queries { @new_detail.member_type }
end
@ -329,12 +329,12 @@ def test_has_one_through_belongs_to_should_update_when_the_through_foreign_key_c
minivan.dashboard
proxy = minivan.send(:association_instance_get, :dashboard)
assert !proxy.stale_target?
assert_not_predicate proxy, :stale_target?
assert_equal dashboards(:cool_first), minivan.dashboard
minivan.speedometer_id = speedometers(:second).id
assert proxy.stale_target?
assert_predicate proxy, :stale_target?
assert_equal dashboards(:second), minivan.dashboard
end
@ -346,7 +346,7 @@ def test_has_one_through_belongs_to_setting_belongs_to_foreign_key_after_nil_tar
minivan.speedometer_id = speedometers(:second).id
assert proxy.stale_target?
assert_predicate proxy, :stale_target?
assert_equal dashboards(:second), minivan.dashboard
end

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