aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/validations
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2016-08-06 18:38:23 +0200
committerXavier Noria <fxn@hashref.com>2016-08-06 18:38:23 +0200
commit4c208254573c3428d82bd8744860bd86e1c78acb (patch)
tree9c8194acb75552fdda62d527d5c2876da9161650 /activemodel/test/cases/validations
parent18a2513729ab90b04b1c86963e7d5b9213270c81 (diff)
downloadrails-4c208254573c3428d82bd8744860bd86e1c78acb.tar.gz
rails-4c208254573c3428d82bd8744860bd86e1c78acb.tar.bz2
rails-4c208254573c3428d82bd8744860bd86e1c78acb.zip
applies new string literal convention in activemodel/test
The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
Diffstat (limited to 'activemodel/test/cases/validations')
-rw-r--r--activemodel/test/cases/validations/absence_validation_test.rb8
-rw-r--r--activemodel/test/cases/validations/acceptance_validation_test.rb8
-rw-r--r--activemodel/test/cases/validations/callbacks_test.rb44
-rw-r--r--activemodel/test/cases/validations/conditional_validation_test.rb4
-rw-r--r--activemodel/test/cases/validations/confirmation_validation_test.rb10
-rw-r--r--activemodel/test/cases/validations/exclusion_validation_test.rb12
-rw-r--r--activemodel/test/cases/validations/format_validation_test.rb8
-rw-r--r--activemodel/test/cases/validations/i18n_generate_message_validation_test.rb46
-rw-r--r--activemodel/test/cases/validations/i18n_validation_test.rb82
-rw-r--r--activemodel/test/cases/validations/inclusion_validation_test.rb44
-rw-r--r--activemodel/test/cases/validations/length_validation_test.rb18
-rw-r--r--activemodel/test/cases/validations/numericality_validation_test.rb78
-rw-r--r--activemodel/test/cases/validations/presence_validation_test.rb8
-rw-r--r--activemodel/test/cases/validations/validates_test.rb48
-rw-r--r--activemodel/test/cases/validations/validations_context_test.rb4
-rw-r--r--activemodel/test/cases/validations/with_validation_test.rb8
16 files changed, 215 insertions, 215 deletions
diff --git a/activemodel/test/cases/validations/absence_validation_test.rb b/activemodel/test/cases/validations/absence_validation_test.rb
index 9cbc77dfb5..3e48e591e9 100644
--- a/activemodel/test/cases/validations/absence_validation_test.rb
+++ b/activemodel/test/cases/validations/absence_validation_test.rb
@@ -1,7 +1,7 @@
-require 'cases/helper'
-require 'models/topic'
-require 'models/person'
-require 'models/custom_reader'
+require "cases/helper"
+require "models/topic"
+require "models/person"
+require "models/custom_reader"
class AbsenceValidationTest < ActiveModel::TestCase
teardown do
diff --git a/activemodel/test/cases/validations/acceptance_validation_test.rb b/activemodel/test/cases/validations/acceptance_validation_test.rb
index d3995ad5af..99f3ed3c2a 100644
--- a/activemodel/test/cases/validations/acceptance_validation_test.rb
+++ b/activemodel/test/cases/validations/acceptance_validation_test.rb
@@ -1,8 +1,8 @@
-require 'cases/helper'
+require "cases/helper"
-require 'models/topic'
-require 'models/reply'
-require 'models/person'
+require "models/topic"
+require "models/reply"
+require "models/person"
class AcceptanceValidationTest < ActiveModel::TestCase
diff --git a/activemodel/test/cases/validations/callbacks_test.rb b/activemodel/test/cases/validations/callbacks_test.rb
index 75eb18e795..06b22f0e06 100644
--- a/activemodel/test/cases/validations/callbacks_test.rb
+++ b/activemodel/test/cases/validations/callbacks_test.rb
@@ -1,4 +1,4 @@
-require 'cases/helper'
+require "cases/helper"
class Dog
include ActiveModel::Validations
@@ -15,37 +15,37 @@ class DogWithMethodCallbacks < Dog
before_validation :set_before_validation_marker
after_validation :set_after_validation_marker
- def set_before_validation_marker; self.history << 'before_validation_marker'; end
- def set_after_validation_marker; self.history << 'after_validation_marker' ; end
+ def set_before_validation_marker; self.history << "before_validation_marker"; end
+ def set_after_validation_marker; self.history << "after_validation_marker" ; end
end
class DogValidatorsAreProc < Dog
- before_validation { self.history << 'before_validation_marker' }
- after_validation { self.history << 'after_validation_marker' }
+ before_validation { self.history << "before_validation_marker" }
+ after_validation { self.history << "after_validation_marker" }
end
class DogWithTwoValidators < Dog
- before_validation { self.history << 'before_validation_marker1' }
- before_validation { self.history << 'before_validation_marker2' }
+ before_validation { self.history << "before_validation_marker1" }
+ before_validation { self.history << "before_validation_marker2" }
end
class DogDeprecatedBeforeValidatorReturningFalse < Dog
before_validation { false }
- before_validation { self.history << 'before_validation_marker2' }
+ before_validation { self.history << "before_validation_marker2" }
end
class DogBeforeValidatorThrowingAbort < Dog
before_validation { throw :abort }
- before_validation { self.history << 'before_validation_marker2' }
+ before_validation { self.history << "before_validation_marker2" }
end
class DogAfterValidatorReturningFalse < Dog
after_validation { false }
- after_validation { self.history << 'after_validation_marker' }
+ after_validation { self.history << "after_validation_marker" }
end
class DogWithMissingName < Dog
- before_validation { self.history << 'before_validation_marker' }
+ before_validation { self.history << "before_validation_marker" }
validates_presence_of :name
end
@@ -53,8 +53,8 @@ class DogValidatorWithOnCondition < Dog
before_validation :set_before_validation_marker, on: :create
after_validation :set_after_validation_marker, on: :create
- def set_before_validation_marker; self.history << 'before_validation_marker'; end
- def set_after_validation_marker; self.history << 'after_validation_marker' ; end
+ def set_before_validation_marker; self.history << "before_validation_marker"; end
+ def set_after_validation_marker; self.history << "after_validation_marker" ; end
end
class DogValidatorWithIfCondition < Dog
@@ -64,11 +64,11 @@ class DogValidatorWithIfCondition < Dog
after_validation :set_after_validation_marker1, if: -> { true }
after_validation :set_after_validation_marker2, if: -> { false }
- def set_before_validation_marker1; self.history << 'before_validation_marker1'; end
- def set_before_validation_marker2; self.history << 'before_validation_marker2' ; end
+ def set_before_validation_marker1; self.history << "before_validation_marker1"; end
+ def set_before_validation_marker2; self.history << "before_validation_marker2" ; end
- def set_after_validation_marker1; self.history << 'after_validation_marker1'; end
- def set_after_validation_marker2; self.history << 'after_validation_marker2' ; end
+ def set_after_validation_marker1; self.history << "after_validation_marker1"; end
+ def set_after_validation_marker2; self.history << "after_validation_marker2" ; end
end
@@ -101,19 +101,19 @@ class CallbacksWithMethodNamesShouldBeCalled < ActiveModel::TestCase
def test_before_validation_and_after_validation_callbacks_should_be_called
d = DogWithMethodCallbacks.new
d.valid?
- assert_equal ['before_validation_marker', 'after_validation_marker'], d.history
+ assert_equal ["before_validation_marker", "after_validation_marker"], d.history
end
def test_before_validation_and_after_validation_callbacks_should_be_called_with_proc
d = DogValidatorsAreProc.new
d.valid?
- assert_equal ['before_validation_marker', 'after_validation_marker'], d.history
+ assert_equal ["before_validation_marker", "after_validation_marker"], d.history
end
def test_before_validation_and_after_validation_callbacks_should_be_called_in_declared_order
d = DogWithTwoValidators.new
d.valid?
- assert_equal ['before_validation_marker1', 'before_validation_marker2'], d.history
+ assert_equal ["before_validation_marker1", "before_validation_marker2"], d.history
end
def test_further_callbacks_should_not_be_called_if_before_validation_throws_abort
@@ -135,13 +135,13 @@ class CallbacksWithMethodNamesShouldBeCalled < ActiveModel::TestCase
def test_further_callbacks_should_be_called_if_after_validation_returns_false
d = DogAfterValidatorReturningFalse.new
d.valid?
- assert_equal ['after_validation_marker'], d.history
+ assert_equal ["after_validation_marker"], d.history
end
def test_validation_test_should_be_done
d = DogWithMissingName.new
output = d.valid?
- assert_equal ['before_validation_marker'], d.history
+ assert_equal ["before_validation_marker"], d.history
assert_equal false, output
end
diff --git a/activemodel/test/cases/validations/conditional_validation_test.rb b/activemodel/test/cases/validations/conditional_validation_test.rb
index 296d3b4407..d92aa74e2a 100644
--- a/activemodel/test/cases/validations/conditional_validation_test.rb
+++ b/activemodel/test/cases/validations/conditional_validation_test.rb
@@ -1,6 +1,6 @@
-require 'cases/helper'
+require "cases/helper"
-require 'models/topic'
+require "models/topic"
class ConditionalValidationTest < ActiveModel::TestCase
diff --git a/activemodel/test/cases/validations/confirmation_validation_test.rb b/activemodel/test/cases/validations/confirmation_validation_test.rb
index c56bf1c0ad..9ce3955a89 100644
--- a/activemodel/test/cases/validations/confirmation_validation_test.rb
+++ b/activemodel/test/cases/validations/confirmation_validation_test.rb
@@ -1,7 +1,7 @@
-require 'cases/helper'
+require "cases/helper"
-require 'models/topic'
-require 'models/person'
+require "models/topic"
+require "models/person"
class ConfirmationValidationTest < ActiveModel::TestCase
@@ -56,9 +56,9 @@ class ConfirmationValidationTest < ActiveModel::TestCase
@old_load_path, @old_backend = I18n.load_path.dup, I18n.backend
I18n.load_path.clear
I18n.backend = I18n::Backend::Simple.new
- I18n.backend.store_translations('en', {
+ I18n.backend.store_translations("en", {
errors: { messages: { confirmation: "doesn't match %{attribute}" } },
- activemodel: { attributes: { topic: { title: 'Test Title'} } }
+ activemodel: { attributes: { topic: { title: "Test Title"} } }
})
Topic.validates_confirmation_of(:title)
diff --git a/activemodel/test/cases/validations/exclusion_validation_test.rb b/activemodel/test/cases/validations/exclusion_validation_test.rb
index 005bc15df5..42e99091fb 100644
--- a/activemodel/test/cases/validations/exclusion_validation_test.rb
+++ b/activemodel/test/cases/validations/exclusion_validation_test.rb
@@ -1,8 +1,8 @@
-require 'cases/helper'
-require 'active_support/core_ext/numeric/time'
+require "cases/helper"
+require "active_support/core_ext/numeric/time"
-require 'models/topic'
-require 'models/person'
+require "models/topic"
+require "models/person"
class ExclusionValidationTest < ActiveModel::TestCase
@@ -68,8 +68,8 @@ class ExclusionValidationTest < ActiveModel::TestCase
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 Topic.new(content: "g").invalid?
+ assert Topic.new(content: "h").valid?
end
def test_validates_exclusion_of_with_time_range
diff --git a/activemodel/test/cases/validations/format_validation_test.rb b/activemodel/test/cases/validations/format_validation_test.rb
index ea4c2ee7df..5c4a1863cd 100644
--- a/activemodel/test/cases/validations/format_validation_test.rb
+++ b/activemodel/test/cases/validations/format_validation_test.rb
@@ -1,7 +1,7 @@
-require 'cases/helper'
+require "cases/helper"
-require 'models/topic'
-require 'models/person'
+require "models/topic"
+require "models/person"
class PresenceValidationTest < ActiveModel::TestCase
@@ -63,7 +63,7 @@ class PresenceValidationTest < ActiveModel::TestCase
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')
+ t = Topic.new(title: "Invalid title")
assert t.invalid?
assert_equal ["can't be Invalid title"], t.errors[:title]
end
diff --git a/activemodel/test/cases/validations/i18n_generate_message_validation_test.rb b/activemodel/test/cases/validations/i18n_generate_message_validation_test.rb
index da63df9152..f049ee26e8 100644
--- a/activemodel/test/cases/validations/i18n_generate_message_validation_test.rb
+++ b/activemodel/test/cases/validations/i18n_generate_message_validation_test.rb
@@ -1,6 +1,6 @@
require "cases/helper"
-require 'models/person'
+require "models/person"
class I18nGenerateMessageValidationTest < ActiveModel::TestCase
def setup
@@ -10,29 +10,29 @@ class I18nGenerateMessageValidationTest < ActiveModel::TestCase
# validates_inclusion_of: generate_message(attr_name, :inclusion, message: custom_message, value: value)
def test_generate_message_inclusion_with_default_message
- assert_equal 'is not included in the list', @person.errors.generate_message(:title, :inclusion, value: 'title')
+ assert_equal "is not included in the list", @person.errors.generate_message(:title, :inclusion, value: "title")
end
def test_generate_message_inclusion_with_custom_message
- assert_equal 'custom message title', @person.errors.generate_message(:title, :inclusion, message: 'custom message %{value}', value: 'title')
+ assert_equal "custom message title", @person.errors.generate_message(:title, :inclusion, message: "custom message %{value}", value: "title")
end
# validates_exclusion_of: generate_message(attr_name, :exclusion, message: custom_message, value: value)
def test_generate_message_exclusion_with_default_message
- assert_equal 'is reserved', @person.errors.generate_message(:title, :exclusion, value: 'title')
+ assert_equal "is reserved", @person.errors.generate_message(:title, :exclusion, value: "title")
end
def test_generate_message_exclusion_with_custom_message
- assert_equal 'custom message title', @person.errors.generate_message(:title, :exclusion, message: 'custom message %{value}', value: 'title')
+ assert_equal "custom message title", @person.errors.generate_message(:title, :exclusion, message: "custom message %{value}", value: "title")
end
# validates_format_of: generate_message(attr_name, :invalid, message: custom_message, value: value)
def test_generate_message_invalid_with_default_message
- assert_equal 'is invalid', @person.errors.generate_message(:title, :invalid, value: 'title')
+ assert_equal "is invalid", @person.errors.generate_message(:title, :invalid, value: "title")
end
def test_generate_message_invalid_with_custom_message
- assert_equal 'custom message title', @person.errors.generate_message(:title, :invalid, message: 'custom message %{value}', value: 'title')
+ assert_equal "custom message title", @person.errors.generate_message(:title, :invalid, message: "custom message %{value}", value: "title")
end
# validates_confirmation_of: generate_message(attr_name, :confirmation, message: custom_message)
@@ -41,7 +41,7 @@ class I18nGenerateMessageValidationTest < ActiveModel::TestCase
end
def test_generate_message_confirmation_with_custom_message
- assert_equal 'custom message', @person.errors.generate_message(:title, :confirmation, message: 'custom message')
+ assert_equal "custom message", @person.errors.generate_message(:title, :confirmation, message: "custom message")
end
# validates_acceptance_of: generate_message(attr_name, :accepted, message: custom_message)
@@ -50,7 +50,7 @@ class I18nGenerateMessageValidationTest < ActiveModel::TestCase
end
def test_generate_message_accepted_with_custom_message
- assert_equal 'custom message', @person.errors.generate_message(:title, :accepted, message: 'custom message')
+ assert_equal "custom message", @person.errors.generate_message(:title, :accepted, message: "custom message")
end
# add_on_empty: generate_message(attr, :empty, message: custom_message)
@@ -59,7 +59,7 @@ class I18nGenerateMessageValidationTest < ActiveModel::TestCase
end
def test_generate_message_empty_with_custom_message
- assert_equal 'custom message', @person.errors.generate_message(:title, :empty, message: 'custom message')
+ assert_equal "custom message", @person.errors.generate_message(:title, :empty, message: "custom message")
end
# validates_presence_of: generate_message(attr, :blank, message: custom_message)
@@ -68,7 +68,7 @@ class I18nGenerateMessageValidationTest < ActiveModel::TestCase
end
def test_generate_message_blank_with_custom_message
- assert_equal 'custom message', @person.errors.generate_message(:title, :blank, message: 'custom message')
+ assert_equal "custom message", @person.errors.generate_message(:title, :blank, message: "custom message")
end
# validates_length_of: generate_message(attr, :too_long, message: custom_message, count: option_value.end)
@@ -81,7 +81,7 @@ class I18nGenerateMessageValidationTest < ActiveModel::TestCase
end
def test_generate_message_too_long_with_custom_message
- assert_equal 'custom message 10', @person.errors.generate_message(:title, :too_long, message: 'custom message %{count}', count: 10)
+ assert_equal "custom message 10", @person.errors.generate_message(:title, :too_long, message: "custom message %{count}", count: 10)
end
# validates_length_of: generate_message(attr, :too_short, default: custom_message, count: option_value.begin)
@@ -94,7 +94,7 @@ class I18nGenerateMessageValidationTest < ActiveModel::TestCase
end
def test_generate_message_too_short_with_custom_message
- assert_equal 'custom message 10', @person.errors.generate_message(:title, :too_short, message: 'custom message %{count}', count: 10)
+ assert_equal "custom message 10", @person.errors.generate_message(:title, :too_short, message: "custom message %{count}", count: 10)
end
# validates_length_of: generate_message(attr, :wrong_length, message: custom_message, count: option_value)
@@ -107,44 +107,44 @@ class I18nGenerateMessageValidationTest < ActiveModel::TestCase
end
def test_generate_message_wrong_length_with_custom_message
- assert_equal 'custom message 10', @person.errors.generate_message(:title, :wrong_length, message: 'custom message %{count}', count: 10)
+ assert_equal "custom message 10", @person.errors.generate_message(:title, :wrong_length, message: "custom message %{count}", count: 10)
end
# validates_numericality_of: generate_message(attr_name, :not_a_number, value: raw_value, message: custom_message)
def test_generate_message_not_a_number_with_default_message
- assert_equal "is not a number", @person.errors.generate_message(:title, :not_a_number, value: 'title')
+ assert_equal "is not a number", @person.errors.generate_message(:title, :not_a_number, value: "title")
end
def test_generate_message_not_a_number_with_custom_message
- assert_equal 'custom message title', @person.errors.generate_message(:title, :not_a_number, message: 'custom message %{value}', value: 'title')
+ assert_equal "custom message title", @person.errors.generate_message(:title, :not_a_number, message: "custom message %{value}", value: "title")
end
# validates_numericality_of: generate_message(attr_name, option, value: raw_value, default: custom_message)
def test_generate_message_greater_than_with_default_message
- assert_equal "must be greater than 10", @person.errors.generate_message(:title, :greater_than, value: 'title', count: 10)
+ assert_equal "must be greater than 10", @person.errors.generate_message(:title, :greater_than, value: "title", count: 10)
end
def test_generate_message_greater_than_or_equal_to_with_default_message
- assert_equal "must be greater than or equal to 10", @person.errors.generate_message(:title, :greater_than_or_equal_to, value: 'title', count: 10)
+ assert_equal "must be greater than or equal to 10", @person.errors.generate_message(:title, :greater_than_or_equal_to, value: "title", count: 10)
end
def test_generate_message_equal_to_with_default_message
- assert_equal "must be equal to 10", @person.errors.generate_message(:title, :equal_to, value: 'title', count: 10)
+ assert_equal "must be equal to 10", @person.errors.generate_message(:title, :equal_to, value: "title", count: 10)
end
def test_generate_message_less_than_with_default_message
- assert_equal "must be less than 10", @person.errors.generate_message(:title, :less_than, value: 'title', count: 10)
+ assert_equal "must be less than 10", @person.errors.generate_message(:title, :less_than, value: "title", count: 10)
end
def test_generate_message_less_than_or_equal_to_with_default_message
- assert_equal "must be less than or equal to 10", @person.errors.generate_message(:title, :less_than_or_equal_to, value: 'title', count: 10)
+ assert_equal "must be less than or equal to 10", @person.errors.generate_message(:title, :less_than_or_equal_to, value: "title", count: 10)
end
def test_generate_message_odd_with_default_message
- assert_equal "must be odd", @person.errors.generate_message(:title, :odd, value: 'title', count: 10)
+ assert_equal "must be odd", @person.errors.generate_message(:title, :odd, value: "title", count: 10)
end
def test_generate_message_even_with_default_message
- assert_equal "must be even", @person.errors.generate_message(:title, :even, value: 'title', count: 10)
+ assert_equal "must be even", @person.errors.generate_message(:title, :even, value: "title", count: 10)
end
end
diff --git a/activemodel/test/cases/validations/i18n_validation_test.rb b/activemodel/test/cases/validations/i18n_validation_test.rb
index 09d7226b5a..06ce91f838 100644
--- a/activemodel/test/cases/validations/i18n_validation_test.rb
+++ b/activemodel/test/cases/validations/i18n_validation_test.rb
@@ -1,5 +1,5 @@
require "cases/helper"
-require 'models/person'
+require "models/person"
class I18nValidationTest < ActiveModel::TestCase
@@ -10,7 +10,7 @@ class I18nValidationTest < ActiveModel::TestCase
@old_load_path, @old_backend = I18n.load_path.dup, I18n.backend
I18n.load_path.clear
I18n.backend = I18n::Backend::Simple.new
- I18n.backend.store_translations('en', errors: { messages: { custom: nil } })
+ I18n.backend.store_translations("en", errors: { messages: { custom: nil } })
end
def teardown
@@ -21,23 +21,23 @@ class I18nValidationTest < ActiveModel::TestCase
end
def test_full_message_encoding
- I18n.backend.store_translations('en', errors: {
- messages: { too_short: '猫舌' } })
+ I18n.backend.store_translations("en", errors: {
+ messages: { too_short: "猫舌" } })
Person.validates_length_of :title, within: 3..5
@person.valid?
- assert_equal ['Title 猫舌'], @person.errors.full_messages
+ assert_equal ["Title 猫舌"], @person.errors.full_messages
end
def test_errors_full_messages_translates_human_attribute_name_for_model_attributes
- @person.errors.add(:name, 'not found')
- assert_called_with(Person, :human_attribute_name, [:name, default: 'Name'], returns: "Person's name") do
+ @person.errors.add(:name, "not found")
+ assert_called_with(Person, :human_attribute_name, [:name, default: "Name"], returns: "Person's name") do
assert_equal ["Person's name not found"], @person.errors.full_messages
end
end
def test_errors_full_messages_uses_format
- I18n.backend.store_translations('en', errors: { format: "Field %{attribute} %{message}" })
- @person.errors.add('name', 'empty')
+ I18n.backend.store_translations("en", errors: { format: "Field %{attribute} %{message}" })
+ @person.errors.add("name", "empty")
assert_equal ["Field Name empty"], @person.errors.full_messages
end
@@ -58,8 +58,8 @@ class I18nValidationTest < ActiveModel::TestCase
COMMON_CASES.each do |name, validation_options, generate_message_options|
test "validates_confirmation_of on generated message #{name}" do
Person.validates_confirmation_of :title, validation_options
- @person.title_confirmation = 'foo'
- call = [:title_confirmation, :confirmation, generate_message_options.merge(attribute: 'Title')]
+ @person.title_confirmation = "foo"
+ call = [:title_confirmation, :confirmation, generate_message_options.merge(attribute: "Title")]
assert_called_with(@person.errors, :generate_message, call) do
@person.valid?
end
@@ -99,7 +99,7 @@ class I18nValidationTest < ActiveModel::TestCase
COMMON_CASES.each do |name, validation_options, generate_message_options|
test "validates_length_of for :too_long generated message #{name}" do
Person.validates_length_of :title, validation_options.merge(within: 3..5)
- @person.title = 'this title is too long'
+ @person.title = "this title is too long"
call = [:title, :too_long, generate_message_options.merge(count: 5)]
assert_called_with(@person.errors, :generate_message, call) do
@person.valid?
@@ -120,8 +120,8 @@ class I18nValidationTest < ActiveModel::TestCase
COMMON_CASES.each do |name, validation_options, generate_message_options|
test "validates_format_of on generated message #{name}" do
Person.validates_format_of :title, validation_options.merge(with: /\A[1-9][0-9]*\z/)
- @person.title = '72x'
- call = [:title, :invalid, generate_message_options.merge(value: '72x')]
+ @person.title = "72x"
+ call = [:title, :invalid, generate_message_options.merge(value: "72x")]
assert_called_with(@person.errors, :generate_message, call) do
@person.valid?
end
@@ -131,8 +131,8 @@ class I18nValidationTest < ActiveModel::TestCase
COMMON_CASES.each do |name, validation_options, generate_message_options|
test "validates_inclusion_of on generated message #{name}" do
Person.validates_inclusion_of :title, validation_options.merge(in: %w(a b c))
- @person.title = 'z'
- call = [:title, :inclusion, generate_message_options.merge(value: 'z')]
+ @person.title = "z"
+ call = [:title, :inclusion, generate_message_options.merge(value: "z")]
assert_called_with(@person.errors, :generate_message, call) do
@person.valid?
end
@@ -142,8 +142,8 @@ class I18nValidationTest < ActiveModel::TestCase
COMMON_CASES.each do |name, validation_options, generate_message_options|
test "validates_inclusion_of using :within on generated message #{name}" do
Person.validates_inclusion_of :title, validation_options.merge(within: %w(a b c))
- @person.title = 'z'
- call = [:title, :inclusion, generate_message_options.merge(value: 'z')]
+ @person.title = "z"
+ call = [:title, :inclusion, generate_message_options.merge(value: "z")]
assert_called_with(@person.errors, :generate_message, call) do
@person.valid?
end
@@ -153,8 +153,8 @@ class I18nValidationTest < ActiveModel::TestCase
COMMON_CASES.each do |name, validation_options, generate_message_options|
test "validates_exclusion_of generated message #{name}" do
Person.validates_exclusion_of :title, validation_options.merge(in: %w(a b c))
- @person.title = 'a'
- call = [:title, :exclusion, generate_message_options.merge(value: 'a')]
+ @person.title = "a"
+ call = [:title, :exclusion, generate_message_options.merge(value: "a")]
assert_called_with(@person.errors, :generate_message, call) do
@person.valid?
end
@@ -164,8 +164,8 @@ class I18nValidationTest < ActiveModel::TestCase
COMMON_CASES.each do |name, validation_options, generate_message_options|
test "validates_exclusion_of using :within generated message #{name}" do
Person.validates_exclusion_of :title, validation_options.merge(within: %w(a b c))
- @person.title = 'a'
- call = [:title, :exclusion, generate_message_options.merge(value: 'a')]
+ @person.title = "a"
+ call = [:title, :exclusion, generate_message_options.merge(value: "a")]
assert_called_with(@person.errors, :generate_message, call) do
@person.valid?
end
@@ -175,8 +175,8 @@ class I18nValidationTest < ActiveModel::TestCase
COMMON_CASES.each do |name, validation_options, generate_message_options|
test "validates_numericality_of generated message #{name}" do
Person.validates_numericality_of :title, validation_options
- @person.title = 'a'
- call = [:title, :not_a_number, generate_message_options.merge(value: 'a')]
+ @person.title = "a"
+ call = [:title, :not_a_number, generate_message_options.merge(value: "a")]
assert_called_with(@person.errors, :generate_message, call) do
@person.valid?
end
@@ -186,8 +186,8 @@ class I18nValidationTest < ActiveModel::TestCase
COMMON_CASES.each do |name, validation_options, generate_message_options|
test "validates_numericality_of for :only_integer on generated message #{name}" do
Person.validates_numericality_of :title, validation_options.merge(only_integer: true)
- @person.title = '0.0'
- call = [:title, :not_an_integer, generate_message_options.merge(value: '0.0')]
+ @person.title = "0.0"
+ call = [:title, :not_an_integer, generate_message_options.merge(value: "0.0")]
assert_called_with(@person.errors, :generate_message, call) do
@person.valid?
end
@@ -225,35 +225,35 @@ class I18nValidationTest < ActiveModel::TestCase
end
test "#{validation} finds custom model key translation when #{error_type}" do
- I18n.backend.store_translations 'en', activemodel: { errors: { models: { person: { attributes: { attribute => { error_type => 'custom message' } } } } } }
- I18n.backend.store_translations 'en', errors: { messages: { error_type => 'global message'}}
+ I18n.backend.store_translations "en", activemodel: { errors: { models: { person: { attributes: { attribute => { error_type => "custom message" } } } } } }
+ I18n.backend.store_translations "en", errors: { messages: { error_type => "global message"}}
yield(@person, {})
@person.valid?
- assert_equal ['custom message'], @person.errors[attribute]
+ assert_equal ["custom message"], @person.errors[attribute]
end
test "#{validation} finds custom model key translation with interpolation when #{error_type}" do
- I18n.backend.store_translations 'en', activemodel: { errors: { models: { person: { attributes: { attribute => { error_type => 'custom message with %{extra}' } } } } } }
- I18n.backend.store_translations 'en', errors: { messages: {error_type => 'global message'} }
+ I18n.backend.store_translations "en", activemodel: { errors: { models: { person: { attributes: { attribute => { error_type => "custom message with %{extra}" } } } } } }
+ I18n.backend.store_translations "en", errors: { messages: {error_type => "global message"} }
yield(@person, { extra: "extra information" })
@person.valid?
- assert_equal ['custom message with extra information'], @person.errors[attribute]
+ assert_equal ["custom message with extra information"], @person.errors[attribute]
end
test "#{validation} finds global default key translation when #{error_type}" do
- I18n.backend.store_translations 'en', errors: { messages: {error_type => 'global message'} }
+ I18n.backend.store_translations "en", errors: { messages: {error_type => "global message"} }
yield(@person, {})
@person.valid?
- assert_equal ['global message'], @person.errors[attribute]
+ assert_equal ["global message"], @person.errors[attribute]
end
end
set_expectations_for_validation "validates_confirmation_of", :confirmation do |person, options_to_merge|
Person.validates_confirmation_of :title, options_to_merge
- person.title_confirmation = 'foo'
+ person.title_confirmation = "foo"
end
set_expectations_for_validation "validates_acceptance_of", :accepted do |person, options_to_merge|
@@ -287,17 +287,17 @@ class I18nValidationTest < ActiveModel::TestCase
set_expectations_for_validation "validates_exclusion_of", :exclusion do |person, options_to_merge|
Person.validates_exclusion_of :title, options_to_merge.merge(in: %w(a b c))
- person.title = 'a'
+ person.title = "a"
end
set_expectations_for_validation "validates_numericality_of", :not_a_number do |person, options_to_merge|
Person.validates_numericality_of :title, options_to_merge
- person.title = 'a'
+ person.title = "a"
end
set_expectations_for_validation "validates_numericality_of", :not_an_integer do |person, options_to_merge|
Person.validates_numericality_of :title, options_to_merge.merge(only_integer: true)
- person.title = '1.0'
+ person.title = "1.0"
end
set_expectations_for_validation "validates_numericality_of", :odd do |person, options_to_merge|
@@ -311,7 +311,7 @@ class I18nValidationTest < ActiveModel::TestCase
end
def test_validations_with_message_symbol_must_translate
- I18n.backend.store_translations 'en', errors: { messages: { custom_error: "I am a custom error" } }
+ I18n.backend.store_translations "en", errors: { messages: { custom_error: "I am a custom error" } }
Person.validates_presence_of :title, message: :custom_error
@person.title = nil
@person.valid?
@@ -319,7 +319,7 @@ class I18nValidationTest < ActiveModel::TestCase
end
def test_validates_with_message_symbol_must_translate_per_attribute
- I18n.backend.store_translations 'en', activemodel: { errors: { models: { person: { attributes: { title: { custom_error: "I am a custom error" } } } } } }
+ I18n.backend.store_translations "en", activemodel: { errors: { models: { person: { attributes: { title: { custom_error: "I am a custom error" } } } } } }
Person.validates_presence_of :title, message: :custom_error
@person.title = nil
@person.valid?
@@ -327,7 +327,7 @@ class I18nValidationTest < ActiveModel::TestCase
end
def test_validates_with_message_symbol_must_translate_per_model
- I18n.backend.store_translations 'en', activemodel: { errors: { models: { person: { custom_error: "I am a custom error" } } } }
+ I18n.backend.store_translations "en", activemodel: { errors: { models: { person: { custom_error: "I am a custom error" } } } }
Person.validates_presence_of :title, message: :custom_error
@person.title = nil
@person.valid?
diff --git a/activemodel/test/cases/validations/inclusion_validation_test.rb b/activemodel/test/cases/validations/inclusion_validation_test.rb
index 9bd44175a6..96d55c1352 100644
--- a/activemodel/test/cases/validations/inclusion_validation_test.rb
+++ b/activemodel/test/cases/validations/inclusion_validation_test.rb
@@ -1,8 +1,8 @@
-require 'cases/helper'
-require 'active_support/all'
+require "cases/helper"
+require "active_support/all"
-require 'models/topic'
-require 'models/person'
+require "models/topic"
+require "models/person"
class InclusionValidationTest < ActiveModel::TestCase
@@ -11,7 +11,7 @@ class InclusionValidationTest < ActiveModel::TestCase
end
def test_validates_inclusion_of_range
- Topic.validates_inclusion_of(:title, in: 'aaa'..'bbb')
+ 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?
@@ -24,35 +24,35 @@ class InclusionValidationTest < ActiveModel::TestCase
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 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?
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 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?
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 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?
end
def test_validates_inclusion_of
diff --git a/activemodel/test/cases/validations/length_validation_test.rb b/activemodel/test/cases/validations/length_validation_test.rb
index 11dce1df20..dbbfb8351b 100644
--- a/activemodel/test/cases/validations/length_validation_test.rb
+++ b/activemodel/test/cases/validations/length_validation_test.rb
@@ -1,7 +1,7 @@
-require 'cases/helper'
+require "cases/helper"
-require 'models/topic'
-require 'models/person'
+require "models/topic"
+require "models/person"
class LengthValidationTest < ActiveModel::TestCase
def teardown
@@ -125,7 +125,7 @@ class LengthValidationTest < ActiveModel::TestCase
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')
+ t = Topic.new("title" => "abc", "content" => "abcd")
assert t.valid?
t.title = nil
@@ -228,17 +228,17 @@ class LengthValidationTest < ActiveModel::TestCase
end
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'
+ Topic.validates_length_of :title, minimum: 3, maximum: 5, too_short: "too short", too_long: "too long"
- t = Topic.new(title: 'a')
+ t = Topic.new(title: "a")
assert t.invalid?
assert t.errors[:title].any?
- assert_equal ['too short'], t.errors['title']
+ assert_equal ["too short"], t.errors["title"]
- t = Topic.new(title: 'aaaaaa')
+ t = Topic.new(title: "aaaaaa")
assert t.invalid?
assert t.errors[:title].any?
- assert_equal ['too long'], t.errors['title']
+ assert_equal ["too long"], t.errors["title"]
end
def test_validates_length_of_custom_errors_for_is_with_message
diff --git a/activemodel/test/cases/validations/numericality_validation_test.rb b/activemodel/test/cases/validations/numericality_validation_test.rb
index 74a048537d..742a9fc679 100644
--- a/activemodel/test/cases/validations/numericality_validation_test.rb
+++ b/activemodel/test/cases/validations/numericality_validation_test.rb
@@ -1,10 +1,10 @@
-require 'cases/helper'
+require "cases/helper"
-require 'models/topic'
-require 'models/person'
+require "models/topic"
+require "models/person"
-require 'bigdecimal'
-require 'active_support/core_ext/big_decimal'
+require "bigdecimal"
+require "active_support/core_ext/big_decimal"
class NumericalityValidationTest < ActiveModel::TestCase
@@ -68,119 +68,119 @@ class NumericalityValidationTest < ActiveModel::TestCase
def test_validates_numericality_with_greater_than
Topic.validates_numericality_of :approved, greater_than: 10
- invalid!([-10, 10], 'must be greater than 10')
+ invalid!([-10, 10], "must be greater than 10")
valid!([11])
end
def test_validates_numericality_with_greater_than_using_differing_numeric_types
- Topic.validates_numericality_of :approved, greater_than: BigDecimal.new('97.18')
+ Topic.validates_numericality_of :approved, greater_than: BigDecimal.new("97.18")
- invalid!([-97.18, BigDecimal.new('97.18'), BigDecimal('-97.18')], 'must be greater than 97.18')
- valid!([97.18, 98, BigDecimal.new('98')]) # Notice the 97.18 as a float is greater than 97.18 as a BigDecimal due to floating point precision
+ invalid!([-97.18, BigDecimal.new("97.18"), BigDecimal("-97.18")], "must be greater than 97.18")
+ valid!([97.18, 98, BigDecimal.new("98")]) # Notice the 97.18 as a float is greater than 97.18 as a BigDecimal due to floating point precision
end
def test_validates_numericality_with_greater_than_using_string_value
Topic.validates_numericality_of :approved, greater_than: 10
- invalid!(['-10', '9', '9.9', '10'], 'must be greater than 10')
- valid!(['10.1', '11'])
+ invalid!(["-10", "9", "9.9", "10"], "must be greater than 10")
+ valid!(["10.1", "11"])
end
def test_validates_numericality_with_greater_than_or_equal
Topic.validates_numericality_of :approved, greater_than_or_equal_to: 10
- invalid!([-9, 9], 'must be greater than or equal to 10')
+ invalid!([-9, 9], "must be greater than or equal to 10")
valid!([10])
end
def test_validates_numericality_with_greater_than_or_equal_using_differing_numeric_types
- Topic.validates_numericality_of :approved, greater_than_or_equal_to: BigDecimal.new('97.18')
+ Topic.validates_numericality_of :approved, greater_than_or_equal_to: BigDecimal.new("97.18")
- invalid!([-97.18, 97.17, 97, BigDecimal.new('97.17'), BigDecimal.new('-97.18')], 'must be greater than or equal to 97.18')
- valid!([97.18, 98, BigDecimal.new('97.19')])
+ invalid!([-97.18, 97.17, 97, BigDecimal.new("97.17"), BigDecimal.new("-97.18")], "must be greater than or equal to 97.18")
+ valid!([97.18, 98, BigDecimal.new("97.19")])
end
def test_validates_numericality_with_greater_than_or_equal_using_string_value
Topic.validates_numericality_of :approved, greater_than_or_equal_to: 10
- invalid!(['-10', '9', '9.9'], 'must be greater than or equal to 10')
- valid!(['10', '10.1', '11'])
+ invalid!(["-10", "9", "9.9"], "must be greater than or equal to 10")
+ valid!(["10", "10.1", "11"])
end
def test_validates_numericality_with_equal_to
Topic.validates_numericality_of :approved, equal_to: 10
- invalid!([-10, 11] + INFINITY, 'must be equal to 10')
+ invalid!([-10, 11] + INFINITY, "must be equal to 10")
valid!([10])
end
def test_validates_numericality_with_equal_to_using_differing_numeric_types
- Topic.validates_numericality_of :approved, equal_to: BigDecimal.new('97.18')
+ Topic.validates_numericality_of :approved, equal_to: BigDecimal.new("97.18")
- invalid!([-97.18, 97.18], 'must be equal to 97.18')
- valid!([BigDecimal.new('97.18')])
+ invalid!([-97.18, 97.18], "must be equal to 97.18")
+ valid!([BigDecimal.new("97.18")])
end
def test_validates_numericality_with_equal_to_using_string_value
Topic.validates_numericality_of :approved, equal_to: 10
- invalid!(['-10', '9', '9.9', '10.1', '11'], 'must be equal to 10')
- valid!(['10'])
+ invalid!(["-10", "9", "9.9", "10.1", "11"], "must be equal to 10")
+ valid!(["10"])
end
def test_validates_numericality_with_less_than
Topic.validates_numericality_of :approved, less_than: 10
- invalid!([10], 'must be less than 10')
+ invalid!([10], "must be less than 10")
valid!([-9, 9])
end
def test_validates_numericality_with_less_than_using_differing_numeric_types
- Topic.validates_numericality_of :approved, less_than: BigDecimal.new('97.18')
+ Topic.validates_numericality_of :approved, less_than: BigDecimal.new("97.18")
- invalid!([97.18, BigDecimal.new('97.18')], 'must be less than 97.18')
- valid!([-97.0, 97.0, -97, 97, BigDecimal.new('-97'), BigDecimal.new('97')])
+ invalid!([97.18, BigDecimal.new("97.18")], "must be less than 97.18")
+ valid!([-97.0, 97.0, -97, 97, BigDecimal.new("-97"), BigDecimal.new("97")])
end
def test_validates_numericality_with_less_than_using_string_value
Topic.validates_numericality_of :approved, less_than: 10
- invalid!(['10', '10.1', '11'], 'must be less than 10')
- valid!(['-10', '9', '9.9'])
+ invalid!(["10", "10.1", "11"], "must be less than 10")
+ valid!(["-10", "9", "9.9"])
end
def test_validates_numericality_with_less_than_or_equal_to
Topic.validates_numericality_of :approved, less_than_or_equal_to: 10
- invalid!([11], 'must be less than or equal to 10')
+ invalid!([11], "must be less than or equal to 10")
valid!([-10, 10])
end
def test_validates_numericality_with_less_than_or_equal_to_using_differing_numeric_types
- Topic.validates_numericality_of :approved, less_than_or_equal_to: BigDecimal.new('97.18')
+ Topic.validates_numericality_of :approved, less_than_or_equal_to: BigDecimal.new("97.18")
- invalid!([97.18, 98], 'must be less than or equal to 97.18')
- valid!([-97.18, BigDecimal.new('-97.18'), BigDecimal.new('97.18')])
+ invalid!([97.18, 98], "must be less than or equal to 97.18")
+ valid!([-97.18, BigDecimal.new("-97.18"), BigDecimal.new("97.18")])
end
def test_validates_numericality_with_less_than_or_equal_using_string_value
Topic.validates_numericality_of :approved, less_than_or_equal_to: 10
- invalid!(['10.1', '11'], 'must be less than or equal to 10')
- valid!(['-10', '9', '9.9', '10'])
+ invalid!(["10.1", "11"], "must be less than or equal to 10")
+ valid!(["-10", "9", "9.9", "10"])
end
def test_validates_numericality_with_odd
Topic.validates_numericality_of :approved, odd: true
- invalid!([-2, 2], 'must be odd')
+ invalid!([-2, 2], "must be odd")
valid!([-1, 1])
end
def test_validates_numericality_with_even
Topic.validates_numericality_of :approved, even: true
- invalid!([-1, 1], 'must be even')
+ invalid!([-1, 1], "must be even")
valid!([-2, 2])
end
@@ -201,8 +201,8 @@ class NumericalityValidationTest < ActiveModel::TestCase
def test_validates_numericality_with_other_than_using_string_value
Topic.validates_numericality_of :approved, other_than: 0
- invalid!(['0', '0.0'])
- valid!(['-1', '1.1', '42'])
+ invalid!(["0", "0.0"])
+ valid!(["-1", "1.1", "42"])
end
def test_validates_numericality_with_proc
diff --git a/activemodel/test/cases/validations/presence_validation_test.rb b/activemodel/test/cases/validations/presence_validation_test.rb
index 59b9db0795..639a443632 100644
--- a/activemodel/test/cases/validations/presence_validation_test.rb
+++ b/activemodel/test/cases/validations/presence_validation_test.rb
@@ -1,8 +1,8 @@
-require 'cases/helper'
+require "cases/helper"
-require 'models/topic'
-require 'models/person'
-require 'models/custom_reader'
+require "models/topic"
+require "models/person"
+require "models/custom_reader"
class PresenceValidationTest < ActiveModel::TestCase
diff --git a/activemodel/test/cases/validations/validates_test.rb b/activemodel/test/cases/validations/validates_test.rb
index 04101f3545..af89a5e0b8 100644
--- a/activemodel/test/cases/validations/validates_test.rb
+++ b/activemodel/test/cases/validations/validates_test.rb
@@ -1,8 +1,8 @@
-require 'cases/helper'
-require 'models/person'
-require 'models/topic'
-require 'models/person_with_validator'
-require 'validators/namespace/email_validator'
+require "cases/helper"
+require "models/person"
+require "models/topic"
+require "models/person_with_validator"
+require "validators/namespace/email_validator"
class ValidatesTest < ActiveModel::TestCase
setup :reset_callbacks
@@ -17,21 +17,21 @@ class ValidatesTest < ActiveModel::TestCase
def test_validates_with_messages_empty
Person.validates :title, presence: { message: "" }
person = Person.new
- assert !person.valid?, 'person should not be valid.'
+ assert !person.valid?, "person should not be valid."
end
def test_validates_with_built_in_validation
Person.validates :title, numericality: true
person = Person.new
person.valid?
- assert_equal ['is not a number'], person.errors[:title]
+ assert_equal ["is not a number"], person.errors[:title]
end
def test_validates_with_attribute_specified_as_string
Person.validates "title", numericality: true
person = Person.new
person.valid?
- assert_equal ['is not a number'], person.errors[:title]
+ assert_equal ["is not a number"], person.errors[:title]
person = Person.new
person.title = 123
@@ -39,24 +39,24 @@ class ValidatesTest < ActiveModel::TestCase
end
def test_validates_with_built_in_validation_and_options
- Person.validates :salary, numericality: { message: 'my custom message' }
+ Person.validates :salary, numericality: { message: "my custom message" }
person = Person.new
person.valid?
- assert_equal ['my custom message'], person.errors[:salary]
+ assert_equal ["my custom message"], person.errors[:salary]
end
def test_validates_with_validator_class
Person.validates :karma, email: true
person = Person.new
person.valid?
- assert_equal ['is not an email'], person.errors[:karma]
+ assert_equal ["is not an email"], person.errors[:karma]
end
def test_validates_with_namespaced_validator_class
Person.validates :karma, :'namespace/email' => true
person = Person.new
person.valid?
- assert_equal ['is not an email'], person.errors[:karma]
+ assert_equal ["is not an email"], person.errors[:karma]
end
def test_validates_with_if_as_local_conditions
@@ -89,7 +89,7 @@ class ValidatesTest < ActiveModel::TestCase
Person.validates :karma, format: /positive|negative/
person = Person.new
assert person.invalid?
- assert_equal ['is invalid'], person.errors[:karma]
+ assert_equal ["is invalid"], person.errors[:karma]
person.karma = "positive"
assert person.valid?
end
@@ -98,7 +98,7 @@ class ValidatesTest < ActiveModel::TestCase
Person.validates :gender, inclusion: %w(m f)
person = Person.new
assert person.invalid?
- assert_equal ['is not included in the list'], person.errors[:gender]
+ assert_equal ["is not included in the list"], person.errors[:gender]
person.gender = "m"
assert person.valid?
end
@@ -107,16 +107,16 @@ class ValidatesTest < ActiveModel::TestCase
Person.validates :karma, length: 6..20
person = Person.new
assert person.invalid?
- assert_equal ['is too short (minimum is 6 characters)'], person.errors[:karma]
- person.karma = 'something'
+ assert_equal ["is too short (minimum is 6 characters)"], person.errors[:karma]
+ person.karma = "something"
assert person.valid?
end
def test_validates_with_validator_class_and_options
- Person.validates :karma, email: { message: 'my custom message' }
+ Person.validates :karma, email: { message: "my custom message" }
person = Person.new
person.valid?
- assert_equal ['my custom message'], person.errors[:karma]
+ assert_equal ["my custom message"], person.errors[:karma]
end
def test_validates_with_unknown_validator
@@ -127,14 +127,14 @@ class ValidatesTest < ActiveModel::TestCase
PersonWithValidator.validates :title, presence: true
person = PersonWithValidator.new
person.valid?
- assert_equal ['Local validator'], person.errors[:title]
+ assert_equal ["Local validator"], person.errors[:title]
end
def test_validates_with_included_validator_and_options
- PersonWithValidator.validates :title, presence: { custom: ' please' }
+ PersonWithValidator.validates :title, presence: { custom: " please" }
person = PersonWithValidator.new
person.valid?
- assert_equal ['Local validator please'], person.errors[:title]
+ assert_equal ["Local validator please"], person.errors[:title]
end
def test_validates_with_included_validator_and_wildcard_shortcut
@@ -143,15 +143,15 @@ class ValidatesTest < ActiveModel::TestCase
person = PersonWithValidator.new
person.title = "Ms. Pacman"
person.valid?
- assert_equal ['does not appear to be like Mr.'], person.errors[:title]
+ assert_equal ["does not appear to be like Mr."], person.errors[:title]
end
def test_defining_extra_default_keys_for_validates
- Topic.validates :title, confirmation: true, message: 'Y U NO CONFIRM'
+ Topic.validates :title, confirmation: true, message: "Y U NO CONFIRM"
topic = Topic.new
topic.title = "What's happening"
topic.title_confirmation = "Not this"
assert !topic.valid?
- assert_equal ['Y U NO CONFIRM'], topic.errors[:title_confirmation]
+ assert_equal ["Y U NO CONFIRM"], topic.errors[:title_confirmation]
end
end
diff --git a/activemodel/test/cases/validations/validations_context_test.rb b/activemodel/test/cases/validations/validations_context_test.rb
index b901a1523e..e5690da89a 100644
--- a/activemodel/test/cases/validations/validations_context_test.rb
+++ b/activemodel/test/cases/validations/validations_context_test.rb
@@ -1,6 +1,6 @@
-require 'cases/helper'
+require "cases/helper"
-require 'models/topic'
+require "models/topic"
class ValidationsContextTest < ActiveModel::TestCase
def teardown
diff --git a/activemodel/test/cases/validations/with_validation_test.rb b/activemodel/test/cases/validations/with_validation_test.rb
index c73580138d..4932ce1d9a 100644
--- a/activemodel/test/cases/validations/with_validation_test.rb
+++ b/activemodel/test/cases/validations/with_validation_test.rb
@@ -1,6 +1,6 @@
-require 'cases/helper'
+require "cases/helper"
-require 'models/topic'
+require "models/topic"
class ValidatesWithTest < ActiveModel::TestCase
@@ -160,7 +160,7 @@ class ValidatesWithTest < ActiveModel::TestCase
topic = Topic.new
assert !topic.valid?
- assert_equal ['is missing'], topic.errors[:title]
+ assert_equal ["is missing"], topic.errors[:title]
end
test "optionally pass in the attribute being validated when validating with an instance method" do
@@ -169,6 +169,6 @@ class ValidatesWithTest < ActiveModel::TestCase
topic = Topic.new title: "foo"
assert !topic.valid?
assert topic.errors[:title].empty?
- assert_equal ['is missing'], topic.errors[:content]
+ assert_equal ["is missing"], topic.errors[:content]
end
end