activemodel 5.2.2.1 → 5.2.3.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50e1a001409e179ef71bb44a8738a7135472425f371d24ba43007ce3aa7b38fb
4
- data.tar.gz: 79f2b79394edbfee813a93680aa39d4a4b1c3d317e3e919bf51688a8c53f86ed
3
+ metadata.gz: 57fe827ff814dde112447074f27149b1b723e25ee1161210adcd46906b384222
4
+ data.tar.gz: 362da50ed52cdba8bfeb824673b37b0466cb92bb3ffafa70e6ede1daf27f8a47
5
5
  SHA512:
6
- metadata.gz: 2ee66856a97f62a65e477a8c2994f03f5597dfed6640df689538705c574cf8d25490b362a28b23978647242ac01556a6a0e892b8fdd3927e45db3e5f4ef5b069
7
- data.tar.gz: 9a3a881760b780af3d74ef50e896a941ff9ed9b724b4ce4bb2a260d51a71e68d09644c333302b79806ca52fad68899337f91e859dd003a7fc31aae7ce931615d
6
+ metadata.gz: ed20115eaf44cc76db921bdd8339c96525751ab6285879a773d1aa0db7c9226e5b89c0b626d35bf50a41a51c23c2d9128270c2a908e845d521fae9634e612953
7
+ data.tar.gz: a4aa37d04da1aa165e945a587998dededb9197f96a57c7af5d289ebe45d873703a161d8595d91271bd997aa6433ef5ff05c9ba11f5b0feb2cac85a6751980db7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,28 @@
1
+ ## Rails 5.2.3.rc1 (March 21, 2019) ##
2
+
3
+ * Fix date value when casting a multiparameter date hash to not convert
4
+ from Gregorian date to Julian date.
5
+
6
+ Before:
7
+
8
+ Day.new({"day(1i)"=>"1", "day(2i)"=>"1", "day(3i)"=>"1"})
9
+ => #<Day id: nil, day: "0001-01-03", created_at: nil, updated_at: nil>
10
+
11
+ After:
12
+
13
+ Day.new({"day(1i)"=>"1", "day(2i)"=>"1", "day(3i)"=>"1"})
14
+ => #<Day id: nil, day: "0001-01-01", created_at: nil, updated_at: nil>
15
+
16
+ Fixes #28521.
17
+
18
+ *Sayan Chakraborty*
19
+
20
+ * Fix numericality equality validation of `BigDecimal` and `Float`
21
+ by casting to `BigDecimal` on both ends of the validation.
22
+
23
+ *Gannon McGibbon*
24
+
25
+
1
26
  ## Rails 5.2.2.1 (March 11, 2019) ##
2
27
 
3
28
  * No changes.
@@ -9,8 +9,8 @@ module ActiveModel
9
9
  module VERSION
10
10
  MAJOR = 5
11
11
  MINOR = 2
12
- TINY = 2
13
- PRE = "1"
12
+ TINY = 3
13
+ PRE = "rc1"
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
16
16
  end
@@ -3,6 +3,7 @@
3
3
  module ActiveModel
4
4
  module Type
5
5
  class Date < Value # :nodoc:
6
+ include Helpers::Timezone
6
7
  include Helpers::AcceptsMultiparameterTime.new
7
8
 
8
9
  def type
@@ -49,7 +50,7 @@ module ActiveModel
49
50
 
50
51
  def value_from_multiparameter_assignment(*)
51
52
  time = super
52
- time && time.to_date
53
+ time && new_date(time.year, time.mon, time.mday)
53
54
  end
54
55
  end
55
56
  end
@@ -3,6 +3,7 @@
3
3
  module ActiveModel
4
4
  module Type
5
5
  class DateTime < Value # :nodoc:
6
+ include Helpers::Timezone
6
7
  include Helpers::TimeValue
