activemodel 6.0.0.beta1 → 6.0.0.beta2

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: 69b55e1af8331655f54dbced151a75b1ccbd7e48757fc4a3fd1ee2e5f2236d5a
4
- data.tar.gz: e756ba5fc97ccd6ee212f32568e58e372b6e94d79082c81711b8e39ac6d86a3a
3
+ metadata.gz: cbb3fa68163e411fcb037eada5a704a71587d3926088d115dcc5bf2db1b95c30
4
+ data.tar.gz: 71bc2a8ae24f2d44e88ae0a4a9a02631dd01148c0b698fca2cd971db9465c0bb
5
5
  SHA512:
6
- metadata.gz: 394b1945a1c68549337a884d68985f0e15c2cbef0e0f968ee50ab55076327e6d55558d9d884d580b7359ea87f460c9a31211090f621f919b3967aa2e9b93188d
7
- data.tar.gz: 0e1e72d58afc1f7b3f572276c9efa4b21586fa4741d8e31ab2c3bf7bb19e98888f571731d4b5dc04c0ae5f76e5e6c8ee4cf481458eef8e1669c03445277317ec
6
+ metadata.gz: 1eda3fdc7cbc1f14d26cb6615a00cc597622c006619ef988430218ec97081880dde6067e1d1e672f36812d19a39b23475841d0ff6fece86454e836abdff7b892
7
+ data.tar.gz: 9ef29b02bfc1454aa06d99a29db09bdcd5f3cc08e44637fe94b881f738b701b3766613536e28371899edab2485dd63ecc6bc477a52b4c7ad2e25e31ad9c2e286
@@ -1,3 +1,50 @@
1
+ ## Rails 6.0.0.beta2 (February 25, 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 year value when casting a multiparameter time hash.
21
+
22
+ When assigning a hash to a time attribute that's missing a year component
23
+ (e.g. a `time_select` with `:ignore_date` set to `true`) then the year
24
+ defaults to 1970 instead of the expected 2000. This results in the attribute
25
+ changing as a result of the save.
26
+
27
+ Before:
28
+ ```
29
+ event = Event.new(start_time: { 4 => 20, 5 => 30 })
30
+ event.start_time # => 1970-01-01 20:30:00 UTC
31
+ event.save
32
+ event.reload
33
+ event.start_time # => 2000-01-01 20:30:00 UTC
34
+ ```
35
+
36
+ After:
37
+ ```
38
+ event = Event.new(start_time: { 4 => 20, 5 => 30 })
39
+ event.start_time # => 2000-01-01 20:30:00 UTC
40
+ event.save
41
+ event.reload
42
+ event.start_time # => 2000-01-01 20:30:00 UTC
43
+ ```
44
+
45
+ *Andrew White*
46
+
47
+
1
48
  ## Rails 6.0.0.beta1 (January 18, 2019) ##
2
49
 
3
50
  * Add `ActiveModel::Errors#of_kind?`.
@@ -10,7 +10,7 @@ module ActiveModel
10
10
  MAJOR = 6
11
11
  MINOR = 0
12
12
  TINY = 0
13
- PRE = "beta1"
13
+ PRE = "beta2"
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
16
16
  end
@@ -3,16 +3,13 @@
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
9
10
  :date
10
11
  end
11
12
 
12
- def serialize(value)
13
- cast(value)
14
- end
15
-
16
13
  def type_cast_for_schema(value)
17
14
  value.to_s(:db).inspect
18
15
  end
@@ -49,7 +46,7 @@ module ActiveModel
49
46
 
50
47
  def value_from_multiparameter_assignment(*)
51
48
  time = super
52
- time && time.to_date
49
+ time && new_date(time.year, time.mon, time.mday)
53
50
  end
54
51
  end
55
52
  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 }
@@ -12,10 +13,6 @@ module ActiveModel
12
13
  :datetime
13
14
  end
14
15
 
15
- def serialize(value)
16
- super(cast(value))
17
- end
18
-
19
16
  private
20
17
 
21
18
  def cast_value(value)
@@ -12,10 +12,6 @@ module ActiveModel
12
12
  :decimal
13
13
  end
14
14
 
15
- def serialize(value)
16
- cast(value)
17
- end
18
-
19
15
  def type_cast_for_schema(value)
20
16
  value.to_s.inspect
21
17
  end
@@ -18,8 +18,6 @@ module ActiveModel
18
18
  end
19
19
  end
20
20
 
21
- alias serialize cast
22
-
23
21
  private
24
22
 
25
23
  def cast_value(value)
@@ -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"
@@ -5,6 +5,10 @@ module ActiveModel
5
5
  module Helpers # :nodoc: all
6
6
  class AcceptsMultiparameterTime < Module
7
7
  def initialize(defaults: {})
8
+ define_method(:serialize) do |value|
9
+ super(cast(value))
10
+ end
11
+
8
12
  define_method(:cast) do |value|
9
13
  if value.is_a?(Hash)
10
14
  value_from_multiparameter_assignment(value)
@@ -4,6 +4,10 @@ module ActiveModel
4
4
  module Type
5
5
  module Helpers # :nodoc: all
6
6
  module Numeric
7
+ def serialize(value)
8
+ cast(value)
9
+ end
10
+
7
11
  def cast(value)
8
12
  value = \
9
13
  case value
@@ -22,15 +26,18 @@ module ActiveModel
22
26
  private
23
27
 
24
28
  def number_to_non_number?(old_value, new_value_before_type_cast)
25
- old_value != nil && non_numeric_string?(new_value_before_type_cast)
29
+ old_value != nil && non_numeric_string?(new_value_before_type_cast.to_s)
26
30
  end
27
31
 
28
32
  def non_numeric_string?(value)
29
33
  # 'wibble'.to_i will give zero, we want to make sure
30
34
  # that we aren't marking int zero to string zero as
31
35
  # changed.
32
- !/\A[-+]?\d+/.match?(value.to_s)
36
+ !NUMERIC_REGEX.match?(value)
33
37
  end
38
+
39
+ NUMERIC_REGEX = /\A\s*[+-]?\d/
40
+ private_constant :NUMERIC_REGEX
34
41
  end
35
42
  end
36
43
  end
@@ -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
@@ -18,35 +18,23 @@ module ActiveModel
18
18
  :integer
19
19
  end
20
20
 
21
- def deserialize(value)
22
- return if value.nil?
23
- value.to_i
24
- end
25
-
26
21
  def serialize(value)
27
- result = cast(value)
28
- if result
29
- ensure_in_range(result)
30
- end
31
- result
22
+ return if value.is_a?(::String) && non_numeric_string?(value)
23
+ ensure_in_range(super)
32
24
  end
33
25
 
34
26
  private
35
27
  attr_reader :range
36
28
 
37
29
  def cast_value(value)
38
- case value
39
- when true then 1
40
- when false then 0
41
- else
42
- value.to_i rescue nil
43
- end
30
+ value.to_i rescue nil
44
31
  end
45
32
 
46
33
  def ensure_in_range(value)
47
- unless range.cover?(value)
34
+ if value && !range.cover?(value)
48
35
  raise ActiveModel::RangeError, "#{value} is out of range for #{self.class} with limit #{_limit} bytes"
49
36
  end
37
+ value
50
38
  end
51
39
 
52
40
  def max_value
@@ -3,9 +3,10 @@
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
- defaults: { 1 => 1970, 2 => 1, 3 => 1, 4 => 0, 5 => 0 }
9
+ defaults: { 1 => 2000, 2 => 1, 3 => 1, 4 => 0, 5 => 0 }
9
10
  )
10
11
 
11
12
  def type
@@ -32,7 +32,7 @@ module ActiveModel
32
32
  value = options[key]
33
33
 
34
34
  unless (value.is_a?(Integer) && value >= 0) || value == Float::INFINITY || value.is_a?(Symbol) || value.is_a?(Proc)
35
- raise ArgumentError, ":#{key} must be a nonnegative Integer, Infinity, Symbol, or Proc"
35
+ raise ArgumentError, ":#{key} must be a non-negative Integer, Infinity, Symbol, or Proc"
36
36
  end
37
37
  end
38
38
  end
@@ -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:
@@ -10,7 +12,6 @@ module ActiveModel
10
12
  RESERVED_OPTIONS = CHECKS.keys + [:only_integer]
11
13
 
12
14
  INTEGER_REGEX = /\A[+-]?\d+\z/
13
- DECIMAL_REGEX = /\A[+-]?\d+\.?\d*(e|e[+-])?\d+\z/
14
15
 
15
16
  def check_validity!
16
17
  keys = CHECKS.keys - [:odd, :even]
@@ -92,8 +93,8 @@ module ActiveModel
92
93
  raw_value
93
94
  elsif is_integer?(raw_value)
94
95
  raw_value.to_i
95
- elsif is_decimal?(raw_value) && !is_hexadecimal_literal?(raw_value)
96
- BigDecimal(raw_value)
96
+ elsif !is_hexadecimal_literal?(raw_value)
97
+ Kernel.Float(raw_value).to_d
97
98
  end
98
99
  end
99
100
 
@@ -101,12 +102,8 @@ module ActiveModel
101
102
  INTEGER_REGEX.match?(raw_value.to_s)
102
103
  end
103
104
 
104
- def is_decimal?(raw_value)
105
- DECIMAL_REGEX.match?(raw_value.to_s)
106
- end
107
-
108
105
  def is_hexadecimal_literal?(raw_value)
109
- /\A0[xX]/.match?(raw_value)
106
+ /\A0[xX]/.match?(raw_value.to_s)
110
107
  end
111
108
 
112
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: 6.0.0.beta1
4
+ version: 6.0.0.beta2
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-01-18 00:00:00.000000000 Z
11
+ date: 2019-02-25 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: 6.0.0.beta1
19
+ version: 6.0.0.beta2
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: 6.0.0.beta1
26
+ version: 6.0.0.beta2
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/v6.0.0.beta1/activemodel
104
- changelog_uri: https://github.com/rails/rails/blob/v6.0.0.beta1/activemodel/CHANGELOG.md
104
+ source_code_uri: https://github.com/rails/rails/tree/v6.0.0.beta2/activemodel
105
+ changelog_uri: https://github.com/rails/rails/blob/v6.0.0.beta2/activemodel/CHANGELOG.md
105
106
  post_install_message:
106
107
  rdoc_options: []
107
108
  require_paths: