diff options
Diffstat (limited to 'activemodel')
18 files changed, 65 insertions, 65 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 17ed5de420..14adfa081f 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -211,7 +211,7 @@ module ActiveModel # # <error>name can't be blank</error> # # <error>name must be specified</error> # # </errors> - def to_xml(options={}) + def to_xml(options = {}) to_a.to_xml({ root: "errors", skip_types: true }.merge!(options)) end @@ -221,7 +221,7 @@ module ActiveModel # # person.errors.as_json # => {:name=>["cannot be nil"]} # person.errors.as_json(full_messages: true) # => {:name=>["name cannot be nil"]} - def as_json(options=nil) + def as_json(options = nil) to_hash(options && options[:full_messages]) end diff --git a/activemodel/lib/active_model/model.rb b/activemodel/lib/active_model/model.rb index f5765c0c54..e683050787 100644 --- a/activemodel/lib/active_model/model.rb +++ b/activemodel/lib/active_model/model.rb @@ -75,7 +75,7 @@ module ActiveModel # person = Person.new(name: 'bob', age: '18') # person.name # => "bob" # person.age # => "18" - def initialize(attributes={}) + def initialize(attributes = {}) assign_attributes(attributes) if attributes super() diff --git a/activemodel/lib/active_model/naming.rb b/activemodel/lib/active_model/naming.rb index 840fc663c0..9532c63b65 100644 --- a/activemodel/lib/active_model/naming.rb +++ b/activemodel/lib/active_model/naming.rb @@ -173,7 +173,7 @@ module ActiveModel # BlogPost.model_name.human # => "Blog post" # # Specify +options+ with additional translating options. - def human(options={}) + def human(options = {}) return @human unless @klass.respond_to?(:lookup_ancestors) && @klass.respond_to?(:i18n_scope) diff --git a/activemodel/lib/active_model/serializers/json.rb b/activemodel/lib/active_model/serializers/json.rb index b5e030a59b..a9d92eb92a 100644 --- a/activemodel/lib/active_model/serializers/json.rb +++ b/activemodel/lib/active_model/serializers/json.rb @@ -134,7 +134,7 @@ module ActiveModel # person.name # => "bob" # person.age # => 22 # person.awesome # => true - def from_json(json, include_root=include_root_in_json) + def from_json(json, include_root = include_root_in_json) hash = ActiveSupport::JSON.decode(json) hash = hash.values.first if include_root self.attributes = hash diff --git a/activemodel/lib/active_model/type/helpers/time_value.rb b/activemodel/lib/active_model/type/helpers/time_value.rb index d8c5d929a3..ad78fd49ec 100644 --- a/activemodel/lib/active_model/type/helpers/time_value.rb +++ b/activemodel/lib/active_model/type/helpers/time_value.rb @@ -33,7 +33,7 @@ module ActiveModel def apply_seconds_precision(value) return value unless precision && value.respond_to?(:usec) number_of_insignificant_digits = 6 - precision - round_power = 10 ** number_of_insignificant_digits + round_power = 10**number_of_insignificant_digits value.change(usec: value.usec / round_power * round_power) end diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb index df6d3f2bcb..8b815155b1 100644 --- a/activemodel/lib/active_model/validations.rb +++ b/activemodel/lib/active_model/validations.rb @@ -50,7 +50,7 @@ module ActiveModel define_callbacks :validate, scope: :name class_attribute :_validators, instance_writer: false - self._validators = Hash.new { |h,k| h[k] = [] } + self._validators = Hash.new { |h, k| h[k] = [] } end module ClassMethods diff --git a/activemodel/lib/active_model/validations/acceptance.rb b/activemodel/lib/active_model/validations/acceptance.rb index 4fadc795cd..9826c2fe9c 100644 --- a/activemodel/lib/active_model/validations/acceptance.rb +++ b/activemodel/lib/active_model/validations/acceptance.rb @@ -24,7 +24,7 @@ module ActiveModel class LazilyDefineAttributes < Module def initialize(attribute_definition) - define_method(:respond_to_missing?) do |method_name, include_private=false| + define_method(:respond_to_missing?) do |method_name, include_private = false| super(method_name, include_private) || attribute_definition.matches?(method_name) end diff --git a/activemodel/lib/active_model/validations/length.rb b/activemodel/lib/active_model/validations/length.rb index f73f16830f..de1524829e 100644 --- a/activemodel/lib/active_model/validations/length.rb +++ b/activemodel/lib/active_model/validations/length.rb @@ -6,7 +6,7 @@ module ActiveModel MESSAGES = { is: :wrong_length, minimum: :too_short, maximum: :too_long }.freeze CHECKS = { is: :==, minimum: :>=, maximum: :<= }.freeze - RESERVED_OPTIONS = [:minimum, :maximum, :within, :is, :too_short, :too_long] + RESERVED_OPTIONS = [:minimum, :maximum, :within, :is, :too_short, :too_long] def initialize(options) if range = (options.delete(:in) || options.delete(:within)) diff --git a/activemodel/lib/active_model/validator.rb b/activemodel/lib/active_model/validator.rb index 9c6065f61f..8212744170 100644 --- a/activemodel/lib/active_model/validator.rb +++ b/activemodel/lib/active_model/validator.rb @@ -104,7 +104,7 @@ module ActiveModel # Accepts options that will be made available through the +options+ reader. def initialize(options = {}) - @options = options.except(:class).freeze + @options = options.except(:class).freeze end # Returns the kind for this validator. diff --git a/activemodel/test/cases/serialization_test.rb b/activemodel/test/cases/serialization_test.rb index 5ee53285a3..f78efd2f0c 100644 --- a/activemodel/test/cases/serialization_test.rb +++ b/activemodel/test/cases/serialization_test.rb @@ -51,32 +51,32 @@ class SerializationTest < ActiveModel::TestCase end def test_method_serializable_hash_should_work - expected = { "name"=>"David", "gender"=>"male", "email"=>"david@example.com" } + expected = { "name" => "David", "gender" => "male", "email" => "david@example.com" } assert_equal expected, @user.serializable_hash end def test_method_serializable_hash_should_work_with_only_option - expected = { "name"=>"David" } + expected = { "name" => "David" } assert_equal expected, @user.serializable_hash(only: [:name]) end def test_method_serializable_hash_should_work_with_except_option - expected = { "gender"=>"male", "email"=>"david@example.com" } + expected = { "gender" => "male", "email" => "david@example.com" } assert_equal expected, @user.serializable_hash(except: [:name]) end def test_method_serializable_hash_should_work_with_methods_option - expected = { "name"=>"David", "gender"=>"male", "foo"=>"i_am_foo", "bar"=>"i_am_bar", "email"=>"david@example.com" } + expected = { "name" => "David", "gender" => "male", "foo" => "i_am_foo", "bar" => "i_am_bar", "email" => "david@example.com" } assert_equal expected, @user.serializable_hash(methods: [:foo, :bar]) end def test_method_serializable_hash_should_work_with_only_and_methods - expected = { "foo"=>"i_am_foo", "bar"=>"i_am_bar" } + expected = { "foo" => "i_am_foo", "bar" => "i_am_bar" } assert_equal expected, @user.serializable_hash(only: [], methods: [:foo, :bar]) end def test_method_serializable_hash_should_work_with_except_and_methods - expected = { "gender"=>"male", "foo"=>"i_am_foo", "bar"=>"i_am_bar" } + expected = { "gender" => "male", "foo" => "i_am_foo", "bar" => "i_am_bar" } assert_equal expected, @user.serializable_hash(except: [:name, :email], methods: [:foo, :bar]) end @@ -94,21 +94,21 @@ class SerializationTest < ActiveModel::TestCase end def test_include_option_with_singular_association - expected = { "name"=>"David", "gender"=>"male", "email"=>"david@example.com", - "address"=>{ "street"=>"123 Lane", "city"=>"Springfield", "state"=>"CA", "zip"=>11111 } } + expected = { "name" => "David", "gender" => "male", "email" => "david@example.com", + "address" => { "street" => "123 Lane", "city" => "Springfield", "state" => "CA", "zip" => 11111 } } assert_equal expected, @user.serializable_hash(include: :address) end 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" }] } + 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" }] } assert_equal expected, @user.serializable_hash(include: :friends) end def test_include_option_with_empty_association @user.friends = [] - expected = { "email"=>"david@example.com", "gender"=>"male", "name"=>"David", "friends"=>[] } + expected = { "email" => "david@example.com", "gender" => "male", "name" => "David", "friends" => [] } assert_equal expected, @user.serializable_hash(include: :friends) end @@ -124,52 +124,52 @@ 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" }] } + 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" }] } 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" }] } + 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" }] } assert_equal expected, @user.serializable_hash(include: [:address, :friends]) end def test_include_with_options - expected = { "email"=>"david@example.com", "gender"=>"male", "name"=>"David", - "address"=>{ "street"=>"123 Lane" } } + expected = { "email" => "david@example.com", "gender" => "male", "name" => "David", + "address" => { "street" => "123 Lane" } } assert_equal expected, @user.serializable_hash(include: { address: { only: "street" } }) end 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"=> [{ "email"=>"david@example.com", "gender"=>"male", "name"=>"David" }] }, - { "name"=>"Sue", "email"=>"sue@example.com", "gender"=>"female", "friends"=> [] }] } + expected = { "email" => "david@example.com", "gender" => "male", "name" => "David", + "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" => [] }] } assert_equal expected, @user.serializable_hash(include: { friends: { include: :friends } }) end def test_only_include - expected = { "name"=>"David", "friends" => [{ "name" => "Joe" }, { "name" => "Sue" }] } + expected = { "name" => "David", "friends" => [{ "name" => "Joe" }, { "name" => "Sue" }] } assert_equal expected, @user.serializable_hash(only: :name, include: { friends: { only: :name } }) end def test_except_include - expected = { "name"=>"David", "email"=>"david@example.com", - "friends"=> [{ "name" => "Joe", "email" => "joe@example.com" }, + expected = { "name" => "David", "email" => "david@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" }] } + 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" }] } assert_equal expected, @user.serializable_hash(include: [{ address: { only: "street" } }, :friends]) end end diff --git a/activemodel/test/cases/type/integer_test.rb b/activemodel/test/cases/type/integer_test.rb index d81ce189e6..2b9b03f3cf 100644 --- a/activemodel/test/cases/type/integer_test.rb +++ b/activemodel/test/cases/type/integer_test.rb @@ -20,7 +20,7 @@ module ActiveModel test "random objects cast to nil" do type = Type::Integer.new - assert_nil type.cast([1,2]) + assert_nil type.cast([1, 2]) assert_nil type.cast(1 => 2) assert_nil type.cast(1..2) end @@ -33,7 +33,7 @@ module ActiveModel test "casting nan and infinity" do type = Type::Integer.new assert_nil type.cast(::Float::NAN) - assert_nil type.cast(1.0/0.0) + assert_nil type.cast(1.0 / 0.0) end test "casting booleans for database" do diff --git a/activemodel/test/cases/validations/absence_validation_test.rb b/activemodel/test/cases/validations/absence_validation_test.rb index 3e48e591e9..833f694c5a 100644 --- a/activemodel/test/cases/validations/absence_validation_test.rb +++ b/activemodel/test/cases/validations/absence_validation_test.rb @@ -19,7 +19,7 @@ class AbsenceValidationTest < ActiveModel::TestCase assert_equal ["must be blank"], t.errors[:title] assert_equal ["must be blank"], t.errors[:content] t.title = "" - t.content = "something" + t.content = "something" assert t.invalid? assert_equal ["must be blank"], t.errors[:content] assert_equal [], t.errors[:title] diff --git a/activemodel/test/cases/validations/acceptance_validation_test.rb b/activemodel/test/cases/validations/acceptance_validation_test.rb index 55ab213498..fbd994e914 100644 --- a/activemodel/test/cases/validations/acceptance_validation_test.rb +++ b/activemodel/test/cases/validations/acceptance_validation_test.rb @@ -19,7 +19,7 @@ class AcceptanceValidationTest < ActiveModel::TestCase def test_terms_of_service_agreement Topic.validates_acceptance_of(:terms_of_service) - t = Topic.new("title" => "We should be confirmed","terms_of_service" => "") + t = Topic.new("title" => "We should be confirmed", "terms_of_service" => "") assert t.invalid? assert_equal ["must be accepted"], t.errors[:terms_of_service] @@ -30,7 +30,7 @@ class AcceptanceValidationTest < ActiveModel::TestCase def test_eula Topic.validates_acceptance_of(:eula, message: "must be abided") - t = Topic.new("title" => "We should be confirmed","eula" => "") + t = Topic.new("title" => "We should be confirmed", "eula" => "") assert t.invalid? assert_equal ["must be abided"], t.errors[:eula] diff --git a/activemodel/test/cases/validations/conditional_validation_test.rb b/activemodel/test/cases/validations/conditional_validation_test.rb index 5e81083b63..4881008017 100644 --- a/activemodel/test/cases/validations/conditional_validation_test.rb +++ b/activemodel/test/cases/validations/conditional_validation_test.rb @@ -106,7 +106,7 @@ class ConditionalValidationTest < ActiveModel::TestCase def test_unless_validation_using_block_false # When the block returns false Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}", - unless: Proc.new { |r| r.title != "uhohuhoh" } ) + unless: Proc.new { |r| r.title != "uhohuhoh" }) t = Topic.new("title" => "uhohuhoh", "content" => "whatever") assert t.invalid? assert t.errors[:title].any? diff --git a/activemodel/test/cases/validations/confirmation_validation_test.rb b/activemodel/test/cases/validations/confirmation_validation_test.rb index b88e1c4ca4..7ddf3ad273 100644 --- a/activemodel/test/cases/validations/confirmation_validation_test.rb +++ b/activemodel/test/cases/validations/confirmation_validation_test.rb @@ -28,7 +28,7 @@ class ConfirmationValidationTest < ActiveModel::TestCase def test_title_confirmation Topic.validates_confirmation_of(:title) - t = Topic.new("title" => "We should be confirmed","title_confirmation" => "") + t = Topic.new("title" => "We should be confirmed", "title_confirmation" => "") assert t.invalid? t.title_confirmation = "We should be confirmed" @@ -61,7 +61,7 @@ class ConfirmationValidationTest < ActiveModel::TestCase Topic.validates_confirmation_of(:title) - t = Topic.new("title" => "We should be confirmed","title_confirmation" => "") + t = Topic.new("title" => "We should be confirmed", "title_confirmation" => "") assert t.invalid? assert_equal ["doesn't match Test Title"], t.errors[:title_confirmation] ensure diff --git a/activemodel/test/cases/validations/length_validation_test.rb b/activemodel/test/cases/validations/length_validation_test.rb index 62d9eaa346..95ee87b401 100644 --- a/activemodel/test/cases/validations/length_validation_test.rb +++ b/activemodel/test/cases/validations/length_validation_test.rb @@ -9,7 +9,7 @@ class LengthValidationTest < ActiveModel::TestCase end def test_validates_length_of_with_allow_nil - Topic.validates_length_of( :title, is: 5, allow_nil: true ) + Topic.validates_length_of(:title, is: 5, allow_nil: true) assert Topic.new("title" => "ab").invalid? assert Topic.new("title" => "").invalid? @@ -18,7 +18,7 @@ class LengthValidationTest < ActiveModel::TestCase end def test_validates_length_of_with_allow_blank - Topic.validates_length_of( :title, is: 5, allow_blank: true ) + Topic.validates_length_of(:title, is: 5, allow_blank: true) assert Topic.new("title" => "ab").invalid? assert Topic.new("title" => "").valid? @@ -104,7 +104,7 @@ class LengthValidationTest < ActiveModel::TestCase assert_equal ["is too short (minimum is 3 characters)"], t.errors[:content] t.title = "abe" - t.content = "mad" + t.content = "mad" assert t.valid? end @@ -161,8 +161,8 @@ class LengthValidationTest < ActiveModel::TestCase end def test_validates_length_of_using_bignum - bigmin = 2 ** 30 - bigmax = 2 ** 32 + bigmin = 2**30 + bigmax = 2**32 bigrange = bigmin...bigmax assert_nothing_raised do Topic.validates_length_of :title, is: bigmin + 5 @@ -183,7 +183,7 @@ class LengthValidationTest < ActiveModel::TestCase end def test_validates_length_of_custom_errors_for_minimum_with_message - Topic.validates_length_of( :title, minimum: 5, message: "boo %{count}" ) + Topic.validates_length_of(:title, minimum: 5, message: "boo %{count}") t = Topic.new("title" => "uhoh", "content" => "whatever") assert t.invalid? assert t.errors[:title].any? @@ -191,7 +191,7 @@ class LengthValidationTest < ActiveModel::TestCase end def test_validates_length_of_custom_errors_for_minimum_with_too_short - Topic.validates_length_of( :title, minimum: 5, too_short: "hoo %{count}" ) + Topic.validates_length_of(:title, minimum: 5, too_short: "hoo %{count}") t = Topic.new("title" => "uhoh", "content" => "whatever") assert t.invalid? assert t.errors[:title].any? @@ -199,7 +199,7 @@ class LengthValidationTest < ActiveModel::TestCase end def test_validates_length_of_custom_errors_for_maximum_with_message - Topic.validates_length_of( :title, maximum: 5, message: "boo %{count}" ) + Topic.validates_length_of(:title, maximum: 5, message: "boo %{count}") t = Topic.new("title" => "uhohuhoh", "content" => "whatever") assert t.invalid? assert t.errors[:title].any? @@ -220,7 +220,7 @@ class LengthValidationTest < ActiveModel::TestCase end def test_validates_length_of_custom_errors_for_maximum_with_too_long - Topic.validates_length_of( :title, maximum: 5, too_long: "hoo %{count}" ) + Topic.validates_length_of(:title, maximum: 5, too_long: "hoo %{count}") t = Topic.new("title" => "uhohuhoh", "content" => "whatever") assert t.invalid? assert t.errors[:title].any? @@ -242,7 +242,7 @@ class LengthValidationTest < ActiveModel::TestCase end def test_validates_length_of_custom_errors_for_is_with_message - Topic.validates_length_of( :title, is: 5, message: "boo %{count}" ) + Topic.validates_length_of(:title, is: 5, message: "boo %{count}") t = Topic.new("title" => "uhohuhoh", "content" => "whatever") assert t.invalid? assert t.errors[:title].any? @@ -250,7 +250,7 @@ class LengthValidationTest < ActiveModel::TestCase end def test_validates_length_of_custom_errors_for_is_with_wrong_length - Topic.validates_length_of( :title, is: 5, wrong_length: "hoo %{count}" ) + Topic.validates_length_of(:title, is: 5, wrong_length: "hoo %{count}") t = Topic.new("title" => "uhohuhoh", "content" => "whatever") assert t.invalid? assert t.errors[:title].any? @@ -289,7 +289,7 @@ class LengthValidationTest < ActiveModel::TestCase assert_equal ["is too short (minimum is 3 characters)"], t.errors[:title] assert_equal ["is too long (maximum is 5 characters)"], t.errors[:content] t.title = "一二三" - t.content = "12三" + t.content = "12三" assert t.valid? end @@ -403,7 +403,7 @@ class LengthValidationTest < ActiveModel::TestCase def test_validates_with_diff_in_option Topic.validates_length_of(:title, is: 5) - Topic.validates_length_of(:title, is: 5, if: Proc.new { false } ) + Topic.validates_length_of(:title, is: 5, if: Proc.new { false }) assert Topic.new("title" => "david").valid? assert Topic.new("title" => "david2").invalid? diff --git a/activemodel/test/cases/validations/numericality_validation_test.rb b/activemodel/test/cases/validations/numericality_validation_test.rb index fefab29f15..36efa6caf5 100644 --- a/activemodel/test/cases/validations/numericality_validation_test.rb +++ b/activemodel/test/cases/validations/numericality_validation_test.rb @@ -20,7 +20,7 @@ class NumericalityValidationTest < ActiveModel::TestCase INTEGERS = [0, 10, -10] + INTEGER_STRINGS BIGDECIMAL = BIGDECIMAL_STRINGS.collect! { |bd| BigDecimal.new(bd) } JUNK = ["not a number", "42 not a number", "0xdeadbeef", "0xinvalidhex", "0Xdeadbeef", "00-1", "--3", "+-3", "+3-1", "-+019.0", "12.12.13.12", "123\nnot a number"] - INFINITY = [1.0/0.0] + INFINITY = [1.0 / 0.0] def test_default_validates_numericality_of Topic.validates_numericality_of :approved diff --git a/activemodel/test/cases/validations/presence_validation_test.rb b/activemodel/test/cases/validations/presence_validation_test.rb index feda817698..642dd0f144 100644 --- a/activemodel/test/cases/validations/presence_validation_test.rb +++ b/activemodel/test/cases/validations/presence_validation_test.rb @@ -20,7 +20,7 @@ class PresenceValidationTest < ActiveModel::TestCase assert_equal ["can't be blank"], t.errors[:content] t.title = "something" - t.content = " " + t.content = " " assert t.invalid? assert_equal ["can't be blank"], t.errors[:content] |