7
8
  include Helpers::AcceptsMultiparameterTime.new(
8
9
  defaults: { 4 => 0, 5 => 0 }
@@ -4,3 +4,4 @@ require "active_model/type/helpers/accepts_multiparameter_time"
4
4
  require "active_model/type/helpers/numeric"
5
5
  require "active_model/type/helpers/mutable"
6
6
  require "active_model/type/helpers/time_value"
7
+ require "active_model/type/helpers/timezone"
@@ -21,18 +21,6 @@ module ActiveModel
21
21
  value
22
22
  end
23
23
 
24
- def is_utc?
25
- ::Time.zone_default.nil? || ::Time.zone_default =~ "UTC"
26
- end
27
-
28
- def default_timezone
29
- if is_utc?
30
- :utc
31
- else
32
- :local
33
- end
34
- end
35
-
36
24
  def apply_seconds_precision(value)
37
25
  return value unless precision && value.respond_to?(:usec)
38
26
  number_of_insignificant_digits = 6 - precision
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/time/zones"
4
+
5
+ module ActiveModel
6
+ module Type
7
+ module Helpers # :nodoc: all
8
+ module Timezone
9
+ def is_utc?
10
+ ::Time.zone_default.nil? || ::Time.zone_default =~ "UTC"
11
+ end
12
+
13
+ def default_timezone
14
+ is_utc? ? :utc : :local
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -3,6 +3,7 @@
3
3
  module ActiveModel
4
4
  module Type
5
5
  class Time < Value # :nodoc:
6
+ include Helpers::Timezone
6
7
  include Helpers::TimeValue
7
8
  include Helpers::AcceptsMultiparameterTime.new(
8
9
  defaults: { 1 => 1970, 2 => 1, 3 => 1, 4 => 0, 5 => 0 }
@@ -12,6 +13,10 @@ module ActiveModel
12
13
  :time
13
14
  end
14
15
 
16
+ def serialize(value)
17
+ super(cast(value))
18
+ end
19
+
15
20
  def user_input_in_time_zone(value)
16
21
  return unless value.present?
17
22
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "bigdecimal/util"
4
+
3
5
  module ActiveModel
4
6
  module Validations
5
7
  class NumericalityValidator < EachValidator # :nodoc:
@@ -9,6 +11,8 @@ module ActiveModel
9
11
 
10
12
  RESERVED_OPTIONS = CHECKS.keys + [:only_integer]
11
13
 
14
+ INTEGER_REGEX = /\A[+-]?\d+\z/
15
+
12
16
  def check_validity!
13
17
  keys = CHECKS.keys - [:odd, :even]
14
18
  options.slice(*keys).each do |option, value|
@@ -49,11 +53,7 @@ module ActiveModel
49
53
  return
50
54
  end
51
55
 
52
- if raw_value.is_a?(Numeric)
53
- value = raw_value
54
- else
55
- value = parse_raw_value_as_a_number(raw_value)
56
- end
56
+ value = parse_as_number(raw_value)
57
57
 
58
58
  options.slice(*CHECKS.keys).each do |option, option_value|
59
59
  case option
@@ -69,6 +69,8 @@ module ActiveModel
69
69
  option_value = record.send(option_value)
70
70
  end
71
71
 
72
+ option_value = parse_as_number(option_value)
73
+
72
74
  unless value.send(CHECKS[option], option_value)
73
75
  record.errors.add(attr_name, option, filtered_options(value).merge!(count: option_value))
74
76
  end
@@ -79,22 +81,29 @@ module ActiveModel
79
81
  private
80
82
 
81
83
  def is_number?(raw_value)
82
- !parse_raw_value_as_a_number(raw_value).nil?
84
+ !parse_as_number(raw_value).nil?
83
85
  rescue ArgumentError, TypeError
84
86
  false
85
87
  end
86
88
 
87
- def parse_raw_value_as_a_number(raw_value)
88
- return raw_value.to_i if is_integer?(raw_value)
89
- Kernel.Float(raw_value) unless is_hexadecimal_literal?(raw_value)
89
+ def parse_as_number(raw_value)
90
+ if raw_value.is_a?(Float)
91
+ raw_value.to_d
92
+ elsif raw_value.is_a?(Numeric)
93
+ raw_value
94
+ elsif is_integer?(raw_value)
95
+ raw_value.to_i
96
+ elsif !is_hexadecimal_literal?(raw_value)
97
+ Kernel.Float(raw_value).to_d
98
+ end
90
99
  end
91
100
 
92
101
  def is_integer?(raw_value)
93
- /\A[+-]?\d+\z/ === raw_value.to_s
102
+ INTEGER_REGEX === raw_value.to_s
94
103
  end
95
104
 
96
105
  def is_hexadecimal_literal?(raw_value)
97
- /\A0[xX]/ === raw_value
106
+ /\A0[xX]/ === raw_value.to_s
98
107
  end
99
108
 
100
109
  def filtered_options(value)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activemodel
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.2.1
4
+ version: 5.2.3.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-13 00:00:00.000000000 Z
11
+ date: 2019-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 5.2.2.1
19
+ version: 5.2.3.rc1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 5.2.2.1
26
+ version: 5.2.3.rc1
27
27
  description: A toolkit for building modeling frameworks like Active Record. Rich support
28
28
  for attributes, callbacks, validations, serialization, internationalization, and
29
29
  testing.
@@ -73,6 +73,7 @@ files:
73
73
  - lib/active_model/type/helpers/mutable.rb
74
74
  - lib/active_model/type/helpers/numeric.rb
75
75
  - lib/active_model/type/helpers/time_value.rb
76
+ - lib/active_model/type/helpers/timezone.rb
76
77
  - lib/active_model/type/immutable_string.rb
77
78
  - lib/active_model/type/integer.rb
78
79
  - lib/active_model/type/registry.rb
@@ -100,8 +101,8 @@ homepage: http://rubyonrails.org
100
101
  licenses:
101
102
  - MIT
102
103
  metadata:
103
- source_code_uri: https://github.com/rails/rails/tree/v5.2.2.1/activemodel
104
- changelog_uri: https://github.com/rails/rails/blob/v5.2.2.1/activemodel/CHANGELOG.md
104
+ source_code_uri: https://github.com/rails/rails/tree/v5.2.3.rc1/activemodel
105
+ changelog_uri: https://github.com/rails/rails/blob/v5.2.3.rc1/activemodel/CHANGELOG.md
105
106
  post_install_message:
106
107
  rdoc_options: []
107
108
  require_paths:
@@ -113,9 +114,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
114
  version: 2.2.2
114
115
  required_rubygems_version: !ruby/object:Gem::Requirement
115
116
  requirements:
116
- - - ">="
117
+ - - ">"
117
118
  - !ruby/object:Gem::Version
118
- version: '0'
119
+ version: 1.3.1
119
120
  requirements: []
120
121
  rubygems_version: 3.0.1
121
122
  signing_key: