aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activemodel/test/cases/attribute_methods_test.rb80
-rw-r--r--activemodel/test/cases/callbacks_test.rb4
-rw-r--r--activemodel/test/cases/conversion_test.rb6
-rw-r--r--activemodel/test/cases/dirty_test.rb46
-rw-r--r--activemodel/test/cases/errors_test.rb34
-rw-r--r--activemodel/test/cases/forbidden_attributes_protection_test.rb6
-rw-r--r--activemodel/test/cases/helper.rb12
-rw-r--r--activemodel/test/cases/lint_test.rb2
-rw-r--r--activemodel/test/cases/model_test.rb14
-rw-r--r--activemodel/test/cases/naming_test.rb94
-rw-r--r--activemodel/test/cases/railtie_test.rb14
-rw-r--r--activemodel/test/cases/secure_password_test.rb118
-rw-r--r--activemodel/test/cases/serialization_test.rb36
-rw-r--r--activemodel/test/cases/serializers/json_serialization_test.rb16
-rw-r--r--activemodel/test/cases/translation_test.rb82
-rw-r--r--activemodel/test/cases/type/decimal_test.rb6
-rw-r--r--activemodel/test/cases/type/integer_test.rb18
-rw-r--r--activemodel/test/cases/types_test.rb60
-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
-rw-r--r--activemodel/test/cases/validations_test.rb42
-rw-r--r--activemodel/test/models/reply.rb2
-rw-r--r--activemodel/test/validators/email_validator.rb2
-rw-r--r--activemodel/test/validators/namespace/email_validator.rb2
38 files changed, 563 insertions, 563 deletions
diff --git a/activemodel/test/cases/attribute_methods_test.rb b/activemodel/test/cases/attribute_methods_test.rb
index e81b7ac424..89166f2f1e 100644
--- a/activemodel/test/cases/attribute_methods_test.rb
+++ b/activemodel/test/cases/attribute_methods_test.rb
@@ -1,16 +1,16 @@
-require 'cases/helper'
+require "cases/helper"
class ModelWithAttributes
include ActiveModel::AttributeMethods
class << self
define_method(:bar) do
- 'original bar'
+ "original bar"
end
end
def attributes
- { foo: 'value of foo', baz: 'value of baz' }
+ { foo: "value of foo", baz: "value of baz" }
end
private
@@ -24,7 +24,7 @@ class ModelWithAttributes2
attr_accessor :attributes
- attribute_method_suffix '_test'
+ attribute_method_suffix "_test"
private
def attribute(name)
@@ -48,7 +48,7 @@ class ModelWithAttributesWithSpaces
include ActiveModel::AttributeMethods
def attributes
- { :'foo bar' => 'value of foo bar'}
+ { :'foo bar' => "value of foo bar"}
end
private
@@ -62,12 +62,12 @@ class ModelWithWeirdNamesAttributes
class << self
define_method(:'c?d') do
- 'original c?d'
+ "original c?d"
end
end
def attributes
- { :'a?b' => 'value of a?b' }
+ { :'a?b' => "value of a?b" }
end
private
@@ -80,7 +80,7 @@ class ModelWithRubyKeywordNamedAttributes
include ActiveModel::AttributeMethods
def attributes
- { begin: 'value of begin', end: 'value of end' }
+ { begin: "value of begin", end: "value of end" }
end
private
@@ -94,16 +94,16 @@ class ModelWithoutAttributesMethod
end
class AttributeMethodsTest < ActiveModel::TestCase
- test 'method missing works correctly even if attributes method is not defined' do
+ test "method missing works correctly even if attributes method is not defined" do
assert_raises(NoMethodError) { ModelWithoutAttributesMethod.new.foo }
end
- test 'unrelated classes should not share attribute method matchers' do
+ test "unrelated classes should not share attribute method matchers" do
assert_not_equal ModelWithAttributes.send(:attribute_method_matchers),
ModelWithAttributes2.send(:attribute_method_matchers)
end
- test '#define_attribute_method generates attribute method' do
+ test "#define_attribute_method generates attribute method" do
begin
ModelWithAttributes.define_attribute_method(:foo)
@@ -114,19 +114,19 @@ class AttributeMethodsTest < ActiveModel::TestCase
end
end
- test '#define_attribute_method does not generate attribute method if already defined in attribute module' do
+ test "#define_attribute_method does not generate attribute method if already defined in attribute module" do
klass = Class.new(ModelWithAttributes)
klass.generated_attribute_methods.module_eval do
def foo
- '<3'
+ "<3"
end
end
klass.define_attribute_method(:foo)
- assert_equal '<3', klass.new.foo
+ assert_equal "<3", klass.new.foo
end
- test '#define_attribute_method generates a method that is already defined on the host' do
+ test "#define_attribute_method generates a method that is already defined on the host" do
klass = Class.new(ModelWithAttributes) do
def foo
super
@@ -134,21 +134,21 @@ class AttributeMethodsTest < ActiveModel::TestCase
end
klass.define_attribute_method(:foo)
- assert_equal 'value of foo', klass.new.foo
+ assert_equal "value of foo", klass.new.foo
end
- test '#define_attribute_method generates attribute method with invalid identifier characters' do
+ test "#define_attribute_method generates attribute method with invalid identifier characters" do
begin
ModelWithWeirdNamesAttributes.define_attribute_method(:'a?b')
assert_respond_to ModelWithWeirdNamesAttributes.new, :'a?b'
- assert_equal "value of a?b", ModelWithWeirdNamesAttributes.new.send('a?b')
+ assert_equal "value of a?b", ModelWithWeirdNamesAttributes.new.send("a?b")
ensure
ModelWithWeirdNamesAttributes.undefine_attribute_methods
end
end
- test '#define_attribute_methods works passing multiple arguments' do
+ test "#define_attribute_methods works passing multiple arguments" do
begin
ModelWithAttributes.define_attribute_methods(:foo, :baz)
@@ -159,7 +159,7 @@ class AttributeMethodsTest < ActiveModel::TestCase
end
end
- test '#define_attribute_methods generates attribute methods' do
+ test "#define_attribute_methods generates attribute methods" do
begin
ModelWithAttributes.define_attribute_methods(:foo)
@@ -170,7 +170,7 @@ class AttributeMethodsTest < ActiveModel::TestCase
end
end
- test '#alias_attribute generates attribute_aliases lookup hash' do
+ test "#alias_attribute generates attribute_aliases lookup hash" do
klass = Class.new(ModelWithAttributes) do
define_attribute_methods :foo
alias_attribute :bar, :foo
@@ -179,7 +179,7 @@ class AttributeMethodsTest < ActiveModel::TestCase
assert_equal({ "bar" => "foo" }, klass.attribute_aliases)
end
- test '#define_attribute_methods generates attribute methods with spaces in their names' do
+ test "#define_attribute_methods generates attribute methods with spaces in their names" do
begin
ModelWithAttributesWithSpaces.define_attribute_methods(:'foo bar')
@@ -190,7 +190,7 @@ class AttributeMethodsTest < ActiveModel::TestCase
end
end
- test '#alias_attribute works with attributes with spaces in their names' do
+ test "#alias_attribute works with attributes with spaces in their names" do
begin
ModelWithAttributesWithSpaces.define_attribute_methods(:'foo bar')
ModelWithAttributesWithSpaces.alias_attribute(:'foo_bar', :'foo bar')
@@ -201,7 +201,7 @@ class AttributeMethodsTest < ActiveModel::TestCase
end
end
- test '#alias_attribute works with attributes named as a ruby keyword' do
+ test "#alias_attribute works with attributes named as a ruby keyword" do
begin
ModelWithRubyKeywordNamedAttributes.define_attribute_methods([:begin, :end])
ModelWithRubyKeywordNamedAttributes.alias_attribute(:from, :begin)
@@ -214,7 +214,7 @@ class AttributeMethodsTest < ActiveModel::TestCase
end
end
- test '#undefine_attribute_methods removes attribute methods' do
+ test "#undefine_attribute_methods removes attribute methods" do
ModelWithAttributes.define_attribute_methods(:foo)
ModelWithAttributes.undefine_attribute_methods
@@ -222,21 +222,21 @@ class AttributeMethodsTest < ActiveModel::TestCase
assert_raises(NoMethodError) { ModelWithAttributes.new.foo }
end
- test 'accessing a suffixed attribute' do
+ test "accessing a suffixed attribute" do
m = ModelWithAttributes2.new
- m.attributes = { 'foo' => 'bar' }
+ m.attributes = { "foo" => "bar" }
- assert_equal 'bar', m.foo
- assert_equal 'bar', m.foo_test
+ assert_equal "bar", m.foo
+ assert_equal "bar", m.foo_test
end
- test 'should not interfere with method_missing if the attr has a private/protected method' do
+ test "should not interfere with method_missing if the attr has a private/protected method" do
m = ModelWithAttributes2.new
- m.attributes = { 'private_method' => '<3', 'protected_method' => 'O_o' }
+ m.attributes = { "private_method" => "<3", "protected_method" => "O_o" }
# dispatches to the *method*, not the attribute
- assert_equal '<3 <3', m.send(:private_method)
- assert_equal 'O_o O_o', m.send(:protected_method)
+ assert_equal "<3 <3", m.send(:private_method)
+ assert_equal "O_o O_o", m.send(:protected_method)
# sees that a method is already defined, so doesn't intervene
assert_raises(NoMethodError) { m.private_method }
@@ -249,9 +249,9 @@ class AttributeMethodsTest < ActiveModel::TestCase
end
end
- test 'should not interfere with respond_to? if the attribute has a private/protected method' do
+ test "should not interfere with respond_to? if the attribute has a private/protected method" do
m = ModelWithAttributes2.new
- m.attributes = { 'private_method' => '<3', 'protected_method' => 'O_o' }
+ m.attributes = { "private_method" => "<3", "protected_method" => "O_o" }
assert !m.respond_to?(:private_method)
assert m.respond_to?(:private_method, true)
@@ -264,9 +264,9 @@ class AttributeMethodsTest < ActiveModel::TestCase
assert m.respond_to?(:protected_method, true)
end
- test 'should use attribute_missing to dispatch a missing attribute' do
+ test "should use attribute_missing to dispatch a missing attribute" do
m = ModelWithAttributes2.new
- m.attributes = { 'foo' => 'bar' }
+ m.attributes = { "foo" => "bar" }
def m.attribute_missing(match, *args, &block)
match
@@ -274,8 +274,8 @@ class AttributeMethodsTest < ActiveModel::TestCase
match = m.foo_test
- assert_equal 'foo', match.attr_name
- assert_equal 'attribute_test', match.target
- assert_equal 'foo_test', match.method_name
+ assert_equal "foo", match.attr_name
+ assert_equal "attribute_test", match.target
+ assert_equal "foo_test", match.method_name
end
end
diff --git a/activemodel/test/cases/callbacks_test.rb b/activemodel/test/cases/callbacks_test.rb
index e4ecc0adb4..a0686c7561 100644
--- a/activemodel/test/cases/callbacks_test.rb
+++ b/activemodel/test/cases/callbacks_test.rb
@@ -110,8 +110,8 @@ class CallbacksTest < ActiveModel::TestCase
end
extend ActiveModel::Callbacks
define_model_callbacks :create
- def callback1; self.history << 'callback1'; end
- def callback2; self.history << 'callback2'; end
+ def callback1; self.history << "callback1"; end
+ def callback2; self.history << "callback2"; end
def create
run_callbacks(:create) {}
self
diff --git a/activemodel/test/cases/conversion_test.rb b/activemodel/test/cases/conversion_test.rb
index 800cad6d9a..4a93347abc 100644
--- a/activemodel/test/cases/conversion_test.rb
+++ b/activemodel/test/cases/conversion_test.rb
@@ -1,6 +1,6 @@
-require 'cases/helper'
-require 'models/contact'
-require 'models/helicopter'
+require "cases/helper"
+require "models/contact"
+require "models/helicopter"
class ConversionTest < ActiveModel::TestCase
test "to_model default implementation returns self" do
diff --git a/activemodel/test/cases/dirty_test.rb b/activemodel/test/cases/dirty_test.rb
index d17a12ad12..fdd18d7601 100644
--- a/activemodel/test/cases/dirty_test.rb
+++ b/activemodel/test/cases/dirty_test.rb
@@ -62,13 +62,13 @@ class DirtyTest < ActiveModel::TestCase
test "list of changed attribute keys" do
assert_equal [], @model.changed
@model.name = "Paul"
- assert_equal ['name'], @model.changed
+ assert_equal ["name"], @model.changed
end
test "changes to attribute values" do
- assert !@model.changes['name']
+ assert !@model.changes["name"]
@model.name = "John"
- assert_equal [nil, "John"], @model.changes['name']
+ assert_equal [nil, "John"], @model.changes["name"]
end
test "checking if an attribute has changed to a particular value" do
@@ -84,14 +84,14 @@ class DirtyTest < ActiveModel::TestCase
test "changes accessible through both strings and symbols" do
@model.name = "David"
assert_not_nil @model.changes[:name]
- assert_not_nil @model.changes['name']
+ assert_not_nil @model.changes["name"]
end
test "be consistent with symbols arguments after the changes are applied" do
@model.name = "David"
assert @model.attribute_changed?(:name)
@model.save
- @model.name = 'Rafael'
+ @model.name = "Rafael"
assert @model.attribute_changed?(:name)
end
@@ -134,7 +134,7 @@ class DirtyTest < ActiveModel::TestCase
test "saving should preserve previous changes" do
@model.name = "Jericho Cane"
@model.save
- assert_equal [nil, "Jericho Cane"], @model.previous_changes['name']
+ assert_equal [nil, "Jericho Cane"], @model.previous_changes["name"]
end
test "setting new attributes should not affect previous changes" do
@@ -176,13 +176,13 @@ class DirtyTest < ActiveModel::TestCase
end
test "reload should reset all changes" do
- @model.name = 'Dmitry'
+ @model.name = "Dmitry"
@model.name_changed?
@model.save
- @model.name = 'Bob'
+ @model.name = "Bob"
- assert_equal [nil, 'Dmitry'], @model.previous_changes['name']
- assert_equal 'Dmitry', @model.changed_attributes['name']
+ assert_equal [nil, "Dmitry"], @model.previous_changes["name"]
+ assert_equal "Dmitry", @model.changed_attributes["name"]
@model.reload
@@ -191,30 +191,30 @@ class DirtyTest < ActiveModel::TestCase
end
test "restore_attributes should restore all previous data" do
- @model.name = 'Dmitry'
- @model.color = 'Red'
+ @model.name = "Dmitry"
+ @model.color = "Red"
@model.save
- @model.name = 'Bob'
- @model.color = 'White'
+ @model.name = "Bob"
+ @model.color = "White"
@model.restore_attributes
assert_not @model.changed?
- assert_equal 'Dmitry', @model.name
- assert_equal 'Red', @model.color
+ assert_equal "Dmitry", @model.name
+ assert_equal "Red", @model.color
end
test "restore_attributes can restore only some attributes" do
- @model.name = 'Dmitry'
- @model.color = 'Red'
+ @model.name = "Dmitry"
+ @model.color = "Red"
@model.save
- @model.name = 'Bob'
- @model.color = 'White'
+ @model.name = "Bob"
+ @model.color = "White"
- @model.restore_attributes(['name'])
+ @model.restore_attributes(["name"])
assert @model.changed?
- assert_equal 'Dmitry', @model.name
- assert_equal 'White', @model.color
+ assert_equal "Dmitry", @model.name
+ assert_equal "White", @model.color
end
end
diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb
index 13fa5c76bc..da99a0eca0 100644
--- a/activemodel/test/cases/errors_test.rb
+++ b/activemodel/test/cases/errors_test.rb
@@ -29,45 +29,45 @@ class ErrorsTest < ActiveModel::TestCase
def test_delete
errors = ActiveModel::Errors.new(self)
- errors[:foo] << 'omg'
+ errors[:foo] << "omg"
errors.delete(:foo)
assert_empty errors[:foo]
end
def test_include?
errors = ActiveModel::Errors.new(self)
- errors[:foo] << 'omg'
- assert errors.include?(:foo), 'errors should include :foo'
+ errors[:foo] << "omg"
+ assert errors.include?(:foo), "errors should include :foo"
end
def test_dup
errors = ActiveModel::Errors.new(self)
- errors[:foo] << 'bar'
+ errors[:foo] << "bar"
errors_dup = errors.dup
- errors_dup[:bar] << 'omg'
+ errors_dup[:bar] << "omg"
assert_not_same errors_dup.messages, errors.messages
end
def test_has_key?
errors = ActiveModel::Errors.new(self)
- errors[:foo] << 'omg'
- assert_equal true, errors.has_key?(:foo), 'errors should have key :foo'
+ errors[:foo] << "omg"
+ assert_equal true, errors.has_key?(:foo), "errors should have key :foo"
end
def test_has_no_key
errors = ActiveModel::Errors.new(self)
- assert_equal false, errors.has_key?(:name), 'errors should not have key :name'
+ assert_equal false, errors.has_key?(:name), "errors should not have key :name"
end
def test_key?
errors = ActiveModel::Errors.new(self)
- errors[:foo] << 'omg'
- assert_equal true, errors.key?(:foo), 'errors should have key :foo'
+ errors[:foo] << "omg"
+ assert_equal true, errors.key?(:foo), "errors should have key :foo"
end
def test_no_key
errors = ActiveModel::Errors.new(self)
- assert_equal false, errors.key?(:name), 'errors should not have key :name'
+ assert_equal false, errors.key?(:name), "errors should not have key :name"
end
test "clear errors" do
@@ -145,7 +145,7 @@ class ErrorsTest < ActiveModel::TestCase
test "assign error" do
person = Person.new
assert_deprecated do
- person.errors[:name] = 'should not be nil'
+ person.errors[:name] = "should not be nil"
end
assert_equal ["should not be nil"], person.errors[:name]
end
@@ -331,16 +331,16 @@ class ErrorsTest < ActiveModel::TestCase
test "add_on_empty generates message with custom default message" do
person = Person.new
- assert_called_with(person.errors, :generate_message, [:name, :empty, { message: 'custom' }]) do
+ assert_called_with(person.errors, :generate_message, [:name, :empty, { message: "custom" }]) do
assert_deprecated do
- person.errors.add_on_empty :name, message: 'custom'
+ person.errors.add_on_empty :name, message: "custom"
end
end
end
test "add_on_empty generates message with empty string value" do
person = Person.new
- person.name = ''
+ person.name = ""
assert_called_with(person.errors, :generate_message, [:name, :empty, {}]) do
assert_deprecated do
person.errors.add_on_empty :name
@@ -369,9 +369,9 @@ class ErrorsTest < ActiveModel::TestCase
test "add_on_blank generates message with custom default message" do
person = Person.new
- assert_called_with(person.errors, :generate_message, [:name, :blank, { message: 'custom' }]) do
+ assert_called_with(person.errors, :generate_message, [:name, :blank, { message: "custom" }]) do
assert_deprecated do
- person.errors.add_on_blank :name, message: 'custom'
+ person.errors.add_on_blank :name, message: "custom"
end
end
end
diff --git a/activemodel/test/cases/forbidden_attributes_protection_test.rb b/activemodel/test/cases/forbidden_attributes_protection_test.rb
index d8d757f52a..af61a566cb 100644
--- a/activemodel/test/cases/forbidden_attributes_protection_test.rb
+++ b/activemodel/test/cases/forbidden_attributes_protection_test.rb
@@ -1,6 +1,6 @@
-require 'cases/helper'
-require 'active_support/core_ext/hash/indifferent_access'
-require 'models/account'
+require "cases/helper"
+require "active_support/core_ext/hash/indifferent_access"
+require "models/account"
class ProtectedParams
attr_accessor :permitted
diff --git a/activemodel/test/cases/helper.rb b/activemodel/test/cases/helper.rb
index c589fd2c33..4e9f43ad86 100644
--- a/activemodel/test/cases/helper.rb
+++ b/activemodel/test/cases/helper.rb
@@ -1,4 +1,4 @@
-require 'active_model'
+require "active_model"
# Show backtraces for deprecated behavior for quicker cleanup.
ActiveSupport::Deprecation.debug = true
@@ -6,15 +6,15 @@ ActiveSupport::Deprecation.debug = true
# Disable available locale checks to avoid warnings running the test suite.
I18n.enforce_available_locales = false
-require 'active_support/testing/autorun'
-require 'active_support/testing/method_call_assertions'
+require "active_support/testing/autorun"
+require "active_support/testing/method_call_assertions"
# Skips the current run on Rubinius using Minitest::Assertions#skip
-def rubinius_skip(message = '')
- skip message if RUBY_ENGINE == 'rbx'
+def rubinius_skip(message = "")
+ skip message if RUBY_ENGINE == "rbx"
end
# Skips the current run on JRuby using Minitest::Assertions#skip
-def jruby_skip(message = '')
+def jruby_skip(message = "")
skip message if defined?(JRUBY_VERSION)
end
diff --git a/activemodel/test/cases/lint_test.rb b/activemodel/test/cases/lint_test.rb
index 8faf93c056..7a817d7c01 100644
--- a/activemodel/test/cases/lint_test.rb
+++ b/activemodel/test/cases/lint_test.rb
@@ -1,4 +1,4 @@
-require 'cases/helper'
+require "cases/helper"
class LintTest < ActiveModel::TestCase
include ActiveModel::Lint::Tests
diff --git a/activemodel/test/cases/model_test.rb b/activemodel/test/cases/model_test.rb
index 3017f3541b..ba87cd1506 100644
--- a/activemodel/test/cases/model_test.rb
+++ b/activemodel/test/cases/model_test.rb
@@ -1,4 +1,4 @@
-require 'cases/helper'
+require "cases/helper"
class ModelTest < ActiveModel::TestCase
include ActiveModel::Lint::Tests
@@ -9,7 +9,7 @@ class ModelTest < ActiveModel::TestCase
end
def initialize(*args)
- @attr ||= 'default value'
+ @attr ||= "default value"
super
end
end
@@ -50,7 +50,7 @@ class ModelTest < ActiveModel::TestCase
BasicModel.new()
BasicModel.new(nil)
BasicModel.new({})
- SimpleModel.new(attr: 'value')
+ SimpleModel.new(attr: "value")
end
end
@@ -61,17 +61,17 @@ class ModelTest < ActiveModel::TestCase
def test_mixin_inclusion_chain
object = BasicModel.new
- assert_equal 'default value', object.attr
+ assert_equal "default value", object.attr
end
def test_mixin_initializer_when_args_exist
- object = BasicModel.new(hello: 'world')
- assert_equal 'world', object.hello
+ object = BasicModel.new(hello: "world")
+ assert_equal "world", object.hello
end
def test_mixin_initializer_when_args_dont_exist
assert_raises(ActiveModel::UnknownAttributeError) do
- SimpleModel.new(hello: 'world')
+ SimpleModel.new(hello: "world")
end
end
end
diff --git a/activemodel/test/cases/naming_test.rb b/activemodel/test/cases/naming_test.rb
index 7b8287edbf..d5cb1a62bc 100644
--- a/activemodel/test/cases/naming_test.rb
+++ b/activemodel/test/cases/naming_test.rb
@@ -1,8 +1,8 @@
-require 'cases/helper'
-require 'models/contact'
-require 'models/sheep'
-require 'models/track_back'
-require 'models/blog_post'
+require "cases/helper"
+require "models/contact"
+require "models/sheep"
+require "models/track_back"
+require "models/blog_post"
class NamingTest < ActiveModel::TestCase
def setup
@@ -10,31 +10,31 @@ class NamingTest < ActiveModel::TestCase
end
def test_singular
- assert_equal 'post_track_back', @model_name.singular
+ assert_equal "post_track_back", @model_name.singular
end
def test_plural
- assert_equal 'post_track_backs', @model_name.plural
+ assert_equal "post_track_backs", @model_name.plural
end
def test_element
- assert_equal 'track_back', @model_name.element
+ assert_equal "track_back", @model_name.element
end
def test_collection
- assert_equal 'post/track_backs', @model_name.collection
+ assert_equal "post/track_backs", @model_name.collection
end
def test_human
- assert_equal 'Track back', @model_name.human
+ assert_equal "Track back", @model_name.human
end
def test_route_key
- assert_equal 'post_track_backs', @model_name.route_key
+ assert_equal "post_track_backs", @model_name.route_key
end
def test_param_key
- assert_equal 'post_track_back', @model_name.param_key
+ assert_equal "post_track_back", @model_name.param_key
end
def test_i18n_key
@@ -48,31 +48,31 @@ class NamingWithNamespacedModelInIsolatedNamespaceTest < ActiveModel::TestCase
end
def test_singular
- assert_equal 'blog_post', @model_name.singular
+ assert_equal "blog_post", @model_name.singular
end
def test_plural
- assert_equal 'blog_posts', @model_name.plural
+ assert_equal "blog_posts", @model_name.plural
end
def test_element
- assert_equal 'post', @model_name.element
+ assert_equal "post", @model_name.element
end
def test_collection
- assert_equal 'blog/posts', @model_name.collection
+ assert_equal "blog/posts", @model_name.collection
end
def test_human
- assert_equal 'Post', @model_name.human
+ assert_equal "Post", @model_name.human
end
def test_route_key
- assert_equal 'posts', @model_name.route_key
+ assert_equal "posts", @model_name.route_key
end
def test_param_key
- assert_equal 'post', @model_name.param_key
+ assert_equal "post", @model_name.param_key
end
def test_i18n_key
@@ -86,31 +86,31 @@ class NamingWithNamespacedModelInSharedNamespaceTest < ActiveModel::TestCase
end
def test_singular
- assert_equal 'blog_post', @model_name.singular
+ assert_equal "blog_post", @model_name.singular
end
def test_plural
- assert_equal 'blog_posts', @model_name.plural
+ assert_equal "blog_posts", @model_name.plural
end
def test_element
- assert_equal 'post', @model_name.element
+ assert_equal "post", @model_name.element
end
def test_collection
- assert_equal 'blog/posts', @model_name.collection
+ assert_equal "blog/posts", @model_name.collection
end
def test_human
- assert_equal 'Post', @model_name.human
+ assert_equal "Post", @model_name.human
end
def test_route_key
- assert_equal 'blog_posts', @model_name.route_key
+ assert_equal "blog_posts", @model_name.route_key
end
def test_param_key
- assert_equal 'blog_post', @model_name.param_key
+ assert_equal "blog_post", @model_name.param_key
end
def test_i18n_key
@@ -120,35 +120,35 @@ end
class NamingWithSuppliedModelNameTest < ActiveModel::TestCase
def setup
- @model_name = ActiveModel::Name.new(Blog::Post, nil, 'Article')
+ @model_name = ActiveModel::Name.new(Blog::Post, nil, "Article")
end
def test_singular
- assert_equal 'article', @model_name.singular
+ assert_equal "article", @model_name.singular
end
def test_plural
- assert_equal 'articles', @model_name.plural
+ assert_equal "articles", @model_name.plural
end
def test_element
- assert_equal 'article', @model_name.element
+ assert_equal "article", @model_name.element
end
def test_collection
- assert_equal 'articles', @model_name.collection
+ assert_equal "articles", @model_name.collection
end
def test_human
- assert_equal 'Article', @model_name.human
+ assert_equal "Article", @model_name.human
end
def test_route_key
- assert_equal 'articles', @model_name.route_key
+ assert_equal "articles", @model_name.route_key
end
def test_param_key
- assert_equal 'article', @model_name.param_key
+ assert_equal "article", @model_name.param_key
end
def test_i18n_key
@@ -162,31 +162,31 @@ class NamingUsingRelativeModelNameTest < ActiveModel::TestCase
end
def test_singular
- assert_equal 'blog_post', @model_name.singular
+ assert_equal "blog_post", @model_name.singular
end
def test_plural
- assert_equal 'blog_posts', @model_name.plural
+ assert_equal "blog_posts", @model_name.plural
end
def test_element
- assert_equal 'post', @model_name.element
+ assert_equal "post", @model_name.element
end
def test_collection
- assert_equal 'blog/posts', @model_name.collection
+ assert_equal "blog/posts", @model_name.collection
end
def test_human
- assert_equal 'Post', @model_name.human
+ assert_equal "Post", @model_name.human
end
def test_route_key
- assert_equal 'posts', @model_name.route_key
+ assert_equal "posts", @model_name.route_key
end
def test_param_key
- assert_equal 'post', @model_name.param_key
+ assert_equal "post", @model_name.param_key
end
def test_i18n_key
@@ -198,16 +198,16 @@ class NamingHelpersTest < ActiveModel::TestCase
def setup
@klass = Contact
@record = @klass.new
- @singular = 'contact'
- @plural = 'contacts'
+ @singular = "contact"
+ @plural = "contacts"
@uncountable = Sheep
- @singular_route_key = 'contact'
- @route_key = 'contacts'
- @param_key = 'contact'
+ @singular_route_key = "contact"
+ @route_key = "contacts"
+ @param_key = "contact"
end
def test_to_model_called_on_record
- assert_equal 'post_named_track_backs', plural(Post::TrackBack.new)
+ assert_equal "post_named_track_backs", plural(Post::TrackBack.new)
end
def test_singular
diff --git a/activemodel/test/cases/railtie_test.rb b/activemodel/test/cases/railtie_test.rb
index 96b3b07e50..a56b26b5ee 100644
--- a/activemodel/test/cases/railtie_test.rb
+++ b/activemodel/test/cases/railtie_test.rb
@@ -1,11 +1,11 @@
-require 'cases/helper'
-require 'active_support/testing/isolation'
+require "cases/helper"
+require "active_support/testing/isolation"
class RailtieTest < ActiveModel::TestCase
include ActiveSupport::Testing::Isolation
def setup
- require 'active_model/railtie'
+ require "active_model/railtie"
# Set a fake logger to avoid creating the log directory automatically
fake_logger = Logger.new(nil)
@@ -16,15 +16,15 @@ class RailtieTest < ActiveModel::TestCase
end
end
- test 'secure password min_cost is false in the development environment' do
- Rails.env = 'development'
+ test "secure password min_cost is false in the development environment" do
+ Rails.env = "development"
@app.initialize!
assert_equal false, ActiveModel::SecurePassword.min_cost
end
- test 'secure password min_cost is true in the test environment' do
- Rails.env = 'test'
+ test "secure password min_cost is true in the test environment" do
+ Rails.env = "test"
@app.initialize!
assert_equal true, ActiveModel::SecurePassword.min_cost
diff --git a/activemodel/test/cases/secure_password_test.rb b/activemodel/test/cases/secure_password_test.rb
index 6d56c8344a..9423df2c09 100644
--- a/activemodel/test/cases/secure_password_test.rb
+++ b/activemodel/test/cases/secure_password_test.rb
@@ -1,6 +1,6 @@
-require 'cases/helper'
-require 'models/user'
-require 'models/visitor'
+require "cases/helper"
+require "models/user"
+require "models/visitor"
class SecurePasswordTest < ActiveModel::TestCase
setup do
@@ -13,7 +13,7 @@ class SecurePasswordTest < ActiveModel::TestCase
# Simulate loading an existing user from the DB
@existing_user = User.new
- @existing_user.password_digest = BCrypt::Password.create('password', cost: BCrypt::Engine::MIN_COST)
+ @existing_user.password_digest = BCrypt::Password.create("password", cost: BCrypt::Engine::MIN_COST)
end
teardown do
@@ -29,152 +29,152 @@ class SecurePasswordTest < ActiveModel::TestCase
end
test "create a new user with validations and valid password/confirmation" do
- @user.password = 'password'
- @user.password_confirmation = 'password'
+ @user.password = "password"
+ @user.password_confirmation = "password"
- assert @user.valid?(:create), 'user should be valid'
+ assert @user.valid?(:create), "user should be valid"
- @user.password = 'a' * 72
- @user.password_confirmation = 'a' * 72
+ @user.password = "a" * 72
+ @user.password_confirmation = "a" * 72
- assert @user.valid?(:create), 'user should be valid'
+ assert @user.valid?(:create), "user should be valid"
end
test "create a new user with validation and a spaces only password" do
- @user.password = ' ' * 72
- assert @user.valid?(:create), 'user should be valid'
+ @user.password = " " * 72
+ assert @user.valid?(:create), "user should be valid"
end
test "create a new user with validation and a blank password" do
- @user.password = ''
- assert !@user.valid?(:create), 'user should be invalid'
+ @user.password = ""
+ assert !@user.valid?(:create), "user should be invalid"
assert_equal 1, @user.errors.count
assert_equal ["can't be blank"], @user.errors[:password]
end
test "create a new user with validation and a nil password" do
@user.password = nil
- assert !@user.valid?(:create), 'user should be invalid'
+ assert !@user.valid?(:create), "user should be invalid"
assert_equal 1, @user.errors.count
assert_equal ["can't be blank"], @user.errors[:password]
end
- test 'create a new user with validation and password length greater than 72' do
- @user.password = 'a' * 73
- @user.password_confirmation = 'a' * 73
- assert !@user.valid?(:create), 'user should be invalid'
+ test "create a new user with validation and password length greater than 72" do
+ @user.password = "a" * 73
+ @user.password_confirmation = "a" * 73
+ assert !@user.valid?(:create), "user should be invalid"
assert_equal 1, @user.errors.count
assert_equal ["is too long (maximum is 72 characters)"], @user.errors[:password]
end
test "create a new user with validation and a blank password confirmation" do
- @user.password = 'password'
- @user.password_confirmation = ''
- assert !@user.valid?(:create), 'user should be invalid'
+ @user.password = "password"
+ @user.password_confirmation = ""
+ assert !@user.valid?(:create), "user should be invalid"
assert_equal 1, @user.errors.count
assert_equal ["doesn't match Password"], @user.errors[:password_confirmation]
end
test "create a new user with validation and a nil password confirmation" do
- @user.password = 'password'
+ @user.password = "password"
@user.password_confirmation = nil
- assert @user.valid?(:create), 'user should be valid'
+ assert @user.valid?(:create), "user should be valid"
end
test "create a new user with validation and an incorrect password confirmation" do
- @user.password = 'password'
- @user.password_confirmation = 'something else'
- assert !@user.valid?(:create), 'user should be invalid'
+ @user.password = "password"
+ @user.password_confirmation = "something else"
+ assert !@user.valid?(:create), "user should be invalid"
assert_equal 1, @user.errors.count
assert_equal ["doesn't match Password"], @user.errors[:password_confirmation]
end
test "update an existing user with validation and no change in password" do
- assert @existing_user.valid?(:update), 'user should be valid'
+ assert @existing_user.valid?(:update), "user should be valid"
end
test "update an existing user with validations and valid password/confirmation" do
- @existing_user.password = 'password'
- @existing_user.password_confirmation = 'password'
+ @existing_user.password = "password"
+ @existing_user.password_confirmation = "password"
- assert @existing_user.valid?(:update), 'user should be valid'
+ assert @existing_user.valid?(:update), "user should be valid"
- @existing_user.password = 'a' * 72
- @existing_user.password_confirmation = 'a' * 72
+ @existing_user.password = "a" * 72
+ @existing_user.password_confirmation = "a" * 72
- assert @existing_user.valid?(:update), 'user should be valid'
+ assert @existing_user.valid?(:update), "user should be valid"
end
test "updating an existing user with validation and a blank password" do
- @existing_user.password = ''
- assert @existing_user.valid?(:update), 'user should be valid'
+ @existing_user.password = ""
+ assert @existing_user.valid?(:update), "user should be valid"
end
test "updating an existing user with validation and a spaces only password" do
- @user.password = ' ' * 72
- assert @user.valid?(:update), 'user should be valid'
+ @user.password = " " * 72
+ assert @user.valid?(:update), "user should be valid"
end
test "updating an existing user with validation and a blank password and password_confirmation" do
- @existing_user.password = ''
- @existing_user.password_confirmation = ''
- assert @existing_user.valid?(:update), 'user should be valid'
+ @existing_user.password = ""
+ @existing_user.password_confirmation = ""
+ assert @existing_user.valid?(:update), "user should be valid"
end
test "updating an existing user with validation and a nil password" do
@existing_user.password = nil
- assert !@existing_user.valid?(:update), 'user should be invalid'
+ assert !@existing_user.valid?(:update), "user should be invalid"
assert_equal 1, @existing_user.errors.count
assert_equal ["can't be blank"], @existing_user.errors[:password]
end
- test 'updating an existing user with validation and password length greater than 72' do
- @existing_user.password = 'a' * 73
- @existing_user.password_confirmation = 'a' * 73
- assert !@existing_user.valid?(:update), 'user should be invalid'
+ test "updating an existing user with validation and password length greater than 72" do
+ @existing_user.password = "a" * 73
+ @existing_user.password_confirmation = "a" * 73
+ assert !@existing_user.valid?(:update), "user should be invalid"
assert_equal 1, @existing_user.errors.count
assert_equal ["is too long (maximum is 72 characters)"], @existing_user.errors[:password]
end
test "updating an existing user with validation and a blank password confirmation" do
- @existing_user.password = 'password'
- @existing_user.password_confirmation = ''
- assert !@existing_user.valid?(:update), 'user should be invalid'
+ @existing_user.password = "password"
+ @existing_user.password_confirmation = ""
+ assert !@existing_user.valid?(:update), "user should be invalid"
assert_equal 1, @existing_user.errors.count
assert_equal ["doesn't match Password"], @existing_user.errors[:password_confirmation]
end
test "updating an existing user with validation and a nil password confirmation" do
- @existing_user.password = 'password'
+ @existing_user.password = "password"
@existing_user.password_confirmation = nil
- assert @existing_user.valid?(:update), 'user should be valid'
+ assert @existing_user.valid?(:update), "user should be valid"
end
test "updating an existing user with validation and an incorrect password confirmation" do
- @existing_user.password = 'password'
- @existing_user.password_confirmation = 'something else'
- assert !@existing_user.valid?(:update), 'user should be invalid'
+ @existing_user.password = "password"
+ @existing_user.password_confirmation = "something else"
+ assert !@existing_user.valid?(:update), "user should be invalid"
assert_equal 1, @existing_user.errors.count
assert_equal ["doesn't match Password"], @existing_user.errors[:password_confirmation]
end
test "updating an existing user with validation and a blank password digest" do
- @existing_user.password_digest = ''
- assert !@existing_user.valid?(:update), 'user should be invalid'
+ @existing_user.password_digest = ""
+ assert !@existing_user.valid?(:update), "user should be invalid"
assert_equal 1, @existing_user.errors.count
assert_equal ["can't be blank"], @existing_user.errors[:password]
end
test "updating an existing user with validation and a nil password digest" do
@existing_user.password_digest = nil
- assert !@existing_user.valid?(:update), 'user should be invalid'
+ assert !@existing_user.valid?(:update), "user should be invalid"
assert_equal 1, @existing_user.errors.count
assert_equal ["can't be blank"], @existing_user.errors[:password]
end
test "setting a blank password should not change an existing password" do
- @existing_user.password = ''
- assert @existing_user.password_digest == 'password'
+ @existing_user.password = ""
+ assert @existing_user.password_digest == "password"
end
test "setting a nil password should clear an existing password" do
diff --git a/activemodel/test/cases/serialization_test.rb b/activemodel/test/cases/serialization_test.rb
index 8d3165cd78..cead0bee22 100644
--- a/activemodel/test/cases/serialization_test.rb
+++ b/activemodel/test/cases/serialization_test.rb
@@ -1,5 +1,5 @@
require "cases/helper"
-require 'active_support/core_ext/object/instance_variables'
+require "active_support/core_ext/object/instance_variables"
class SerializationTest < ActiveModel::TestCase
class User
@@ -18,14 +18,14 @@ class SerializationTest < ActiveModel::TestCase
def method_missing(method_name, *args)
if method_name == :bar
- 'i_am_bar'
+ "i_am_bar"
else
super
end
end
def foo
- 'i_am_foo'
+ "i_am_foo"
end
end
@@ -40,14 +40,14 @@ class SerializationTest < ActiveModel::TestCase
end
setup do
- @user = User.new('David', 'david@example.com', 'male')
+ @user = User.new("David", "david@example.com", "male")
@user.address = Address.new
@user.address.street = "123 Lane"
@user.address.city = "Springfield"
@user.address.state = "CA"
@user.address.zip = 11111
- @user.friends = [User.new('Joe', 'joe@example.com', 'male'),
- User.new('Sue', 'sue@example.com', 'female')]
+ @user.friends = [User.new("Joe", "joe@example.com", "male"),
+ User.new("Sue", "sue@example.com", "female")]
end
def test_method_serializable_hash_should_work
@@ -101,8 +101,8 @@ class SerializationTest < ActiveModel::TestCase
def test_include_option_with_plural_association
expected = {"email"=>"david@example.com", "gender"=>"male", "name"=>"David",
- "friends"=>[{"name"=>'Joe', "email"=>'joe@example.com', "gender"=>'male'},
- {"name"=>'Sue', "email"=>'sue@example.com', "gender"=>'female'}]}
+ "friends"=>[{"name"=>"Joe", "email"=>"joe@example.com", "gender"=>"male"},
+ {"name"=>"Sue", "email"=>"sue@example.com", "gender"=>"female"}]}
assert_equal expected, @user.serializable_hash(include: :friends)
end
@@ -125,16 +125,16 @@ class SerializationTest < ActiveModel::TestCase
def test_include_option_with_ary
@user.friends = FriendList.new(@user.friends)
expected = {"email"=>"david@example.com", "gender"=>"male", "name"=>"David",
- "friends"=>[{"name"=>'Joe', "email"=>'joe@example.com', "gender"=>'male'},
- {"name"=>'Sue', "email"=>'sue@example.com', "gender"=>'female'}]}
+ "friends"=>[{"name"=>"Joe", "email"=>"joe@example.com", "gender"=>"male"},
+ {"name"=>"Sue", "email"=>"sue@example.com", "gender"=>"female"}]}
assert_equal expected, @user.serializable_hash(include: :friends)
end
def test_multiple_includes
expected = {"email"=>"david@example.com", "gender"=>"male", "name"=>"David",
"address"=>{"street"=>"123 Lane", "city"=>"Springfield", "state"=>"CA", "zip"=>11111},
- "friends"=>[{"name"=>'Joe', "email"=>'joe@example.com', "gender"=>'male'},
- {"name"=>'Sue', "email"=>'sue@example.com', "gender"=>'female'}]}
+ "friends"=>[{"name"=>"Joe", "email"=>"joe@example.com", "gender"=>"male"},
+ {"name"=>"Sue", "email"=>"sue@example.com", "gender"=>"female"}]}
assert_equal expected, @user.serializable_hash(include: [:address, :friends])
end
@@ -147,9 +147,9 @@ class SerializationTest < ActiveModel::TestCase
def test_nested_include
@user.friends.first.friends = [@user]
expected = {"email"=>"david@example.com", "gender"=>"male", "name"=>"David",
- "friends"=>[{"name"=>'Joe', "email"=>'joe@example.com', "gender"=>'male',
+ "friends"=>[{"name"=>"Joe", "email"=>"joe@example.com", "gender"=>"male",
"friends"=> [{"email"=>"david@example.com", "gender"=>"male", "name"=>"David"}]},
- {"name"=>'Sue', "email"=>'sue@example.com', "gender"=>'female', "friends"=> []}]}
+ {"name"=>"Sue", "email"=>"sue@example.com", "gender"=>"female", "friends"=> []}]}
assert_equal expected, @user.serializable_hash(include: { friends: { include: :friends } })
end
@@ -160,16 +160,16 @@ class SerializationTest < ActiveModel::TestCase
def test_except_include
expected = {"name"=>"David", "email"=>"david@example.com",
- "friends"=> [{"name" => 'Joe', "email" => 'joe@example.com'},
- {"name" => "Sue", "email" => 'sue@example.com'}]}
+ "friends"=> [{"name" => "Joe", "email" => "joe@example.com"},
+ {"name" => "Sue", "email" => "sue@example.com"}]}
assert_equal expected, @user.serializable_hash(except: :gender, include: { friends: { except: :gender } })
end
def test_multiple_includes_with_options
expected = {"email"=>"david@example.com", "gender"=>"male", "name"=>"David",
"address"=>{"street"=>"123 Lane"},
- "friends"=>[{"name"=>'Joe', "email"=>'joe@example.com', "gender"=>'male'},
- {"name"=>'Sue', "email"=>'sue@example.com', "gender"=>'female'}]}
+ "friends"=>[{"name"=>"Joe", "email"=>"joe@example.com", "gender"=>"male"},
+ {"name"=>"Sue", "email"=>"sue@example.com", "gender"=>"female"}]}
assert_equal expected, @user.serializable_hash(include: [{ address: {only: "street" } }, :friends])
end
end
diff --git a/activemodel/test/cases/serializers/json_serialization_test.rb b/activemodel/test/cases/serializers/json_serialization_test.rb
index d765a47636..45c166f33a 100644
--- a/activemodel/test/cases/serializers/json_serialization_test.rb
+++ b/activemodel/test/cases/serializers/json_serialization_test.rb
@@ -1,15 +1,15 @@
-require 'cases/helper'
-require 'models/contact'
-require 'active_support/core_ext/object/instance_variables'
+require "cases/helper"
+require "models/contact"
+require "active_support/core_ext/object/instance_variables"
class JsonSerializationTest < ActiveModel::TestCase
def setup
@contact = Contact.new
- @contact.name = 'Konata Izumi'
+ @contact.name = "Konata Izumi"
@contact.age = 16
@contact.created_at = Time.utc(2006, 8, 1)
@contact.awesome = true
- @contact.preferences = { 'shows' => 'anime' }
+ @contact.preferences = { "shows" => "anime" }
end
test "should not include root in json (class method)" do
@@ -53,7 +53,7 @@ class JsonSerializationTest < ActiveModel::TestCase
end
test "should include custom root in json" do
- json = @contact.to_json(root: 'json_contact')
+ json = @contact.to_json(root: "json_contact")
assert_match %r{^\{"json_contact":\{}, json
assert_match %r{"name":"Konata Izumi"}, json
@@ -134,9 +134,9 @@ class JsonSerializationTest < ActiveModel::TestCase
json = @contact.as_json
assert_kind_of Hash, json
- assert_kind_of Hash, json['contact']
+ assert_kind_of Hash, json["contact"]
%w(name age created_at awesome preferences).each do |field|
- assert_equal @contact.send(field), json['contact'][field]
+ assert_equal @contact.send(field), json["contact"][field]
end
ensure
Contact.include_root_in_json = original_include_root_in_json
diff --git a/activemodel/test/cases/translation_test.rb b/activemodel/test/cases/translation_test.rb
index 2c89388f14..95655e03b4 100644
--- a/activemodel/test/cases/translation_test.rb
+++ b/activemodel/test/cases/translation_test.rb
@@ -1,5 +1,5 @@
-require 'cases/helper'
-require 'models/person'
+require "cases/helper"
+require "models/person"
class ActiveModelI18nTests < ActiveModel::TestCase
@@ -12,102 +12,102 @@ class ActiveModelI18nTests < ActiveModel::TestCase
end
def test_translated_model_attributes
- I18n.backend.store_translations 'en', activemodel: { attributes: { person: { name: 'person name attribute' } } }
- assert_equal 'person name attribute', Person.human_attribute_name('name')
+ I18n.backend.store_translations "en", activemodel: { attributes: { person: { name: "person name attribute" } } }
+ assert_equal "person name attribute", Person.human_attribute_name("name")
end
def test_translated_model_attributes_with_default
- I18n.backend.store_translations 'en', attributes: { name: 'name default attribute' }
- assert_equal 'name default attribute', Person.human_attribute_name('name')
+ I18n.backend.store_translations "en", attributes: { name: "name default attribute" }
+ assert_equal "name default attribute", Person.human_attribute_name("name")
end
def test_translated_model_attributes_using_default_option
- assert_equal 'name default attribute', Person.human_attribute_name('name', default: "name default attribute")
+ assert_equal "name default attribute", Person.human_attribute_name("name", default: "name default attribute")
end
def test_translated_model_attributes_using_default_option_as_symbol
- I18n.backend.store_translations 'en', default_name: 'name default attribute'
- assert_equal 'name default attribute', Person.human_attribute_name('name', default: :default_name)
+ I18n.backend.store_translations "en", default_name: "name default attribute"
+ assert_equal "name default attribute", Person.human_attribute_name("name", default: :default_name)
end
def test_translated_model_attributes_falling_back_to_default
- assert_equal 'Name', Person.human_attribute_name('name')
+ assert_equal "Name", Person.human_attribute_name("name")
end
def test_translated_model_attributes_using_default_option_as_symbol_and_falling_back_to_default
- assert_equal 'Name', Person.human_attribute_name('name', default: :default_name)
+ assert_equal "Name", Person.human_attribute_name("name", default: :default_name)
end
def test_translated_model_attributes_with_symbols
- I18n.backend.store_translations 'en', activemodel: { attributes: { person: { name: 'person name attribute'} } }
- assert_equal 'person name attribute', Person.human_attribute_name(:name)
+ I18n.backend.store_translations "en", activemodel: { attributes: { person: { name: "person name attribute"} } }
+ assert_equal "person name attribute", Person.human_attribute_name(:name)
end
def test_translated_model_attributes_with_ancestor
- I18n.backend.store_translations 'en', activemodel: { attributes: { child: { name: 'child name attribute'} } }
- assert_equal 'child name attribute', Child.human_attribute_name('name')
+ I18n.backend.store_translations "en", activemodel: { attributes: { child: { name: "child name attribute"} } }
+ assert_equal "child name attribute", Child.human_attribute_name("name")
end
def test_translated_model_attributes_with_ancestors_fallback
- I18n.backend.store_translations 'en', activemodel: { attributes: { person: { name: 'person name attribute'} } }
- assert_equal 'person name attribute', Child.human_attribute_name('name')
+ I18n.backend.store_translations "en", activemodel: { attributes: { person: { name: "person name attribute"} } }
+ assert_equal "person name attribute", Child.human_attribute_name("name")
end
def test_translated_model_attributes_with_attribute_matching_namespaced_model_name
- I18n.backend.store_translations 'en', activemodel: { attributes: {
- person: { gender: 'person gender'},
- :"person/gender" => { attribute: 'person gender attribute' }
+ I18n.backend.store_translations "en", activemodel: { attributes: {
+ person: { gender: "person gender"},
+ :"person/gender" => { attribute: "person gender attribute" }
} }
- assert_equal 'person gender', Person.human_attribute_name('gender')
- assert_equal 'person gender attribute', Person::Gender.human_attribute_name('attribute')
+ assert_equal "person gender", Person.human_attribute_name("gender")
+ assert_equal "person gender attribute", Person::Gender.human_attribute_name("attribute")
end
def test_translated_deeply_nested_model_attributes
- I18n.backend.store_translations 'en', activemodel: { attributes: { :"person/contacts/addresses" => { street: 'Deeply Nested Address Street' } } }
- assert_equal 'Deeply Nested Address Street', Person.human_attribute_name('contacts.addresses.street')
+ I18n.backend.store_translations "en", activemodel: { attributes: { :"person/contacts/addresses" => { street: "Deeply Nested Address Street" } } }
+ assert_equal "Deeply Nested Address Street", Person.human_attribute_name("contacts.addresses.street")
end
def test_translated_nested_model_attributes
- I18n.backend.store_translations 'en', activemodel: { attributes: { :"person/addresses" => { street: 'Person Address Street' } } }
- assert_equal 'Person Address Street', Person.human_attribute_name('addresses.street')
+ I18n.backend.store_translations "en", activemodel: { attributes: { :"person/addresses" => { street: "Person Address Street" } } }
+ assert_equal "Person Address Street", Person.human_attribute_name("addresses.street")
end
def test_translated_nested_model_attributes_with_namespace_fallback
- I18n.backend.store_translations 'en', activemodel: { attributes: { addresses: { street: 'Cool Address Street' } } }
- assert_equal 'Cool Address Street', Person.human_attribute_name('addresses.street')
+ I18n.backend.store_translations "en", activemodel: { attributes: { addresses: { street: "Cool Address Street" } } }
+ assert_equal "Cool Address Street", Person.human_attribute_name("addresses.street")
end
def test_translated_model_names
- I18n.backend.store_translations 'en', activemodel: { models: { person: 'person model' } }
- assert_equal 'person model', Person.model_name.human
+ I18n.backend.store_translations "en", activemodel: { models: { person: "person model" } }
+ assert_equal "person model", Person.model_name.human
end
def test_translated_model_names_with_sti
- I18n.backend.store_translations 'en', activemodel: { models: { child: 'child model' } }
- assert_equal 'child model', Child.model_name.human
+ I18n.backend.store_translations "en", activemodel: { models: { child: "child model" } }
+ assert_equal "child model", Child.model_name.human
end
def test_translated_model_with_namespace
- I18n.backend.store_translations 'en', activemodel: { models: { 'person/gender': 'gender model' } }
- assert_equal 'gender model', Person::Gender.model_name.human
+ I18n.backend.store_translations "en", activemodel: { models: { 'person/gender': "gender model" } }
+ assert_equal "gender model", Person::Gender.model_name.human
end
def test_translated_model_names_with_ancestors_fallback
- I18n.backend.store_translations 'en', activemodel: { models: { person: 'person model' } }
- assert_equal 'person model', Child.model_name.human
+ I18n.backend.store_translations "en", activemodel: { models: { person: "person model" } }
+ assert_equal "person model", Child.model_name.human
end
def test_human_does_not_modify_options
- options = { default: 'person model' }
+ options = { default: "person model" }
Person.model_name.human(options)
- assert_equal({ default: 'person model' }, options)
+ assert_equal({ default: "person model" }, options)
end
def test_human_attribute_name_does_not_modify_options
- options = { default: 'Cool gender' }
- Person.human_attribute_name('gender', options)
- assert_equal({ default: 'Cool gender' }, options)
+ options = { default: "Cool gender" }
+ Person.human_attribute_name("gender", options)
+ assert_equal({ default: "Cool gender" }, options)
end
end
diff --git a/activemodel/test/cases/type/decimal_test.rb b/activemodel/test/cases/type/decimal_test.rb
index 1950566c0e..46a913258e 100644
--- a/activemodel/test/cases/type/decimal_test.rb
+++ b/activemodel/test/cases/type/decimal_test.rb
@@ -48,9 +48,9 @@ module ActiveModel
def test_changed?
type = Decimal.new
- assert type.changed?(5.0, 5.0, '5.0wibble')
- assert_not type.changed?(5.0, 5.0, '5.0')
- assert_not type.changed?(-5.0, -5.0, '-5.0')
+ assert type.changed?(5.0, 5.0, "5.0wibble")
+ assert_not type.changed?(5.0, 5.0, "5.0")
+ assert_not type.changed?(-5.0, -5.0, "-5.0")
end
def test_scale_is_applied_before_precision_to_prevent_rounding_errors
diff --git a/activemodel/test/cases/type/integer_test.rb b/activemodel/test/cases/type/integer_test.rb
index 6603f25c9a..0fa7a12de0 100644
--- a/activemodel/test/cases/type/integer_test.rb
+++ b/activemodel/test/cases/type/integer_test.rb
@@ -7,10 +7,10 @@ module ActiveModel
test "simple values" do
type = Type::Integer.new
assert_equal 1, type.cast(1)
- assert_equal 1, type.cast('1')
- assert_equal 1, type.cast('1ignore')
- assert_equal 0, type.cast('bad1')
- assert_equal 0, type.cast('bad')
+ assert_equal 1, type.cast("1")
+ assert_equal 1, type.cast("1ignore")
+ assert_equal 0, type.cast("bad1")
+ assert_equal 0, type.cast("bad")
assert_equal 1, type.cast(1.7)
assert_equal 0, type.cast(false)
assert_equal 1, type.cast(true)
@@ -44,11 +44,11 @@ module ActiveModel
test "changed?" do
type = Type::Integer.new
- assert type.changed?(5, 5, '5wibble')
- assert_not type.changed?(5, 5, '5')
- assert_not type.changed?(5, 5, '5.0')
- assert_not type.changed?(-5, -5, '-5')
- assert_not type.changed?(-5, -5, '-5.0')
+ assert type.changed?(5, 5, "5wibble")
+ assert_not type.changed?(5, 5, "5")
+ assert_not type.changed?(5, 5, "5.0")
+ assert_not type.changed?(-5, -5, "-5")
+ assert_not type.changed?(-5, -5, "-5.0")
assert_not type.changed?(nil, nil, nil)
end
diff --git a/activemodel/test/cases/types_test.rb b/activemodel/test/cases/types_test.rb
index 558c56f157..900afe836a 100644
--- a/activemodel/test/cases/types_test.rb
+++ b/activemodel/test/cases/types_test.rb
@@ -6,33 +6,33 @@ module ActiveModel
class TypesTest < ActiveModel::TestCase
def test_type_cast_boolean
type = Type::Boolean.new
- assert type.cast('').nil?
+ assert type.cast("").nil?
assert type.cast(nil).nil?
assert type.cast(true)
assert type.cast(1)
- assert type.cast('1')
- assert type.cast('t')
- assert type.cast('T')
- assert type.cast('true')
- assert type.cast('TRUE')
- assert type.cast('on')
- assert type.cast('ON')
- assert type.cast(' ')
+ assert type.cast("1")
+ assert type.cast("t")
+ assert type.cast("T")
+ assert type.cast("true")
+ assert type.cast("TRUE")
+ assert type.cast("on")
+ assert type.cast("ON")
+ assert type.cast(" ")
assert type.cast("\u3000\r\n")
assert type.cast("\u0000")
- assert type.cast('SOMETHING RANDOM')
+ assert type.cast("SOMETHING RANDOM")
# explicitly check for false vs nil
assert_equal false, type.cast(false)
assert_equal false, type.cast(0)
- assert_equal false, type.cast('0')
- assert_equal false, type.cast('f')
- assert_equal false, type.cast('F')
- assert_equal false, type.cast('false')
- assert_equal false, type.cast('FALSE')
- assert_equal false, type.cast('off')
- assert_equal false, type.cast('OFF')
+ assert_equal false, type.cast("0")
+ assert_equal false, type.cast("f")
+ assert_equal false, type.cast("F")
+ assert_equal false, type.cast("false")
+ assert_equal false, type.cast("FALSE")
+ assert_equal false, type.cast("off")
+ assert_equal false, type.cast("OFF")
end
def test_type_cast_float
@@ -43,9 +43,9 @@ module ActiveModel
def test_changing_float
type = Type::Float.new
- assert type.changed?(5.0, 5.0, '5wibble')
- assert_not type.changed?(5.0, 5.0, '5')
- assert_not type.changed?(5.0, 5.0, '5.0')
+ assert type.changed?(5.0, 5.0, "5wibble")
+ assert_not type.changed?(5.0, 5.0, "5")
+ assert_not type.changed?(5.0, 5.0, "5.0")
assert_not type.changed?(nil, nil, nil)
end
@@ -59,22 +59,22 @@ module ActiveModel
def test_type_cast_time
type = Type::Time.new
assert_equal nil, type.cast(nil)
- assert_equal nil, type.cast('')
- assert_equal nil, type.cast('ABC')
+ assert_equal nil, type.cast("")
+ assert_equal nil, type.cast("ABC")
time_string = Time.now.utc.strftime("%T")
assert_equal time_string, type.cast(time_string).strftime("%T")
- assert_equal ::Time.utc(2000, 1, 1, 16, 45, 54), type.cast('2015-06-13T19:45:54+03:00')
- assert_equal ::Time.utc(1999, 12, 31, 21, 7, 8), type.cast('06:07:08+09:00')
+ assert_equal ::Time.utc(2000, 1, 1, 16, 45, 54), type.cast("2015-06-13T19:45:54+03:00")
+ assert_equal ::Time.utc(1999, 12, 31, 21, 7, 8), type.cast("06:07:08+09:00")
end
def test_type_cast_datetime_and_timestamp
type = Type::DateTime.new
assert_equal nil, type.cast(nil)
- assert_equal nil, type.cast('')
- assert_equal nil, type.cast(' ')
- assert_equal nil, type.cast('ABC')
+ assert_equal nil, type.cast("")
+ assert_equal nil, type.cast(" ")
+ assert_equal nil, type.cast("ABC")
datetime_string = Time.now.utc.strftime("%FT%T")
assert_equal datetime_string, type.cast(datetime_string).strftime("%FT%T")
@@ -83,9 +83,9 @@ module ActiveModel
def test_type_cast_date
type = Type::Date.new
assert_equal nil, type.cast(nil)
- assert_equal nil, type.cast('')
- assert_equal nil, type.cast(' ')
- assert_equal nil, type.cast('ABC')
+ assert_equal nil, type.cast("")
+ assert_equal nil, type.cast(" ")
+ assert_equal nil, type.cast("ABC")
date_string = Time.now.utc.strftime("%F")
assert_equal date_string, type.cast(date_string).strftime("%F")
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
diff --git a/activemodel/test/cases/validations_test.rb b/activemodel/test/cases/validations_test.rb
index 2a4e9f842f..51607ba955 100644
--- a/activemodel/test/cases/validations_test.rb
+++ b/activemodel/test/cases/validations_test.rb
@@ -1,11 +1,11 @@
-require 'cases/helper'
+require "cases/helper"
-require 'models/topic'
-require 'models/reply'
-require 'models/custom_reader'
+require "models/topic"
+require "models/reply"
+require "models/custom_reader"
-require 'active_support/json'
-require 'active_support/xml_mini'
+require "active_support/json"
+require "active_support/xml_mini"
class ValidationsTest < ActiveModel::TestCase
class CustomStrictValidationException < StandardError; end
@@ -116,7 +116,7 @@ class ValidationsTest < ActiveModel::TestCase
def test_validates_each
hits = 0
Topic.validates_each(:title, :content, [:title, :content]) do |record, attr|
- record.errors.add attr, 'gotcha'
+ record.errors.add attr, "gotcha"
hits += 1
end
t = Topic.new("title" => "valid", "content" => "whatever")
@@ -129,7 +129,7 @@ class ValidationsTest < ActiveModel::TestCase
def test_validates_each_custom_reader
hits = 0
CustomReader.validates_each(:title, :content, [:title, :content]) do |record, attr|
- record.errors.add attr, 'gotcha'
+ record.errors.add attr, "gotcha"
hits += 1
end
t = CustomReader.new("title" => "valid", "content" => "whatever")
@@ -170,7 +170,7 @@ class ValidationsTest < ActiveModel::TestCase
# A common mistake -- we meant to call 'validates'
Topic.validate :title, presence: true
end
- message = 'Unknown key: :presence. Valid keys are: :on, :if, :unless, :prepend. Perhaps you meant to call `validates` instead of `validate`?'
+ message = "Unknown key: :presence. Valid keys are: :on, :if, :unless, :prepend. Perhaps you meant to call `validates` instead of `validate`?"
assert_equal message, error.message
end
@@ -233,21 +233,21 @@ class ValidationsTest < ActiveModel::TestCase
assert 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.validate {errors.add("author_email_address", "will never be valid")}
Topic.validates_length_of :title, :content, minimum: 2
- t = Topic.new title: ''
+ t = Topic.new title: ""
assert t.invalid?
assert_equal :title, key = t.errors.keys[0]
assert_equal "can't be blank", t.errors[key][0]
- assert_equal 'is too short (minimum is 2 characters)', t.errors[key][1]
+ assert_equal "is too short (minimum is 2 characters)", t.errors[key][1]
assert_equal :author_name, key = t.errors.keys[1]
assert_equal "can't be blank", t.errors[key][0]
assert_equal :author_email_address, key = t.errors.keys[2]
- assert_equal 'will never be valid', t.errors[key][0]
+ assert_equal "will never be valid", t.errors[key][0]
assert_equal :content, key = t.errors.keys[3]
- assert_equal 'is too short (minimum is 2 characters)', t.errors[key][0]
+ assert_equal "is too short (minimum is 2 characters)", t.errors[key][0]
end
def test_validation_with_if_and_on
@@ -271,7 +271,7 @@ class ValidationsTest < ActiveModel::TestCase
assert t.invalid?
assert t.errors[:title].any?
- t.title = 'Things are going to change'
+ t.title = "Things are going to change"
assert !t.invalid?
end
@@ -332,9 +332,9 @@ class ValidationsTest < ActiveModel::TestCase
assert 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.'
+ topic.title = "Some Title"
+ topic.author_name = "Some Author"
+ topic.content = "Some Content Whose Length is more than 10."
assert topic.valid?
end
@@ -440,7 +440,7 @@ class ValidationsTest < ActiveModel::TestCase
assert duped.invalid?
topic.title = nil
- duped.title = 'Mathematics'
+ duped.title = "Mathematics"
assert topic.invalid?
assert duped.valid?
end
@@ -448,7 +448,7 @@ class ValidationsTest < ActiveModel::TestCase
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')
+ t = Topic.new(author_name: "Admiral")
assert t.invalid?
assert_equal ["You have failed me for the last time, Admiral."], t.errors[:title]
end
@@ -456,7 +456,7 @@ class ValidationsTest < ActiveModel::TestCase
def test_validation_with_message_as_proc_that_takes_record_and_data_as_a_parameters
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')
+ t = Topic.new(author_name: "Admiral")
assert t.invalid?
assert_equal ["Title is missing. You have failed me for the last time, Admiral."], t.errors[:title]
end
diff --git a/activemodel/test/models/reply.rb b/activemodel/test/models/reply.rb
index b77910e671..3fe11043d2 100644
--- a/activemodel/test/models/reply.rb
+++ b/activemodel/test/models/reply.rb
@@ -1,4 +1,4 @@
-require 'models/topic'
+require "models/topic"
class Reply < Topic
validate :errors_on_empty_content
diff --git a/activemodel/test/validators/email_validator.rb b/activemodel/test/validators/email_validator.rb
index 5dc1fc5ae2..43011b277b 100644
--- a/activemodel/test/validators/email_validator.rb
+++ b/activemodel/test/validators/email_validator.rb
@@ -1,4 +1,4 @@
-require 'active_support/core_ext/regexp'
+require "active_support/core_ext/regexp"
class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
diff --git a/activemodel/test/validators/namespace/email_validator.rb b/activemodel/test/validators/namespace/email_validator.rb
index 57e2793ce2..8639045b0d 100644
--- a/activemodel/test/validators/namespace/email_validator.rb
+++ b/activemodel/test/validators/namespace/email_validator.rb
@@ -1,4 +1,4 @@
-require 'validators/email_validator'
+require "validators/email_validator"
module Namespace
class EmailValidator < ::EmailValidator